Compare commits
25 Commits
main-gitea
...
main-gitea
Author | SHA1 | Date |
---|---|---|
|
438feb1290 | |
|
89bfff7b1d | |
|
09f55f4656 | |
|
b4480d5a72 | |
|
df81339d0d | |
|
dcbbbe3a48 | |
|
e21b18f420 | |
|
e6f955449b | |
|
04f26dba03 | |
|
41022131d0 | |
|
0ed5a7a7f5 | |
|
a8847eb76d | |
|
b3b2ca0627 | |
|
965a30ea8c | |
|
e10905a400 | |
|
bef9333795 | |
|
4ba90ebe56 | |
|
9559bd3f50 | |
|
1ace43429a | |
|
38b4f63652 | |
|
34f5859c41 | |
|
19db37d2cf | |
|
747c9cf771 | |
|
f33791fad3 | |
|
a84a4ca90b |
|
@ -0,0 +1,3 @@
|
|||
@echo off
|
||||
cd E:/Kerja/JMBDEV/Grand-Apps/Stk/stk-web
|
||||
E:/laragon/bin/php/php-8.1.10-Win32-vs16-x64/php.exe artisan queue:work
|
|
@ -31,9 +31,9 @@ class CreateRoutePermissionCommand extends Command
|
|||
$routes = Route::getRoutes()->getRoutesByName();
|
||||
// dd($routes);
|
||||
foreach ($routes as $route) {
|
||||
try {
|
||||
if ($route->getName() != '' && count($route->getAction()['middleware']) >= 2) {
|
||||
$permission = Permission::where('name', $route->getName())->first();
|
||||
|
||||
$data = $route->getName();
|
||||
[$first_group] = explode('.', $data);
|
||||
$comment = $route->getComment();
|
||||
|
@ -44,6 +44,11 @@ class CreateRoutePermissionCommand extends Command
|
|||
permission::create(['name' => $data, 'group_name' => $first_group, 'desc' => $comment]);
|
||||
$this->info('Permission routes ' . $route->getName() . ' added successfully.');
|
||||
}
|
||||
} else {
|
||||
$this->info('Permission routes ' . $route->getName() . ' not added.');
|
||||
}
|
||||
} catch (\Throwable $th) {
|
||||
$this->info('Permission routes ' . $route->getName() . ' not added.');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,149 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admins;
|
||||
|
||||
use App\Helpers\ResponseFormatter;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\MasterDistributor;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
class MasterDistributorController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return view('pages.admin.master_distributor.index');
|
||||
}
|
||||
|
||||
|
||||
public function getDataDistributor()
|
||||
{
|
||||
$data = MasterDistributor::get();
|
||||
|
||||
return datatables()->of($data)
|
||||
->addColumn('action', function ($data) {
|
||||
return '
|
||||
<button class="btn btn-sm btn-warning btn-edit-distributor" data-distributor=' . $data . ' data-idDistributor=' . $data->id . '><i class="fas fa-edit"></i></button>
|
||||
<button class="btn btn-sm btn-danger btn-hapus-distributor" data-distributor=' . $data . ' data-idDistributor=' . $data->id . '><i class="fas fa-trash"></i></button>
|
||||
';
|
||||
})
|
||||
->rawColumns(['action' => 'action'])
|
||||
->addIndexColumn()
|
||||
->make(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
// validation
|
||||
$validator = Validator::make($request->all(), [
|
||||
'nama_distributor' => 'required',
|
||||
], [
|
||||
'nama_distributor.required' => 'Nama Distributor tidak boleh kosong!',
|
||||
]);
|
||||
|
||||
// check validation
|
||||
if ($validator->fails()) {
|
||||
return ResponseFormatter::error($validator->errors()->first());
|
||||
}
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
// create new data
|
||||
$distributor = MasterDistributor::create([
|
||||
'nama_distributor' => $request->nama_distributor,
|
||||
'alamat' => $request->alamat,
|
||||
'telepon' => $request->telepon,
|
||||
]);
|
||||
|
||||
DB::commit();
|
||||
return ResponseFormatter::success($distributor, "Distributor berhasil ditambahkan");
|
||||
} catch (\Throwable $th) {
|
||||
DB::rollBack();
|
||||
return ResponseFormatter::error($th->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit(string $id)
|
||||
{
|
||||
// get data from distributor
|
||||
$distributor = MasterDistributor::findOrFail($id);
|
||||
return ResponseFormatter::success([
|
||||
'distributor' => $distributor
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, string $id)
|
||||
{
|
||||
|
||||
// validation
|
||||
$validator = Validator::make($request->all(), [
|
||||
'nama_distributor_edit' => 'required',
|
||||
], [
|
||||
'nama_distributor_edit.required' => 'Nama Distributor tidak boleh kosong!',
|
||||
]);
|
||||
|
||||
// check validation
|
||||
if ($validator->fails()) {
|
||||
return ResponseFormatter::error($validator->errors()->first());
|
||||
}
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
// create new data
|
||||
$distributor = MasterDistributor::findOrFail($id);
|
||||
$distributor->update([
|
||||
'nama_distributor' => $request->nama_distributor_edit,
|
||||
'alamat' => $request->alamat_edit,
|
||||
'telepon' => $request->telepon_edit
|
||||
]);
|
||||
|
||||
DB::commit();
|
||||
return ResponseFormatter::success($distributor, "Distributor berhasil diubah");
|
||||
} catch (\Throwable $th) {
|
||||
DB::rollBack();
|
||||
return ResponseFormatter::error($th->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(string $id)
|
||||
{
|
||||
// get data from distributor
|
||||
$distributor = MasterDistributor::findOrFail($id);
|
||||
|
||||
// check distributor
|
||||
if (!$distributor) {
|
||||
return ResponseFormatter::error("Data distributor tidak ditemukan!");
|
||||
}
|
||||
|
||||
// delete distributor
|
||||
$distributor->deleted_by = Auth::user()->id;
|
||||
$distributor->save();
|
||||
$distributor->delete();
|
||||
|
||||
return ResponseFormatter::success(null, "Distributor berhasil dihapus!");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,148 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admins;
|
||||
|
||||
use App\Helpers\ResponseFormatter;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\MasterSatuan;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
class MasterSatuanController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return view('pages.admin.master_satuan.index');
|
||||
}
|
||||
|
||||
|
||||
public function getDataSatuan()
|
||||
{
|
||||
$data = MasterSatuan::get();
|
||||
|
||||
return datatables()->of($data)
|
||||
->addColumn('action', function ($data) {
|
||||
return '
|
||||
<button class="btn btn-sm btn-warning btn-edit-satuan" data-satuan=' . $data . ' data-idSatuan=' . $data->id . '><i class="fas fa-edit"></i></button>
|
||||
<button class="btn btn-sm btn-danger btn-hapus-satuan" data-satuan=' . $data . ' data-idSatuan=' . $data->id . '><i class="fas fa-trash"></i></button>
|
||||
';
|
||||
})
|
||||
->rawColumns(['action' => 'action'])
|
||||
->addIndexColumn()
|
||||
->make(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
// validation
|
||||
$validator = Validator::make($request->all(), [
|
||||
'nama_satuan' => 'required',
|
||||
'simbol' => 'required',
|
||||
], [
|
||||
'nama_satuan.required' => 'Nama Satuan tidak boleh kosong!',
|
||||
'simbol.required' => 'Simbol satuan tidak boleh kosong!',
|
||||
]);
|
||||
|
||||
// check validation
|
||||
if ($validator->fails()) {
|
||||
return ResponseFormatter::error($validator->errors()->first());
|
||||
}
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
// create new data
|
||||
$satuan = MasterSatuan::create([
|
||||
'nama_satuan' => $request->nama_satuan,
|
||||
'simbol' => $request->simbol,
|
||||
]);
|
||||
|
||||
DB::commit();
|
||||
return ResponseFormatter::success($satuan, "Satuan berhasil ditambahkan");
|
||||
} catch (\Throwable $th) {
|
||||
DB::rollBack();
|
||||
return ResponseFormatter::error($th->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit(string $id)
|
||||
{
|
||||
// get data from satuan
|
||||
$satuan = MasterSatuan::findOrFail($id);
|
||||
return ResponseFormatter::success([
|
||||
'satuan' => $satuan
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, string $id)
|
||||
{
|
||||
|
||||
// validation
|
||||
$validator = Validator::make($request->all(), [
|
||||
'nama_satuan_edit' => 'required',
|
||||
'simbol_edit' => 'required',
|
||||
], [
|
||||
'nama_satuan_edit.required' => 'Nama Satuan tidak boleh kosong!',
|
||||
'simbol_edit.required' => 'Simbol satuan tidak boleh kosong!',
|
||||
]);
|
||||
|
||||
// check validation
|
||||
if ($validator->fails()) {
|
||||
return ResponseFormatter::error($validator->errors()->first());
|
||||
}
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
// create new data
|
||||
$satuan = MasterSatuan::findOrFail($id);
|
||||
$satuan->update([
|
||||
'nama_satuan' => $request->nama_satuan_edit,
|
||||
'simbol' => $request->simbol_edit
|
||||
]);
|
||||
|
||||
DB::commit();
|
||||
return ResponseFormatter::success($satuan, "Satuan berhasil diubah");
|
||||
} catch (\Throwable $th) {
|
||||
DB::rollBack();
|
||||
return ResponseFormatter::error($th->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(string $id)
|
||||
{
|
||||
// get data from satuan
|
||||
$satuan = MasterSatuan::findOrFail($id);
|
||||
|
||||
// check satuan
|
||||
if (!$satuan) {
|
||||
return ResponseFormatter::error("Data satuan tidak ditemukan!");
|
||||
}
|
||||
|
||||
// delete satuan
|
||||
$satuan->delete();
|
||||
|
||||
return ResponseFormatter::success(null, "Satuan berhasil dihapus!");
|
||||
}
|
||||
}
|
|
@ -4,6 +4,8 @@ namespace App\Http\Controllers\Admins\Pengeluaran;
|
|||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\BukuBesar;
|
||||
use App\Models\MasterDistributor;
|
||||
use App\Models\MasterSatuan;
|
||||
use App\Models\Pengeluaran;
|
||||
use App\Models\RekeningCoa;
|
||||
use Carbon\Carbon;
|
||||
|
@ -18,69 +20,96 @@ class PengeluaranController extends Controller
|
|||
public function index()
|
||||
{
|
||||
$coaBiaya = RekeningCoa::where('kode_coa', 5)->get();
|
||||
$coaPengeluaran = RekeningCoa::where('kode_coa', 5)->where('sub_kode_coa', 500)->get();
|
||||
$rekeningCoaTf = RekeningCoa::where('kode_coa', 1)->where('sub_kode_coa', 200)->get();
|
||||
|
||||
return view('pages.admin.pengeluaran.index', compact('coaBiaya', 'rekeningCoaTf'));
|
||||
$distributors = MasterDistributor::all();
|
||||
$satuans = MasterSatuan::all();
|
||||
$getLastCoaKebutuhan = RekeningCoa::where('kode_coa', 5)->where('sub_kode_coa', 500)->orderBy('id', 'desc')->first();
|
||||
if ($getLastCoaKebutuhan == null) {
|
||||
$getLastCoaKebutuhan = 1;
|
||||
} else {
|
||||
$getLastCoaKebutuhan = $getLastCoaKebutuhan->detail_coa + 1;
|
||||
}
|
||||
return view('pages.admin.pengeluaran.index', compact('coaBiaya', 'rekeningCoaTf', 'coaPengeluaran', 'distributors', 'satuans', 'getLastCoaKebutuhan'));
|
||||
}
|
||||
|
||||
public function simpan(Request $request)
|
||||
{
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
$user = request()->user();
|
||||
|
||||
Pengeluaran::create([
|
||||
foreach ($request->rekening_coa_kebutuhan as $key => $value) {
|
||||
$rekening_coa_id = explode('|', $request->rekening_coa_kebutuhan[$key])[0];
|
||||
$kode_coa = explode('|', $request->rekening_coa_kebutuhan[$key])[1];
|
||||
$keterangan_coa = explode('|', $request->rekening_coa_kebutuhan[$key])[2];
|
||||
|
||||
// detail kebutuhan
|
||||
$harga_total = $request->nominal[$key] ?? 0 * $request->satuan[$key] ?? 0;
|
||||
$pengeluaran = Pengeluaran::create([
|
||||
'faktur' => "PG-" . date('YmdHis'),
|
||||
'tanggal' => $request->tanggal,
|
||||
'tanggal' => $request->tanggal_belanja,
|
||||
'jenis_transaksi' => $request->jenis_transaksi,
|
||||
'nominal' => $request->nominal,
|
||||
'keterangan' => $request->keterangan,
|
||||
'rekening_coa_transfer_id' => $request->id_rekening_coa_transfer ? $request->id_rekening_coa_transfer : null,
|
||||
|
||||
'rekening_coa_id' => $rekening_coa_id,
|
||||
'master_distributors_id' => $request->supplier[$key] ? $request->supplier[$key] : null,
|
||||
'master_satuans_id' => $request->pilihansatuan[$key] ? $request->pilihansatuan[$key] : null,
|
||||
'satuan' => $request->satuan[$key] ? $request->satuan[$key] : 0,
|
||||
'nominal' => $request->nominal[$key] ? $request->nominal[$key] : 0,
|
||||
'total_harga' => $harga_total,
|
||||
'keterangan' => $request->keterangan[$key] ? $request->keterangan[$key] : null,
|
||||
'user_id' => $user->id
|
||||
]);
|
||||
|
||||
if ($request->jenis_transaksi == "1") {
|
||||
BukuBesar::create([
|
||||
'faktur' => "PG-" . date('YmdHis'),
|
||||
'tanggal' => $request->tanggal,
|
||||
'tanggal' => $request->tanggal_belanja,
|
||||
'rekening_coa_id' => "2",
|
||||
'pengeluaran_id' => $pengeluaran->id,
|
||||
'kode_rekening_coa' => "1.100.01",
|
||||
'keterangan_coa' => "Kas Kasir",
|
||||
'keterangan' => $request->keterangan,
|
||||
'keterangan' => $request->keterangan[$key] ?? '',
|
||||
'debet' => 0,
|
||||
'kredit' => $request->nominal
|
||||
'kredit' => $request->nominal[$key] ?? 0
|
||||
]);
|
||||
BukuBesar::create([
|
||||
'faktur' => "PG-" . date('YmdHis'),
|
||||
'tanggal' => $request->tanggal,
|
||||
'rekening_coa_id' => $request->id_rekening_coa,
|
||||
'kode_rekening_coa' => $request->kode_coa,
|
||||
'keterangan_coa' => $request->keterangan_coa,
|
||||
'keterangan' => $request->keterangan,
|
||||
'debet' => $request->nominal,
|
||||
'tanggal' => $request->tanggal_belanja,
|
||||
'rekening_coa_id' => $rekening_coa_id,
|
||||
'kode_rekening_coa' => $kode_coa,
|
||||
'pengeluaran_id' => $pengeluaran->id,
|
||||
'keterangan_coa' => $keterangan_coa,
|
||||
'keterangan' => $request->keterangan[$key] ?? '',
|
||||
'debet' => $request->nominal[$key] ?? '',
|
||||
'kredit' => 0,
|
||||
]);
|
||||
} else {
|
||||
BukuBesar::create([
|
||||
'faktur' => "PG-" . date('YmdHis'),
|
||||
'tanggal' => $request->tanggal,
|
||||
'tanggal' => $request->tanggal_belanja,
|
||||
'rekening_coa_id' => $request->id_rekening_coa_transfer,
|
||||
'kode_rekening_coa' => $request->kode_coa_transfer,
|
||||
'pengeluaran_id' => $pengeluaran->id,
|
||||
'keterangan_coa' => $request->keterangan_coa_transfer,
|
||||
'keterangan' => $request->keterangan,
|
||||
'keterangan' => $request->keterangan[$key],
|
||||
'debet' => 0,
|
||||
'kredit' => $request->nominal
|
||||
'kredit' => $request->nominal[$key]
|
||||
]);
|
||||
BukuBesar::create([
|
||||
'faktur' => "PG-" . date('YmdHis'),
|
||||
'tanggal' => $request->tanggal,
|
||||
'rekening_coa_id' => $request->id_rekening_coa,
|
||||
'kode_rekening_coa' => $request->kode_coa,
|
||||
'keterangan_coa' => $request->keterangan_coa,
|
||||
'keterangan' => $request->keterangan,
|
||||
'debet' => $request->nominal,
|
||||
'tanggal' => $request->tanggal_belanja,
|
||||
'rekening_coa_id' => $rekening_coa_id,
|
||||
'kode_rekening_coa' => $kode_coa,
|
||||
'pengeluaran_id' => $pengeluaran->id,
|
||||
'keterangan_coa' => $keterangan_coa,
|
||||
'keterangan' => $request->keterangan[$key],
|
||||
'debet' => $request->nominal[$key],
|
||||
'kredit' => 0,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
|
||||
|
@ -88,7 +117,7 @@ class PengeluaranController extends Controller
|
|||
} catch (\Throwable $th) {
|
||||
DB::rollBack();
|
||||
|
||||
dd($th->getMessage());
|
||||
dd($th->getMessage() . ' ' . $th->getLine() . ' ' . $th->getFile());
|
||||
return response()->json(['status' => false, 'message' => 'Kesalahan menyimpan data']);
|
||||
}
|
||||
}
|
||||
|
@ -98,7 +127,7 @@ class PengeluaranController extends Controller
|
|||
$mpdf = new \Mpdf\Mpdf([
|
||||
'mode' => 'utf-8',
|
||||
'format' => 'A4',
|
||||
'orientation' => 'portrait',
|
||||
'orientation' => 'Landscape',
|
||||
'margin_left' => 15,
|
||||
'margin_right' => 15,
|
||||
'margin_top' => 10,
|
||||
|
@ -109,7 +138,7 @@ class PengeluaranController extends Controller
|
|||
$mpdf->AddPage();
|
||||
$mpdf->setFooter('{PAGENO}');
|
||||
|
||||
$data = Pengeluaran::with('user')->whereDate('tanggal', '>=', $request->filter_tanggal_1)
|
||||
$data = Pengeluaran::with('user', 'masterDistributor', 'masterSatuan', 'rekeningCoa', 'rekeningCoaTransfer')->whereDate('tanggal', '>=', $request->filter_tanggal_1)
|
||||
->whereDate('tanggal', '<=', $request->filter_tanggal_2)
|
||||
->get();
|
||||
$html = view('pages.admin.pengeluaran.laporan', [
|
||||
|
@ -127,7 +156,7 @@ class PengeluaranController extends Controller
|
|||
$nomor = 1;
|
||||
$filter_tanggal_1 = $request->filter_tanggal_1;
|
||||
$filter_tanggal_2 = $request->filter_tanggal_2;
|
||||
$data = Pengeluaran::with('user')
|
||||
$data = Pengeluaran::with('user', 'masterDistributor', 'masterSatuan', 'rekeningCoa', 'rekeningCoaTransfer')
|
||||
->when($filter_tanggal_1, function ($query) use ($filter_tanggal_1) {
|
||||
return $query->whereDate('tanggal', '>=', $filter_tanggal_1);
|
||||
})
|
||||
|
@ -139,17 +168,68 @@ class PengeluaranController extends Controller
|
|||
})
|
||||
->orderBy('tanggal', 'desc')
|
||||
->get();
|
||||
|
||||
return datatables()
|
||||
->of($data)
|
||||
->addColumn('suppliersnya', function ($data) {
|
||||
if ($data->master_distributors_id == null) {
|
||||
return '-';
|
||||
} else {
|
||||
return $data->masterDistributor->nama_distributor;
|
||||
}
|
||||
})
|
||||
->addColumn('transaksinya', function ($data) {
|
||||
if ($data->jenis_transaksi == 1) {
|
||||
return "Tunai";
|
||||
} else {
|
||||
return "Transfer" . " " . $data->rekeningCoaTransfer->keterangan_coa;
|
||||
}
|
||||
})
|
||||
->addColumn('satuannya', function ($data) {
|
||||
return $data->satuan . " " . $data->masterSatuan?->simbol ?? '';
|
||||
})
|
||||
->addColumn('rekening_coa', function ($data) {
|
||||
return $data->rekeningCoa->keterangan_coa . " " . $data->keterangan ?? '';
|
||||
})
|
||||
->addColumn('nomor', function ($data) use (&$nomor) {
|
||||
return $nomor++;
|
||||
})
|
||||
->addColumn('ubah', function ($data) {
|
||||
->addColumn('action', function ($data) {
|
||||
return '<div class="btn-group">
|
||||
<a href="javascript:void(0)" onclick="detail(\'' . $data->id . '\')"><span class="btn btn-xs btn-warning mr-1"><i class="fas fa-eye"></i></span></a>
|
||||
<a href="javascript:void(0)" onclick="print(\'' . $data->id . '\')"><span class="btn btn-xs btn-success"><i class="fas fa-print"></i></span></a></div>';
|
||||
<button href="javascript:void(0)" class="btn btn-xs btn-danger mr-1 delete_pengeluaran" data-id="' . $data->id . '" data-kebutuhan="' . $data->rekeningCoa->keterangan_coa . '" data-faktur="' . $data->faktur . '"><i class="fas fa-trash"></i></button>
|
||||
</div>';
|
||||
})
|
||||
->rawColumns(['ubah'])
|
||||
->rawColumns(['action'])
|
||||
->make(true);
|
||||
}
|
||||
|
||||
public function delete(Request $request)
|
||||
{
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
$pengeluaran = Pengeluaran::find($request->id);
|
||||
$pengeluaran->delete();
|
||||
BukuBesar::where('faktur', $request->faktur)->delete();
|
||||
DB::commit();
|
||||
return response()->json(['status' => true, 'message' => 'Data berhasil dihapus']);
|
||||
} catch (\Throwable $th) {
|
||||
DB::rollBack();
|
||||
return response()->json(['status' => false, 'message' => 'Kesalahan menghapus data']);
|
||||
}
|
||||
}
|
||||
|
||||
public function generateLocalStorage(Request $request)
|
||||
{
|
||||
$coaPengeluaran = RekeningCoa::where('kode_coa', 5)->where('sub_kode_coa', 500)->get();
|
||||
$distributors = MasterDistributor::all();
|
||||
$satuans = MasterSatuan::all();
|
||||
$rekening_coa_kebutuhan = $request->rekening_coa_kebutuhan;
|
||||
$nominal = $request->nominal;
|
||||
$pilihansatuan = $request->pilihansatuan;
|
||||
$satuannya = $request->satuan;
|
||||
$supplier = $request->supplier;
|
||||
$keterangan = $request->keterangan;
|
||||
$total_harga = $request->total;
|
||||
return view('pages.admin.pengeluaran.cardpengeluaran', compact('coaPengeluaran', 'distributors', 'satuans', 'rekening_coa_kebutuhan', 'nominal', 'pilihansatuan', 'satuannya', 'supplier', 'keterangan', 'total_harga'));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,15 +5,19 @@ namespace App\Http\Controllers\Admins\Penjualan;
|
|||
use App\Http\Controllers\Controller;
|
||||
use App\Models\DetailPesanan;
|
||||
use App\Models\Pesanan;
|
||||
use App\Models\RekeningCoa;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
|
||||
class PenjualanController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return view('pages.admin.penjualan.index');
|
||||
$aba = RekeningCoa::where('kode_coa', 1)->where('sub_kode_coa', 200)->get();
|
||||
|
||||
return view('pages.admin.penjualan.index', compact('aba'));
|
||||
}
|
||||
|
||||
public function getDataPenjualan(Request $request)
|
||||
|
@ -21,6 +25,8 @@ class PenjualanController extends Controller
|
|||
$nomor = 1;
|
||||
$filter_tanggal_1 = $request->filter_tanggal_1;
|
||||
$filter_tanggal_2 = $request->filter_tanggal_2;
|
||||
$akun_coa = $request->akun_coa;
|
||||
if ($request->akun_coa == null) {
|
||||
$data = Pesanan::with(['detailPesanan', 'user'])
|
||||
->when($filter_tanggal_1, function ($query) use ($filter_tanggal_1) {
|
||||
return $query->whereDate('tanggal_pesanan', '>=', $filter_tanggal_1);
|
||||
|
@ -33,6 +39,21 @@ class PenjualanController extends Controller
|
|||
})
|
||||
->orderBy('tanggal_pesanan', 'desc')
|
||||
->get();
|
||||
} else {
|
||||
$data = Pesanan::with(['detailPesanan', 'user', 'rekening_coa'])
|
||||
->where('rekening_coa_id', $akun_coa)
|
||||
->when($filter_tanggal_1, function ($query) use ($filter_tanggal_1) {
|
||||
return $query->whereDate('tanggal_pesanan', '>=', $filter_tanggal_1);
|
||||
})
|
||||
->when($filter_tanggal_2, function ($query) use ($filter_tanggal_2) {
|
||||
return $query->whereDate('tanggal_pesanan', '<=', $filter_tanggal_2);
|
||||
})
|
||||
->when(!$filter_tanggal_1 && !$filter_tanggal_2, function ($query) {
|
||||
return $query->whereDate('tanggal_pesanan', Carbon::today());
|
||||
})
|
||||
->orderBy('tanggal_pesanan', 'desc')
|
||||
->get();
|
||||
}
|
||||
|
||||
return datatables()
|
||||
->of($data)
|
||||
|
@ -55,9 +76,11 @@ class PenjualanController extends Controller
|
|||
->addColumn('grand_total_rp', function ($data) {
|
||||
return 'Rp ' . number_format($data->grand_total, 0, ',', '.');
|
||||
})
|
||||
->addColumn('jenis_pembayarannya', function ($data) {
|
||||
return $data->jenis_pembayaran == 1 ? 'Tunai' : ($data->jenis_pembayaran == null ? 'Tunai' : 'Non-Tunai' . ' (' . ($data->rekening_coa?->keterangan_coa ?? '') . ')');
|
||||
})
|
||||
->addColumn('ubah', function ($data) {
|
||||
return '<div class="btn-group">
|
||||
<button href="javascript:void(0)" class="btn btn-xs btn-danger mr-1 cancelOrderBtn" data-id="' . $data->id . '" data-kode_pesanan="' . $data->kode_pesanan . '" data-nama_pemesan="' . $data->nama_pemesan . '">cancel</button>
|
||||
<a class="btn btn-xs btn-warning mr-1" href="javascript:void(0)" onclick="detail(\'' . $data->id . '\')"><i class="fas fa-eye"></i></a>
|
||||
<a class="btn btn-xs btn-success" href="javascript:void(0)" onclick="print(\'' . $data->id . '\')"><i class="fas fa-print"></i></a></div>';
|
||||
})
|
||||
|
@ -74,13 +97,14 @@ class PenjualanController extends Controller
|
|||
|
||||
public function getDataDetailPenjualan(Request $request)
|
||||
{
|
||||
$data = DetailPesanan::with('pesanan')->where('pesanan_id', $request->id_pesanan)->get();
|
||||
$data = DetailPesanan::with('pesanan')->where('pesanan_id', $request->id_pesanan)->withTrashed()->get();
|
||||
$pesanan = Pesanan::find($request->id_pesanan);
|
||||
return response()->json(['status' => true, 'data' => $data, 'pesanan' => $pesanan]);
|
||||
}
|
||||
|
||||
public function laporan(Request $request)
|
||||
{
|
||||
try {
|
||||
$mpdf = new \Mpdf\Mpdf([
|
||||
'mode' => 'utf-8',
|
||||
'format' => 'A4',
|
||||
|
@ -95,18 +119,47 @@ class PenjualanController extends Controller
|
|||
$mpdf->AddPage();
|
||||
$mpdf->setFooter('{PAGENO}');
|
||||
|
||||
$data = Pesanan::with(['user', 'bukuBesar'])->whereDate('tanggal_pesanan', '>=', $request->filter_tanggal_1)
|
||||
$filter_tanggal_1 = $request->filter_tanggal_1;
|
||||
$filter_tanggal_2 = $request->filter_tanggal_2;
|
||||
if ($request->jenis_coa == null) {
|
||||
$keterangan_coa = 'Semua';
|
||||
$data = Pesanan::with(['user', 'bukuBesar', 'rekening_coa'])->whereDate('tanggal_pesanan', '>=', $request->filter_tanggal_1)
|
||||
->whereDate('tanggal_pesanan', '<=', $request->filter_tanggal_2)
|
||||
->get();
|
||||
$html = view('pages.admin.penjualan.laporan', [
|
||||
} else {
|
||||
$keterangan_coa = RekeningCoa::find($request->jenis_coa)->keterangan_coa;
|
||||
$data = Pesanan::with(['user', 'bukuBesar', 'rekening_coa'])->where('rekening_coa_id', $request->jenis_coa)->whereDate('tanggal_pesanan', '>=', $request->filter_tanggal_1)
|
||||
->whereDate('tanggal_pesanan', '<=', $request->filter_tanggal_2)
|
||||
->get();
|
||||
}
|
||||
|
||||
$alldata = [
|
||||
'data' => $data,
|
||||
'filter_tanggal_1' => $request->filter_tanggal_1,
|
||||
'filter_tanggal_2' => $request->filter_tanggal_2,
|
||||
]);
|
||||
'filter_tanggal_1' => $filter_tanggal_1,
|
||||
'filter_tanggal_2' => $filter_tanggal_2,
|
||||
'keterangan_coa' => $keterangan_coa
|
||||
];
|
||||
|
||||
$html = view('pages.admin.penjualan.laporan', $alldata);
|
||||
// $html->render();
|
||||
// $mpdf->WriteHTML($html);
|
||||
|
||||
// $mpdf->chunkLoadView('<html-separator/>', 'pages.admin.penjualan.laporan', $alldata);
|
||||
// return $mpdf->stream('document.pdf');
|
||||
|
||||
$chunks = explode("chunk", (string)$html);
|
||||
foreach ($chunks as $key => $val) {
|
||||
// $mpdf->WriteHTML($val);
|
||||
}
|
||||
$mpdf->writeHTML($html);
|
||||
|
||||
$mpdf->Output('Laporan_Penjualan.pdf', 'I');
|
||||
return response()->header('Content-Type', 'application/pdf');
|
||||
} catch (\Throwable $th) {
|
||||
Session::flash('errors', 'Gagal membuat laporan, coba lagi dengan rentang tanggal yang lebih pendek');
|
||||
return redirect()->back();
|
||||
//throw $th;
|
||||
}
|
||||
}
|
||||
|
||||
public function cancel(Request $request)
|
||||
|
@ -130,6 +183,33 @@ class PenjualanController extends Controller
|
|||
}
|
||||
}
|
||||
|
||||
public function cancelDetail(Request $request)
|
||||
{
|
||||
try {
|
||||
|
||||
DB::beginTransaction();
|
||||
$detailPesanan = DetailPesanan::find($request->id);
|
||||
|
||||
$pesanan = Pesanan::find($detailPesanan->pesanan_id);
|
||||
$pesanan->total_bayar = $pesanan->total_bayar - $detailPesanan->total_harga_produk;
|
||||
// check the diskon in pesanan
|
||||
$pesanan->grand_total = $pesanan->total_bayar - $pesanan->diskon_rupiah;
|
||||
$pesanan->total_pesanan = $pesanan->total_pesanan - $detailPesanan->jumlah_produk;
|
||||
$pesanan->save();
|
||||
|
||||
$detailPesanan->status_pesanan = '3';
|
||||
$detailPesanan->delete();
|
||||
$detailPesanan->save();
|
||||
|
||||
DB::commit();
|
||||
return response()->json(['status' => true, 'message' => 'Pesanan berhasil di cancel']);
|
||||
} catch (\Throwable $th) {
|
||||
DB::rollBack();
|
||||
return response()->json(['status' => false, 'message' => 'Pesanan gagal di cancel']);
|
||||
//throw $th;
|
||||
}
|
||||
}
|
||||
|
||||
public function dibatalkan()
|
||||
{
|
||||
if (request()->ajax()) {
|
||||
|
|
|
@ -0,0 +1,180 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admins\PerangkatPrinter;
|
||||
|
||||
use App\Helpers\ResponseFormatter;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\PerangkatPrinter;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Mpdf\Tag\Q;
|
||||
|
||||
class PerangkatPrinterController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return view('pages.admin.perangkat_printer.index');
|
||||
}
|
||||
|
||||
|
||||
public function getDataPrinter()
|
||||
{
|
||||
$data = PerangkatPrinter::get();
|
||||
|
||||
return datatables()->of($data)
|
||||
->addColumn('status_printer', function ($data) {
|
||||
if ($data->status == '1') {
|
||||
return '<span class="badge badge-success">Aktif</span>';
|
||||
} else {
|
||||
return '<span class="badge badge-danger">Tidak Aktif</span>';
|
||||
}
|
||||
})
|
||||
->addColumn('action', function ($data) {
|
||||
return '
|
||||
<button class="btn btn-sm btn-warning btn-edit-printer" data-printer=' . $data . '><i class="fas fa-edit"></i></button>
|
||||
<button class="btn btn-sm btn-danger btn-hapus-printer" data-printer=' . $data . '><i class="fas fa-trash"></i></button>
|
||||
';
|
||||
})
|
||||
->rawColumns(['action' => 'action', 'status_printer' => 'status_printer'])
|
||||
->addIndexColumn()
|
||||
->make(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
// validation
|
||||
$validator = Validator::make($request->all(), [
|
||||
'printer_nama' => 'required',
|
||||
'printer_mm' => 'required',
|
||||
'printer_for' => 'required',
|
||||
], [
|
||||
'printer_nama.required' => 'Nama tidak boleh kosong!',
|
||||
'printer_mm.required' => 'Ukuran kertas printer tidak boleh kosong!',
|
||||
'printer_for.required' => 'Printer digunakan untuk tidak boleh kosong!',
|
||||
]);
|
||||
|
||||
// check validation
|
||||
if ($validator->fails()) {
|
||||
return ResponseFormatter::error($validator->errors()->first());
|
||||
}
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
if ($request->printer_status != 'on' || $request->printer_status == null) {
|
||||
$status = '0';
|
||||
} else {
|
||||
$status = '1';
|
||||
}
|
||||
|
||||
// create new account
|
||||
$printer = PerangkatPrinter::create([
|
||||
'nama_printer' => $request->printer_nama,
|
||||
'printer_connection' => $request->printer_connection,
|
||||
'ip_address' => $request->ip_address,
|
||||
'printer_mm' => $request->printer_mm,
|
||||
'printer_for' => $request->printer_for,
|
||||
'status' => $status,
|
||||
]);
|
||||
|
||||
DB::commit();
|
||||
return ResponseFormatter::success($printer, "Printer berhasil ditambahkan");
|
||||
} catch (\Throwable $th) {
|
||||
DB::rollBack();
|
||||
return ResponseFormatter::error($th->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit(string $id)
|
||||
{
|
||||
// get data from printer
|
||||
$printer = PerangkatPrinter::findOrFail($id);
|
||||
return ResponseFormatter::success([
|
||||
'printer' => $printer
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, string $id)
|
||||
{
|
||||
|
||||
// validation
|
||||
$validator = Validator::make($request->all(), [
|
||||
'printer_nama_edit' => 'required',
|
||||
'printer_mm_edit' => 'required',
|
||||
'printer_for_edit' => 'required',
|
||||
], [
|
||||
'printer_nama_edit.required' => 'Nama tidak boleh kosong!',
|
||||
'printer_mm_edit.required' => 'Ukuran kertas printer tidak boleh kosong!',
|
||||
'printer_for_edit.required' => 'Printer digunakan untuk tidak boleh kosong!'
|
||||
]);
|
||||
|
||||
// check validation
|
||||
if ($validator->fails()) {
|
||||
return ResponseFormatter::error($validator->errors()->first());
|
||||
}
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
if ($request->printer_status_edit != 'on' || $request->printer_status_edit == null) {
|
||||
$status = '0';
|
||||
} else {
|
||||
$status = '1';
|
||||
}
|
||||
|
||||
// create new account
|
||||
$printer = PerangkatPrinter::findOrFail($id);
|
||||
$printer->update([
|
||||
'nama_printer' => $request->printer_nama_edit,
|
||||
'printer_connection' => $request->printer_connection_edit,
|
||||
'ip_address' => $request->ip_address_edit,
|
||||
'printer_mm' => $request->printer_mm_edit,
|
||||
'printer_for' => $request->printer_for_edit,
|
||||
'status' => $status,
|
||||
]);
|
||||
|
||||
DB::commit();
|
||||
return ResponseFormatter::success($printer, "Printer berhasil diubah");
|
||||
} catch (\Throwable $th) {
|
||||
DB::rollBack();
|
||||
return ResponseFormatter::error($th->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(string $id)
|
||||
{
|
||||
// get data from printer
|
||||
$printer = PerangkatPrinter::findOrFail($id);
|
||||
|
||||
// check printer
|
||||
if (!$printer) {
|
||||
return ResponseFormatter::error("Data printer tidak ditemukan!");
|
||||
}
|
||||
|
||||
// delete printer
|
||||
$printer->delete();
|
||||
|
||||
return ResponseFormatter::success(null, "Printer berhasil dihapus!");
|
||||
}
|
||||
}
|
|
@ -8,11 +8,13 @@ use Illuminate\Http\Request;
|
|||
|
||||
class RekeningCoaController extends Controller
|
||||
{
|
||||
public function index(){
|
||||
public function index()
|
||||
{
|
||||
return view('pages.admin.rekening_coa.index');
|
||||
}
|
||||
|
||||
public function getData(){
|
||||
public function getData()
|
||||
{
|
||||
$rekeningCoa = RekeningCoa::orderBy('coa', 'asc')->get();
|
||||
$nomor = 1;
|
||||
|
||||
|
@ -34,7 +36,8 @@ class RekeningCoaController extends Controller
|
|||
->make(true);
|
||||
}
|
||||
|
||||
public function simpan(Request $request){
|
||||
public function simpan(Request $request)
|
||||
{
|
||||
try {
|
||||
if ($request->detail_coa <> null) {
|
||||
$status = 1;
|
||||
|
@ -52,14 +55,14 @@ class RekeningCoaController extends Controller
|
|||
'status' => $status
|
||||
]);
|
||||
|
||||
return redirect()->route('coa.index')->with(['success' => 'Data berhasil ditambahkan']);
|
||||
|
||||
return redirect()->back()->with(['success' => 'Data berhasil ditambahkan']);
|
||||
} catch (\Throwable $th) {
|
||||
return back()->withError($th->getMessage())->withInput();
|
||||
}
|
||||
}
|
||||
|
||||
public function ubah(Request $request){
|
||||
public function ubah(Request $request)
|
||||
{
|
||||
try {
|
||||
$rekeningCoa = RekeningCoa::where('id', $request->id_rekening_coa);
|
||||
$rekeningCoa->update([
|
||||
|
@ -68,7 +71,6 @@ class RekeningCoaController extends Controller
|
|||
]);
|
||||
|
||||
return redirect()->route('coa.index')->with(['success' => 'Data berhasil diubah']);
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
return back()->withError($th->getMessage())->withInput();
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@ class History extends Controller
|
|||
|
||||
public function getDataDetailHistory(Request $request)
|
||||
{
|
||||
$data = DetailPesanan::with('pesanan')->where('pesanan_id', $request->id_pesanan)->get();
|
||||
$data = Pesanan::with('detailPesanan')->find($request->id_pesanan);
|
||||
|
||||
return response()->json(['status' => true, 'data' => $data]);
|
||||
}
|
||||
|
|
|
@ -16,11 +16,12 @@ class Menu extends Controller
|
|||
public function index()
|
||||
{
|
||||
$kategori_produks = KategoriProduk::get();
|
||||
|
||||
return view('pages.Menu.index', compact('kategori_produks'));
|
||||
$kelompok_kategoris = KelompokKategori::get();
|
||||
return view('pages.Menu.index', compact('kategori_produks', 'kelompok_kategoris'));
|
||||
}
|
||||
|
||||
public function kelompokKategori($id) {
|
||||
public function kelompokKategori($id)
|
||||
{
|
||||
$kelompok_kategoris = KelompokKategori::where('kategori_produk_id', $id)->get();
|
||||
|
||||
if (empty($kelompok_kategoris[0])) {
|
||||
|
@ -28,13 +29,20 @@ class Menu extends Controller
|
|||
} else {
|
||||
return $kelompok_kategoris;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function getDataMenu()
|
||||
public function getDataMenu(Request $request)
|
||||
{
|
||||
// $data = Produk::with(['kategori_produk'])->get();
|
||||
$kelompok_kategori_id = $request->kelompok_produk;
|
||||
|
||||
if ($kelompok_kategori_id == null || $kelompok_kategori_id == 0) {
|
||||
$data = KelompokKategoriPivot::with(['kelompokKategori', 'produk'])->get();
|
||||
} else {
|
||||
$data = KelompokKategoriPivot::with(['kelompokKategori', 'produk'])
|
||||
->where('kelompok_kategori_id', $kelompok_kategori_id)
|
||||
->get();
|
||||
}
|
||||
|
||||
$nomor = 1;
|
||||
|
||||
return $datatables = datatables()
|
||||
|
@ -69,7 +77,8 @@ class Menu extends Controller
|
|||
}
|
||||
|
||||
// Tambah Menu
|
||||
public function store(Request $request) {
|
||||
public function store(Request $request)
|
||||
{
|
||||
// validation
|
||||
$rules = array(
|
||||
'kategori_produk' => 'required',
|
||||
|
@ -78,8 +87,12 @@ class Menu extends Controller
|
|||
'nama_produk' => 'required',
|
||||
'harga_produk' => 'required',
|
||||
'tersedia' => 'required',
|
||||
'deskripsi_produk' => 'required',
|
||||
);
|
||||
if ($request->kelompok_produk == 9) {
|
||||
$rules = array(
|
||||
'promodatetime' => 'required',
|
||||
);
|
||||
}
|
||||
$validator = Validator::make($request->all(), $rules);
|
||||
|
||||
// check validation
|
||||
|
@ -87,6 +100,22 @@ class Menu extends Controller
|
|||
// If validation fails, return with errors
|
||||
return response()->json(['errors' => $validator->errors()], 422);
|
||||
} else {
|
||||
|
||||
if ($request->kelompok_produk == 9) {
|
||||
// date promo 02/27/2024 12:00 AM - 03/30/2024 11:00 PM
|
||||
$tanggal_array = explode(" - ", $request->promodatetime);
|
||||
$tanggal_awal_string = $tanggal_array[0];
|
||||
$tanggal_akhir_string = $tanggal_array[1];
|
||||
|
||||
// Konversi string tanggal menjadi objek Carbon
|
||||
$tanggal_awal = Carbon::createFromFormat('m/d/Y h:i A', $tanggal_awal_string);
|
||||
$tanggal_akhir = Carbon::createFromFormat('m/d/Y h:i A', $tanggal_akhir_string);
|
||||
|
||||
// Mendapatkan tanggal dan waktu awal serta akhir
|
||||
$tgl_start_promo = $tanggal_awal->toDateTimeString();
|
||||
$tgl_end_promo = $tanggal_akhir->toDateTimeString();
|
||||
}
|
||||
|
||||
// create product
|
||||
$produk = Produk::create([
|
||||
'kategori_produk_id' => $request->kategori_produk,
|
||||
|
@ -95,6 +124,9 @@ class Menu extends Controller
|
|||
'harga_produk' => $request->harga_produk,
|
||||
'tersedia' => $request->tersedia,
|
||||
'deskripsi_produk' => $request->deskripsi_produk,
|
||||
'stok_promo' => $request->stok_promo,
|
||||
'tgl_start_promo' => $tgl_start_promo,
|
||||
'tgl_end_promo' => $tgl_end_promo,
|
||||
'created_at' => Carbon::now()
|
||||
]);
|
||||
|
||||
|
@ -109,13 +141,16 @@ class Menu extends Controller
|
|||
}
|
||||
}
|
||||
|
||||
public function show($id) {
|
||||
public function show($id)
|
||||
{
|
||||
$data = KelompokKategoriPivot::with(['kelompokKategori', 'produk'])->findOrFail($id);
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
// Ubah Menu
|
||||
public function update(Request $request, $id) {
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
|
||||
// validation
|
||||
$rules = array(
|
||||
'kategori_produk' => 'required',
|
||||
|
@ -124,8 +159,12 @@ class Menu extends Controller
|
|||
'nama_produk' => 'required',
|
||||
'harga_produk' => 'required',
|
||||
'tersedia' => 'required',
|
||||
'deskripsi_produk' => 'required',
|
||||
);
|
||||
if ($request->kelompok_produk == 9) {
|
||||
$rules = array(
|
||||
'promodatetime' => 'required',
|
||||
);
|
||||
}
|
||||
$validator = Validator::make($request->all(), $rules);
|
||||
|
||||
// check validation
|
||||
|
@ -133,6 +172,22 @@ class Menu extends Controller
|
|||
// If validation fails, return with errors
|
||||
return response()->json(['errors' => $validator->errors()], 422);
|
||||
} else {
|
||||
|
||||
if ($request->kelompok_produk == 9) {
|
||||
// date promo 02/27/2024 12:00 AM - 03/30/2024 11:00 PM
|
||||
$tanggal_array = explode(" - ", $request->promodatetime);
|
||||
$tanggal_awal_string = $tanggal_array[0];
|
||||
$tanggal_akhir_string = $tanggal_array[1];
|
||||
|
||||
// Konversi string tanggal menjadi objek Carbon
|
||||
$tanggal_awal = Carbon::createFromFormat('m/d/Y h:i A', $tanggal_awal_string);
|
||||
$tanggal_akhir = Carbon::createFromFormat('m/d/Y h:i A', $tanggal_akhir_string);
|
||||
|
||||
// Mendapatkan tanggal dan waktu awal serta akhir
|
||||
$tgl_start_promo = $tanggal_awal->toDateTimeString();
|
||||
$tgl_end_promo = $tanggal_akhir->toDateTimeString();
|
||||
}
|
||||
|
||||
$pivot = KelompokKategoriPivot::findOrFail($id);
|
||||
$produk = Produk::find($pivot->produk_id);
|
||||
|
||||
|
@ -149,6 +204,9 @@ class Menu extends Controller
|
|||
'harga_produk' => $request->harga_produk,
|
||||
'tersedia' => $request->tersedia,
|
||||
'deskripsi_produk' => $request->deskripsi_produk,
|
||||
'stok_promo' => $request->stok_promo,
|
||||
'tgl_start_promo' => $tgl_start_promo,
|
||||
'tgl_end_promo' => $tgl_end_promo,
|
||||
]);
|
||||
|
||||
// Return a success response
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Kasir;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\PerangkatPrinter;
|
||||
use App\Models\Pesanan;
|
||||
use Illuminate\Http\Request;
|
||||
use Zelda\EscposPhp\PrintConnectors\WindowsPrintConnector;
|
||||
use Zelda\EscposPhp\Printer;
|
||||
|
||||
class PrintOutController extends Controller
|
||||
{
|
||||
public function print($id)
|
||||
{
|
||||
// begin set data
|
||||
$pesanan = Pesanan::with('detailPesanan', 'user')->where('id', $id)->first();
|
||||
|
||||
$printer = PerangkatPrinter::where('status', 1)->get();
|
||||
foreach ($printer as $key => $value) {
|
||||
if ($value->printer_mm == '58') {
|
||||
$print58mm = new kolomPrinter58mmController();
|
||||
if ($value->printer_for == 'dapur') {
|
||||
$print58mm->print58mmDapur($pesanan, $value);
|
||||
} else {
|
||||
$print58mm->print58mm($pesanan, $value);
|
||||
}
|
||||
} else {
|
||||
$print88mm = new kolomPrinter88mmController();
|
||||
if ($value->printer_for == 'dapur') {
|
||||
$print88mm->print88mmDapur($pesanan, $value);
|
||||
} else {
|
||||
$print88mm->print88mm($pesanan, $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// public function directMMPrint($printer, $data)
|
||||
// {
|
||||
// foreach ($printer as $key => $value) {
|
||||
// if ($value->printer_mm == '58mm') {
|
||||
// $print58mm = new kolomPrinter58mmController();
|
||||
// if ($value->printer_for == 'dapur') {
|
||||
// $print58mm->print58mmDapur($data, $value->nama_printer);
|
||||
// } else {
|
||||
// $print58mm->print58mm($data, $value->nama_printer);
|
||||
// }
|
||||
// } else {
|
||||
// $print88mm = new kolomPrinter88mmController();
|
||||
// if ($value->printer_for == 'dapur') {
|
||||
// $print88mm->print88mmDapur($data, $value->nama_printer);
|
||||
// } else {
|
||||
// $print88mm->print88mm($data, $value->nama_printer);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
|
@ -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;
|
||||
|
@ -23,7 +24,11 @@ class Transaksi extends Controller
|
|||
|
||||
public function index()
|
||||
{
|
||||
$orderCode = "ORD-" . strtoupper(random_str(6, random_str()));
|
||||
// count pesanan by date now and add 1 for next count pesanan today
|
||||
$lastCountPesanan = Pesanan::whereDate('created_at', date('Y-m-d'))->count() + 1;
|
||||
// add 0 in front of lastCountPesanan if lastCountPesanan less than 10
|
||||
$lastCountPesanan = str_pad($lastCountPesanan, 2, '0', STR_PAD_LEFT);
|
||||
$orderCode = "ORD-" . date('ym') . strtoupper(random_str(3, random_str())) . date('d') . '-' . $lastCountPesanan;
|
||||
$KelompokKategori = KelompokKategori::with('kelompokKategoriPivot.produk')->get();
|
||||
$aba = RekeningCoa::where('kode_coa', 1)->where('sub_kode_coa', 200)->get();
|
||||
|
||||
|
@ -105,7 +110,6 @@ class Transaksi extends Controller
|
|||
|
||||
public function store(Request $request)
|
||||
{
|
||||
|
||||
$request->validate([
|
||||
'orderCode' => 'required',
|
||||
'namaPemesan' => 'required',
|
||||
|
@ -134,9 +138,16 @@ class Transaksi extends Controller
|
|||
// calculate nomor antrian
|
||||
$nomorAntrian = $lastCountPesanan;
|
||||
|
||||
$kodenya = substr($request->orderCode, 0, -3); // Menghapus tiga karakter terakhir,
|
||||
|
||||
// check antrian pesanan jika sudah ada di database maka tambahkan 1 untuk nomor antrian selanjutnya
|
||||
$lastCountPesanan = Pesanan::whereDate('created_at', date('Y-m-d'))->count() + 1;
|
||||
|
||||
$kodenya = $kodenya . '-' . $lastCountPesanan;
|
||||
|
||||
if ($request->jenis_pembayaran == "1") {
|
||||
$pesananDatas = [
|
||||
'kode_pesanan' => $request->orderCode,
|
||||
'kode_pesanan' => $kodenya,
|
||||
'nama_pemesan' => $request->namaPemesan,
|
||||
'nomor_pemesan' => $request->nomorPemesan,
|
||||
'nomor_meja' => $request->nomorMeja,
|
||||
|
@ -157,7 +168,7 @@ class Transaksi extends Controller
|
|||
$pesananModels = \App\Models\Pesanan::create($pesananDatas);
|
||||
} else {
|
||||
$pesananDatas = [
|
||||
'kode_pesanan' => $request->orderCode,
|
||||
'kode_pesanan' => $kodenya,
|
||||
'nama_pemesan' => $request->namaPemesan,
|
||||
'nomor_pemesan' => $request->nomorPemesan,
|
||||
'nomor_meja' => $request->nomorMeja,
|
||||
|
@ -174,6 +185,7 @@ class Transaksi extends Controller
|
|||
'status_bayar' => '1',
|
||||
'user_id' => $user->id,
|
||||
'jenis_pembayaran' => $request->jenis_pembayaran,
|
||||
'rekening_coa_id' => $request->id_rekening_coa,
|
||||
];
|
||||
$pesananModels = \App\Models\Pesanan::create($pesananDatas);
|
||||
}
|
||||
|
@ -200,6 +212,7 @@ class Transaksi extends Controller
|
|||
'total_harga_produk' => $value['total'],
|
||||
'diskon_persen' => $value['diskonSatuan'] ?? null,
|
||||
'keterangan_produk' => $value['keterangan'] ?? null,
|
||||
'status_pesanan' => $value['status_pesanan_dinein'] ?? null,
|
||||
];
|
||||
$detailPesananModels = \App\Models\DetailPesanan::create($oderDatas);
|
||||
}
|
||||
|
@ -214,7 +227,7 @@ class Transaksi extends Controller
|
|||
'pesanans_id' => $pesananModels->id,
|
||||
'kode_rekening_coa' => $request->kode_coa,
|
||||
'keterangan_coa' => $request->keterangan_coa,
|
||||
'keterangan' => 'Penjualan Non Tunai['.$request->orderCode.']',
|
||||
'keterangan' => 'Penjualan Non Tunai[' . $kodenya . ']',
|
||||
'debet' => $request->totalDiskon,
|
||||
'kredit' => 0
|
||||
]);
|
||||
|
@ -225,7 +238,7 @@ class Transaksi extends Controller
|
|||
'pesanans_id' => $pesananModels->id,
|
||||
'kode_rekening_coa' => "4.100.01",
|
||||
'keterangan_coa' => "Pendapatan Penjualan",
|
||||
'keterangan' => 'Penjualan Non Tunai['.$request->orderCode.']',
|
||||
'keterangan' => 'Penjualan Non Tunai[' . $kodenya . ']',
|
||||
'debet' => 0,
|
||||
'kredit' => $request->totalDiskon
|
||||
]);
|
||||
|
@ -238,7 +251,7 @@ class Transaksi extends Controller
|
|||
'pesanans_id' => $pesananModels->id,
|
||||
'kode_rekening_coa' => "1.100.01",
|
||||
'keterangan_coa' => "Kas Kasir",
|
||||
'keterangan' => 'Penjualan Tunai['.$request->orderCode.']',
|
||||
'keterangan' => 'Penjualan Tunai[' . $kodenya . ']',
|
||||
'debet' => $request->totalDiskon,
|
||||
'kredit' => 0
|
||||
]);
|
||||
|
@ -249,18 +262,33 @@ class Transaksi extends Controller
|
|||
'pesanans_id' => $pesananModels->id,
|
||||
'kode_rekening_coa' => "4.100.01",
|
||||
'keterangan_coa' => "Pendapatan Penjualan",
|
||||
'keterangan' => 'Penjualan Tunai['.$request->orderCode.']',
|
||||
'keterangan' => 'Penjualan Tunai[' . $kodenya . ']',
|
||||
'debet' => 0,
|
||||
'kredit' => $request->totalDiskon
|
||||
]);
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
|
||||
// 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'];
|
||||
} catch (\Throwable $th) {
|
||||
DB::rollBack();
|
||||
dd($th->getMessage());
|
||||
// dd('Store Catch ', $th->getMessage(), $th->getLine());
|
||||
return redirect()->back()->with('error', 'Terjadi kesalahan');
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,400 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Kasir;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Zelda\EscposPhp\EscposImage;
|
||||
use Zelda\EscposPhp\PrintConnectors\NetworkPrintConnector;
|
||||
use Zelda\EscposPhp\PrintConnectors\WindowsPrintConnector;
|
||||
use Zelda\EscposPhp\Printer;
|
||||
|
||||
// jumlah character yang bisa ditampung oleh printer 58mm adalah 36 karakter per baris tapi yang dipakai hanya 32 atau 34 saja
|
||||
class kolomPrinter58mmController extends Controller
|
||||
{
|
||||
|
||||
public function print58mm($pesanan, $printernya)
|
||||
{
|
||||
// begin set data
|
||||
$items = [];
|
||||
/* Information for the receipt */
|
||||
foreach ($pesanan->detailPesanan as $key => $value) {
|
||||
|
||||
$theDiskon = $value->diskon_persen != '' || $value->diskon_persen != 0 || $value->diskon_persen != null ? $value->diskon_persen . '%' : '';
|
||||
$items[] = $this->buatBaris1Kolom($value->nama_produk);
|
||||
// $items[] = new itemReceipt($value->jumlah_produk . ' Rp. ' . format_uang($value->harga_produk) . ' ' . $theDiskon, 'Rp. ' . format_uang($value->total_harga_produk));
|
||||
$items[] = $this->buatBaris4Kolom($value->jumlah_produk, 'Rp. ' . format_uang($value->harga_produk), $theDiskon, 'Rp. ' . format_uang($value->total_harga_produk));
|
||||
}
|
||||
|
||||
// $images = EscposImage::load(env('PATH_LOGO_STK'), false);
|
||||
$stk = "Sepiring Telur \nKeriting\n";
|
||||
$address = "Jln. Jawa No. 28A, Jember\n";
|
||||
$dashline = " \n";
|
||||
$ordercode = $pesanan->kode_pesanan . "\n";
|
||||
$line1 = $this->buatBaris2Kolom('Meja: ' . $pesanan->nomor_meja, ' Kasir:');
|
||||
$line2 = $this->buatBaris2Kolom('Antrian: ' . $pesanan->nomor_antrian, $pesanan->user->name . 'ssssss');
|
||||
$line3 = $this->buatBaris1Kolom('Pemesan: ' . $pesanan->nama_pemesan);
|
||||
|
||||
$total = $this->buatBaris3Kolom($pesanan->total_pesanan, 'Total:', 'Rp. ' . format_uang($pesanan->total_bayar));
|
||||
$theDiskonAll = $pesanan->diskon_persen != '' || $pesanan->diskon_persen != 0 || $pesanan->diskon_persen != null ? $pesanan->diskon_persen . '%' : '0%';
|
||||
$diskon = $this->buatBaris3Kolom('', 'Diskon:', $theDiskonAll);
|
||||
$rpgrand_total = 'Rp. ' . format_uang($pesanan->grand_total);
|
||||
$grand_Total = $this->buatBaris3Kolom('', 'Grand Total:', $rpgrand_total);
|
||||
$bayar = $this->buatBaris3Kolom('', 'Bayar:', 'Rp. ' . format_uang($pesanan->nominal_bayar));
|
||||
$kembali = $this->buatBaris3Kolom('', 'Kembali:', 'Rp. ' . format_uang($pesanan->nominal_kembali));
|
||||
$terimakasih = "Terima Kasih,\nSelamat Datang Kembali\n";
|
||||
$stkfooter = "@sepiringtelurkeriting";
|
||||
/* Date is kept the same for testing */
|
||||
$date = tanggal_indonesia($pesanan->tanggal_pesanan) . date('H:i', strtotime($pesanan->tanggal_pesanan));
|
||||
// end set data
|
||||
|
||||
// begin print action
|
||||
/* Fill in your own connector here */
|
||||
$connector = null;
|
||||
if ($printernya->printer_connection == 'wired') {
|
||||
$connector = new WindowsPrintConnector($printernya->nama_printer);
|
||||
$connector->finalize();
|
||||
} else {
|
||||
$connector = new NetworkPrintConnector($printernya->ip_address, 9100);
|
||||
}
|
||||
|
||||
/* Start the printer */
|
||||
$printer = new Printer($connector);
|
||||
|
||||
/* Print top logo */
|
||||
$printer->setJustification(Printer::JUSTIFY_CENTER);
|
||||
|
||||
/* Name of shop */
|
||||
// $printer->bitImage($images);
|
||||
$printer->selectPrintMode(Printer::MODE_DOUBLE_WIDTH);
|
||||
$printer->text($stk);
|
||||
$printer->selectPrintMode();
|
||||
$printer->text($address);
|
||||
$printer->setUnderline(Printer::UNDERLINE_DOUBLE);
|
||||
$printer->text($dashline);
|
||||
$printer->selectPrintMode();
|
||||
|
||||
/* Title of receipt */
|
||||
$printer->setEmphasis(true);
|
||||
$printer->text($ordercode);
|
||||
$printer->text($date . "\n");
|
||||
$printer->setEmphasis(false);
|
||||
|
||||
$printer->setJustification(Printer::JUSTIFY_LEFT);
|
||||
|
||||
$printer->text($line1);
|
||||
$printer->text($line2);
|
||||
$printer->text($line3);
|
||||
|
||||
/* Items */
|
||||
$printer->setJustification(Printer::JUSTIFY_LEFT);
|
||||
$printer->setEmphasis(true);
|
||||
|
||||
$printer->setJustification(Printer::JUSTIFY_CENTER);
|
||||
$printer->setUnderline(Printer::UNDERLINE_DOUBLE);
|
||||
$printer->text($dashline);
|
||||
$printer->selectPrintMode();
|
||||
$printer->setJustification(Printer::JUSTIFY_LEFT);
|
||||
|
||||
$printer->setEmphasis(false);
|
||||
foreach ($items as $item) {
|
||||
$printer->text($item);
|
||||
}
|
||||
|
||||
$printer->setJustification(Printer::JUSTIFY_CENTER);
|
||||
$printer->setUnderline(Printer::UNDERLINE_DOUBLE);
|
||||
$printer->text($dashline);
|
||||
$printer->selectPrintMode();
|
||||
$printer->setJustification(Printer::JUSTIFY_LEFT);
|
||||
|
||||
// $printer->text($totalItem);
|
||||
$printer->text($total);
|
||||
$printer->text($diskon);
|
||||
$printer->text($grand_Total);
|
||||
$printer->text($bayar);
|
||||
$printer->text($kembali);
|
||||
|
||||
$printer->setJustification(Printer::JUSTIFY_CENTER);
|
||||
$printer->setUnderline(Printer::UNDERLINE_DOUBLE);
|
||||
$printer->text($dashline);
|
||||
$printer->selectPrintMode();
|
||||
$printer->setJustification(Printer::JUSTIFY_LEFT);
|
||||
|
||||
/* Footer */
|
||||
$printer->setJustification(Printer::JUSTIFY_CENTER);
|
||||
$printer->text($terimakasih);
|
||||
$printer->text($stkfooter);
|
||||
$printer->feed();
|
||||
|
||||
/* Cut the receipt and open the cash drawer */
|
||||
$printer->cut();
|
||||
$printer->pulse();
|
||||
|
||||
$printer->close();
|
||||
// end print action
|
||||
return true;
|
||||
}
|
||||
|
||||
public function print58mmDapur($pesanan, $printernya)
|
||||
{
|
||||
// begin set data
|
||||
$items = [];
|
||||
/* Information for the receipt */
|
||||
foreach ($pesanan->detailPesanan as $key => $value) {
|
||||
$status_pesanan = $value->status_pesanan == 0 ? '(TAKEAWAY)' : ($value->status_pesanan == 3 ? '(CANCEL)' : '');
|
||||
if ($value->keterangan_produk != '') {
|
||||
$items[] = $this->buatBaris1Kolom('(' . $value->jumlah_produk . ') ' . $value->nama_produk . ' ' . $status_pesanan);
|
||||
$items[] = $this->buatBaris1Kolom('Ket: ' . $value->keterangan_produk . "\n");
|
||||
} else {
|
||||
$items[] = $this->buatBaris1Kolom('(' . $value->jumlah_produk . ') ' . $value->nama_produk . ' ' . $status_pesanan . "\n");
|
||||
}
|
||||
}
|
||||
|
||||
$stk = "Sepiring Telur \nKeriting\n";
|
||||
$address = "Jln. Jawa No. 28A, Jember\n";
|
||||
$dashline = " \n";
|
||||
$ordercode = $pesanan->kode_pesanan . "\n";
|
||||
$line1 = $this->buatBaris2Kolom('Meja: ' . $pesanan->nomor_meja, ' Kasir:');
|
||||
$line2 = $this->buatBaris2Kolom('Antrian: ' . $pesanan->nomor_antrian, $pesanan->user->name . 'ssssss');
|
||||
$line3 = $this->buatBaris1Kolom('Pemesan: ' . $pesanan->nama_pemesan);
|
||||
$total_pesanan = $this->buatBaris1Kolom($pesanan->total_pesanan . ' Total item');
|
||||
$keterangan_seluruh = $this->buatBaris1Kolom('Keterangan Pesan Keseluruhan:');
|
||||
$keterangan_pesanannya = $this->buatBaris1Kolom($pesanan->keterangan_pesanan);
|
||||
/* Date is kept the same for testing */
|
||||
$date = tanggal_indonesia($pesanan->tanggal_pesanan) . date('H:i', strtotime($pesanan->tanggal_pesanan));
|
||||
// end set data
|
||||
|
||||
// begin print action
|
||||
/* Fill in your own connector here */
|
||||
$connector = null;
|
||||
if ($printernya->printer_connection == 'wired') {
|
||||
$connector = new WindowsPrintConnector($printernya->nama_printer);
|
||||
$connector->finalize();
|
||||
} else {
|
||||
$connector = new NetworkPrintConnector($printernya->ip_address, 9100);
|
||||
}
|
||||
|
||||
/* Start the printer */
|
||||
$printer = new Printer($connector);
|
||||
|
||||
/* Print top logo */
|
||||
$printer->setJustification(Printer::JUSTIFY_CENTER);
|
||||
|
||||
/* Name of shop */
|
||||
$printer->selectPrintMode(Printer::MODE_DOUBLE_WIDTH);
|
||||
$printer->text($stk);
|
||||
$printer->selectPrintMode();
|
||||
$printer->text($address);
|
||||
$printer->setUnderline(Printer::UNDERLINE_DOUBLE);
|
||||
$printer->text($dashline);
|
||||
$printer->selectPrintMode();
|
||||
|
||||
/* Title of receipt */
|
||||
$printer->setEmphasis(true);
|
||||
$printer->text($ordercode);
|
||||
$printer->text($date . "\n");
|
||||
$printer->setEmphasis(false);
|
||||
|
||||
$printer->setJustification(Printer::JUSTIFY_LEFT);
|
||||
|
||||
$printer->text($line1);
|
||||
$printer->text($line2);
|
||||
$printer->text($line3);
|
||||
|
||||
/* Items */
|
||||
$printer->setJustification(Printer::JUSTIFY_LEFT);
|
||||
$printer->setEmphasis(true);
|
||||
|
||||
$printer->setJustification(Printer::JUSTIFY_CENTER);
|
||||
$printer->setUnderline(Printer::UNDERLINE_DOUBLE);
|
||||
$printer->text($dashline);
|
||||
$printer->selectPrintMode();
|
||||
$printer->setJustification(Printer::JUSTIFY_LEFT);
|
||||
|
||||
$printer->setEmphasis(false);
|
||||
foreach ($items as $item) {
|
||||
$printer->text($item);
|
||||
}
|
||||
|
||||
$printer->setJustification(Printer::JUSTIFY_CENTER);
|
||||
$printer->setUnderline(Printer::UNDERLINE_DOUBLE);
|
||||
$printer->text($dashline);
|
||||
$printer->selectPrintMode();
|
||||
$printer->setJustification(Printer::JUSTIFY_LEFT);
|
||||
|
||||
$printer->text($total_pesanan);
|
||||
$printer->text($keterangan_seluruh);
|
||||
$printer->text($keterangan_pesanannya);
|
||||
|
||||
$printer->setJustification(Printer::JUSTIFY_CENTER);
|
||||
$printer->setUnderline(Printer::UNDERLINE_DOUBLE);
|
||||
$printer->text($dashline);
|
||||
$printer->selectPrintMode();
|
||||
$printer->setJustification(Printer::JUSTIFY_LEFT);
|
||||
|
||||
/* Footer */
|
||||
$printer->feed();
|
||||
|
||||
/* Cut the receipt and open the cash drawer */
|
||||
$printer->cut();
|
||||
$printer->pulse();
|
||||
|
||||
$printer->close();
|
||||
// end print action
|
||||
return true;
|
||||
}
|
||||
|
||||
function buatBaris1Kolom($kolom1)
|
||||
{
|
||||
// Mengatur lebar setiap kolom (dalam satuan karakter)
|
||||
$lebar_kolom_1 = 32;
|
||||
|
||||
// Melakukan wordwrap(), jadi jika karakter teks melebihi lebar kolom, ditambahkan \n
|
||||
$kolom1 = wordwrap($kolom1, $lebar_kolom_1, "\n", true);
|
||||
|
||||
// Merubah hasil wordwrap menjadi array, kolom yang memiliki 2 index array berarti memiliki 2 baris (kena wordwrap)
|
||||
$kolom1Array = explode("\n", $kolom1);
|
||||
|
||||
// Mengambil jumlah baris terbanyak dari kolom-kolom untuk dijadikan titik akhir perulangan
|
||||
$jmlBarisTerbanyak = count($kolom1Array);
|
||||
|
||||
// Mendeklarasikan variabel untuk menampung kolom yang sudah di edit
|
||||
$hasilBaris = array();
|
||||
|
||||
// Melakukan perulangan setiap baris (yang dibentuk wordwrap), untuk menggabungkan setiap kolom menjadi 1 baris
|
||||
for ($i = 0; $i < $jmlBarisTerbanyak; $i++) {
|
||||
|
||||
// memberikan spasi di setiap cell berdasarkan lebar kolom yang ditentukan,
|
||||
$hasilKolom1 = str_pad((isset($kolom1Array[$i]) ? $kolom1Array[$i] : ""), $lebar_kolom_1, " ");
|
||||
|
||||
// Menggabungkan kolom tersebut menjadi 1 baris dan ditampung ke variabel hasil (ada 1 spasi disetiap kolom)
|
||||
$hasilBaris[] = $hasilKolom1;
|
||||
}
|
||||
|
||||
// Hasil yang berupa array, disatukan kembali menjadi string dan tambahkan \n disetiap barisnya.
|
||||
return implode($hasilBaris) . "\n";
|
||||
}
|
||||
|
||||
function buatBaris2Kolom($kolom1, $kolom2)
|
||||
{
|
||||
// Mengatur lebar setiap kolom (dalam satuan karakter)
|
||||
$lebar_kolom_1 = 12;
|
||||
$lebar_kolom_2 = 19;
|
||||
|
||||
// Melakukan wordwrap(), jadi jika karakter teks melebihi lebar kolom, ditambahkan \n
|
||||
$kolom1 = wordwrap($kolom1, $lebar_kolom_1, "\n", true);
|
||||
$kolom2 = wordwrap($kolom2, $lebar_kolom_2, "\n", true);
|
||||
|
||||
// Merubah hasil wordwrap menjadi array, kolom yang memiliki 2 index array berarti memiliki 2 baris (kena wordwrap)
|
||||
$kolom1Array = explode("\n", $kolom1);
|
||||
$kolom2Array = explode("\n", $kolom2);
|
||||
|
||||
// Mengambil jumlah baris terbanyak dari kolom-kolom untuk dijadikan titik akhir perulangan
|
||||
$jmlBarisTerbanyak = max(count($kolom1Array), count($kolom2Array));
|
||||
|
||||
// Mendeklarasikan variabel untuk menampung kolom yang sudah di edit
|
||||
$hasilBaris = array();
|
||||
|
||||
// Melakukan perulangan setiap baris (yang dibentuk wordwrap), untuk menggabungkan setiap kolom menjadi 1 baris
|
||||
for ($i = 0; $i < $jmlBarisTerbanyak; $i++) {
|
||||
|
||||
// memberikan spasi di setiap cell berdasarkan lebar kolom yang ditentukan,
|
||||
$hasilKolom1 = str_pad((isset($kolom1Array[$i]) ? $kolom1Array[$i] : ""), $lebar_kolom_1, " ");
|
||||
// memberikan rata kanan pada kolom 3 dan 4 karena akan kita gunakan untuk harga dan total harga
|
||||
$hasilKolom2 = str_pad((isset($kolom2Array[$i]) ? $kolom2Array[$i] : ""), $lebar_kolom_2, " ", STR_PAD_LEFT);
|
||||
|
||||
// Menggabungkan kolom tersebut menjadi 1 baris dan ditampung ke variabel hasil (ada 1 spasi disetiap kolom)
|
||||
$hasilBaris[] = $hasilKolom1 . " " . $hasilKolom2;
|
||||
}
|
||||
|
||||
// Hasil yang berupa array, disatukan kembali menjadi string dan tambahkan \n disetiap barisnya.
|
||||
return implode($hasilBaris) . "\n";
|
||||
}
|
||||
|
||||
function buatBaris3Kolom($kolom1, $kolom2, $kolom3)
|
||||
{
|
||||
// Mengatur lebar setiap kolom (dalam satuan karakter)
|
||||
$lebar_kolom_1 = 2;
|
||||
$lebar_kolom_2 = 13;
|
||||
$lebar_kolom_3 = 15;
|
||||
|
||||
// Melakukan wordwrap(), jadi jika karakter teks melebihi lebar kolom, ditambahkan \n
|
||||
$kolom1 = wordwrap($kolom1, $lebar_kolom_1, "\n", true);
|
||||
$kolom2 = wordwrap($kolom2, $lebar_kolom_2, "\n", true);
|
||||
$kolom3 = wordwrap($kolom3, $lebar_kolom_3, "\n", true);
|
||||
|
||||
// Merubah hasil wordwrap menjadi array, kolom yang memiliki 2 index array berarti memiliki 2 baris (kena wordwrap)
|
||||
$kolom1Array = explode("\n", $kolom1);
|
||||
$kolom2Array = explode("\n", $kolom2);
|
||||
$kolom3Array = explode("\n", $kolom3);
|
||||
|
||||
// Mengambil jumlah baris terbanyak dari kolom-kolom untuk dijadikan titik akhir perulangan
|
||||
$jmlBarisTerbanyak = max(count($kolom1Array), count($kolom2Array), count($kolom3Array));
|
||||
|
||||
// Mendeklarasikan variabel untuk menampung kolom yang sudah di edit
|
||||
$hasilBaris = array();
|
||||
|
||||
// Melakukan perulangan setiap baris (yang dibentuk wordwrap), untuk menggabungkan setiap kolom menjadi 1 baris
|
||||
for ($i = 0; $i < $jmlBarisTerbanyak; $i++) {
|
||||
|
||||
// memberikan spasi di setiap cell berdasarkan lebar kolom yang ditentukan,
|
||||
$hasilKolom1 = str_pad((isset($kolom1Array[$i]) ? $kolom1Array[$i] : ""), $lebar_kolom_1, " ");
|
||||
// memberikan rata kanan pada kolom 3 dan 4 karena akan kita gunakan untuk harga dan total harga
|
||||
$hasilKolom2 = str_pad((isset($kolom2Array[$i]) ? $kolom2Array[$i] : ""), $lebar_kolom_2, " ", STR_PAD_LEFT);
|
||||
|
||||
$hasilKolom3 = str_pad((isset($kolom3Array[$i]) ? $kolom3Array[$i] : ""), $lebar_kolom_3, " ", STR_PAD_LEFT);
|
||||
|
||||
// Menggabungkan kolom tersebut menjadi 1 baris dan ditampung ke variabel hasil (ada 1 spasi disetiap kolom)
|
||||
$hasilBaris[] = $hasilKolom1 . " " . $hasilKolom2 . " " . $hasilKolom3;
|
||||
}
|
||||
|
||||
// Hasil yang berupa array, disatukan kembali menjadi string dan tambahkan \n disetiap barisnya.
|
||||
return implode($hasilBaris) . "\n";
|
||||
}
|
||||
|
||||
function buatBaris4Kolom($kolom1, $kolom2, $kolom3, $kolom4)
|
||||
{
|
||||
// Mengatur lebar setiap kolom (dalam satuan karakter)
|
||||
$lebar_kolom_1 = 2;
|
||||
$lebar_kolom_2 = 10;
|
||||
$lebar_kolom_3 = 3;
|
||||
$lebar_kolom_4 = 14;
|
||||
|
||||
// Melakukan wordwrap(), jadi jika karakter teks melebihi lebar kolom, ditambahkan \n
|
||||
$kolom1 = wordwrap($kolom1, $lebar_kolom_1, "\n", true);
|
||||
$kolom2 = wordwrap($kolom2, $lebar_kolom_2, "\n", true);
|
||||
$kolom3 = wordwrap($kolom3, $lebar_kolom_3, "\n", true);
|
||||
$kolom4 = wordwrap($kolom4, $lebar_kolom_4, "\n", true);
|
||||
|
||||
// Merubah hasil wordwrap menjadi array, kolom yang memiliki 2 index array berarti memiliki 2 baris (kena wordwrap)
|
||||
$kolom1Array = explode("\n", $kolom1);
|
||||
$kolom2Array = explode("\n", $kolom2);
|
||||
$kolom3Array = explode("\n", $kolom3);
|
||||
$kolom4Array = explode("\n", $kolom4);
|
||||
|
||||
// Mengambil jumlah baris terbanyak dari kolom-kolom untuk dijadikan titik akhir perulangan
|
||||
$jmlBarisTerbanyak = max(count($kolom1Array), count($kolom2Array), count($kolom3Array), count($kolom4Array));
|
||||
|
||||
// Mendeklarasikan variabel untuk menampung kolom yang sudah di edit
|
||||
$hasilBaris = array();
|
||||
|
||||
// Melakukan perulangan setiap baris (yang dibentuk wordwrap), untuk menggabungkan setiap kolom menjadi 1 baris
|
||||
for ($i = 0; $i < $jmlBarisTerbanyak; $i++) {
|
||||
|
||||
// memberikan spasi di setiap cell berdasarkan lebar kolom yang ditentukan,
|
||||
$hasilKolom1 = str_pad((isset($kolom1Array[$i]) ? $kolom1Array[$i] : ""), $lebar_kolom_1, " ");
|
||||
// memberikan rata kanan pada kolom 3 dan 4 karena akan kita gunakan untuk harga dan total harga
|
||||
$hasilKolom2 = str_pad((isset($kolom2Array[$i]) ? $kolom2Array[$i] : ""), $lebar_kolom_2, " ", STR_PAD_LEFT);
|
||||
|
||||
$hasilKolom3 = str_pad((isset($kolom3Array[$i]) ? $kolom3Array[$i] : ""), $lebar_kolom_3, " ", STR_PAD_LEFT);
|
||||
|
||||
$hasilKolom4 = str_pad((isset($kolom4Array[$i]) ? $kolom4Array[$i] : ""), $lebar_kolom_4, " ", STR_PAD_LEFT);
|
||||
|
||||
// Menggabungkan kolom tersebut menjadi 1 baris dan ditampung ke variabel hasil (ada 1 spasi disetiap kolom)
|
||||
$hasilBaris[] = $hasilKolom1 . " " . $hasilKolom2 . " " . $hasilKolom3 . " " . $hasilKolom4;
|
||||
}
|
||||
|
||||
// Hasil yang berupa array, disatukan kembali menjadi string dan tambahkan \n disetiap barisnya.
|
||||
return implode($hasilBaris) . "\n";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,399 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Kasir;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Zelda\EscposPhp\EscposImage;
|
||||
use Zelda\EscposPhp\PrintConnectors\NetworkPrintConnector;
|
||||
use Zelda\EscposPhp\PrintConnectors\WindowsPrintConnector;
|
||||
use Zelda\EscposPhp\Printer;
|
||||
|
||||
// jumlah character yang bisa ditampung oleh printer 88mm adalah 48 karakter per baris tapi yang dipakai hanya 46 atau 42 saja
|
||||
class kolomPrinter88mmController extends Controller
|
||||
{
|
||||
public function print88mm($pesanan, $printernya)
|
||||
{
|
||||
// begin set data
|
||||
$items = [];
|
||||
/* Information for the receipt */
|
||||
foreach ($pesanan->detailPesanan as $key => $value) {
|
||||
|
||||
$theDiskon = $value->diskon_persen != '' || $value->diskon_persen != 0 || $value->diskon_persen != null ? $value->diskon_persen . '%' : '';
|
||||
$items[] = $this->buatBaris1Kolom($value->nama_produk);
|
||||
// $items[] = new itemReceipt($value->jumlah_produk . ' Rp. ' . format_uang($value->harga_produk) . ' ' . $theDiskon, 'Rp. ' . format_uang($value->total_harga_produk));
|
||||
$items[] = $this->buatBaris4Kolom($value->jumlah_produk, 'Rp. ' . format_uang($value->harga_produk), $theDiskon, 'Rp. ' . format_uang($value->total_harga_produk));
|
||||
}
|
||||
|
||||
// $images = EscposImage::load(env('PATH_LOGO_STK'), false);
|
||||
$stk = "Sepiring Telur Keriting\n";
|
||||
$address = "Jln. Jawa No. 28A, Jember\n";
|
||||
$dashline = " \n";
|
||||
$ordercode = $pesanan->kode_pesanan . "\n";
|
||||
$line1 = $this->buatBaris2Kolom('Meja: ' . $pesanan->nomor_meja, ' Kasir:');
|
||||
$line2 = $this->buatBaris2Kolom('Antrian: ' . $pesanan->nomor_antrian, $pesanan->user->name . 'ssssss');
|
||||
$line3 = $this->buatBaris1Kolom('Pemesan: ' . $pesanan->nama_pemesan);
|
||||
|
||||
$total = $this->buatBaris3Kolom($pesanan->total_pesanan, 'Total: ', 'Rp. ' . format_uang($pesanan->total_bayar));
|
||||
$theDiskonAll = $pesanan->diskon_persen != '' || $pesanan->diskon_persen != 0 || $pesanan->diskon_persen != null ? $pesanan->diskon_persen . '%' : '0%';
|
||||
$diskon = $this->buatBaris3Kolom('', 'Diskon: ', $theDiskonAll);
|
||||
$rpgrand_total = 'Rp. ' . format_uang($pesanan->grand_total);
|
||||
$grand_Total = $this->buatBaris3Kolom('', 'Grand Total: ', $rpgrand_total);
|
||||
$bayar = $this->buatBaris3Kolom('', 'Bayar: ', 'Rp. ' . format_uang($pesanan->nominal_bayar));
|
||||
$kembali = $this->buatBaris3Kolom('', 'Kembali: ', 'Rp. ' . format_uang($pesanan->nominal_kembali));
|
||||
$terimakasih = "Terima Kasih, Selamat Datang Kembali\n";
|
||||
$stkfooter = "@sepiringtelurkeriting";
|
||||
/* Date is kept the same for testing */
|
||||
$date = tanggal_indonesia($pesanan->tanggal_pesanan) . date('H:i', strtotime($pesanan->tanggal_pesanan));
|
||||
// end set data
|
||||
|
||||
// begin print action
|
||||
/* Fill in your own connector here */
|
||||
$connector = null;
|
||||
if ($printernya->printer_connection == 'wired') {
|
||||
$connector = new WindowsPrintConnector($printernya->nama_printer);
|
||||
$connector->finalize();
|
||||
} else {
|
||||
$connector = new NetworkPrintConnector($printernya->ip_address, 9100);
|
||||
}
|
||||
|
||||
/* Start the printer */
|
||||
$printer = new Printer($connector);
|
||||
|
||||
/* Print top logo */
|
||||
$printer->setJustification(Printer::JUSTIFY_CENTER);
|
||||
|
||||
/* Name of shop */
|
||||
// $printer->bitImage($images);
|
||||
$printer->selectPrintMode(Printer::MODE_DOUBLE_WIDTH);
|
||||
$printer->text($stk);
|
||||
$printer->selectPrintMode();
|
||||
$printer->text($address);
|
||||
$printer->setUnderline(Printer::UNDERLINE_DOUBLE);
|
||||
$printer->text($dashline);
|
||||
$printer->selectPrintMode();
|
||||
|
||||
/* Title of receipt */
|
||||
$printer->setEmphasis(true);
|
||||
$printer->selectPrintMode(Printer::MODE_DOUBLE_WIDTH);
|
||||
$printer->text($ordercode);
|
||||
$printer->selectPrintMode();
|
||||
$printer->text($date . "\n");
|
||||
$printer->setEmphasis(false);
|
||||
|
||||
$printer->setJustification(Printer::JUSTIFY_LEFT);
|
||||
|
||||
$printer->text($line1);
|
||||
$printer->text($line2);
|
||||
$printer->text($line3);
|
||||
|
||||
/* Items */
|
||||
$printer->setJustification(Printer::JUSTIFY_LEFT);
|
||||
$printer->setEmphasis(true);
|
||||
|
||||
$printer->setJustification(Printer::JUSTIFY_CENTER);
|
||||
$printer->setUnderline(Printer::UNDERLINE_DOUBLE);
|
||||
$printer->text($dashline);
|
||||
$printer->selectPrintMode();
|
||||
$printer->setJustification(Printer::JUSTIFY_LEFT);
|
||||
|
||||
$printer->setEmphasis(false);
|
||||
foreach ($items as $item) {
|
||||
$printer->text($item);
|
||||
}
|
||||
|
||||
$printer->setJustification(Printer::JUSTIFY_CENTER);
|
||||
$printer->setUnderline(Printer::UNDERLINE_DOUBLE);
|
||||
$printer->text($dashline);
|
||||
$printer->selectPrintMode();
|
||||
$printer->setJustification(Printer::JUSTIFY_LEFT);
|
||||
|
||||
// $printer->text($totalItem);
|
||||
$printer->text($total);
|
||||
$printer->text($diskon);
|
||||
$printer->text($grand_Total);
|
||||
$printer->text($bayar);
|
||||
$printer->text($kembali);
|
||||
|
||||
$printer->setJustification(Printer::JUSTIFY_CENTER);
|
||||
$printer->setUnderline(Printer::UNDERLINE_DOUBLE);
|
||||
$printer->text($dashline);
|
||||
$printer->selectPrintMode();
|
||||
$printer->setJustification(Printer::JUSTIFY_LEFT);
|
||||
|
||||
/* Footer */
|
||||
$printer->setJustification(Printer::JUSTIFY_CENTER);
|
||||
$printer->text($terimakasih);
|
||||
$printer->text($stkfooter);
|
||||
$printer->feed();
|
||||
|
||||
/* Cut the receipt and open the cash drawer */
|
||||
$printer->cut();
|
||||
$printer->pulse();
|
||||
|
||||
$printer->close();
|
||||
// end print action
|
||||
return true;
|
||||
}
|
||||
|
||||
public function print88mmDapur($pesanan, $printernya)
|
||||
{
|
||||
// begin set data
|
||||
$items = [];
|
||||
/* Information for the receipt */
|
||||
foreach ($pesanan->detailPesanan as $key => $value) {
|
||||
$status_pesanan = $value->status_pesanan == 0 ? '(TAKEAWAY)' : ($value->status_pesanan == 3 ? '(CANCEL)' : '');
|
||||
if ($value->keterangan_produk != '') {
|
||||
$items[] = $this->buatBaris1Kolom('(' . $value->jumlah_produk . ') ' . $value->nama_produk . ' ' . $status_pesanan);
|
||||
$items[] = $this->buatBaris1Kolom('Ket: ' . $value->keterangan_produk . "\n");
|
||||
} else {
|
||||
$items[] = $this->buatBaris1Kolom('(' . $value->jumlah_produk . ') ' . $value->nama_produk . ' ' . $status_pesanan . "\n");
|
||||
}
|
||||
}
|
||||
|
||||
$stk = "Sepiring Telur Keriting\n";
|
||||
$address = "Jln. Jawa No. 28A, Jember\n";
|
||||
$dashline = " \n";
|
||||
$ordercode = $pesanan->kode_pesanan . "\n";
|
||||
$line1 = $this->buatBaris2Kolom('Meja: ' . $pesanan->nomor_meja, ' Kasir:');
|
||||
$line2 = $this->buatBaris2Kolom('Antrian: ' . $pesanan->nomor_antrian, $pesanan->user->name . 'ssssss');
|
||||
$line3 = $this->buatBaris1Kolom('Pemesan: ' . $pesanan->nama_pemesan);
|
||||
$total_pesanan = $this->buatBaris1Kolom($pesanan->total_pesanan . ' Total item');
|
||||
$keterangan_seluruh = $this->buatBaris1Kolom('Keterangan Pesan Keseluruhan:');
|
||||
$keterangan_pesanannya = $this->buatBaris1Kolom($pesanan->keterangan_pesanan);
|
||||
/* Date is kept the same for testing */
|
||||
$date = tanggal_indonesia($pesanan->tanggal_pesanan) . date('H:i', strtotime($pesanan->tanggal_pesanan));
|
||||
// end set data
|
||||
|
||||
// begin print action
|
||||
/* Fill in your own connector here */
|
||||
$connector = null;
|
||||
if ($printernya->printer_connection == 'wired') {
|
||||
$connector = new WindowsPrintConnector($printernya->nama_printer);
|
||||
} else {
|
||||
$connector = new NetworkPrintConnector($printernya->ip_address, 9100);
|
||||
}
|
||||
/* Start the printer */
|
||||
$printer = new Printer($connector);
|
||||
|
||||
/* Print top logo */
|
||||
$printer->setJustification(Printer::JUSTIFY_CENTER);
|
||||
|
||||
/* Name of shop */
|
||||
$printer->selectPrintMode(Printer::MODE_DOUBLE_WIDTH);
|
||||
$printer->text($stk);
|
||||
$printer->selectPrintMode();
|
||||
$printer->text($address);
|
||||
$printer->setUnderline(Printer::UNDERLINE_DOUBLE);
|
||||
$printer->text($dashline);
|
||||
$printer->selectPrintMode();
|
||||
|
||||
/* Title of receipt */
|
||||
$printer->setEmphasis(true);
|
||||
$printer->text($ordercode);
|
||||
$printer->text($date . "\n");
|
||||
$printer->setEmphasis(false);
|
||||
|
||||
$printer->setJustification(Printer::JUSTIFY_LEFT);
|
||||
|
||||
$printer->text($line1);
|
||||
$printer->text($line2);
|
||||
$printer->text($line3);
|
||||
|
||||
/* Items */
|
||||
$printer->setJustification(Printer::JUSTIFY_LEFT);
|
||||
$printer->setEmphasis(true);
|
||||
|
||||
$printer->setJustification(Printer::JUSTIFY_CENTER);
|
||||
$printer->setUnderline(Printer::UNDERLINE_DOUBLE);
|
||||
$printer->text($dashline);
|
||||
$printer->selectPrintMode();
|
||||
$printer->setJustification(Printer::JUSTIFY_LEFT);
|
||||
|
||||
$printer->setEmphasis(false);
|
||||
foreach ($items as $item) {
|
||||
$printer->text($item);
|
||||
}
|
||||
|
||||
$printer->setJustification(Printer::JUSTIFY_CENTER);
|
||||
$printer->setUnderline(Printer::UNDERLINE_DOUBLE);
|
||||
$printer->text($dashline);
|
||||
$printer->selectPrintMode();
|
||||
$printer->setJustification(Printer::JUSTIFY_LEFT);
|
||||
|
||||
$printer->text($total_pesanan);
|
||||
$printer->text($keterangan_seluruh);
|
||||
$printer->text($keterangan_pesanannya);
|
||||
|
||||
$printer->setJustification(Printer::JUSTIFY_CENTER);
|
||||
$printer->setUnderline(Printer::UNDERLINE_DOUBLE);
|
||||
$printer->text($dashline);
|
||||
$printer->selectPrintMode();
|
||||
$printer->setJustification(Printer::JUSTIFY_LEFT);
|
||||
|
||||
/* Footer */
|
||||
$printer->feed();
|
||||
|
||||
/* Cut the receipt and open the cash drawer */
|
||||
$printer->cut();
|
||||
$printer->pulse();
|
||||
|
||||
$printer->close();
|
||||
// end print action
|
||||
return true;
|
||||
}
|
||||
|
||||
function buatBaris1Kolom($kolom1)
|
||||
{
|
||||
// Mengatur lebar setiap kolom (dalam satuan karakter)
|
||||
$lebar_kolom_1 = 46;
|
||||
|
||||
// Melakukan wordwrap(), jadi jika karakter teks melebihi lebar kolom, ditambahkan \n
|
||||
$kolom1 = wordwrap($kolom1, $lebar_kolom_1, "\n", true);
|
||||
|
||||
// Merubah hasil wordwrap menjadi array, kolom yang memiliki 2 index array berarti memiliki 2 baris (kena wordwrap)
|
||||
$kolom1Array = explode("\n", $kolom1);
|
||||
|
||||
// Mengambil jumlah baris terbanyak dari kolom-kolom untuk dijadikan titik akhir perulangan
|
||||
$jmlBarisTerbanyak = count($kolom1Array);
|
||||
|
||||
// Mendeklarasikan variabel untuk menampung kolom yang sudah di edit
|
||||
$hasilBaris = array();
|
||||
|
||||
// Melakukan perulangan setiap baris (yang dibentuk wordwrap), untuk menggabungkan setiap kolom menjadi 1 baris
|
||||
for ($i = 0; $i < $jmlBarisTerbanyak; $i++) {
|
||||
|
||||
// memberikan spasi di setiap cell berdasarkan lebar kolom yang ditentukan,
|
||||
$hasilKolom1 = str_pad((isset($kolom1Array[$i]) ? $kolom1Array[$i] : ""), $lebar_kolom_1, " ");
|
||||
|
||||
// Menggabungkan kolom tersebut menjadi 1 baris dan ditampung ke variabel hasil (ada 1 spasi disetiap kolom)
|
||||
$hasilBaris[] = $hasilKolom1;
|
||||
}
|
||||
|
||||
// Hasil yang berupa array, disatukan kembali menjadi string dan tambahkan \n disetiap barisnya.
|
||||
return implode($hasilBaris) . "\n";
|
||||
}
|
||||
|
||||
function buatBaris2Kolom($kolom1, $kolom2)
|
||||
{
|
||||
// Mengatur lebar setiap kolom (dalam satuan karakter)
|
||||
$lebar_kolom_1 = 23;
|
||||
$lebar_kolom_2 = 23;
|
||||
|
||||
// Melakukan wordwrap(), jadi jika karakter teks melebihi lebar kolom, ditambahkan \n
|
||||
$kolom1 = wordwrap($kolom1, $lebar_kolom_1, "\n", true);
|
||||
$kolom2 = wordwrap($kolom2, $lebar_kolom_2, "\n", true);
|
||||
|
||||
// Merubah hasil wordwrap menjadi array, kolom yang memiliki 2 index array berarti memiliki 2 baris (kena wordwrap)
|
||||
$kolom1Array = explode("\n", $kolom1);
|
||||
$kolom2Array = explode("\n", $kolom2);
|
||||
|
||||
// Mengambil jumlah baris terbanyak dari kolom-kolom untuk dijadikan titik akhir perulangan
|
||||
$jmlBarisTerbanyak = max(count($kolom1Array), count($kolom2Array));
|
||||
|
||||
// Mendeklarasikan variabel untuk menampung kolom yang sudah di edit
|
||||
$hasilBaris = array();
|
||||
|
||||
// Melakukan perulangan setiap baris (yang dibentuk wordwrap), untuk menggabungkan setiap kolom menjadi 1 baris
|
||||
for ($i = 0; $i < $jmlBarisTerbanyak; $i++) {
|
||||
|
||||
// memberikan spasi di setiap cell berdasarkan lebar kolom yang ditentukan,
|
||||
$hasilKolom1 = str_pad((isset($kolom1Array[$i]) ? $kolom1Array[$i] : ""), $lebar_kolom_1, " ");
|
||||
// memberikan rata kanan pada kolom 3 dan 4 karena akan kita gunakan untuk harga dan total harga
|
||||
$hasilKolom2 = str_pad((isset($kolom2Array[$i]) ? $kolom2Array[$i] : ""), $lebar_kolom_2, " ", STR_PAD_LEFT);
|
||||
|
||||
// Menggabungkan kolom tersebut menjadi 1 baris dan ditampung ke variabel hasil (ada 1 spasi disetiap kolom)
|
||||
$hasilBaris[] = $hasilKolom1 . " " . $hasilKolom2;
|
||||
}
|
||||
|
||||
// Hasil yang berupa array, disatukan kembali menjadi string dan tambahkan \n disetiap barisnya.
|
||||
return implode($hasilBaris) . "\n";
|
||||
}
|
||||
|
||||
function buatBaris3Kolom($kolom1, $kolom2, $kolom3)
|
||||
{
|
||||
// Mengatur lebar setiap kolom (dalam satuan karakter)
|
||||
$lebar_kolom_1 = 4;
|
||||
$lebar_kolom_2 = 18;
|
||||
$lebar_kolom_3 = 24;
|
||||
|
||||
// Melakukan wordwrap(), jadi jika karakter teks melebihi lebar kolom, ditambahkan \n
|
||||
$kolom1 = wordwrap($kolom1, $lebar_kolom_1, "\n", true);
|
||||
$kolom2 = wordwrap($kolom2, $lebar_kolom_2, "\n", true);
|
||||
$kolom3 = wordwrap($kolom3, $lebar_kolom_3, "\n", true);
|
||||
|
||||
// Merubah hasil wordwrap menjadi array, kolom yang memiliki 2 index array berarti memiliki 2 baris (kena wordwrap)
|
||||
$kolom1Array = explode("\n", $kolom1);
|
||||
$kolom2Array = explode("\n", $kolom2);
|
||||
$kolom3Array = explode("\n", $kolom3);
|
||||
|
||||
// Mengambil jumlah baris terbanyak dari kolom-kolom untuk dijadikan titik akhir perulangan
|
||||
$jmlBarisTerbanyak = max(count($kolom1Array), count($kolom2Array), count($kolom3Array));
|
||||
|
||||
// Mendeklarasikan variabel untuk menampung kolom yang sudah di edit
|
||||
$hasilBaris = array();
|
||||
|
||||
// Melakukan perulangan setiap baris (yang dibentuk wordwrap), untuk menggabungkan setiap kolom menjadi 1 baris
|
||||
for ($i = 0; $i < $jmlBarisTerbanyak; $i++) {
|
||||
|
||||
// memberikan spasi di setiap cell berdasarkan lebar kolom yang ditentukan,
|
||||
$hasilKolom1 = str_pad((isset($kolom1Array[$i]) ? $kolom1Array[$i] : ""), $lebar_kolom_1, " ");
|
||||
// memberikan rata kanan pada kolom 3 dan 4 karena akan kita gunakan untuk harga dan total harga
|
||||
$hasilKolom2 = str_pad((isset($kolom2Array[$i]) ? $kolom2Array[$i] : ""), $lebar_kolom_2, " ", STR_PAD_LEFT);
|
||||
|
||||
$hasilKolom3 = str_pad((isset($kolom3Array[$i]) ? $kolom3Array[$i] : ""), $lebar_kolom_3, " ", STR_PAD_LEFT);
|
||||
|
||||
// Menggabungkan kolom tersebut menjadi 1 baris dan ditampung ke variabel hasil (ada 1 spasi disetiap kolom)
|
||||
$hasilBaris[] = $hasilKolom1 . " " . $hasilKolom2 . " " . $hasilKolom3;
|
||||
}
|
||||
|
||||
// Hasil yang berupa array, disatukan kembali menjadi string dan tambahkan \n disetiap barisnya.
|
||||
return implode($hasilBaris) . "\n";
|
||||
}
|
||||
|
||||
function buatBaris4Kolom($kolom1, $kolom2, $kolom3, $kolom4)
|
||||
{
|
||||
// Mengatur lebar setiap kolom (dalam satuan karakter)
|
||||
$lebar_kolom_1 = 4;
|
||||
$lebar_kolom_2 = 12;
|
||||
$lebar_kolom_3 = 4;
|
||||
$lebar_kolom_4 = 25;
|
||||
|
||||
// Melakukan wordwrap(), jadi jika karakter teks melebihi lebar kolom, ditambahkan \n
|
||||
$kolom1 = wordwrap($kolom1, $lebar_kolom_1, "\n", true);
|
||||
$kolom2 = wordwrap($kolom2, $lebar_kolom_2, "\n", true);
|
||||
$kolom3 = wordwrap($kolom3, $lebar_kolom_3, "\n", true);
|
||||
$kolom4 = wordwrap($kolom4, $lebar_kolom_4, "\n", true);
|
||||
|
||||
// Merubah hasil wordwrap menjadi array, kolom yang memiliki 2 index array berarti memiliki 2 baris (kena wordwrap)
|
||||
$kolom1Array = explode("\n", $kolom1);
|
||||
$kolom2Array = explode("\n", $kolom2);
|
||||
$kolom3Array = explode("\n", $kolom3);
|
||||
$kolom4Array = explode("\n", $kolom4);
|
||||
|
||||
// Mengambil jumlah baris terbanyak dari kolom-kolom untuk dijadikan titik akhir perulangan
|
||||
$jmlBarisTerbanyak = max(count($kolom1Array), count($kolom2Array), count($kolom3Array), count($kolom4Array));
|
||||
|
||||
// Mendeklarasikan variabel untuk menampung kolom yang sudah di edit
|
||||
$hasilBaris = array();
|
||||
|
||||
// Melakukan perulangan setiap baris (yang dibentuk wordwrap), untuk menggabungkan setiap kolom menjadi 1 baris
|
||||
for ($i = 0; $i < $jmlBarisTerbanyak; $i++) {
|
||||
|
||||
// memberikan spasi di setiap cell berdasarkan lebar kolom yang ditentukan,
|
||||
$hasilKolom1 = str_pad((isset($kolom1Array[$i]) ? $kolom1Array[$i] : ""), $lebar_kolom_1, " ");
|
||||
// memberikan rata kanan pada kolom 3 dan 4 karena akan kita gunakan untuk harga dan total harga
|
||||
$hasilKolom2 = str_pad((isset($kolom2Array[$i]) ? $kolom2Array[$i] : ""), $lebar_kolom_2, " ", STR_PAD_LEFT);
|
||||
|
||||
$hasilKolom3 = str_pad((isset($kolom3Array[$i]) ? $kolom3Array[$i] : ""), $lebar_kolom_3, " ", STR_PAD_LEFT);
|
||||
|
||||
$hasilKolom4 = str_pad((isset($kolom4Array[$i]) ? $kolom4Array[$i] : ""), $lebar_kolom_4, " ", STR_PAD_LEFT);
|
||||
|
||||
// Menggabungkan kolom tersebut menjadi 1 baris dan ditampung ke variabel hasil (ada 1 spasi disetiap kolom)
|
||||
$hasilBaris[] = $hasilKolom1 . " " . $hasilKolom2 . " " . $hasilKolom3 . " " . $hasilKolom4;
|
||||
}
|
||||
|
||||
// Hasil yang berupa array, disatukan kembali menjadi string dan tambahkan \n disetiap barisnya.
|
||||
return implode($hasilBaris) . "\n";
|
||||
}
|
||||
}
|
|
@ -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::error('Printing: ' . $pesanan->id);
|
||||
$print = new PrintOutController();
|
||||
|
||||
$print->print($pesanan->id);
|
||||
Log::error('Printed: ' . $pesanan->id);
|
||||
} catch (\Throwable $th) {
|
||||
//throw $th;
|
||||
Log::error($th->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -16,6 +16,7 @@ class BukuBesar extends Model
|
|||
'tanggal',
|
||||
'rekening_coa_id',
|
||||
'pesanans_id',
|
||||
'pengeluaran_id',
|
||||
'kode_rekening_coa',
|
||||
'keterangan_coa',
|
||||
'keterangan',
|
||||
|
|
|
@ -19,6 +19,7 @@ class DetailPesanan extends Model
|
|||
'nama_produk',
|
||||
'harga_produk',
|
||||
'jumlah_produk',
|
||||
'status_pesanan', // 0=takeaway,1=default,2=dinein,3=cancel
|
||||
'total_harga_produk',
|
||||
'keterangan_produk',
|
||||
'diskon_id',
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Traits\Blameable;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class MasterDistributor extends Model
|
||||
{
|
||||
use HasFactory, Blameable, SoftDeletes;
|
||||
|
||||
protected $table = 'master_distributors';
|
||||
|
||||
protected $fillable = [
|
||||
'nama_distributor',
|
||||
'alamat',
|
||||
'telepon',
|
||||
];
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Traits\Blameable;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class MasterSatuan extends Model
|
||||
{
|
||||
use HasFactory, Blameable, SoftDeletes;
|
||||
|
||||
protected $table = 'master_satuans';
|
||||
|
||||
protected $fillable = [
|
||||
'nama_satuan',
|
||||
'simbol'
|
||||
];
|
||||
}
|
|
@ -2,21 +2,45 @@
|
|||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Traits\Blameable;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Pengeluaran extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use HasFactory, Blameable, SoftDeletes;
|
||||
|
||||
protected $table = 'pengeluaran';
|
||||
protected $guarded = [];
|
||||
|
||||
public function user(){
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id');
|
||||
}
|
||||
|
||||
public function jenis_kelamin(){
|
||||
public function jenis_kelamin()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id');
|
||||
}
|
||||
|
||||
public function rekeningCoa()
|
||||
{
|
||||
return $this->belongsTo(RekeningCoa::class, 'rekening_coa_id');
|
||||
}
|
||||
|
||||
public function rekeningCoaTransfer()
|
||||
{
|
||||
return $this->belongsTo(RekeningCoa::class, 'rekening_coa_transfer_id');
|
||||
}
|
||||
|
||||
public function masterDistributor()
|
||||
{
|
||||
return $this->belongsTo(MasterDistributor::class, 'master_distributors_id');
|
||||
}
|
||||
|
||||
public function masterSatuan()
|
||||
{
|
||||
return $this->belongsTo(MasterSatuan::class, 'master_satuans_id');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Traits\Blameable;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class PerangkatPrinter extends Model
|
||||
{
|
||||
use HasFactory, Blameable, SoftDeletes;
|
||||
|
||||
protected $table = 'perangkat_printers';
|
||||
protected $fillable = ['nama_printer', 'ip_address', 'printer_connection', 'printer_mm', 'printer_for', 'status'];
|
||||
}
|
|
@ -34,7 +34,7 @@ class Pesanan extends Model
|
|||
'diskon_rupiah',
|
||||
'user_id',
|
||||
'jenis_pembayaran',
|
||||
'coa_kas',
|
||||
'rekening_coa_id',
|
||||
];
|
||||
|
||||
public function detailPesanan()
|
||||
|
@ -62,4 +62,9 @@ class Pesanan extends Model
|
|||
{
|
||||
return $this->hasMany(BukuBesar::class, 'pesanans_id');
|
||||
}
|
||||
|
||||
public function rekening_coa()
|
||||
{
|
||||
return $this->belongsTo(RekeningCoa::class, 'rekening_coa_id');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
"license": "MIT",
|
||||
"require": {
|
||||
"php": "^8.1",
|
||||
"enqueue/amqp-bunny": "^0.10.19",
|
||||
"guzzlehttp/guzzle": "^7.2",
|
||||
"laravel/framework": "^10.10",
|
||||
"laravel/sanctum": "^3.3",
|
||||
|
@ -16,7 +17,9 @@
|
|||
"mpdf/mpdf": "^8.2",
|
||||
"realrashid/sweet-alert": "^6.0",
|
||||
"spatie/laravel-permission": "^6.3",
|
||||
"yajra/laravel-datatables": "^10.1"
|
||||
"vladimir-yuldashev/laravel-queue-rabbitmq": "^13.3",
|
||||
"yajra/laravel-datatables": "^10.1",
|
||||
"zelda/escpos-php": "@dev"
|
||||
},
|
||||
"require-dev": {
|
||||
"fakerphp/faker": "^1.9.1",
|
||||
|
@ -27,6 +30,15 @@
|
|||
"phpunit/phpunit": "^10.1",
|
||||
"spatie/laravel-ignition": "^2.0"
|
||||
},
|
||||
"repositories": [
|
||||
{
|
||||
"type": "path",
|
||||
"url": "./packages/escpos-php",
|
||||
"options": {
|
||||
"symlink": true
|
||||
}
|
||||
}
|
||||
],
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"App\\": "app/",
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -71,6 +71,80 @@ return [
|
|||
'after_commit' => false,
|
||||
],
|
||||
|
||||
'rabbitmq' => [
|
||||
'driver' => 'rabbitmq',
|
||||
/*
|
||||
* Set to "horizon" if you wish to use Laravel Horizon.
|
||||
*/
|
||||
'worker' => env('RABBITMQ_WORKER', 'default'),
|
||||
'dsn' => env('RABBITMQ_DSN', null),
|
||||
/*
|
||||
* Could be one a class that implements \Interop\Amqp\AmqpConnectionFactory for example:
|
||||
* - \EnqueueAmqpExt\AmqpConnectionFactory if you install enqueue/amqp-ext
|
||||
* - \EnqueueAmqpLib\AmqpConnectionFactory if you install enqueue/amqp-lib
|
||||
* - \EnqueueAmqpBunny\AmqpConnectionFactory if you install enqueue/amqp-bunny
|
||||
*/
|
||||
'factory_class' => \Enqueue\AmqpBunny\AmqpConnectionFactory::class,
|
||||
'host' => env('RABBITMQ_HOST', '127.0.0.1'),
|
||||
'port' => env('RABBITMQ_PORT', 5672),
|
||||
'vhost' => env('RABBITMQ_VHOST', '/'),
|
||||
'login' => env('RABBITMQ_LOGIN', 'guest'),
|
||||
'password' => env('RABBITMQ_PASSWORD', 'guest'),
|
||||
'queue' => env('RABBITMQ_QUEUE', 'default'),
|
||||
'options' => [
|
||||
'exchange' => [
|
||||
'name' => env('RABBITMQ_EXCHANGE_NAME'),
|
||||
/*
|
||||
* Determine if exchange should be created if it does not exist.
|
||||
*/
|
||||
'declare' => env('RABBITMQ_EXCHANGE_DECLARE', true),
|
||||
/*
|
||||
* Read more about possible values at https://www.rabbitmq.com/tutorials/amqp-concepts.html
|
||||
*/
|
||||
'type' => env('RABBITMQ_EXCHANGE_TYPE', \Interop\Amqp\AmqpTopic::TYPE_DIRECT),
|
||||
'passive' => env('RABBITMQ_EXCHANGE_PASSIVE', false),
|
||||
'durable' => env('RABBITMQ_EXCHANGE_DURABLE', true),
|
||||
'auto_delete' => env('RABBITMQ_EXCHANGE_AUTODELETE', false),
|
||||
'arguments' => env('RABBITMQ_EXCHANGE_ARGUMENTS'),
|
||||
],
|
||||
'queue' => [
|
||||
/*
|
||||
* Determine if queue should be created if it does not exist.
|
||||
*/
|
||||
'declare' => env('RABBITMQ_QUEUE_DECLARE', true),
|
||||
/*
|
||||
* Determine if queue should be binded to the exchange created.
|
||||
*/
|
||||
'bind' => env('RABBITMQ_QUEUE_DECLARE_BIND', true),
|
||||
/*
|
||||
* Read more about possible values at https://www.rabbitmq.com/tutorials/amqp-concepts.html
|
||||
*/
|
||||
'passive' => env('RABBITMQ_QUEUE_PASSIVE', false),
|
||||
'durable' => env('RABBITMQ_QUEUE_DURABLE', true),
|
||||
'exclusive' => env('RABBITMQ_QUEUE_EXCLUSIVE', false),
|
||||
'auto_delete' => env('RABBITMQ_QUEUE_AUTODELETE', false),
|
||||
'arguments' => env('RABBITMQ_QUEUE_ARGUMENTS'),
|
||||
],
|
||||
],
|
||||
/*
|
||||
* Determine the number of seconds to sleep if there's an error communicating with rabbitmq
|
||||
* If set to false, it'll throw an exception rather than doing the sleep for X seconds.
|
||||
*/
|
||||
'sleep_on_error' => env('RABBITMQ_ERROR_SLEEP', 5),
|
||||
/*
|
||||
* Optional SSL params if an SSL connection is used
|
||||
* Using an SSL connection will also require to configure your RabbitMQ to enable SSL. More details can be founds here: https://www.rabbitmq.com/ssl.html
|
||||
*/
|
||||
'ssl_params' => [
|
||||
'ssl_on' => env('RABBITMQ_SSL', false),
|
||||
'cafile' => env('RABBITMQ_SSL_CAFILE', null),
|
||||
'local_cert' => env('RABBITMQ_SSL_LOCALCERT', null),
|
||||
'local_key' => env('RABBITMQ_SSL_LOCALKEY', null),
|
||||
'verify_peer' => env('RABBITMQ_SSL_VERIFY_PEER', true),
|
||||
'passphrase' => env('RABBITMQ_SSL_PASSPHRASE', null),
|
||||
],
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
/*
|
||||
|
|
Binary file not shown.
|
@ -0,0 +1,28 @@
|
|||
<?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::table('detail_pesanans', function (Blueprint $table) {
|
||||
$table->enum('status_pesanan', [0, 1, 2, 3])->default(1)->comment('0=takeaway,1=default,2=dinein,3=cancel')->after('jumlah_produk');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('detail_pesanans', function (Blueprint $table) {
|
||||
$table->dropColumn('status_pesanan');
|
||||
});
|
||||
}
|
||||
};
|
|
@ -0,0 +1,30 @@
|
|||
<?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::table('pesanans', function (Blueprint $table) {
|
||||
$table->dropForeign(['coa_kas']);
|
||||
$table->dropColumn('coa_kas');
|
||||
$table->foreignId('rekening_coa_id')->nullable()->after('jenis_pembayaran')->comment('relation in id coa kas')->references('id')->on('rekening_coa')->onUpdate('cascade')->onDelete('cascade');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('pesanans', function (Blueprint $table) {
|
||||
$table->dropColumn('coa_kas');
|
||||
});
|
||||
}
|
||||
};
|
|
@ -0,0 +1,38 @@
|
|||
<?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('perangkat_printers', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string("nama_printer")->nullable();
|
||||
$table->enum("printer_mm", ["80", "58"])->default("80")->comment("0=80, 1=58");
|
||||
$table->enum("printer_connection", ["wireless", "wired"])->default("wired")->comment("0=wireless, 1=wired/usb");
|
||||
$table->string("ip_address")->nullable();
|
||||
$table->enum("printer_for", ["kasir", "dapur"])->default("kasir")->comment("0=kasir, 1=dapur");
|
||||
$table->enum("status", [1, 0])->default(0)->comment("0=nonaktif, 1=aktif");
|
||||
|
||||
$table->unsignedBigInteger("updated_by")->nullable();
|
||||
$table->unsignedBigInteger("created_by")->nullable();
|
||||
$table->unsignedBigInteger("deleted_by")->nullable();
|
||||
$table->softDeletes();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('perangkat_printers');
|
||||
}
|
||||
};
|
|
@ -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');
|
||||
}
|
||||
};
|
|
@ -0,0 +1,34 @@
|
|||
<?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('master_satuans', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string("nama_satuan")->nullable();
|
||||
$table->string("simbol")->nullable();
|
||||
|
||||
$table->unsignedBigInteger("updated_by")->nullable();
|
||||
$table->unsignedBigInteger("created_by")->nullable();
|
||||
$table->unsignedBigInteger("deleted_by")->nullable();
|
||||
$table->softDeletes();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('master_satuans');
|
||||
}
|
||||
};
|
|
@ -0,0 +1,35 @@
|
|||
<?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('master_distributors', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string("nama_distributor")->nullable();
|
||||
$table->string("alamat")->nullable();
|
||||
$table->string("telepon")->nullable();
|
||||
|
||||
$table->unsignedBigInteger("updated_by")->nullable();
|
||||
$table->unsignedBigInteger("created_by")->nullable();
|
||||
$table->unsignedBigInteger("deleted_by")->nullable();
|
||||
$table->softDeletes();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('master_distributors');
|
||||
}
|
||||
};
|
|
@ -0,0 +1,39 @@
|
|||
<?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::table('pengeluaran', function (Blueprint $table) {
|
||||
$table->foreignId('rekening_coa_id')->nullable()->after('jenis_transaksi')->references('id')->on('rekening_coa')->onUpdate('cascade')->onDelete('cascade');
|
||||
$table->foreignId('master_distributors_id')->nullable()->after('rekening_coa_id')->references('id')->on('master_distributors')->onUpdate('cascade')->onDelete('cascade');
|
||||
$table->foreignId('master_satuans_id')->nullable()->after('master_distributors_id')->references('id')->on('master_satuans')->onUpdate('cascade')->onDelete('cascade');
|
||||
$table->double('satuan')->nullable()->after('master_satuans_id');
|
||||
|
||||
$table->unsignedBigInteger("updated_by")->nullable();
|
||||
$table->unsignedBigInteger("created_by")->nullable();
|
||||
$table->unsignedBigInteger("deleted_by")->nullable();
|
||||
$table->softDeletes();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('pengeluaran', function (Blueprint $table) {
|
||||
$table->dropColumn("updated_by");
|
||||
$table->dropColumn("created_by");
|
||||
$table->dropColumn("deleted_by");
|
||||
$table->dropSoftDeletes();
|
||||
});
|
||||
}
|
||||
};
|
|
@ -0,0 +1,29 @@
|
|||
<?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::table('buku_besar', function (Blueprint $table) {
|
||||
$table->foreignId('pengeluaran_id')->nullable()->after('pesanans_id')->references('id')->on('pengeluaran')->onUpdate('cascade')->onDelete('cascade');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('buku_besar', function (Blueprint $table) {
|
||||
$table->dropForeign(['pengeluaran_id']);
|
||||
$table->dropColumn('pengeluaran_id');
|
||||
});
|
||||
}
|
||||
};
|
|
@ -0,0 +1,28 @@
|
|||
<?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::table('pengeluaran', function (Blueprint $table) {
|
||||
$table->foreignId('rekening_coa_transfer_id')->nullable()->after('jenis_transaksi')->references('id')->on('rekening_coa')->onUpdate('cascade')->onDelete('cascade');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('pengeluaran', function (Blueprint $table) {
|
||||
$table->dropColumn('rekening_coa_transfer_id');
|
||||
});
|
||||
}
|
||||
};
|
|
@ -0,0 +1,28 @@
|
|||
<?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::table('pengeluaran', function (Blueprint $table) {
|
||||
$table->decimal('total_harga', 15, 2)->after('keterangan')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('pengeluaran', function (Blueprint $table) {
|
||||
$table->dropColumn('total_harga');
|
||||
});
|
||||
}
|
||||
};
|
|
@ -15,6 +15,7 @@ class GenerateFreshSeeder extends Seeder
|
|||
$classes = [
|
||||
UserSeeder::class,
|
||||
KasirSeeder::class,
|
||||
MasterSatuanSeeder::class,
|
||||
];
|
||||
foreach ($classes as $class) $this->call($class);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class MasterDistributorSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$data = [
|
||||
['nama_distributor' => 'PT. Sinar Sosro', 'alamat' => 'Jl. Raya Soreang No. 1, Bandung', 'telepon' => '022-1234567'],
|
||||
['nama_distributor' => 'PT. Coca Cola', 'alamat' => 'Jl. Raya Cibaduyut No. 2, Bandung', 'telepon' => '022-7654321'],
|
||||
['nama_distributor' => 'PT. Indofood', 'alamat' => 'Jl. Raya Cimahi No. 3, Bandung', 'telepon' => '022-9876543'],
|
||||
['nama_distributor' => 'PT. Unilever', 'alamat' => 'Jl. Raya Cileunyi No. 4, Bandung', 'telepon' => '022-3456789'],
|
||||
];
|
||||
|
||||
foreach ($data as $item) {
|
||||
\App\Models\MasterDistributor::create($item);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class MasterSatuanSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$data = [
|
||||
['nama_satuan' => 'Kilogram', 'simbol' => 'Kg'],
|
||||
['nama_satuan' => 'Gram', 'simbol' => 'g'],
|
||||
['nama_satuan' => 'Liter', 'simbol' => 'L'],
|
||||
['nama_satuan' => 'Mililiter', 'simbol' => 'mL'],
|
||||
['nama_satuan' => 'Pcs', 'simbol' => 'Pcs'],
|
||||
['nama_satuan' => 'Botol', 'simbol' => 'Botol'],
|
||||
['nama_satuan' => 'Sachet', 'simbol' => 'Sachet'],
|
||||
['nama_satuan' => 'Dus', 'simbol' => 'Dus'],
|
||||
['nama_satuan' => 'Kardus', 'simbol' => 'Kardus'],
|
||||
['nama_satuan' => 'Buah', 'simbol' => 'Buah'],
|
||||
['nama_satuan' => 'Bungkus (Paket)', 'simbol' => 'Bks'],
|
||||
['nama_satuan' => 'Kodi', 'simbol' => 'Kodi'],
|
||||
['nama_satuan' => 'Lusin', 'simbol' => 'Lusin'],
|
||||
['nama_satuan' => 'Rim', 'simbol' => 'Rim'],
|
||||
['nama_satuan' => 'Gross', 'simbol' => 'Gross'],
|
||||
['nama_satuan' => 'Karton', 'simbol' => 'Karton'],
|
||||
];
|
||||
|
||||
foreach ($data as $item) {
|
||||
\App\Models\MasterSatuan::create($item);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class PerangkatPrinterSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
[ViewState]
|
||||
Mode=
|
||||
Vid=
|
||||
FolderType=Generic
|
|
@ -0,0 +1,12 @@
|
|||
version: "3.9"
|
||||
services:
|
||||
rabbitmq:
|
||||
image: "rabbitmq:3-management"
|
||||
hostname: "rabbit"
|
||||
ports:
|
||||
- "15672:15672"
|
||||
- "5672:5672"
|
||||
labels:
|
||||
NAME: "rabbitmq"
|
||||
volumes:
|
||||
- ./rabbitmq-isolated.conf:/etc/rabbitmq/rabbitmq.config
|
|
@ -0,0 +1,3 @@
|
|||
@echo off
|
||||
cd E:/Kerja/JMBDEV/Grand-Apps/Stk/stk-web
|
||||
E:/laragon/bin/php/php-8.1.10-Win32-vs16-x64/php.exe artisan serve --host=0.0.0.0 --port=8081
|
|
@ -0,0 +1,4 @@
|
|||
service_name: travis-ci
|
||||
coverage_clover: build/logs/clover.xml
|
||||
json_path: build/logs/coveralls-upload.json
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
# Eclipse files
|
||||
.settings/*
|
||||
.project
|
||||
.buildpath
|
||||
|
||||
# doxygen files
|
||||
doc/html
|
||||
doc/latex
|
||||
doc/doxygen_sqlite3.db
|
||||
|
||||
# composer files
|
||||
vendor/
|
||||
|
||||
# other build files
|
||||
build/*
|
||||
*.phar
|
|
@ -0,0 +1,40 @@
|
|||
---
|
||||
dist: xenial
|
||||
sudo: required
|
||||
|
||||
language: php
|
||||
|
||||
php:
|
||||
- '7.3'
|
||||
- '7.4'
|
||||
- '8.0'
|
||||
- nightly
|
||||
|
||||
matrix:
|
||||
allow_failures:
|
||||
- php: nightly
|
||||
|
||||
before_install:
|
||||
- sudo apt-get -qq update
|
||||
- sudo apt-get install -y imagemagick ghostscript unifont
|
||||
|
||||
install:
|
||||
- composer install
|
||||
|
||||
before_script:
|
||||
# Install 'imagick' plugin
|
||||
- bash -c 'if [[ $TRAVIS_PHP_VERSION != 8* ]] && [[ $TRAVIS_PHP_VERSION != "nightly" ]] ; then printf "\n" | pecl install imagick; fi'
|
||||
# Directory for coverage report
|
||||
- mkdir -p build/logs/
|
||||
|
||||
script:
|
||||
# Check code style
|
||||
- php vendor/bin/phpcs --standard=psr2 src/ -n
|
||||
# Run tests
|
||||
- php vendor/bin/phpunit --coverage-clover build/logs/clover.xml
|
||||
|
||||
after_success:
|
||||
# Upload coverage statistics to coveralls service after test
|
||||
- wget -c -nc https://github.com/satooshi/php-coveralls/releases/download/v1.0.1/coveralls.phar
|
||||
- php coveralls.phar -v
|
||||
...
|
|
@ -0,0 +1,65 @@
|
|||
# How to contribute
|
||||
|
||||
This project is open to many different types of contribution. You can help with improving the documentation and examples, sharing your insights on the issue tracker, adding fixes to the code, providing test cases, or just [writing about your hardware setup that you use](https://github.com/mike42/escpos-php/issues/new).
|
||||
|
||||
## Issue tracker
|
||||
|
||||
Open issues of all sorts are tracked on the [issue tracker](https://github.com/mike42/escpos-php/issues). Please check [the FAQ](https://github.com/mike42/escpos-php/blob/development/doc/FAQ.md) before you post, and practice good [bug tracker etiquette](https://bugzilla.mozilla.org/page.cgi?id=etiquette.html) to keep it running smoothly.
|
||||
|
||||
Issues are [loosely categorised](https://github.com/mike42/escpos-php/labels), and will stay open while there is still something that can be resolved.
|
||||
|
||||
Anybody may add to the discussion on the bug tracker. Just be sure to add new questions as separate issues, and to avoid commenting on closed issues.
|
||||
|
||||
## Submitting changes
|
||||
|
||||
Code changes may be submitted as a "[pull request](https://help.github.com/articles/about-pull-requests/)" at [mike42/escpos-php](https://github.com/mike42/escpos-php). The description should include some information about how the change improves the library.
|
||||
|
||||
The project is MIT-licensed (see [LICENSE.md](https://github.com/mike42/escpos-php/blob/development/LICENSE.md) for details). You are not required to assign copyright in order to submit changes, but you do need to agree for your code to be distributed under this license in order for it to be accepted.
|
||||
|
||||
### Documentation changes
|
||||
|
||||
The official documentaton is also located in the main repository, under the [doc/](https://github.com/mike42/escpos-php/tree/development/doc) folder.
|
||||
|
||||
You are welcome to post any suggested improvements as pull requests.
|
||||
|
||||
### Release process
|
||||
|
||||
Once a pull request is accepted, it usually appears in a release a few days later.
|
||||
|
||||
Branches:
|
||||
|
||||
- "development" is the most recent code, possibly containing unreleased fixes
|
||||
- "master" contains the most recently released code (old versions are not maintained).
|
||||
|
||||
The release process for your changes is:
|
||||
|
||||
- Changes are submitted via pull request to the shared "development" branch.
|
||||
- A new release is staged on the "master" branch via another pull request, and then tagged.
|
||||
|
||||
## Code style
|
||||
|
||||
This project uses the [PSR-2 standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md) for all PHP source code.
|
||||
|
||||
## Testing and CI
|
||||
|
||||
The tests are executed on [Travis CI](https://travis-ci.org/mike42/escpos-php) over PHP 5.4, 5.5, 5.6, 7.0, 7.1 and 7.2, plus the latest LTS version of HHVM, 3.21. Older versions of PHP are not supported in current releases.
|
||||
|
||||
For development, it's suggested that you load `imagick`, `gd` and `Xdebug` PHP exensions, and install `composer`.
|
||||
|
||||
Fetch a copy of this code and load dependencies with composer:
|
||||
|
||||
git clone https://github.com/mike42/escpos-php
|
||||
cd escpos-php/
|
||||
composer install
|
||||
|
||||
Execute unit tests via `phpunit`:
|
||||
|
||||
php vendor/bin/phpunit --coverage-text
|
||||
|
||||
Code style can be checked via [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer):
|
||||
|
||||
php vendor/bin/phpcs --standard=psr2 src/ -n
|
||||
|
||||
The developer docs are built with [doxygen](https://github.com/doxygen/doxygen). Re-build them to check for documentation warnings:
|
||||
|
||||
make -C doc clean && make -C doc
|
|
@ -0,0 +1,25 @@
|
|||
# escpos-php contributors
|
||||
|
||||
This file contains a list of people who have made contributions of
|
||||
code which appear in the public repository of escpos-php.
|
||||
|
||||
Main repository: [mike42/escpos-php](https://github.com/mike42/escpos-php) ([online contributor list](https://github.com/mike42/escpos-php/graphs/contributors))
|
||||
|
||||
- [Michael Billington](https://github.com/mike42)
|
||||
- [Alif Maulana El Fattah Nataly](https://github.com/alif25r)
|
||||
- [Mareks Sudniks](https://github.com/marech)
|
||||
- [matiasgaston](https://github.com/matiasgaston)
|
||||
- [Mike Stivala](https://github.com/brndwgn)
|
||||
- [Nicholas Long](https://github.com/longsview)
|
||||
- [Evandro Araújo](https://github.com/evsar3)
|
||||
|
||||
Via fork: [wdoyle/EpsonESCPOS-PHP](https://github.com/wdoyle/EpsonESCPOS-PHP):
|
||||
|
||||
- [Warren Doyle](https://github.com/wdoyle)
|
||||
|
||||
Via fork: [ronisaha/php-esc-pos](https://github.com/ronisaha/php-esc-pos):
|
||||
|
||||
- [Roni Saha](https://github.com/ronisaha)
|
||||
- [Gergely Radics](https://github.com/Gerifield)
|
||||
- [vharo](https://github.com/vharo)
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2014-2016 Michael Billington, incorporating modifications by others.
|
||||
See CONTRIBUTORS.md for a full list.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
|
@ -0,0 +1,604 @@
|
|||
# ESC/POS Print Driver for PHP
|
||||
|
||||
[](https://travis-ci.org/mike42/escpos-php) [](https://packagist.org/packages/mike42/escpos-php)
|
||||
[](https://packagist.org/packages/mike42/escpos-php)
|
||||
[](https://packagist.org/packages/mike42/escpos-php)
|
||||
[](https://coveralls.io/github/mike42/escpos-php?branch=development)
|
||||
|
||||
This project implements a subset of Epson's ESC/POS protocol for thermal receipt printers. It allows you to generate and print receipts with basic formatting, cutting, and barcodes on a compatible printer.
|
||||
|
||||
The library was developed to add drop-in support for receipt printing to any PHP app, including web-based point-of-sale (POS) applications.
|
||||
|
||||
## Compatibility
|
||||
|
||||
### Interfaces and operating systems
|
||||
|
||||
This driver is known to work with the following OS/interface combinations:
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<th> </th>
|
||||
<th>Linux</th>
|
||||
<th>Mac</th>
|
||||
<th>Windows</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Ethernet</th>
|
||||
<td><a href="https://github.com/mike42/escpos-php/tree/master/example/interface/ethernet.php">Yes</a></td>
|
||||
<td><a href="https://github.com/mike42/escpos-php/tree/master/example/interface/ethernet.php">Yes</a></td>
|
||||
<td><a href="https://github.com/mike42/escpos-php/tree/master/example/interface/ethernet.php">Yes</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>USB</th>
|
||||
<td><a href="https://github.com/mike42/escpos-php/tree/master/example/interface/linux-usb.php">Yes</a></td>
|
||||
<td>Not tested</td>
|
||||
<td><a href="https://github.com/mike42/escpos-php/tree/master/example/interface/windows-usb.php">Yes</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>USB-serial</th>
|
||||
<td>Yes</td>
|
||||
<td>Yes</td>
|
||||
<td>Yes</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Serial</th>
|
||||
<td>Yes</td>
|
||||
<td>Yes</td>
|
||||
<td>Yes</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Parallel</th>
|
||||
<td><a href="https://github.com/mike42/escpos-php/tree/master/example/interface/windows-lpt.php">Yes</a></td>
|
||||
<td>Not tested</td>
|
||||
<td>Yes</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>SMB shared</th>
|
||||
<td><a href="https://github.com/mike42/escpos-php/tree/master/example/interface/smb.php">Yes</a></td>
|
||||
<td>No</td>
|
||||
<td><a href="https://github.com/mike42/escpos-php/tree/master/example/interface/smb.php">Yes</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>CUPS hosted</th>
|
||||
<td><a href="https://github.com/mike42/escpos-php/tree/master/example/interface/cups.php">Yes</a></td>
|
||||
<td><a href="https://github.com/mike42/escpos-php/tree/master/example/interface/cups.php">Yes</a></td>
|
||||
<td>No</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
### Printers
|
||||
|
||||
Many thermal receipt printers support ESC/POS to some degree. This driver has been known to work with:
|
||||
|
||||
- 3nStar RPT-008
|
||||
- Approx APPPOS80AM
|
||||
- AURES ODP-333
|
||||
- AURES ODP-500
|
||||
- Bematech-4200-TH
|
||||
- Bematech LR2000E
|
||||
- Birch PRP-085III
|
||||
- Bixolon SRP-350III
|
||||
- Bixolon SRP-350Plus
|
||||
- Black Copper BC-85AC
|
||||
- CHD TH-305N
|
||||
- Citizen CBM1000-II
|
||||
- Citizen CT-S310II
|
||||
- Dapper-Geyi Q583P
|
||||
- Daruma DR800
|
||||
- DR-MP200 (manufacturer unknown)
|
||||
- EPOS TEP 220M
|
||||
- Elgin i9
|
||||
- Epson EU-T332C
|
||||
- Epson FX-890 (requires `feedForm()` to release paper).
|
||||
- Epson TM-T20
|
||||
- Epson TM-T20II
|
||||
- Epson TM-T70
|
||||
- Epson TM-T70II
|
||||
- Epson TM-T81
|
||||
- Epson TM-T82II
|
||||
- Epson TM-T88II
|
||||
- Epson TM-T88III
|
||||
- Epson TM-T88IV
|
||||
- Epson TM-T88V
|
||||
- Epson TM-U220
|
||||
- Epson TM-U295 (requires `release()` to release slip).
|
||||
- Epson TM-U590 and TM-U590P
|
||||
- Equal (EQ-IT-001) POS-58
|
||||
- Everycom EC-58
|
||||
- Excelvan HOP-E200
|
||||
- Excelvan HOP-E58
|
||||
- Excelvan HOP-E801
|
||||
- Gainscha GP-2120TF
|
||||
- Gainscha GP-5890x (Also marketed as EC Line 5890x)
|
||||
- Gainscha GP-U80300I (Also marketed as gprinter GP-U80300I)
|
||||
- gprinter GP-U80160I
|
||||
- HOIN HOP-H58
|
||||
- Ithaca iTherm 28
|
||||
- Hasar HTP 250
|
||||
- Metapace T-1
|
||||
- Metapace T-25
|
||||
- Nexa PX700
|
||||
- Nyear NP100
|
||||
- OKI RT322
|
||||
- OKI 80 Plus III
|
||||
- Orient BTP-R580
|
||||
- P-822D
|
||||
- P85A-401 (make unknown)
|
||||
- Partner Tech RP320
|
||||
- POSLIGNE ODP200H-III-G
|
||||
- QPOS Q58M
|
||||
- Rongta RP326US
|
||||
- Rongta RP58-U
|
||||
- Rongta RP80USE
|
||||
- SAM4S GIANT-100DB
|
||||
- Senor TP-100
|
||||
- Sewoo SLK-TS400
|
||||
- SEYPOS PRP-96
|
||||
- SEYPOS PRP-300 (Also marketed as TYSSO PRP-300)
|
||||
- SNBC BTP-R880NPIII
|
||||
- Solux SX-TP-88300
|
||||
- Sicar POS-80
|
||||
- Silicon SP-201 / RP80USE
|
||||
- SPRT SP-POS88V
|
||||
- Star BSC10
|
||||
- Star TSP100 ECO
|
||||
- Star TSP100III FuturePRNT
|
||||
- Star TSP-650
|
||||
- Star TUP-592
|
||||
- TVS RP45 Shoppe
|
||||
- Venus V248T
|
||||
- Xeumior SM-8330
|
||||
- Xprinter F-900
|
||||
- Xprinter XP-365B
|
||||
- Xprinter XP-58 Series
|
||||
- Xprinter XP-80C
|
||||
- Xprinter XP-90
|
||||
- XPrinter XP-Q20011
|
||||
- Xprinter XP-Q800
|
||||
- Zjiang NT-58H
|
||||
- Zjiang ZJ-5870
|
||||
- Zjiang ZJ-5890 (Also sold as POS-5890 by many vendors; ZJ-5890K, ZJ-5890T also work).
|
||||
- Zjiang ZJ-8220 (Also marketed as Excelvan ZJ-8220)
|
||||
- Zjiang ZJ-8250
|
||||
|
||||
If you use any other printer with this code, please [let us know](https://github.com/mike42/escpos-php/issues/new) so that it can be added to the list.
|
||||
|
||||
## Basic usage
|
||||
|
||||
### Include the library
|
||||
|
||||
#### Composer
|
||||
|
||||
This library is designed for use with the `composer` PHP dependency manager. Simply add the `mike42/escpos-php` package to get started:
|
||||
|
||||
```bash
|
||||
composer require mike42/escpos-php
|
||||
```
|
||||
|
||||
If you haven't used `composer` before, you can read about it at [getcomposer.org](https://getcomposer.org/).
|
||||
|
||||
#### Requirements
|
||||
|
||||
This project has few hard dependencies:
|
||||
|
||||
- PHP 7.3 or newer.
|
||||
- `json` extension, used to load bundled printer definitions (see [documentation](https://www.php.net/manual/en/book.json.php))
|
||||
- `intl` extension, used for character encoding (see [documentation](https://www.php.net/manual/en/book.intl.php))
|
||||
- `zlib` extension, used for de-compressing bundled resources (see [documentation](https://www.php.net/manual/en/book.zlib.php)).
|
||||
|
||||
It is also suggested that you install either `imagick` or `gd`, as these can be used to speed up image processing.
|
||||
|
||||
A number of optional extensions can be added to enable more specific features. These
|
||||
are described in the "suggest" section of [composer.json](https://github.com/mike42/escpos-php/tree/master/composer.json).
|
||||
|
||||
### The 'Hello World' receipt
|
||||
|
||||
To make use of this driver, your server (where PHP is installed) must be able to communicate with your printer. Start by generating a simple receipt and sending it to your printer using the command-line.
|
||||
|
||||
```php
|
||||
<?php
|
||||
/* Call this file 'hello-world.php' */
|
||||
require __DIR__ . '/vendor/autoload.php';
|
||||
use Zelda\EscposPhp\PrintConnectors\FilePrintConnector;
|
||||
use Zelda\EscposPhp\Printer;
|
||||
$connector = new FilePrintConnector("php://stdout");
|
||||
$printer = new Printer($connector);
|
||||
$printer -> text("Hello World!\n");
|
||||
$printer -> cut();
|
||||
$printer -> close();
|
||||
```
|
||||
|
||||
Some examples are below for common interfaces.
|
||||
|
||||
Communicate with a printer with an Ethernet interface using `netcat`:
|
||||
|
||||
```bash
|
||||
php hello-world.php | nc 10.x.x.x. 9100
|
||||
```
|
||||
|
||||
A USB local printer connected with `usblp` on Linux has a device file (Includes USB-parallel interfaces):
|
||||
|
||||
```bash
|
||||
php hello-world.php > /dev/usb/lp0
|
||||
```
|
||||
|
||||
A computer installed into the local `cups` server is accessed through `lp` or `lpr`:
|
||||
|
||||
```bash
|
||||
php hello-world.php > foo.txt
|
||||
lpr -o raw -H localhost -P printer foo.txt
|
||||
```
|
||||
|
||||
A local or networked printer on a Windows computer is mapped in to a file, and generally requires you to share the printer first:
|
||||
|
||||
```
|
||||
php hello-world.php > foo.txt
|
||||
net use LPT1 \\server\printer
|
||||
copy foo.txt LPT1
|
||||
del foo.txt
|
||||
```
|
||||
|
||||
If you have troubles at this point, then you should consult your OS and printer system documentation to try to find a working print command.
|
||||
|
||||
### Using a PrintConnector
|
||||
|
||||
To print receipts from PHP, use the most applicable [PrintConnector](https://github.com/mike42/escpos-php/tree/master/src/Mike42/Escpos/PrintConnectors) for your setup. The connector simply provides the plumbing to get data to the printer.
|
||||
|
||||
For example, a `NetworkPrintConnector` accepts an IP address and port:
|
||||
|
||||
```php
|
||||
use Zelda\EscposPhp\PrintConnectors\NetworkPrintConnector;
|
||||
use Zelda\EscposPhp\Printer;
|
||||
$connector = new NetworkPrintConnector("10.x.x.x", 9100);
|
||||
$printer = new Printer($connector);
|
||||
try {
|
||||
// ... Print stuff
|
||||
} finally {
|
||||
$printer -> close();
|
||||
}
|
||||
```
|
||||
|
||||
While a serial printer might use:
|
||||
|
||||
```php
|
||||
use Zelda\EscposPhp\PrintConnectors\FilePrintConnector;
|
||||
use Zelda\EscposPhp\Printer;
|
||||
$connector = new FilePrintConnector("/dev/ttyS0");
|
||||
$printer = new Printer($connector);
|
||||
```
|
||||
|
||||
For each OS/interface combination that's supported, there are examples in the compatibility section of how a `PrintConnector` would be constructed. If you can't get a `PrintConnector` to work, then be sure to include the working print command in your issue.
|
||||
|
||||
### Using a CapabilityProfile
|
||||
|
||||
Support for commands and code pages varies between printer vendors and models. By default, the driver will accept UTF-8, and output commands that are suitable for Epson TM-series printers.
|
||||
|
||||
When trying out a new brand of printer, it's a good idea to use the "simple" `CapabilityProfile`, which instructs the driver to avoid the use of advanced features (generally simpler image handling, ASCII-only text).
|
||||
|
||||
```php
|
||||
use Zelda\EscposPhp\PrintConnectors\WindowsPrintConnector;
|
||||
use Zelda\EscposPhp\CapabilityProfile;
|
||||
$profile = CapabilityProfile::load("simple");
|
||||
$connector = new WindowsPrintConnector("smb://computer/printer");
|
||||
$printer = new Printer($connector, $profile);
|
||||
```
|
||||
|
||||
As another example, Star-branded printers use different commands:
|
||||
|
||||
```php
|
||||
use Zelda\EscposPhp\PrintConnectors\WindowsPrintConnector;
|
||||
use Zelda\EscposPhp\CapabilityProfile;
|
||||
$profile = CapabilityProfile::load("SP2000")
|
||||
$connector = new WindowsPrintConnector("smb://computer/printer");
|
||||
$printer = new Printer($connector, $profile);
|
||||
```
|
||||
|
||||
For a list of available profiles, or to have support for your printer improved, please see the upstream [receipt-print-hq/escpos-printer-db](https://github.com/receipt-print-hq/escpos-printer-db) project.
|
||||
|
||||
### Tips & examples
|
||||
|
||||
On Linux, your printer device file will be somewhere like `/dev/lp0` (parallel), `/dev/usb/lp1` (USB), `/dev/ttyUSB0` (USB-Serial), `/dev/ttyS0` (serial).
|
||||
|
||||
On Windows, the device files will be along the lines of `LPT1` (parallel) or `COM1` (serial). Use the `WindowsPrintConnector` to tap into system printing on Windows (eg. [Windows USB](https://github.com/mike42/escpos-php/tree/master/example/interface/windows-usb.php), [SMB](https://github.com/mike42/escpos-php/tree/master/example/interface/smb.php) or [Windows LPT](https://github.com/mike42/escpos-php/tree/master/example/interface/windows-lpt.php)) - this submits print jobs via a queue rather than communicating directly with the printer.
|
||||
|
||||
A complete real-world receipt can be found in the code of [Auth](https://github.com/mike42/Auth) in [ReceiptPrinter.php](https://github.com/mike42/Auth/blob/master/lib/misc/ReceiptPrinter.php). It includes justification, boldness, and a barcode.
|
||||
|
||||
Other examples are located in the [example/](https://github.com/mike42/escpos-php/blob/master/example/) directory.
|
||||
|
||||
## Available methods
|
||||
|
||||
### \_\_construct(PrintConnector $connector, CapabilityProfile $profile)
|
||||
|
||||
Construct new print object.
|
||||
|
||||
Parameters:
|
||||
|
||||
- `PrintConnector $connector`: The PrintConnector to send data to.
|
||||
- `CapabilityProfile $profile` Supported features of this printer. If not set, the "default" CapabilityProfile will be used, which is suitable for Epson printers.
|
||||
|
||||
See [example/interface/](https://github.com/mike42/escpos-php/tree/master/example/interface/) for ways to open connections for different platforms and interfaces.
|
||||
|
||||
### barcode($content, $type)
|
||||
|
||||
Print a barcode.
|
||||
|
||||
Parameters:
|
||||
|
||||
- `string $content`: The information to encode.
|
||||
- `int $type`: The barcode standard to output. If not specified, `Printer::BARCODE_CODE39` will be used.
|
||||
|
||||
Currently supported barcode standards are (depending on your printer):
|
||||
|
||||
- `BARCODE_UPCA`
|
||||
- `BARCODE_UPCE`
|
||||
- `BARCODE_JAN13`
|
||||
- `BARCODE_JAN8`
|
||||
- `BARCODE_CODE39`
|
||||
- `BARCODE_ITF`
|
||||
- `BARCODE_CODABAR`
|
||||
|
||||
Note that some barcode standards can only encode numbers, so attempting to print non-numeric codes with them may result in strange behaviour.
|
||||
|
||||
### bitImage(EscposImage $image, $size)
|
||||
|
||||
See [graphics()](#graphicsescposimage-image-size) below.
|
||||
|
||||
### cut($mode, $lines)
|
||||
|
||||
Cut the paper.
|
||||
|
||||
Parameters:
|
||||
|
||||
- `int $mode`: Cut mode, either `Printer::CUT_FULL` or `Printer::CUT_PARTIAL`. If not specified, `Printer::CUT_FULL` will be used.
|
||||
- `int $lines`: Number of lines to feed before cutting. If not specified, 3 will be used.
|
||||
|
||||
### feed($lines)
|
||||
|
||||
Print and feed line / Print and feed n lines.
|
||||
|
||||
Parameters:
|
||||
|
||||
- `int $lines`: Number of lines to feed
|
||||
|
||||
### feedForm()
|
||||
|
||||
Some printers require a form feed to release the paper. On most printers, this command is only useful in page mode, which is not implemented in this driver.
|
||||
|
||||
### feedReverse($lines)
|
||||
|
||||
Print and reverse feed n lines.
|
||||
|
||||
Parameters:
|
||||
|
||||
- `int $lines`: number of lines to feed. If not specified, 1 line will be fed.
|
||||
|
||||
### graphics(EscposImage $image, $size)
|
||||
|
||||
Print an image to the printer.
|
||||
|
||||
Parameters:
|
||||
|
||||
- `EscposImage $img`: The image to print.
|
||||
- `int $size`: Output size modifier for the image.
|
||||
|
||||
Size modifiers are:
|
||||
|
||||
- `IMG_DEFAULT` (leave image at original size)
|
||||
- `IMG_DOUBLE_WIDTH`
|
||||
- `IMG_DOUBLE_HEIGHT`
|
||||
|
||||
A minimal example:
|
||||
|
||||
```php
|
||||
<?php
|
||||
$img = EscposImage::load("logo.png");
|
||||
$printer -> graphics($img);
|
||||
```
|
||||
|
||||
See the [example/](https://github.com/mike42/escpos-php/blob/master/example/) folder for detailed examples.
|
||||
|
||||
The function [bitImage()](#bitimageescposimage-image-size) takes the same parameters, and can be used if your printer doesn't support the newer graphics commands. As an additional fallback, the `bitImageColumnFormat()` function is also provided.
|
||||
|
||||
### initialize()
|
||||
|
||||
Initialize printer. This resets formatting back to the defaults.
|
||||
|
||||
### pdf417Code($content, $width, $heightMultiplier, $dataColumnCount, $ec, $options)
|
||||
|
||||
Print a two-dimensional data code using the PDF417 standard.
|
||||
|
||||
Parameters:
|
||||
|
||||
- `string $content`: Text or numbers to store in the code
|
||||
- `number $width`: Width of a module (pixel) in the printed code. Default is 3 dots.
|
||||
- `number $heightMultiplier`: Multiplier for height of a module. Default is 3 times the width.
|
||||
- `number $dataColumnCount`: Number of data columns to use. 0 (default) is to auto-calculate. Smaller numbers will result in a narrower code, making larger pixel sizes possible. Larger numbers require smaller pixel sizes.
|
||||
- `real $ec`: Error correction ratio, from 0.01 to 4.00. Default is 0.10 (10%).
|
||||
- `number $options`: Standard code `Printer::PDF417_STANDARD` with start/end bars, or truncated code `Printer::PDF417_TRUNCATED` with start bars only.
|
||||
|
||||
### pulse($pin, $on_ms, $off_ms)
|
||||
|
||||
Generate a pulse, for opening a cash drawer if one is connected. The default settings (0, 120, 240) should open an Epson drawer.
|
||||
|
||||
Parameters:
|
||||
|
||||
- `int $pin`: 0 or 1, for pin 2 or pin 5 kick-out connector respectively.
|
||||
- `int $on_ms`: pulse ON time, in milliseconds.
|
||||
- `int $off_ms`: pulse OFF time, in milliseconds.
|
||||
|
||||
### qrCode($content, $ec, $size, $model)
|
||||
|
||||
Print the given data as a QR code on the printer.
|
||||
|
||||
- `string $content`: The content of the code. Numeric data will be more efficiently compacted.
|
||||
- `int $ec` Error-correction level to use. One of `Printer::QR_ECLEVEL_L` (default), `Printer::QR_ECLEVEL_M`, `Printer::QR_ECLEVEL_Q` or `Printer::QR_ECLEVEL_H`. Higher error correction results in a less compact code.
|
||||
- `int $size`: Pixel size to use. Must be 1-16 (default 3)
|
||||
- `int $model`: QR code model to use. Must be one of `Printer::QR_MODEL_1`, `Printer::QR_MODEL_2` (default) or `Printer::QR_MICRO` (not supported by all printers).
|
||||
|
||||
### selectPrintMode($mode)
|
||||
|
||||
Select print mode(s).
|
||||
|
||||
Parameters:
|
||||
|
||||
- `int $mode`: The mode to use. Default is `Printer::MODE_FONT_A`, with no special formatting. This has a similar effect to running `initialize()`.
|
||||
|
||||
Several MODE\_\* constants can be OR'd together passed to this function's `$mode` argument. The valid modes are:
|
||||
|
||||
- `MODE_FONT_A`
|
||||
- `MODE_FONT_B`
|
||||
- `MODE_EMPHASIZED`
|
||||
- `MODE_DOUBLE_HEIGHT`
|
||||
- `MODE_DOUBLE_WIDTH`
|
||||
- `MODE_UNDERLINE`
|
||||
|
||||
### setBarcodeHeight($height)
|
||||
|
||||
Set barcode height.
|
||||
|
||||
Parameters:
|
||||
|
||||
- `int $height`: Height in dots. If not specified, 8 will be used.
|
||||
|
||||
### setBarcodeWidth($width)
|
||||
|
||||
Set barcode bar width.
|
||||
|
||||
Parameters:
|
||||
|
||||
- `int $width`: Bar width in dots. If not specified, 3 will be used. Values above 6 appear to have no effect.
|
||||
|
||||
### setColor($color)
|
||||
|
||||
Select print color - on printers that support multiple colors.
|
||||
|
||||
Parameters:
|
||||
|
||||
- `int $color`: Color to use. Must be either `Printer::COLOR_1` (default), or `Printer::COLOR_2`
|
||||
|
||||
### setDoubleStrike($on)
|
||||
|
||||
Turn double-strike mode on/off.
|
||||
|
||||
Parameters:
|
||||
|
||||
- `boolean $on`: true for double strike, false for no double strike.
|
||||
|
||||
### setEmphasis($on)
|
||||
|
||||
Turn emphasized mode on/off.
|
||||
|
||||
Parameters:
|
||||
|
||||
- `boolean $on`: true for emphasis, false for no emphasis.
|
||||
|
||||
### setFont($font)
|
||||
|
||||
Select font. Most printers have two fonts (Fonts A and B), and some have a third (Font C).
|
||||
|
||||
Parameters:
|
||||
|
||||
- `int $font`: The font to use. Must be either `Printer::FONT_A`, `Printer::FONT_B`, or `Printer::FONT_C`.
|
||||
|
||||
### setJustification($justification)
|
||||
|
||||
Select justification.
|
||||
|
||||
Parameters:
|
||||
|
||||
- `int $justification`: One of `Printer::JUSTIFY_LEFT`, `Printer::JUSTIFY_CENTER`, or `Printer::JUSTIFY_RIGHT`.
|
||||
|
||||
### setLineSpacing($height)
|
||||
|
||||
Set the height of the line.
|
||||
|
||||
Some printers will allow you to overlap lines with a smaller line feed.
|
||||
|
||||
Parameters:
|
||||
|
||||
- `int $height`: The height of each line, in dots. If not set, the printer will reset to its default line spacing.
|
||||
|
||||
### setPrintLeftMargin($margin)
|
||||
|
||||
Set print area left margin. Reset to default with `Printer::initialize()`.
|
||||
|
||||
Parameters:
|
||||
|
||||
- `int $margin`: The left margin to set on to the print area, in dots.
|
||||
|
||||
### setPrintWidth($width)
|
||||
|
||||
Set print area width. This can be used to add a right margin to the print area. Reset to default with `Printer::initialize()`.
|
||||
|
||||
Parameters:
|
||||
|
||||
- `int $width`: The width of the page print area, in dots.
|
||||
|
||||
### setReverseColors($on)
|
||||
|
||||
Set black/white reverse mode on or off. In this mode, text is printed white on a black background.
|
||||
|
||||
Parameters:
|
||||
|
||||
- `boolean $on`: True to enable, false to disable.
|
||||
|
||||
### setTextSize($widthMultiplier, $heightMultiplier)
|
||||
|
||||
Set the size of text, as a multiple of the normal size.
|
||||
|
||||
Parameters:
|
||||
|
||||
- `int $widthMultiplier`: Multiple of the regular height to use (range 1 - 8).
|
||||
- `int $heightMultiplier`: Multiple of the regular height to use (range 1 - 8).
|
||||
|
||||
### setUnderline($underline)
|
||||
|
||||
Set underline for printed text.
|
||||
|
||||
Parameters:
|
||||
|
||||
- `int $underline`: Either `true`/`false`, or one of `Printer::UNDERLINE_NONE`, `Printer::UNDERLINE_SINGLE` or `Printer::UNDERLINE_DOUBLE`. Defaults to `Printer::UNDERLINE_SINGLE`.
|
||||
|
||||
### text($str)
|
||||
|
||||
Add text to the buffer. Text should either be followed by a line-break, or `feed()` should be called after this.
|
||||
|
||||
Parameters:
|
||||
|
||||
- `string $str`: The string to print.
|
||||
|
||||
# Further notes
|
||||
|
||||
Posts I've written up for people who are learning how to use receipt printers:
|
||||
|
||||
- [What is ESC/POS, and how do I use it?](https://mike42.me/blog/what-is-escpos-and-how-do-i-use-it), which documents the output of `example/demo.php`.
|
||||
- [Setting up an Epson receipt printer](https://mike42.me/blog/2014-20-26-setting-up-an-epson-receipt-printer)
|
||||
- [Getting a USB receipt printer working on Linux](https://mike42.me/blog/2015-03-getting-a-usb-receipt-printer-working-on-linux)
|
||||
|
||||
# Development
|
||||
|
||||
This code is MIT licensed, and you are encouraged to contribute any modifications back to the project.
|
||||
|
||||
For development, it's suggested that you load `imagick`, `gd` and `Xdebug` PHP extensions.
|
||||
|
||||
The tests are executed on [Travis CI](https://travis-ci.org/mike42/escpos-php) over PHP 7.3, 7.4 and 8.0. Older versions of PHP are not supported in the current release, nor is HHVM.
|
||||
|
||||
Fetch a copy of this code and load dependencies with composer:
|
||||
|
||||
git clone https://github.com/mike42/escpos-php
|
||||
cd escpos-php/
|
||||
composer install
|
||||
|
||||
Execute unit tests via `phpunit`:
|
||||
|
||||
php vendor/bin/phpunit --coverage-text
|
||||
|
||||
This project uses the PSR-2 standard, which can be checked via [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer):
|
||||
|
||||
php vendor/bin/phpcs --standard=psr2 src/ -n
|
||||
|
||||
The developer docs are build with [doxygen](https://github.com/doxygen/doxygen). Re-build them to check for documentation warnings:
|
||||
|
||||
make -C doc clean && make -C doc
|
||||
|
||||
Pull requests and bug reports welcome.
|
|
@ -0,0 +1,21 @@
|
|||
{
|
||||
"name": "zelda/escpos-php",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Zelda\\EscposPhp\\": "src/"
|
||||
}
|
||||
},
|
||||
"authors": [
|
||||
{
|
||||
"name": "Zelda Ababil",
|
||||
"email": "zeldaababil01@gmail.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=7.3.0",
|
||||
"ext-json": "*",
|
||||
"ext-intl": "*",
|
||||
"ext-zlib": "*",
|
||||
"mike42/gfx-php": "^0.6"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
{
|
||||
"_readme": [
|
||||
"This file locks the dependencies of your project to a known state",
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "a71cd13be41b149c160b25f873df6189",
|
||||
"packages": [
|
||||
{
|
||||
"name": "mike42/gfx-php",
|
||||
"version": "v0.6",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/mike42/gfx-php.git",
|
||||
"reference": "ed9ded2a9298e4084a9c557ab74a89b71e43dbdb"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/mike42/gfx-php/zipball/ed9ded2a9298e4084a9c557ab74a89b71e43dbdb",
|
||||
"reference": "ed9ded2a9298e4084a9c557ab74a89b71e43dbdb",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=7.0.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpbench/phpbench": "@dev",
|
||||
"phpunit/phpunit": "^6.5",
|
||||
"squizlabs/php_codesniffer": "^3.3.1"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Mike42\\": "src/Mike42"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"LGPL-2.1-or-later"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Michael Billington",
|
||||
"email": "michael.billington@gmail.com"
|
||||
}
|
||||
],
|
||||
"description": "The pure PHP graphics library",
|
||||
"homepage": "https://github.com/mike42/gfx-php",
|
||||
"support": {
|
||||
"issues": "https://github.com/mike42/gfx-php/issues",
|
||||
"source": "https://github.com/mike42/gfx-php/tree/v0.6"
|
||||
},
|
||||
"time": "2019-10-05T02:44:33+00:00"
|
||||
}
|
||||
],
|
||||
"packages-dev": [],
|
||||
"aliases": [],
|
||||
"minimum-stability": "stable",
|
||||
"stability-flags": [],
|
||||
"prefer-stable": false,
|
||||
"prefer-lowest": false,
|
||||
"platform": {
|
||||
"php": ">=7.3.0",
|
||||
"ext-json": "*",
|
||||
"ext-intl": "*",
|
||||
"ext-zlib": "*"
|
||||
},
|
||||
"platform-dev": [],
|
||||
"plugin-api-version": "2.3.0"
|
||||
}
|
|
@ -0,0 +1,142 @@
|
|||
# Frequently Asked Questions (FAQ)
|
||||
|
||||
## Can I print to File Format X with this?
|
||||
|
||||
If you are trying to generate XPS, PDF or DOCX or HTML files from PHP, then you are most likely in the wrong place.
|
||||
|
||||
The purpose of this driver it to generate binary ESC/POS code, which is understood by many embedded thermal receipt and impact printers.
|
||||
|
||||
## I have Printer X. Can I use this driver?
|
||||
|
||||
If the printer understands ESC/POS, and you know how to get raw binary data to it, then yes. Otherwise, no.
|
||||
|
||||
The [list of printers that are known to work](https://github.com/mike42/escpos-php/blob/development/README.md#printers) is crowd-sourced. We appreciate it when developers try out the driver, then [file information on the bug tracker](https://github.com/mike42/escpos-php/issues/new) with some information about which features worked on their model of printer.
|
||||
|
||||
To see how well your printer works, first check that it supports ESC/POS, then begin by attempting to send the text "Hello World" to your printer on the command-line, from the computer that will run PHP.
|
||||
|
||||
Once you solve this, [try to do the same from PHP](https://github.com/mike42/escpos-php/blob/development/README.md#basic-usage) using the default profile. Further details are in the [README](https://github.com/mike42/escpos-php/blob/development/README.md) file.
|
||||
|
||||
## Can you add support for Printer X?
|
||||
|
||||
Features vary between printers, so we collaborate on an ESC/POS printer compatibility database to collect known differences: [receipt-print-hq/escpos-printer-db](https://github.com/receipt-print-hq/escpos-printer-db).
|
||||
|
||||
If you encounter garbage output when you try to print images or special characters, then please submit a test page and a link to vendor documentation to the `escpos-printer-db` project, so that support can be improved for future versions.
|
||||
|
||||
## I have a printer that does not understand ESC/POS. Can I use this driver?
|
||||
|
||||
No. The purpose of this driver it to generate binary ESC/POS code. If your printer doesn't understand that, then this code wont be much use to you.
|
||||
|
||||
Some printers do have an emulation mode for ESC/POS. The vendor docs will tell if this is the case, and how to enable it.
|
||||
|
||||
## Why do I get this error when I try to print?
|
||||
|
||||
Start by testing that you can send text to your printer outside of escpos-php. The examples linked to in the README are commented with some commands to get you started.
|
||||
|
||||
Generally, initial setup problems seem to have one of these causes:
|
||||
|
||||
1. You are writing to the wrong place. Writing to `LPT1` does not output to parallel port on Linux, and `/dev/ttyS0` is not a serial printer on Windows.
|
||||
2. The printer has not been set up to accept printing the way you expect. This means permissions on Linux, network printers being configured, and shared printers having user accounts and firewalls set up correctly on the print server.
|
||||
3. Your printer actually doesn't work (rare but possible).
|
||||
|
||||
To be clear, these are not escpos-php issues: No amount of PHP code can set up your printer for you. Instead, the driver relies on developers determining how their setup is going to work before using a connector to transport data to their printer.
|
||||
|
||||
Once you have a working command to send text to your printer (from the PHP server), you are ready to use escpos-php. You can try to use a PrintConnector now, based on your operating system and printer interface. A table is located in the README to help you select the right one.
|
||||
|
||||
The connectors are-
|
||||
|
||||
- `FilePrintConnector` and `NetworkPrintConnector` directly use files or network sockets.
|
||||
- `WindowsPrintConnector` and `CupsPrintConnector` tie in with Windows and Unix system printing.
|
||||
- `DummyPrintConnector` does not connect to a real printer, and can be used to save ESC/POS receipts to a database, for example.
|
||||
|
||||
At this point, you might find that the way you would like to print is not supported by escpos-php. You can post your printing command as a feature request on the issue tracker.
|
||||
|
||||
Lastly, you may run in to the final common trap:
|
||||
|
||||
4. Your PHP is not running with the same sort of permissions as your login account. Again, no amount of PHP code can fix this. For example, on LAMP, your `www-data` user needs to be in the `lp` group, while on WAMP, `Local Service` account may run in to problems. SELinux and firewalls are also worth a look.
|
||||
|
||||
When printing fails, you can expect a PHP Exception that explains what went wrong. They are all clues:
|
||||
|
||||
- `Warning: copy(\\pc\printer): failed to open stream: Permission denied`
|
||||
- `/dev/usb/lp0: Permission denied`
|
||||
- `User name or password is incorrect`
|
||||
|
||||
Ensure that while you are developing, you configure PHP to show error messages, so that you can see these problems.
|
||||
|
||||
Please file a bug if you think that there is a specific situation which escpos-php could provide better error messages for.
|
||||
|
||||
## Can I print over the network?
|
||||
|
||||
Certainly, as long as your printer is available over the network.
|
||||
|
||||
- `NetworkPrintConnector` will speak directly to an Ethernet-connected printer on port 9100.
|
||||
|
||||
For USB or Serial printers, you need to install the printer on a computer and then share it, so that it becomes network-accessible.
|
||||
|
||||
- `WindowsPrintConnector` will connect to Windows shared printers from Windows or Linux (Linux users will need Samba).
|
||||
- `CupsPrintConnector` will connect to CUPS-shared printers from Linux or Mac.
|
||||
|
||||
Always start by testing your shared printer setup outside of escpos-php. The examples linked to in the README are commented with some example commands to get you started. Typically, networks, firewalls and permissions need to be set up.
|
||||
|
||||
Once you have a working command to send text to your printer (from the PHP server), you are ready to use escpos-php.
|
||||
|
||||
If you have any issues at this stage, please ask on the issue tracker, and include the commands that you used to verify your setup.
|
||||
|
||||
## Can I print from my server on the Internet?
|
||||
|
||||
Since PHP is a server-side language, escpos-php is a server-side print library. The driver is able to transport data between a server and a printer in a few different ways, all of them server-side. For example, you may print to a USB printer *connected to the server running PHP*, or an Ethernet printer *on a network accessible to the server*.
|
||||
|
||||
Many developers dream of having an application that is hosted on the public Internet, with POS terminals accessing it, and printing via a web browser. Because the webserver cannot see the printer in this sort of setup, a server-side print driver is not much use.
|
||||
|
||||
Because of this, there are no cut-and-paste recipes available, but here are two top-level approaches you could take:
|
||||
|
||||
1. Architect your application so that the server can see your printer
|
||||
2. Use an application which runs client-side to deliver print data instead
|
||||
|
||||
### Option 1: Allow the server to print
|
||||
|
||||
Server-side printing is viable if the server can get to the printer. Here are some ways it could work:
|
||||
|
||||
- Run your server on the LAN instead, and read the section above about printing over the network
|
||||
- Set up a VPN so that your cloud-hosted server can also access the LAN
|
||||
- Expose the printer via some other secure tunnel to the server, via SSH or TLS
|
||||
|
||||
Please do your own research to determine how these may apply to your setup- the escpos-php issue tracker is not a place where you should be requesting network support.
|
||||
|
||||
### Option 2: Use client software to print
|
||||
|
||||
If you aren't able to set up some network infrastructure to implement the above, then you cannot use a server-side print driver.
|
||||
|
||||
Here are some browser-based printing tools which you may like to consider instead.
|
||||
|
||||
- Use system printing with a vendor driver, and some good `@media print` CSS
|
||||
- [Chrome Raw Print](https://github.com/receipt-print-hq/chrome-raw-print) app
|
||||
- [qz](https://qz.io/)
|
||||
- [ePOS-Device SDK for JavaScript](https://reference.epson-biz.com/modules/ref_epos_device_js_en/index.php?content_id=139). Requires network interface card that supports ePOS (UB-E04/R04)
|
||||
|
||||
Please direct queries about client-side printing products to the appropriate project.
|
||||
|
||||
## Why is image printing slow?
|
||||
|
||||
Three things tend to slow down the image processing:
|
||||
|
||||
1. Slow PHP code
|
||||
2. Data link
|
||||
3. The printer itself
|
||||
|
||||
First, ensure you have the Imagick plugin loaded. The driver will avoid a slower image processing implementation once you've got it.
|
||||
|
||||
Next, connect over a faster interface. Serial printers have a low bit-rate, and the printer spends a lot of time waiting for data. If you have USB or Ethernet, then use it (note: storing graphics to the printer memory is not currently implemented).
|
||||
|
||||
Lastly, the printer will go faster if you use less pixels. Since images are two-dimensional, scaling down by 50% removes 75% of the pixels. The driver can then print at a half the density, so that your lower resolution image appears the same size when printed.
|
||||
|
||||
## How can I get the status of the printer?
|
||||
|
||||
This feature is not implemented, but a solution for some Epson printers is planned.
|
||||
|
||||
Only `FilePrintConnector` or `NetworkPrintConnector` will support reading from the printer, ensure that you migrate to those if you would like these features.
|
||||
|
||||
## How do I produce this complex layout?
|
||||
|
||||
ESC/POS "page mode" is not currently supported, which would allow some printers to render some more complex layouts natively
|
||||
|
||||
Since the output is raster anyway, it is suggested that you render your output to an image and print that instead. The driver supports PDF printing via Imagick, and an example that uses `wkhtmltoimage` is available in the repository.
|
|
@ -0,0 +1,20 @@
|
|||
html: escpos.doxyfile
|
||||
# Compile
|
||||
doxygen escpos.doxyfile
|
||||
# Filter out warnings on README.md- doxygen cannot handle image links that
|
||||
# are used there: [](https://example.com/image)
|
||||
sed -i '/README.md\:/d' warnings.log
|
||||
# Show warnings log
|
||||
cat warnings.log
|
||||
# Return failure if there were any doc warnings
|
||||
[ ! -s warnings.log ]
|
||||
|
||||
latex: html
|
||||
# Do nothing
|
||||
|
||||
xml: html
|
||||
xsltproc xml/combine.xslt xml/index.xml > all.xml
|
||||
|
||||
clean:
|
||||
rm --preserve-root -Rf html latex xml doxygen_sqlite3.db all.xml warnings.log
|
||||
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,26 @@
|
|||
Examples
|
||||
--------
|
||||
|
||||
This folder contains a collectoion of feature examples.
|
||||
Generally, demo.php is the fastest way to find out which features your
|
||||
printer supports.
|
||||
|
||||
## Subfolders
|
||||
- `interface/` - contains examples for output interfaces: eg, parallel, serial, USB, network, file-based.
|
||||
- `specific/` - examples made in response to issues & questions. These cover specific languages, printers and interfaces, so hit narrower use cases.
|
||||
|
||||
## List of examples
|
||||
|
||||
Each example prints to standard output, so either edit the print connector, or redirect the output to your printer to see it in action. They are designed for developers: open them in a text editor before you run them!
|
||||
|
||||
- `bit-image.php` - Prints a images to the printer using the older "bit image" commands.
|
||||
- `demo.php` - Demonstrates output using a large subset of availale features.
|
||||
- `qr-code.php` - Prints QR codes, if your printer supports it.
|
||||
- `character-encodings.php` - Shows available character encodings. Change from the DefaultCapabilityProfile to get more useful output for your specific printer.
|
||||
- `graphics.php` - The same output as `bit-image.php`, printed with the newer graphics commands (not supported on many non-Epson printers)
|
||||
- `receipt-with-logo.php` - A simple receipt containing a logo and basic formating.
|
||||
- `character-encodings-with-images.php` - The same as `character-encodings.php`, but also prints each string using an `ImagePrintBuffer`, showing compatibility gaps.
|
||||
- `print-from-html.php` - Runs `wkhtmltoimage` to convert HTML to an image, and then prints the image. (This is very slow)
|
||||
- `character-tables.php` - Prints a compact character code table for each available character set. Used to debug incorrect output from `character-encodings.php`.
|
||||
- `print-from-pdf.php` - Loads a PDF and prints each page in a few different ways (very slow as well)
|
||||
- `rawbt-receipt` (.php & .html) - Demonstration of Back and Front for integration between the site and the Android application “RawBT - Printer Driver for Android”
|
|
@ -0,0 +1,208 @@
|
|||
<?php
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
use Zelda\EscposPhp\Printer;
|
||||
use Zelda\EscposPhp\PrintConnectors\FilePrintConnector;
|
||||
|
||||
$connector = new FilePrintConnector("php://stdout");
|
||||
$printer = new Printer($connector);
|
||||
|
||||
/* Height and width */
|
||||
$printer->selectPrintMode(Printer::MODE_DOUBLE_HEIGHT | Printer::MODE_DOUBLE_WIDTH);
|
||||
$printer->text("Height and bar width\n");
|
||||
$printer->selectPrintMode();
|
||||
$heights = array(1, 2, 4, 8, 16, 32);
|
||||
$widths = array(1, 2, 3, 4, 5, 6, 7, 8);
|
||||
$printer->text("Default look\n");
|
||||
$printer->barcode("ABC", Printer::BARCODE_CODE39);
|
||||
|
||||
foreach ($heights as $height) {
|
||||
$printer->text("\nHeight $height\n");
|
||||
$printer->setBarcodeHeight($height);
|
||||
$printer->barcode("ABC", Printer::BARCODE_CODE39);
|
||||
}
|
||||
foreach ($widths as $width) {
|
||||
$printer->text("\nWidth $width\n");
|
||||
$printer->setBarcodeWidth($width);
|
||||
$printer->barcode("ABC", Printer::BARCODE_CODE39);
|
||||
}
|
||||
$printer->feed();
|
||||
// Set to something sensible for the rest of the examples
|
||||
$printer->setBarcodeHeight(40);
|
||||
$printer->setBarcodeWidth(2);
|
||||
|
||||
/* Text position */
|
||||
$printer->selectPrintMode(Printer::MODE_DOUBLE_HEIGHT | Printer::MODE_DOUBLE_WIDTH);
|
||||
$printer->text("Text position\n");
|
||||
$printer->selectPrintMode();
|
||||
$hri = array(
|
||||
Printer::BARCODE_TEXT_NONE => "No text",
|
||||
Printer::BARCODE_TEXT_ABOVE => "Above",
|
||||
Printer::BARCODE_TEXT_BELOW => "Below",
|
||||
Printer::BARCODE_TEXT_ABOVE | Printer::BARCODE_TEXT_BELOW => "Both"
|
||||
);
|
||||
foreach ($hri as $position => $caption) {
|
||||
$printer->text($caption . "\n");
|
||||
$printer->setBarcodeTextPosition($position);
|
||||
$printer->barcode("012345678901", Printer::BARCODE_JAN13);
|
||||
$printer->feed();
|
||||
}
|
||||
|
||||
/* Barcode types */
|
||||
$standards = array(
|
||||
Printer::BARCODE_UPCA => array(
|
||||
"title" => "UPC-A",
|
||||
"caption" => "Fixed-length numeric product barcodes.",
|
||||
"example" => array(
|
||||
array(
|
||||
"caption" => "12 char numeric including (wrong) check digit.",
|
||||
"content" => "012345678901"
|
||||
),
|
||||
array(
|
||||
"caption" => "Send 11 chars to add check digit automatically.",
|
||||
"content" => "01234567890"
|
||||
)
|
||||
)
|
||||
),
|
||||
Printer::BARCODE_UPCE => array(
|
||||
"title" => "UPC-E",
|
||||
"caption" => "Fixed-length numeric compact product barcodes.",
|
||||
"example" => array(
|
||||
array(
|
||||
"caption" => "6 char numeric - auto check digit & NSC",
|
||||
"content" => "123456"
|
||||
),
|
||||
array(
|
||||
"caption" => "7 char numeric - auto check digit",
|
||||
"content" => "0123456"
|
||||
),
|
||||
array(
|
||||
"caption" => "8 char numeric",
|
||||
"content" => "01234567"
|
||||
),
|
||||
array(
|
||||
"caption" => "11 char numeric - auto check digit",
|
||||
"content" => "01234567890"
|
||||
),
|
||||
array(
|
||||
"caption" => "12 char numeric including (wrong) check digit",
|
||||
"content" => "012345678901"
|
||||
)
|
||||
)
|
||||
),
|
||||
Printer::BARCODE_JAN13 => array(
|
||||
"title" => "JAN13/EAN13",
|
||||
"caption" => "Fixed-length numeric barcodes.",
|
||||
"example" => array(
|
||||
array(
|
||||
"caption" => "12 char numeric - auto check digit",
|
||||
"content" => "012345678901"
|
||||
),
|
||||
array(
|
||||
"caption" => "13 char numeric including (wrong) check digit",
|
||||
"content" => "0123456789012"
|
||||
)
|
||||
)
|
||||
),
|
||||
Printer::BARCODE_JAN8 => array(
|
||||
"title" => "JAN8/EAN8",
|
||||
"caption" => "Fixed-length numeric barcodes.",
|
||||
"example" => array(
|
||||
array(
|
||||
"caption" => "7 char numeric - auto check digit",
|
||||
"content" => "0123456"
|
||||
),
|
||||
array(
|
||||
"caption" => "8 char numeric including (wrong) check digit",
|
||||
"content" => "01234567"
|
||||
)
|
||||
)
|
||||
),
|
||||
Printer::BARCODE_CODE39 => array(
|
||||
"title" => "Code39",
|
||||
"caption" => "Variable length alphanumeric w/ some special chars.",
|
||||
"example" => array(
|
||||
array(
|
||||
"caption" => "Text, numbers, spaces",
|
||||
"content" => "ABC 012"
|
||||
),
|
||||
array(
|
||||
"caption" => "Special characters",
|
||||
"content" => "$%+-./"
|
||||
),
|
||||
array(
|
||||
"caption" => "Extra char (*) Used as start/stop",
|
||||
"content" => "*TEXT*"
|
||||
)
|
||||
)
|
||||
),
|
||||
Printer::BARCODE_ITF => array(
|
||||
"title" => "ITF",
|
||||
"caption" => "Variable length numeric w/even number of digits,\nas they are encoded in pairs.",
|
||||
"example" => array(
|
||||
array(
|
||||
"caption" => "Numeric- even number of digits",
|
||||
"content" => "0123456789"
|
||||
)
|
||||
)
|
||||
),
|
||||
Printer::BARCODE_CODABAR => array(
|
||||
"title" => "Codabar",
|
||||
"caption" => "Varaible length numeric with some allowable\nextra characters. ABCD/abcd must be used as\nstart/stop characters (one at the start, one\nat the end) to distinguish between barcode\napplications.",
|
||||
"example" => array(
|
||||
array(
|
||||
"caption" => "Numeric w/ A A start/stop. ",
|
||||
"content" => "A012345A"
|
||||
),
|
||||
array(
|
||||
"caption" => "Extra allowable characters",
|
||||
"content" => "A012$+-./:A"
|
||||
)
|
||||
)
|
||||
),
|
||||
Printer::BARCODE_CODE93 => array(
|
||||
"title" => "Code93",
|
||||
"caption" => "Variable length- any ASCII is available",
|
||||
"example" => array(
|
||||
array(
|
||||
"caption" => "Text",
|
||||
"content" => "012abcd"
|
||||
)
|
||||
)
|
||||
),
|
||||
Printer::BARCODE_CODE128 => array(
|
||||
"title" => "Code128",
|
||||
"caption" => "Variable length- any ASCII is available",
|
||||
"example" => array(
|
||||
array(
|
||||
"caption" => "Code set A uppercase & symbols",
|
||||
"content" => "{A" . "012ABCD"
|
||||
),
|
||||
array(
|
||||
"caption" => "Code set B general text",
|
||||
"content" => "{B" . "012ABCDabcd"
|
||||
),
|
||||
array(
|
||||
"caption" => "Code set C compact numbers\n Sending chr(21) chr(32) chr(43)",
|
||||
"content" => "{C" . chr(21) . chr(32) . chr(43)
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
$printer->setBarcodeTextPosition(Printer::BARCODE_TEXT_BELOW);
|
||||
foreach ($standards as $type => $standard) {
|
||||
$printer->selectPrintMode(Printer::MODE_DOUBLE_HEIGHT | Printer::MODE_DOUBLE_WIDTH);
|
||||
$printer->text($standard["title"] . "\n");
|
||||
$printer->selectPrintMode();
|
||||
$printer->text($standard["caption"] . "\n\n");
|
||||
foreach ($standard["example"] as $id => $barcode) {
|
||||
$printer->setEmphasis(true);
|
||||
$printer->text($barcode["caption"] . "\n");
|
||||
$printer->setEmphasis(false);
|
||||
$printer->text("Content: " . $barcode["content"] . "\n");
|
||||
$printer->barcode($barcode["content"], $type);
|
||||
$printer->feed();
|
||||
}
|
||||
}
|
||||
$printer->cut();
|
||||
$printer->close();
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
/* Example print-outs using the older bit image print command */
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
use Zelda\EscposPhp\Printer;
|
||||
use Zelda\EscposPhp\EscposImage;
|
||||
use Zelda\EscposPhp\PrintConnectors\FilePrintConnector;
|
||||
|
||||
$connector = new FilePrintConnector("php://stdout");
|
||||
$printer = new Printer($connector);
|
||||
|
||||
try {
|
||||
$tux = EscposImage::load("resources/tux.png", false);
|
||||
|
||||
$printer->text("These example images are printed with the older\nbit image print command. You should only use\n\$p -> bitImage() if \$p -> graphics() does not\nwork on your printer.\n\n");
|
||||
|
||||
$printer->bitImage($tux);
|
||||
$printer->text("Regular Tux (bit image).\n");
|
||||
$printer->feed();
|
||||
|
||||
$printer->bitImage($tux, Printer::IMG_DOUBLE_WIDTH);
|
||||
$printer->text("Wide Tux (bit image).\n");
|
||||
$printer->feed();
|
||||
|
||||
$printer->bitImage($tux, Printer::IMG_DOUBLE_HEIGHT);
|
||||
$printer->text("Tall Tux (bit image).\n");
|
||||
$printer->feed();
|
||||
|
||||
$printer->bitImage($tux, Printer::IMG_DOUBLE_WIDTH | Printer::IMG_DOUBLE_HEIGHT);
|
||||
$printer->text("Large Tux in correct proportion (bit image).\n");
|
||||
} catch (Exception $e) {
|
||||
/* Images not supported on your PHP, or image file not found */
|
||||
$printer->text($e->getMessage() . "\n");
|
||||
}
|
||||
|
||||
$printer->cut();
|
||||
$printer->close();
|
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
/* Change to the correct path if you copy this example! */
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
use Zelda\EscposPhp\Printer;
|
||||
use Zelda\EscposPhp\PrintConnectors\FilePrintConnector;
|
||||
use Zelda\EscposPhp\PrintBuffers\EscposPrintBuffer;
|
||||
use Zelda\EscposPhp\PrintBuffers\ImagePrintBuffer;
|
||||
use Zelda\EscposPhp\CapabilityProfile;
|
||||
|
||||
/**
|
||||
* This example builds on character-encodings.php, also providing an image-based rendering.
|
||||
* This is quite slow, since a) the buffers are changed dozens of
|
||||
* times in the example, and b) It involves sending very wide images, which printers don't like!
|
||||
*
|
||||
* There are currently no test cases around the image printing, since it is an experimental feature.
|
||||
*
|
||||
* It does, however, illustrate the way that more encodings are available when image output is used.
|
||||
*/
|
||||
include(dirname(__FILE__) . '/resources/character-encoding-test-strings.inc');
|
||||
|
||||
try {
|
||||
// Enter connector and capability profile
|
||||
$connector = new FilePrintConnector("php://stdout");
|
||||
$profile = CapabilityProfile::load('default');
|
||||
$buffers = array(new EscposPrintBuffer(), new ImagePrintBuffer());
|
||||
|
||||
/* Print a series of receipts containing i18n example strings */
|
||||
$printer = new Printer($connector, $profile);
|
||||
$printer->selectPrintMode(Printer::MODE_DOUBLE_HEIGHT | Printer::MODE_EMPHASIZED | Printer::MODE_DOUBLE_WIDTH);
|
||||
$printer->text("Implemented languages\n");
|
||||
$printer->selectPrintMode();
|
||||
foreach ($inputsOk as $label => $str) {
|
||||
$printer->setEmphasis(true);
|
||||
$printer->text($label . ":\n");
|
||||
$printer->setEmphasis(false);
|
||||
foreach ($buffers as $buffer) {
|
||||
$printer->setPrintBuffer($buffer);
|
||||
$printer->text($str);
|
||||
}
|
||||
$printer->setPrintBuffer($buffers[0]);
|
||||
}
|
||||
$printer->feed();
|
||||
|
||||
$printer->selectPrintMode(Printer::MODE_DOUBLE_HEIGHT | Printer::MODE_EMPHASIZED | Printer::MODE_DOUBLE_WIDTH);
|
||||
$printer->text("Works in progress\n");
|
||||
$printer->selectPrintMode();
|
||||
foreach ($inputsNotOk as $label => $str) {
|
||||
$printer->setEmphasis(true);
|
||||
$printer->text($label . ":\n");
|
||||
$printer->setEmphasis(false);
|
||||
foreach ($buffers as $buffer) {
|
||||
$printer->setPrintBuffer($buffer);
|
||||
$printer->text($str);
|
||||
}
|
||||
$printer->setPrintBuffer($buffers[0]);
|
||||
}
|
||||
$printer->cut();
|
||||
|
||||
/* Close printer */
|
||||
$printer->close();
|
||||
} catch (Exception $e) {
|
||||
echo "Couldn't print to this printer: " . $e->getMessage() . "\n";
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
/* Change to the correct path if you copy this example! */
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
use Zelda\EscposPhp\Printer;
|
||||
use Zelda\EscposPhp\PrintConnectors\FilePrintConnector;
|
||||
use Zelda\EscposPhp\CapabilityProfile;
|
||||
|
||||
/**
|
||||
* This demonstrates available character encodings. Escpos-php accepts UTF-8,
|
||||
* and converts this to lower-level data to the printer. This is a complex area, so be
|
||||
* prepared to code a model-specific hack ('CapabilityProfile') for your printer.
|
||||
*
|
||||
* If you run into trouble, please file an issue on GitHub, including at a minimum:
|
||||
* - A UTF-8 test string in the language you're working in, and
|
||||
* - A test print or link to a technical document which lists the available
|
||||
* code pages ('character code tables') for your printer.
|
||||
*
|
||||
* The DefaultCapabilityProfile works for Espson-branded printers. For other models, you
|
||||
* must use/create a PrinterCapabilityProfile for your printer containing a list of code
|
||||
* page numbers for your printer- otherwise you will get mojibake.
|
||||
*
|
||||
* If you do not intend to use non-English characters, then use SimpleCapabilityProfile,
|
||||
* which has only the default encoding, effectively disabling code page changes.
|
||||
*/
|
||||
|
||||
include(dirname(__FILE__) . '/resources/character-encoding-test-strings.inc');
|
||||
try {
|
||||
// Enter connector and capability profile (to match your printer)
|
||||
$connector = new FilePrintConnector("php://stdout");
|
||||
$profile = CapabilityProfile::load("default");
|
||||
|
||||
/* Print a series of receipts containing i18n example strings */
|
||||
$printer = new Printer($connector, $profile);
|
||||
$printer->selectPrintMode(Printer::MODE_DOUBLE_HEIGHT | Printer::MODE_EMPHASIZED | Printer::MODE_DOUBLE_WIDTH);
|
||||
$printer->text("Implemented languages\n");
|
||||
$printer->selectPrintMode();
|
||||
foreach ($inputsOk as $label => $str) {
|
||||
$printer->setEmphasis(true);
|
||||
$printer->text($label . ":\n");
|
||||
$printer->setEmphasis(false);
|
||||
$printer->text($str);
|
||||
}
|
||||
$printer->feed();
|
||||
|
||||
$printer->selectPrintMode(Printer::MODE_DOUBLE_HEIGHT | Printer::MODE_EMPHASIZED | Printer::MODE_DOUBLE_WIDTH);
|
||||
$printer->text("Works in progress\n");
|
||||
$printer->selectPrintMode();
|
||||
foreach ($inputsNotOk as $label => $str) {
|
||||
$printer->setEmphasis(true);
|
||||
$printer->text($label . ":\n");
|
||||
$printer->setEmphasis(false);
|
||||
$printer->text($str);
|
||||
}
|
||||
$printer->cut();
|
||||
|
||||
/* Close printer */
|
||||
$printer->close();
|
||||
} catch (Exception $e) {
|
||||
echo "Couldn't print to this printer: " . $e->getMessage() . "\n";
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* This demo prints out supported code pages on your printer. This is intended
|
||||
* for debugging character-encoding issues: If your printer does not work with
|
||||
* a built-in capability profile, you need to check its documentation for
|
||||
* supported code pages.
|
||||
*
|
||||
* These are then loaded into a capability profile, which maps code page
|
||||
* numbers to iconv encoding names on your particular printer. This script
|
||||
* will print all configured code pages, so that you can check that the chosen
|
||||
* iconv encoding name matches the actual code page contents.
|
||||
*
|
||||
* If this is correctly set up for your printer, then the driver will try its
|
||||
* best to map UTF-8 text into these code pages for you, allowing you to accept
|
||||
* arbitrary input from a database, without worrying about encoding it for the printer.
|
||||
*/
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
use Zelda\EscposPhp\Printer;
|
||||
use Zelda\EscposPhp\PrintConnectors\FilePrintConnector;
|
||||
use Zelda\EscposPhp\CapabilityProfile;
|
||||
|
||||
// Enter connector and capability profile (to match your printer)
|
||||
$connector = new FilePrintConnector("php://stdout");
|
||||
$profile = CapabilityProfile::load("default");
|
||||
$verbose = false; // Skip tables which iconv wont convert to (ie, only print characters available with UTF-8 input)
|
||||
|
||||
/* Print a series of receipts containing i18n example strings - Code below shouldn't need changing */
|
||||
$printer = new Zelda\EscposPhp\Printer($connector, $profile);
|
||||
$codePages = $profile->getCodePages();
|
||||
$first = true; // Print larger table for first code-page.
|
||||
foreach ($codePages as $table => $page) {
|
||||
/* Change printer code page */
|
||||
$printer->selectCharacterTable(255);
|
||||
$printer->selectCharacterTable($table);
|
||||
/* Select & print a label for it */
|
||||
$label = $page->getId();
|
||||
if (!$page->isEncodable()) {
|
||||
$label = " (not supported)";
|
||||
}
|
||||
$printer->setEmphasis(true);
|
||||
$printer->textRaw("Table $table: $label\n");
|
||||
$printer->setEmphasis(false);
|
||||
if (!$page->isEncodable() && !$verbose) {
|
||||
continue; // Skip non-recognised
|
||||
}
|
||||
/* Print a table of available characters (first table is larger than subsequent ones */
|
||||
if ($first) {
|
||||
$first = false;
|
||||
compactCharTable($printer, 1, true);
|
||||
} else {
|
||||
compactCharTable($printer);
|
||||
}
|
||||
}
|
||||
$printer->cut();
|
||||
$printer->close();
|
||||
|
||||
function compactCharTable($printer, $start = 4, $header = false)
|
||||
{
|
||||
/* Output a compact character table for the current encoding */
|
||||
$chars = str_repeat(' ', 256);
|
||||
for ($i = 0; $i < 255; $i++) {
|
||||
$chars[$i] = ($i > 32 && $i != 127) ? chr($i) : ' ';
|
||||
}
|
||||
if ($header) {
|
||||
$printer->setEmphasis(true);
|
||||
$printer->textRaw(" 0123456789ABCDEF0123456789ABCDEF\n");
|
||||
$printer->setEmphasis(false);
|
||||
}
|
||||
for ($y = $start; $y < 8; $y++) {
|
||||
$printer->setEmphasis(true);
|
||||
$printer->textRaw(strtoupper(dechex($y * 2)) . " ");
|
||||
$printer->setEmphasis(false);
|
||||
$printer->textRaw(substr($chars, $y * 32, 32) . "\n");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* This demo interacts with an Aures OCD-300 customer display,
|
||||
* showing its support for ESC/POS text encodings.
|
||||
*/
|
||||
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
use Zelda\EscposPhp\PrintConnectors\FilePrintConnector;
|
||||
use Zelda\EscposPhp\CapabilityProfile;
|
||||
use Zelda\EscposPhp\Printer;
|
||||
use Zelda\EscposPhp\Devices\AuresCustomerDisplay;
|
||||
|
||||
/*
|
||||
* Device appears as a serial port.
|
||||
*
|
||||
* stat /dev/ttyACM0
|
||||
* sudo usermod -a -G dialout [username]
|
||||
*/
|
||||
|
||||
$connector = new FilePrintConnector("/dev/ttyACM0");
|
||||
|
||||
// Profile and display
|
||||
$profile = CapabilityProfile::load("OCD-300");
|
||||
$display = new AuresCustomerDisplay($connector, $profile);
|
||||
|
||||
|
||||
// Make a really long test string
|
||||
include(__DIR__ . "/resources/character-encoding-test-strings.inc");
|
||||
$input = "";
|
||||
foreach ($inputsOk as $str) {
|
||||
$input .= $str;
|
||||
}
|
||||
|
||||
// Wrap at a fixed width (as ASCII...), and show the user
|
||||
// what's about to be sent to the printer
|
||||
$wrapped = wordwrap($input, 20);
|
||||
echo ($wrapped);
|
||||
|
||||
// Roll out each line with 0.5s delay
|
||||
foreach (explode("\n", $wrapped) as $line) {
|
||||
$display->feed();
|
||||
$display->text($line);
|
||||
usleep(500000);
|
||||
}
|
||||
|
||||
// Finish by showing "Hello World"
|
||||
$display->clear();
|
||||
$display->text("Hello World\n");
|
||||
|
||||
// Dont forget to close the device
|
||||
$display->close();
|
|
@ -0,0 +1,177 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* This is a demo script for the functions of the PHP ESC/POS print driver,
|
||||
* Escpos.php.
|
||||
*
|
||||
* Most printers implement only a subset of the functionality of the driver, so
|
||||
* will not render this output correctly in all cases.
|
||||
*
|
||||
* @author Michael Billington <michael.billington@gmail.com>
|
||||
*/
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
use Zelda\EscposPhp\Printer;
|
||||
use Zelda\EscposPhp\PrintConnectors\FilePrintConnector;
|
||||
use Zelda\EscposPhp\EscposImage;
|
||||
|
||||
$connector = new FilePrintConnector("php://stdout");
|
||||
$printer = new Printer($connector);
|
||||
|
||||
/* Initialize */
|
||||
$printer->initialize();
|
||||
|
||||
/* Text */
|
||||
$printer->text("Hello world\n");
|
||||
$printer->cut();
|
||||
|
||||
/* Line feeds */
|
||||
$printer->text("ABC");
|
||||
$printer->feed(7);
|
||||
$printer->text("DEF");
|
||||
$printer->feedReverse(3);
|
||||
$printer->text("GHI");
|
||||
$printer->feed();
|
||||
$printer->cut();
|
||||
|
||||
/* Font modes */
|
||||
$modes = array(
|
||||
Printer::MODE_FONT_B,
|
||||
Printer::MODE_EMPHASIZED,
|
||||
Printer::MODE_DOUBLE_HEIGHT,
|
||||
Printer::MODE_DOUBLE_WIDTH,
|
||||
Printer::MODE_UNDERLINE
|
||||
);
|
||||
for ($i = 0; $i < pow(2, count($modes)); $i++) {
|
||||
$bits = str_pad(decbin($i), count($modes), "0", STR_PAD_LEFT);
|
||||
$mode = 0;
|
||||
for ($j = 0; $j < strlen($bits); $j++) {
|
||||
if (substr($bits, $j, 1) == "1") {
|
||||
$mode |= $modes[$j];
|
||||
}
|
||||
}
|
||||
$printer->selectPrintMode($mode);
|
||||
$printer->text("ABCDEFGHIJabcdefghijk\n");
|
||||
}
|
||||
$printer->selectPrintMode(); // Reset
|
||||
$printer->cut();
|
||||
|
||||
/* Underline */
|
||||
for ($i = 0; $i < 3; $i++) {
|
||||
$printer->setUnderline($i);
|
||||
$printer->text("The quick brown fox jumps over the lazy dog\n");
|
||||
}
|
||||
$printer->setUnderline(0); // Reset
|
||||
$printer->cut();
|
||||
|
||||
/* Cuts */
|
||||
$printer->text("Partial cut\n(not available on all printers)\n");
|
||||
$printer->cut(Printer::CUT_PARTIAL);
|
||||
$printer->text("Full cut\n");
|
||||
$printer->cut(Printer::CUT_FULL);
|
||||
|
||||
/* Emphasis */
|
||||
for ($i = 0; $i < 2; $i++) {
|
||||
$printer->setEmphasis($i == 1);
|
||||
$printer->text("The quick brown fox jumps over the lazy dog\n");
|
||||
}
|
||||
$printer->setEmphasis(false); // Reset
|
||||
$printer->cut();
|
||||
|
||||
/* Double-strike (looks basically the same as emphasis) */
|
||||
for ($i = 0; $i < 2; $i++) {
|
||||
$printer->setDoubleStrike($i == 1);
|
||||
$printer->text("The quick brown fox jumps over the lazy dog\n");
|
||||
}
|
||||
$printer->setDoubleStrike(false);
|
||||
$printer->cut();
|
||||
|
||||
/* Fonts (many printers do not have a 'Font C') */
|
||||
$fonts = array(
|
||||
Printer::FONT_A,
|
||||
Printer::FONT_B,
|
||||
Printer::FONT_C
|
||||
);
|
||||
for ($i = 0; $i < count($fonts); $i++) {
|
||||
$printer->setFont($fonts[$i]);
|
||||
$printer->text("The quick brown fox jumps over the lazy dog\n");
|
||||
}
|
||||
$printer->setFont(); // Reset
|
||||
$printer->cut();
|
||||
|
||||
/* Justification */
|
||||
$justification = array(
|
||||
Printer::JUSTIFY_LEFT,
|
||||
Printer::JUSTIFY_CENTER,
|
||||
Printer::JUSTIFY_RIGHT
|
||||
);
|
||||
for ($i = 0; $i < count($justification); $i++) {
|
||||
$printer->setJustification($justification[$i]);
|
||||
$printer->text("A man a plan a canal panama\n");
|
||||
}
|
||||
$printer->setJustification(); // Reset
|
||||
$printer->cut();
|
||||
|
||||
/* Barcodes - see barcode.php for more detail */
|
||||
$printer->setBarcodeHeight(80);
|
||||
$printer->setBarcodeTextPosition(Printer::BARCODE_TEXT_BELOW);
|
||||
$printer->barcode("9876");
|
||||
$printer->feed();
|
||||
$printer->cut();
|
||||
|
||||
/* Graphics - this demo will not work on some non-Epson printers */
|
||||
try {
|
||||
$logo = EscposImage::load("resources/escpos-php.png", false);
|
||||
$imgModes = array(
|
||||
Printer::IMG_DEFAULT,
|
||||
Printer::IMG_DOUBLE_WIDTH,
|
||||
Printer::IMG_DOUBLE_HEIGHT,
|
||||
Printer::IMG_DOUBLE_WIDTH | Printer::IMG_DOUBLE_HEIGHT
|
||||
);
|
||||
foreach ($imgModes as $mode) {
|
||||
$printer->graphics($logo, $mode);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
/* Images not supported on your PHP, or image file not found */
|
||||
$printer->text($e->getMessage() . "\n");
|
||||
}
|
||||
$printer->cut();
|
||||
|
||||
/* Bit image */
|
||||
try {
|
||||
$logo = EscposImage::load("resources/escpos-php.png", false);
|
||||
$imgModes = array(
|
||||
Printer::IMG_DEFAULT,
|
||||
Printer::IMG_DOUBLE_WIDTH,
|
||||
Printer::IMG_DOUBLE_HEIGHT,
|
||||
Printer::IMG_DOUBLE_WIDTH | Printer::IMG_DOUBLE_HEIGHT
|
||||
);
|
||||
foreach ($imgModes as $mode) {
|
||||
$printer->bitImage($logo, $mode);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
/* Images not supported on your PHP, or image file not found */
|
||||
$printer->text($e->getMessage() . "\n");
|
||||
}
|
||||
$printer->cut();
|
||||
|
||||
/* QR Code - see also the more in-depth demo at qr-code.php */
|
||||
$testStr = "Testing 123";
|
||||
$models = array(
|
||||
Printer::QR_MODEL_1 => "QR Model 1",
|
||||
Printer::QR_MODEL_2 => "QR Model 2 (default)",
|
||||
Printer::QR_MICRO => "Micro QR code\n(not supported on all printers)"
|
||||
);
|
||||
foreach ($models as $model => $name) {
|
||||
$printer->qrCode($testStr, Printer::QR_ECLEVEL_L, 3, $model);
|
||||
$printer->text("$name\n");
|
||||
$printer->feed();
|
||||
}
|
||||
$printer->cut();
|
||||
|
||||
/* Pulse */
|
||||
$printer->pulse();
|
||||
|
||||
/* Always close the printer! On some PrintConnectors, no actual
|
||||
* data is sent until the printer is closed. */
|
||||
$printer->close();
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
/* Print-outs using the newer graphics print command */
|
||||
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
use Zelda\EscposPhp\Printer;
|
||||
use Zelda\EscposPhp\EscposImage;
|
||||
use Zelda\EscposPhp\PrintConnectors\FilePrintConnector;
|
||||
|
||||
$connector = new FilePrintConnector("php://stdout");
|
||||
$printer = new Printer($connector);
|
||||
|
||||
try {
|
||||
$tux = EscposImage::load("resources/tux.png", false);
|
||||
|
||||
$printer->graphics($tux);
|
||||
$printer->text("Regular Tux.\n");
|
||||
$printer->feed();
|
||||
|
||||
$printer->graphics($tux, Printer::IMG_DOUBLE_WIDTH);
|
||||
$printer->text("Wide Tux.\n");
|
||||
$printer->feed();
|
||||
|
||||
$printer->graphics($tux, Printer::IMG_DOUBLE_HEIGHT);
|
||||
$printer->text("Tall Tux.\n");
|
||||
$printer->feed();
|
||||
|
||||
$printer->graphics($tux, Printer::IMG_DOUBLE_WIDTH | Printer::IMG_DOUBLE_HEIGHT);
|
||||
$printer->text("Large Tux in correct proportion.\n");
|
||||
|
||||
$printer->cut();
|
||||
} catch (Exception $e) {
|
||||
/* Images not supported on your PHP, or image file not found */
|
||||
$printer->text($e->getMessage() . "\n");
|
||||
}
|
||||
|
||||
$printer->close();
|
|
@ -0,0 +1,8 @@
|
|||
Interfaces
|
||||
----------
|
||||
This directory contains boilerpalte code to show you how to open a print connector
|
||||
to printers which are connected in different ways.
|
||||
|
||||
To get a list of supported interfaces and operating systems, see the main README.md file for the project.
|
||||
|
||||
If you have a printer interface with no example, and you want to help put one together, then please lodge a request on the bug tracker: https://github.com/mike42/escpos-php/issues
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
/* Change to the correct path if you copy this example! */
|
||||
require __DIR__ . '/../../vendor/autoload.php';
|
||||
|
||||
use Zelda\EscposPhp\Printer;
|
||||
use Zelda\EscposPhp\PrintConnectors\CupsPrintConnector;
|
||||
|
||||
try {
|
||||
$connector = new CupsPrintConnector("EPSON_TM-T20");
|
||||
|
||||
/* Print a "Hello world" receipt" */
|
||||
$printer = new Printer($connector);
|
||||
$printer->text("Hello World!\n");
|
||||
$printer->cut();
|
||||
|
||||
/* Close printer */
|
||||
$printer->close();
|
||||
} catch (Exception $e) {
|
||||
echo "Couldn't print to this printer: " . $e->getMessage() . "\n";
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
/* Change to the correct path if you copy this example! */
|
||||
require __DIR__ . '/../../vendor/autoload.php';
|
||||
|
||||
use Zelda\EscposPhp\Printer;
|
||||
use Zelda\EscposPhp\PrintConnectors\NetworkPrintConnector;
|
||||
|
||||
/* Most printers are open on port 9100, so you just need to know the IP
|
||||
* address of your receipt printer, and then fsockopen() it on that port.
|
||||
*/
|
||||
|
||||
try {
|
||||
$connector = new NetworkPrintConnector("10.x.x.x", 9100);
|
||||
|
||||
/* Print a "Hello world" receipt" */
|
||||
$printer = new Printer($connector);
|
||||
$printer->text("Hello World!\n");
|
||||
$printer->cut();
|
||||
|
||||
/* Close printer */
|
||||
$printer->close();
|
||||
} catch (Exception $e) {
|
||||
echo "Couldn't print to this printer: " . $e->getMessage() . "\n";
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
/* Change to the correct path if you copy this example! */
|
||||
require __DIR__ . '/../../vendor/autoload.php';
|
||||
|
||||
use Zelda\EscposPhp\Printer;
|
||||
use Zelda\EscposPhp\PrintConnectors\FilePrintConnector;
|
||||
|
||||
/**
|
||||
* On Linux, use the usblp module to make your printer available as a device
|
||||
* file. This is generally the default behaviour if you don't install any
|
||||
* vendor drivers.
|
||||
*
|
||||
* Once this is done, use a FilePrintConnector to open the device.
|
||||
*
|
||||
* Troubleshooting: On Debian, you must be in the lp group to access this file.
|
||||
* dmesg to see what happens when you plug in your printer to make sure no
|
||||
* other drivers are unloading the module.
|
||||
*/
|
||||
try {
|
||||
// Enter the device file for your USB printer here
|
||||
$connector = new FilePrintConnector("/dev/usb/lp0");
|
||||
//$connector = new FilePrintConnector("/dev/usb/lp1");
|
||||
//$connector = new FilePrintConnector("/dev/usb/lp2");
|
||||
|
||||
/* Print a "Hello world" receipt" */
|
||||
$printer = new Printer($connector);
|
||||
$printer->text("Hello World!\n");
|
||||
$printer->cut();
|
||||
|
||||
/* Close printer */
|
||||
$printer->close();
|
||||
} catch (Exception $e) {
|
||||
echo "Couldn't print to this printer: " . $e->getMessage() . "\n";
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
/* Change to the correct path if you copy this example! */
|
||||
require __DIR__ . '/../../vendor/autoload.php';
|
||||
|
||||
use Zelda\EscposPhp\Printer;
|
||||
use Zelda\EscposPhp\PrintConnectors\WindowsPrintConnector;
|
||||
|
||||
/**
|
||||
* Install the printer using USB printing support, and the "Generic / Text Only" driver,
|
||||
* then share it.
|
||||
*
|
||||
* Use a WindowsPrintConnector with the share name to print. This works on either
|
||||
* Windows or Linux.
|
||||
*
|
||||
* Troubleshooting: Fire up a command prompt/terminal, and ensure that (if your printer is
|
||||
* shared as "Receipt Printer"), the following commands work.
|
||||
*
|
||||
* Windows: (use an appropriate "net use" command if you need authentication)
|
||||
* echo "Hello World" > testfile
|
||||
* ## If you need authentication, use "net use" to hook up the printer:
|
||||
* # net use "\\computername\Receipt Printer" /user:Guest
|
||||
* # net use "\\computername\Receipt Printer" /user:Bob secret
|
||||
* # net use "\\computername\Receipt Printer" /user:workgroup\Bob secret
|
||||
* copy testfile "\\computername\Receipt Printer"
|
||||
* del testfile
|
||||
*
|
||||
* GNU/Linux:
|
||||
* # No authentication
|
||||
* echo "Hello World" | smbclient "//computername/Receipt Printer" -c "print -" -N
|
||||
* # Guest login
|
||||
* echo "Hello World" | smbclient "//computername/Receipt Printer" -U Guest -c "print -" -N
|
||||
* # Basic username/password
|
||||
* echo "Hello World" | smbclient "//computername/Receipt Printer" secret -U "Bob" -c "print -"
|
||||
* # Including domain name
|
||||
* echo "Hello World" | smbclient "//computername/Receipt Printer" secret -U "workgroup\\Bob" -c "print -"
|
||||
*/
|
||||
try {
|
||||
// Enter the share name for your printer here, as a smb:// url format
|
||||
$connector = new WindowsPrintConnector("smb://computername/Receipt Printer");
|
||||
//$connector = new WindowsPrintConnector("smb://Guest@computername/Receipt Printer");
|
||||
//$connector = new WindowsPrintConnector("smb://FooUser:secret@computername/workgroup/Receipt Printer");
|
||||
//$connector = new WindowsPrintConnector("smb://User:secret@computername/Receipt Printer");
|
||||
|
||||
/* Print a "Hello world" receipt" */
|
||||
$printer = new Printer($connector);
|
||||
$printer->text("Hello World!\n");
|
||||
$printer->cut();
|
||||
|
||||
/* Close printer */
|
||||
$printer->close();
|
||||
} catch (Exception $e) {
|
||||
echo "Couldn't print to this printer: " . $e->getMessage() . "\n";
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
/* Change to the correct path if you copy this example! */
|
||||
require __DIR__ . '/../../vendor/autoload.php';
|
||||
|
||||
use Zelda\EscposPhp\Printer;
|
||||
use Zelda\EscposPhp\PrintConnectors\WindowsPrintConnector;
|
||||
|
||||
/**
|
||||
* Assuming your printer is available at LPT1,
|
||||
* simpy instantiate a WindowsPrintConnector to it.
|
||||
*
|
||||
* When troubleshooting, make sure you can send it
|
||||
* data from the command-line first:
|
||||
* echo "Hello World" > LPT1
|
||||
*/
|
||||
try {
|
||||
$connector = new WindowsPrintConnector("LPT1");
|
||||
|
||||
// A FilePrintConnector will also work, but on non-Windows systems, writes
|
||||
// to an actual file called 'LPT1' rather than giving a useful error.
|
||||
// $connector = new FilePrintConnector("LPT1");
|
||||
|
||||
/* Print a "Hello world" receipt" */
|
||||
$printer = new Printer($connector);
|
||||
$printer->text("Hello World!\n");
|
||||
$printer->cut();
|
||||
|
||||
/* Close printer */
|
||||
$printer->close();
|
||||
} catch (Exception $e) {
|
||||
echo "Couldn't print to this printer: " . $e->getMessage() . "\n";
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
/* Change to the correct path if you copy this example! */
|
||||
require __DIR__ . '/../../vendor/autoload.php';
|
||||
|
||||
use Zelda\EscposPhp\Printer;
|
||||
use Zelda\EscposPhp\PrintConnectors\WindowsPrintConnector;
|
||||
|
||||
/**
|
||||
* Install the printer using USB printing support, and the "Generic / Text Only" driver,
|
||||
* then share it (you can use a firewall so that it can only be seen locally).
|
||||
*
|
||||
* Use a WindowsPrintConnector with the share name to print.
|
||||
*
|
||||
* Troubleshooting: Fire up a command prompt, and ensure that (if your printer is shared as
|
||||
* "Receipt Printer), the following commands work:
|
||||
*
|
||||
* echo "Hello World" > testfile
|
||||
* copy testfile "\\%COMPUTERNAME%\Receipt Printer"
|
||||
* del testfile
|
||||
*/
|
||||
try {
|
||||
// Enter the share name for your USB printer here
|
||||
$connector = null;
|
||||
//$connector = new WindowsPrintConnector("Receipt Printer");
|
||||
|
||||
/* Print a "Hello world" receipt" */
|
||||
$printer = new Printer($connector);
|
||||
$printer->text("Hello World!\n");
|
||||
$printer->cut();
|
||||
|
||||
/* Close printer */
|
||||
$printer->close();
|
||||
} catch (Exception $e) {
|
||||
echo "Couldn't print to this printer: " . $e->getMessage() . "\n";
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
/* Left margin & page width demo. */
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
use Zelda\EscposPhp\Printer;
|
||||
use Zelda\EscposPhp\PrintConnectors\FilePrintConnector;
|
||||
|
||||
$connector = new FilePrintConnector("php://stdout"); // Add connector for your printer here.
|
||||
$printer = new Printer($connector);
|
||||
|
||||
/* Line spacing */
|
||||
/*
|
||||
$printer -> setEmphasis(true);
|
||||
$printer -> text("Line spacing\n");
|
||||
$printer -> setEmphasis(false);
|
||||
foreach(array(16, 32, 64, 128, 255) as $spacing) {
|
||||
$printer -> setLineSpacing($spacing);
|
||||
$printer -> text("Spacing $spacing: The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.\n");
|
||||
}
|
||||
$printer -> setLineSpacing(); // Back to default
|
||||
*/
|
||||
|
||||
/* Stuff around with left margin */
|
||||
$printer->setEmphasis(true);
|
||||
$printer->text("Left margin\n");
|
||||
$printer->setEmphasis(false);
|
||||
$printer->text("Default left\n");
|
||||
foreach (array(1, 2, 4, 8, 16, 32, 64, 128, 256, 512) as $margin) {
|
||||
$printer->setPrintLeftMargin($margin);
|
||||
$printer->text("left margin $margin\n");
|
||||
}
|
||||
/* Reset left */
|
||||
$printer->setPrintLeftMargin(0);
|
||||
|
||||
/* Stuff around with page width */
|
||||
$printer->setEmphasis(true);
|
||||
$printer->text("Page width\n");
|
||||
$printer->setEmphasis(false);
|
||||
$printer->setJustification(Printer::JUSTIFY_RIGHT);
|
||||
$printer->text("Default width\n");
|
||||
foreach (array(512, 256, 128, 64) as $width) {
|
||||
$printer->setPrintWidth($width);
|
||||
$printer->text("page width $width\n");
|
||||
}
|
||||
|
||||
/* Printer shutdown */
|
||||
$printer->cut();
|
||||
$printer->close();
|
|
@ -0,0 +1,100 @@
|
|||
<?php
|
||||
/* Demonstration of available options on the pdf417Code() command */
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
use Zelda\EscposPhp\Printer;
|
||||
use Zelda\EscposPhp\PrintConnectors\FilePrintConnector;
|
||||
|
||||
$connector = new FilePrintConnector("php://stdout");
|
||||
$printer = new Printer($connector);
|
||||
|
||||
// Most simple example
|
||||
title($printer, "PDF417 code demo\n");
|
||||
$testStr = "Testing 123";
|
||||
$printer->pdf417Code($testStr);
|
||||
$printer->text("Most simple example\n");
|
||||
$printer->feed();
|
||||
|
||||
// Demo that alignment is the same as text
|
||||
$printer->setJustification(Printer::JUSTIFY_CENTER);
|
||||
$printer->pdf417Code($testStr, 3, 3, 2);
|
||||
$printer->text("Same content, narrow and centred\n");
|
||||
$printer->setJustification();
|
||||
$printer->feed();
|
||||
|
||||
// Demo of error correction
|
||||
title($printer, "Error correction\n");
|
||||
$ec = array(0.1, 0.5, 1.0, 2.0, 4.0);
|
||||
foreach ($ec as $level) {
|
||||
$printer->pdf417Code($testStr, 3, 3, 0, $level);
|
||||
$printer->text("Error correction ratio $level\n");
|
||||
$printer->feed();
|
||||
}
|
||||
|
||||
// Change size
|
||||
title($printer, "Pixel size\n");
|
||||
$sizes = array(
|
||||
2 => "(minimum)",
|
||||
3 => "(default)",
|
||||
4 => "",
|
||||
8 => "(maximum)"
|
||||
);
|
||||
foreach ($sizes as $size => $label) {
|
||||
$printer->pdf417Code($testStr, $size);
|
||||
$printer->text("Module width $size dots $label\n");
|
||||
$printer->feed();
|
||||
}
|
||||
|
||||
// Change height
|
||||
title($printer, "Height multiplier\n");
|
||||
$sizes = array(
|
||||
2 => "(minimum)",
|
||||
3 => "(default)",
|
||||
4 => "",
|
||||
8 => "(maximum)"
|
||||
);
|
||||
foreach ($sizes as $size => $label) {
|
||||
$printer->pdf417Code($testStr, 3, $size);
|
||||
$printer->text("Height multiplier $size $label\n");
|
||||
$printer->feed();
|
||||
}
|
||||
|
||||
// Chage data column count
|
||||
title($printer, "Data column count\n");
|
||||
$columnCounts = array(
|
||||
0 => "(auto, default)",
|
||||
1 => "",
|
||||
2 => "",
|
||||
3 => "",
|
||||
4 => "",
|
||||
5 => "",
|
||||
30 => "(maximum, doesnt fit!)"
|
||||
);
|
||||
foreach ($columnCounts as $columnCount => $label) {
|
||||
$printer->pdf417Code($testStr, 3, 3, $columnCount);
|
||||
$printer->text("Column count $columnCount $label\n");
|
||||
$printer->feed();
|
||||
}
|
||||
|
||||
// Change options
|
||||
title($printer, "Options\n");
|
||||
$models = array(
|
||||
Printer::PDF417_STANDARD => "Standard",
|
||||
Printer::PDF417_TRUNCATED => "Truncated"
|
||||
);
|
||||
foreach ($models as $model => $name) {
|
||||
$printer->pdf417Code($testStr, 3, 3, 0, 0.10, $model);
|
||||
$printer->text("$name\n");
|
||||
$printer->feed();
|
||||
}
|
||||
|
||||
// Cut & close
|
||||
$printer->cut();
|
||||
$printer->close();
|
||||
|
||||
function title(Printer $printer, $str)
|
||||
{
|
||||
$printer->selectPrintMode(Printer::MODE_DOUBLE_HEIGHT | Printer::MODE_DOUBLE_WIDTH);
|
||||
$printer->text($str);
|
||||
$printer->selectPrintMode();
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
<?php
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
use Zelda\EscposPhp\Printer;
|
||||
use Zelda\EscposPhp\EscposImage;
|
||||
use Zelda\EscposPhp\PrintConnectors\FilePrintConnector;
|
||||
|
||||
$connector = new FilePrintConnector("php://stdout"); // Add connector for your printer here.
|
||||
$printer = new Printer($connector);
|
||||
|
||||
/*
|
||||
* Due to its complxity, escpos-php does not support HTML input. To print HTML,
|
||||
* either convert it to calls on the Printer() object, or rasterise the page with
|
||||
* wkhtmltopdf, an external package which is designed to handle HTML efficiently.
|
||||
*
|
||||
* This example is provided to get you started: On Debian, first run-
|
||||
*
|
||||
* sudo apt-get install wkhtmltopdf xvfb
|
||||
*
|
||||
* Note: Depending on the height of your pages, it is suggested that you chop it
|
||||
* into smaller sections, as printers simply don't have the buffer capacity for
|
||||
* very large images.
|
||||
*
|
||||
* As always, you can trade off quality for capacity by halving the width
|
||||
* (550 -> 225 below) and printing w/ Escpos::IMG_DOUBLE_WIDTH | Escpos::IMG_DOUBLE_HEIGHT
|
||||
*/
|
||||
try {
|
||||
/* Set up command */
|
||||
$source = __DIR__ . "/resources/document.html";
|
||||
$width = 550;
|
||||
$dest = tempnam(sys_get_temp_dir(), 'escpos') . ".png";
|
||||
$command = sprintf(
|
||||
"xvfb-run wkhtmltoimage -n -q --width %s %s %s",
|
||||
escapeshellarg($width),
|
||||
escapeshellarg($source),
|
||||
escapeshellarg($dest)
|
||||
);
|
||||
|
||||
/* Test for dependencies */
|
||||
foreach (array("xvfb-run", "wkhtmltoimage") as $cmd) {
|
||||
$testCmd = sprintf("which %s", escapeshellarg($cmd));
|
||||
exec($testCmd, $testOut, $testStatus);
|
||||
if ($testStatus != 0) {
|
||||
throw new Exception("You require $cmd but it could not be found");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Run wkhtmltoimage */
|
||||
$descriptors = array(
|
||||
1 => array("pipe", "w"),
|
||||
2 => array("pipe", "w"),
|
||||
);
|
||||
$process = proc_open($command, $descriptors, $fd);
|
||||
if (is_resource($process)) {
|
||||
/* Read stdout */
|
||||
$outputStr = stream_get_contents($fd[1]);
|
||||
fclose($fd[1]);
|
||||
/* Read stderr */
|
||||
$errorStr = stream_get_contents($fd[2]);
|
||||
fclose($fd[2]);
|
||||
/* Finish up */
|
||||
$retval = proc_close($process);
|
||||
if ($retval != 0) {
|
||||
throw new Exception("Command $cmd failed: $outputStr $errorStr");
|
||||
}
|
||||
} else {
|
||||
throw new Exception("Command '$cmd' failed to start.");
|
||||
}
|
||||
|
||||
/* Load up the image */
|
||||
try {
|
||||
$img = EscposImage::load($dest);
|
||||
} catch (Exception $e) {
|
||||
unlink($dest);
|
||||
throw $e;
|
||||
}
|
||||
unlink($dest);
|
||||
|
||||
/* Print it */
|
||||
$printer->bitImage($img); // bitImage() seems to allow larger images than graphics() on the TM-T20. bitImageColumnFormat() is another option.
|
||||
$printer->cut();
|
||||
} catch (Exception $e) {
|
||||
echo $e->getMessage();
|
||||
} finally {
|
||||
$printer->close();
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
use Zelda\EscposPhp\Printer;
|
||||
use Zelda\EscposPhp\ImagickEscposImage;
|
||||
use Zelda\EscposPhp\PrintConnectors\FilePrintConnector;
|
||||
|
||||
/*
|
||||
* This is three examples in one:
|
||||
* 1: Print an entire PDF, normal quality.
|
||||
* 2: Print at a lower quality for speed increase (CPU & transfer)
|
||||
* 3: Cache rendered documents for a speed increase (removes CPU image processing completely on subsequent prints)
|
||||
*/
|
||||
|
||||
/* 1: Print an entire PDF, start-to-finish (shorter form of the example) */
|
||||
|
||||
$pdf = 'resources/document.pdf';
|
||||
$connector = new FilePrintConnector("php://stdout");
|
||||
$printer = new Printer($connector);
|
||||
try {
|
||||
$pages = ImagickEscposImage::loadPdf($pdf);
|
||||
foreach ($pages as $page) {
|
||||
$printer->graphics($page);
|
||||
}
|
||||
$printer->cut();
|
||||
} catch (Exception $e) {
|
||||
/*
|
||||
* loadPdf() throws exceptions if files or not found, or you don't have the
|
||||
* imagick extension to read PDF's
|
||||
*/
|
||||
echo $e->getMessage() . "\n";
|
||||
} finally {
|
||||
$printer->close();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 2: Speed up printing by roughly halving the resolution, and printing double-size.
|
||||
* This gives a 75% speed increase at the expense of some quality.
|
||||
*
|
||||
* Reduce the page width further if necessary: if it extends past the printing area, your prints will be very slow.
|
||||
*/
|
||||
$connector = new FilePrintConnector("php://stdout");
|
||||
$printer = new Printer($connector);
|
||||
$pdf = 'resources/document.pdf';
|
||||
$pages = ImagickEscposImage::loadPdf($pdf, 260);
|
||||
foreach ($pages as $page) {
|
||||
$printer->graphics($page, Printer::IMG_DOUBLE_HEIGHT | Printer::IMG_DOUBLE_WIDTH);
|
||||
}
|
||||
$printer->cut();
|
||||
$printer->close();
|
||||
|
||||
/*
|
||||
* 3: PDF printing still too slow? If you regularly print the same files, serialize & compress your
|
||||
* EscposImage objects (after printing[1]), instead of throwing them away.
|
||||
*
|
||||
* (You can also do this to print logos on computers which don't have an
|
||||
* image processing library, by preparing a serialized version of your logo on your PC)
|
||||
*
|
||||
* [1]After printing, the pixels are loaded and formatted for the print command you used, so even a raspberry pi can print complex PDF's quickly.
|
||||
*/
|
||||
$connector = new FilePrintConnector("php://stdout");
|
||||
$printer = new Printer($connector);
|
||||
$pdf = 'resources/document.pdf';
|
||||
$ser = 'resources/document.z';
|
||||
if (!file_exists($ser)) {
|
||||
$pages = ImagickEscposImage::loadPdf($pdf);
|
||||
} else {
|
||||
$pages = unserialize(gzuncompress(file_get_contents($ser)));
|
||||
}
|
||||
|
||||
foreach ($pages as $page) {
|
||||
$printer->graphics($page);
|
||||
}
|
||||
$printer->cut();
|
||||
$printer->close();
|
||||
|
||||
if (!file_exists($ser)) {
|
||||
file_put_contents($ser, gzcompress(serialize($pages)));
|
||||
}
|
|
@ -0,0 +1,91 @@
|
|||
<?php
|
||||
/* Demonstration of available options on the qrCode() command */
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
use Zelda\EscposPhp\Printer;
|
||||
use Zelda\EscposPhp\PrintConnectors\FilePrintConnector;
|
||||
|
||||
$connector = new FilePrintConnector("php://stdout");
|
||||
$printer = new Printer($connector);
|
||||
|
||||
// Most simple example
|
||||
title($printer, "QR code demo\n");
|
||||
$testStr = "Testing 123";
|
||||
$printer->qrCode($testStr);
|
||||
$printer->text("Most simple example\n");
|
||||
$printer->feed();
|
||||
|
||||
// Demo that alignment is the same as text
|
||||
$printer->setJustification(Printer::JUSTIFY_CENTER);
|
||||
$printer->qrCode($testStr);
|
||||
$printer->text("Same example, centred\n");
|
||||
$printer->setJustification();
|
||||
$printer->feed();
|
||||
|
||||
// Demo of numeric data being packed more densly
|
||||
title($printer, "Data encoding\n");
|
||||
$test = array(
|
||||
"Numeric" => "0123456789012345678901234567890123456789",
|
||||
"Alphanumeric" => "abcdefghijklmnopqrstuvwxyzabcdefghijklmn",
|
||||
"Binary" => str_repeat("\0", 40)
|
||||
);
|
||||
foreach ($test as $type => $data) {
|
||||
$printer->qrCode($data);
|
||||
$printer->text("$type\n");
|
||||
$printer->feed();
|
||||
}
|
||||
|
||||
// Demo of error correction
|
||||
title($printer, "Error correction\n");
|
||||
$ec = array(
|
||||
Printer::QR_ECLEVEL_L => "L",
|
||||
Printer::QR_ECLEVEL_M => "M",
|
||||
Printer::QR_ECLEVEL_Q => "Q",
|
||||
Printer::QR_ECLEVEL_H => "H"
|
||||
);
|
||||
foreach ($ec as $level => $name) {
|
||||
$printer->qrCode($testStr, $level);
|
||||
$printer->text("Error correction $name\n");
|
||||
$printer->feed();
|
||||
}
|
||||
|
||||
// Change size
|
||||
title($printer, "Pixel size\n");
|
||||
$sizes = array(
|
||||
1 => "(minimum)",
|
||||
2 => "",
|
||||
3 => "(default)",
|
||||
4 => "",
|
||||
5 => "",
|
||||
10 => "",
|
||||
16 => "(maximum)"
|
||||
);
|
||||
foreach ($sizes as $size => $label) {
|
||||
$printer->qrCode($testStr, Printer::QR_ECLEVEL_L, $size);
|
||||
$printer->text("Pixel size $size $label\n");
|
||||
$printer->feed();
|
||||
}
|
||||
|
||||
// Change model
|
||||
title($printer, "QR model\n");
|
||||
$models = array(
|
||||
Printer::QR_MODEL_1 => "QR Model 1",
|
||||
Printer::QR_MODEL_2 => "QR Model 2 (default)",
|
||||
Printer::QR_MICRO => "Micro QR code\n(not supported on all printers)"
|
||||
);
|
||||
foreach ($models as $model => $name) {
|
||||
$printer->qrCode($testStr, Printer::QR_ECLEVEL_L, 3, $model);
|
||||
$printer->text("$name\n");
|
||||
$printer->feed();
|
||||
}
|
||||
|
||||
// Cut & close
|
||||
$printer->cut();
|
||||
$printer->close();
|
||||
|
||||
function title(Printer $printer, $str)
|
||||
{
|
||||
$printer->selectPrintMode(Printer::MODE_DOUBLE_HEIGHT | Printer::MODE_DOUBLE_WIDTH);
|
||||
$printer->text($str);
|
||||
$printer->selectPrintMode();
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="ru">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>RawBT Integration Demo</title>
|
||||
<meta content="width=device-width, initial-scale=1" name="viewport">
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
|
||||
<style>
|
||||
html {
|
||||
background-color: grey;
|
||||
padding: 32px;
|
||||
}
|
||||
|
||||
body {
|
||||
max-width: 640px;
|
||||
margin: 0 auto;
|
||||
padding: 32px;
|
||||
background-color: white;
|
||||
}
|
||||
|
||||
button {
|
||||
background-color: #6e89ff;
|
||||
color: white;
|
||||
padding: 16px;
|
||||
border: none;
|
||||
}
|
||||
|
||||
pre {
|
||||
background-color: #f0f0f0;
|
||||
border-left: #6e89ff solid 3px
|
||||
}
|
||||
|
||||
p {
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #6e89ff;
|
||||
text-decoration: none;
|
||||
}
|
||||
a:before{
|
||||
content: '\1F855';
|
||||
margin-right:4px;
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
// for php demo call
|
||||
function ajax_print(url, btn) {
|
||||
b = $(btn);
|
||||
b.attr('data-old', b.text());
|
||||
b.text('wait');
|
||||
$.get(url, function (data) {
|
||||
window.location.href = data; // main action
|
||||
}).fail(function () {
|
||||
alert("ajax error");
|
||||
}).always(function () {
|
||||
b.text(b.attr('data-old'));
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<img src="resources/rawbtlogo.png" alt="black & white picture">
|
||||
<h1>RawBT Integration Demo</h1>
|
||||
<pre>
|
||||
|
||||
window.location.href = ajax_backend_data;
|
||||
|
||||
</pre>
|
||||
<br/>
|
||||
<button onclick="ajax_print('rawbt-receipt.php',this)">RECEIPT</button>
|
||||
|
||||
<p><a href="https://rawbt.ru/">Visit RawBT site</a></p>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,143 @@
|
|||
<?php
|
||||
require __DIR__ . '/../autoload.php';
|
||||
|
||||
use Zelda\EscposPhp\Printer;
|
||||
use Zelda\EscposPhp\EscposImage;
|
||||
use Zelda\EscposPhp\PrintConnectors\RawbtPrintConnector;
|
||||
use Zelda\EscposPhp\CapabilityProfile;
|
||||
|
||||
try {
|
||||
$profile = CapabilityProfile::load("POS-5890");
|
||||
|
||||
/* Fill in your own connector here */
|
||||
$connector = new RawbtPrintConnector();
|
||||
|
||||
/* Information for the receipt */
|
||||
$items = array(
|
||||
new item("Example item #1", "4.00"),
|
||||
new item("Another thing", "3.50"),
|
||||
new item("Something else", "1.00"),
|
||||
new item("A final item", "4.45"),
|
||||
);
|
||||
$subtotal = new item('Subtotal', '12.95');
|
||||
$tax = new item('A local tax', '1.30');
|
||||
$total = new item('Total', '14.25', true);
|
||||
/* Date is kept the same for testing */
|
||||
// $date = date('l jS \of F Y h:i:s A');
|
||||
$date = "Monday 6th of April 2015 02:56:25 PM";
|
||||
|
||||
/* Start the printer */
|
||||
$logo = EscposImage::load("resources/rawbtlogo.png", false);
|
||||
$printer = new Printer($connector, $profile);
|
||||
|
||||
|
||||
/* Print top logo */
|
||||
if ($profile->getSupportsGraphics()) {
|
||||
$printer->graphics($logo);
|
||||
}
|
||||
if ($profile->getSupportsBitImageRaster() && !$profile->getSupportsGraphics()) {
|
||||
$printer->bitImage($logo);
|
||||
}
|
||||
|
||||
/* Name of shop */
|
||||
$printer->setJustification(Printer::JUSTIFY_CENTER);
|
||||
$printer->selectPrintMode(Printer::MODE_DOUBLE_WIDTH);
|
||||
$printer->text("ExampleMart Ltd.\n");
|
||||
$printer->selectPrintMode();
|
||||
$printer->text("Shop No. 42.\n");
|
||||
$printer->feed();
|
||||
|
||||
|
||||
/* Title of receipt */
|
||||
$printer->setEmphasis(true);
|
||||
$printer->text("SALES INVOICE\n");
|
||||
$printer->setEmphasis(false);
|
||||
|
||||
/* Items */
|
||||
$printer->setJustification(Printer::JUSTIFY_LEFT);
|
||||
$printer->setEmphasis(true);
|
||||
$printer->text(new item('', '$'));
|
||||
$printer->setEmphasis(false);
|
||||
foreach ($items as $item) {
|
||||
$printer->text($item->getAsString(32)); // for 58mm Font A
|
||||
}
|
||||
$printer->setEmphasis(true);
|
||||
$printer->text($subtotal->getAsString(32));
|
||||
$printer->setEmphasis(false);
|
||||
$printer->feed();
|
||||
|
||||
/* Tax and total */
|
||||
$printer->text($tax->getAsString(32));
|
||||
$printer->selectPrintMode(Printer::MODE_DOUBLE_WIDTH);
|
||||
$printer->text($total->getAsString(32));
|
||||
$printer->selectPrintMode();
|
||||
|
||||
/* Footer */
|
||||
$printer->feed(2);
|
||||
$printer->setJustification(Printer::JUSTIFY_CENTER);
|
||||
$printer->text("Thank you for shopping\n");
|
||||
$printer->text("at ExampleMart\n");
|
||||
$printer->text("For trading hours,\n");
|
||||
$printer->text("please visit example.com\n");
|
||||
$printer->feed(2);
|
||||
$printer->text($date . "\n");
|
||||
|
||||
/* Barcode Default look */
|
||||
|
||||
$printer->barcode("ABC", Printer::BARCODE_CODE39);
|
||||
$printer->feed();
|
||||
$printer->feed();
|
||||
|
||||
|
||||
// Demo that alignment QRcode is the same as text
|
||||
$printer2 = new Printer($connector); // dirty printer profile hack !!
|
||||
$printer2->setJustification(Printer::JUSTIFY_CENTER);
|
||||
$printer2->qrCode("https://rawbt.ru/mike42", Printer::QR_ECLEVEL_M, 8);
|
||||
$printer2->text("rawbt.ru/mike42\n");
|
||||
$printer2->setJustification();
|
||||
$printer2->feed();
|
||||
|
||||
|
||||
/* Cut the receipt and open the cash drawer */
|
||||
$printer->cut();
|
||||
$printer->pulse();
|
||||
} catch (Exception $e) {
|
||||
echo $e->getMessage();
|
||||
} finally {
|
||||
$printer->close();
|
||||
}
|
||||
|
||||
/* A wrapper to do organise item names & prices into columns */
|
||||
|
||||
class item
|
||||
{
|
||||
private $name;
|
||||
private $price;
|
||||
private $dollarSign;
|
||||
|
||||
public function __construct($name = '', $price = '', $dollarSign = false)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->price = $price;
|
||||
$this->dollarSign = $dollarSign;
|
||||
}
|
||||
|
||||
public function getAsString($width = 48)
|
||||
{
|
||||
$rightCols = 10;
|
||||
$leftCols = $width - $rightCols;
|
||||
if ($this->dollarSign) {
|
||||
$leftCols = $leftCols / 2 - $rightCols / 2;
|
||||
}
|
||||
$left = str_pad($this->name, $leftCols);
|
||||
|
||||
$sign = ($this->dollarSign ? '$ ' : '');
|
||||
$right = str_pad($sign . $this->price, $rightCols, ' ', STR_PAD_LEFT);
|
||||
return "$left$right\n";
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return $this->getAsString();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,106 @@
|
|||
<?php
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
use Zelda\EscposPhp\Printer;
|
||||
use Zelda\EscposPhp\EscposImage;
|
||||
use Zelda\EscposPhp\PrintConnectors\FilePrintConnector;
|
||||
|
||||
/* Fill in your own connector here */
|
||||
|
||||
$connector = new FilePrintConnector("php://stdout");
|
||||
|
||||
/* Information for the receipt */
|
||||
$items = array(
|
||||
new item("Example item #1", "4.00"),
|
||||
new item("Another thing", "3.50"),
|
||||
new item("Something else", "1.00"),
|
||||
new item("A final item", "4.45"),
|
||||
);
|
||||
$subtotal = new item('Subtotal', '12.95');
|
||||
$tax = new item('A local tax', '1.30');
|
||||
$total = new item('Total', '14.25', true);
|
||||
/* Date is kept the same for testing */
|
||||
// $date = date('l jS \of F Y h:i:s A');
|
||||
$date = "Monday 6th of April 2015 02:56:25 PM";
|
||||
|
||||
/* Start the printer */
|
||||
$logo = EscposImage::load("resources/escpos-php.png", false);
|
||||
$printer = new Printer($connector);
|
||||
|
||||
/* Print top logo */
|
||||
$printer->setJustification(Printer::JUSTIFY_CENTER);
|
||||
$printer->graphics($logo);
|
||||
|
||||
/* Name of shop */
|
||||
$printer->selectPrintMode(Printer::MODE_DOUBLE_WIDTH);
|
||||
$printer->text("ExampleMart Ltd.\n");
|
||||
$printer->selectPrintMode();
|
||||
$printer->text("Shop No. 42.\n");
|
||||
$printer->feed();
|
||||
|
||||
/* Title of receipt */
|
||||
$printer->setEmphasis(true);
|
||||
$printer->text("SALES INVOICE\n");
|
||||
$printer->setEmphasis(false);
|
||||
|
||||
/* Items */
|
||||
$printer->setJustification(Printer::JUSTIFY_LEFT);
|
||||
$printer->setEmphasis(true);
|
||||
$printer->text(new item('', '$'));
|
||||
$printer->setEmphasis(false);
|
||||
foreach ($items as $item) {
|
||||
$printer->text($item);
|
||||
}
|
||||
$printer->setEmphasis(true);
|
||||
$printer->text($subtotal);
|
||||
$printer->setEmphasis(false);
|
||||
$printer->feed();
|
||||
|
||||
/* Tax and total */
|
||||
$printer->text($tax);
|
||||
$printer->selectPrintMode(Printer::MODE_DOUBLE_WIDTH);
|
||||
$printer->text($total);
|
||||
$printer->selectPrintMode();
|
||||
|
||||
/* Footer */
|
||||
$printer->feed(2);
|
||||
$printer->setJustification(Printer::JUSTIFY_CENTER);
|
||||
$printer->text("Thank you for shopping at ExampleMart\n");
|
||||
$printer->text("For trading hours, please visit example.com\n");
|
||||
$printer->feed(2);
|
||||
$printer->text($date . "\n");
|
||||
|
||||
/* Cut the receipt and open the cash drawer */
|
||||
$printer->cut();
|
||||
$printer->pulse();
|
||||
|
||||
$printer->close();
|
||||
|
||||
/* A wrapper to do organise item names & prices into columns */
|
||||
class item
|
||||
{
|
||||
private $name;
|
||||
private $price;
|
||||
private $dollarSign;
|
||||
|
||||
public function __construct($name = '', $price = '', $dollarSign = false)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->price = $price;
|
||||
$this->dollarSign = $dollarSign;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
$rightCols = 10;
|
||||
$leftCols = 38;
|
||||
if ($this->dollarSign) {
|
||||
$leftCols = $leftCols / 2 - $rightCols / 2;
|
||||
}
|
||||
$left = str_pad($this->name, $leftCols);
|
||||
|
||||
$sign = ($this->dollarSign ? '$ ' : '');
|
||||
$right = str_pad($sign . $this->price, $rightCols, ' ', STR_PAD_LEFT);
|
||||
return "$left$right\n";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
/* All strings from EscposPrintBufferTest are included below- These are fully supported
|
||||
* on the default profile, so you can use them to test modified profiles (using the wrong
|
||||
* profile for a printer produces mojibake) */
|
||||
$inputsOk = array(
|
||||
"Danish" => "Quizdeltagerne spiste jordbær med fløde, mens cirkusklovnen Wolther spillede på xylofon.\n",
|
||||
"German" => "Falsches Üben von Xylophonmusik quält jeden größeren Zwerg.\n",
|
||||
"Greek" => "Ξεσκεπάζω την ψυχοφθόρα βδελυγμία\n",
|
||||
"English" => "The quick brown fox jumps over the lazy dog.\n",
|
||||
"Spanish" => "El pingüino Wenceslao hizo kilómetros bajo exhaustiva lluvia y frío, añoraba a su querido cachorro.\n",
|
||||
"French" => "Le cœur déçu mais l'âme plutôt naïve, Louÿs rêva de crapaüter en canoë au delà des îles, près du mälström où brûlent les novæ.\n",
|
||||
"Irish Gaelic" => "D'fhuascail Íosa, Úrmhac na hÓighe Beannaithe, pór Éava agus Ádhaimh.\n",
|
||||
"Hungarian" => "Árvíztűrő tükörfúrógép.\n",
|
||||
"Icelandic" => "Kæmi ný öxi hér ykist þjófum nú bæði víl og ádrepa.\n",
|
||||
"Latvian" => "Glāžšķūņa rūķīši dzērumā čiepj Baha koncertflīģeļu vākus.\n",
|
||||
"Polish" => "Pchnąć w tę łódź jeża lub ośm skrzyń fig.\n",
|
||||
"Russian" => "В чащах юга жил бы цитрус? Да, но фальшивый экземпляр!\n",
|
||||
"Turkish" => "Pijamalı hasta, yağız şoföre çabucak güvendi.\n",
|
||||
"Japanese (Katakana half-width)" => implode("\n", array("イロハニホヘト チリヌルヲ ワカヨタレソ ツネナラム", "ウイノオクヤマ ケフコエテ アサキユメミシ エヒモセスン")) . "\n",
|
||||
"Vietnamese" => "Tiếng Việt, còn gọi tiếng Việt Nam hay Việt ngữ, là ngôn ngữ của người Việt (người Kinh) và là ngôn ngữ chính thức tại Việt Nam.\n"
|
||||
);
|
||||
|
||||
/*
|
||||
* These strings are not expected to print correctly, if at all, even on an Epson printer. This is due to a mix of
|
||||
* escpos driver, printer, and PHP language support issues.
|
||||
*
|
||||
* They are included here as a collection of things not yet implemented.
|
||||
*/
|
||||
$inputsNotOk = array(
|
||||
"Thai (No character encoder available)" => "นายสังฆภัณฑ์ เฮงพิทักษ์ฝั่ง ผู้เฒ่าซึ่งมีอาชีพเป็นฅนขายฃวด ถูกตำรวจปฏิบัติการจับฟ้องศาล ฐานลักนาฬิกาคุณหญิงฉัตรชฎา ฌานสมาธิ\n",
|
||||
"Japanese (Hiragana)" => implode("\n", array("いろはにほへとちりぬるを", " わかよたれそつねならむ", "うゐのおくやまけふこえて", "あさきゆめみしゑひもせす")) . "\n",
|
||||
"Japanese (Katakana full-width)" => implode("\n", array("イロハニホヘト チリヌルヲ ワカヨタレソ ツネナラム", "ウヰノオクヤマ ケフコエテ アサキユメミシ ヱヒモセスン")) . "\n",
|
||||
"Arabic (RTL not supported, encoding issues)" => "صِف خَلقَ خَودِ كَمِثلِ الشَمسِ إِذ بَزَغَت — يَحظى الضَجيعُ بِها نَجلاءَ مِعطارِ" . "\n",
|
||||
"Hebrew (RTL not supported, line break issues)" => "דג סקרן שט בים מאוכזב ולפתע מצא לו חברה איך הקליטה" . "\n"
|
||||
);
|
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 1.9 KiB |
Binary file not shown.
After Width: | Height: | Size: 7.7 KiB |
Binary file not shown.
After Width: | Height: | Size: 1.3 KiB |
Binary file not shown.
After Width: | Height: | Size: 370 KiB |
Binary file not shown.
After Width: | Height: | Size: 5.1 KiB |
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
require __DIR__ . '/../../vendor/autoload.php';
|
||||
|
||||
use Zelda\EscposPhp\Printer;
|
||||
use Zelda\EscposPhp\PrintConnectors\FilePrintConnector;
|
||||
|
||||
$a = "{A012323392982";
|
||||
$b = "{B012323392982";
|
||||
$c = "{C" . chr(01) . chr(23) . chr(23) . chr(39) . chr(29) . chr(82);
|
||||
|
||||
$connector = new FilePrintConnector("php://stdout");
|
||||
$printer = new Printer($connector);
|
||||
$printer->setJustification(Printer::JUSTIFY_CENTER);
|
||||
$printer->setBarcodeHeight(48);
|
||||
$printer->setBarcodeTextPosition(Printer::BARCODE_TEXT_BELOW);
|
||||
foreach (array($a, $b, $c) as $item) {
|
||||
$printer->barcode($item, Printer::BARCODE_CODE128);
|
||||
$printer->feed(1);
|
||||
}
|
||||
$printer->cut();
|
||||
$printer->close();
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
require __DIR__ . '/../../vendor/autoload.php';
|
||||
|
||||
use Zelda\EscposPhp\Printer;
|
||||
use Zelda\EscposPhp\PrintConnectors\FilePrintConnector;
|
||||
|
||||
/**
|
||||
* This example shows how to send a custom command to the printer
|
||||
*
|
||||
* "ESC ( B" is the barcode function for Epson LX300 series.
|
||||
* This is not part of standard ESC/POS, but it's a good example
|
||||
* of how to send some binary to the driver.
|
||||
*/
|
||||
|
||||
/* Barcode type is used in this script */
|
||||
const EAN13 = 0;
|
||||
|
||||
/* Barcode properties */
|
||||
$type = EAN13;
|
||||
$content = "0075678164125";
|
||||
|
||||
/*
|
||||
* Make the command.
|
||||
* This is documented on page A-14 of:
|
||||
* https://files.support.epson.com/pdf/lx300p/lx300pu1.pdf
|
||||
*/
|
||||
$m = chr(EAN13);
|
||||
$n = intLowHigh(strlen($content), 2);
|
||||
$barcodeCommand = Printer::ESC . "G(" . $m . $n . $content;
|
||||
|
||||
/* Send it off as usual */
|
||||
$connector = new FilePrintConnector("php://output");
|
||||
$printer = new Printer($connector);
|
||||
$printer->getPrintConnector()->write($barcodeCommand);
|
||||
$printer->cut();
|
||||
$printer->close();
|
||||
|
||||
/**
|
||||
* Generate two characters for a number: In lower and higher parts, or more parts as needed.
|
||||
*
|
||||
* @param int $input
|
||||
* Input number
|
||||
* @param int $length
|
||||
* The number of bytes to output (1 - 4).
|
||||
*/
|
||||
function intLowHigh($input, $length)
|
||||
{
|
||||
$outp = "";
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
$outp .= chr($input % 256);
|
||||
$input = (int) ($input / 256);
|
||||
}
|
||||
return $outp;
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
/*
|
||||
* Example of one way you could load a PNG data URI into an EscposImage object
|
||||
* without using a file.
|
||||
*/
|
||||
require __DIR__ . '/../../vendor/autoload.php';
|
||||
|
||||
use Zelda\EscposPhp\Printer;
|
||||
use Zelda\EscposPhp\PrintConnectors\FilePrintConnector;
|
||||
use Zelda\EscposPhp\ImagickEscposImage;
|
||||
|
||||
// Data URI for a PNG image (red dot from https://en.wikipedia.org/wiki/Data_URI_scheme )
|
||||
$uri = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA
|
||||
AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
|
||||
9TXL0Y4OHwAAAABJRU5ErkJggg==";
|
||||
|
||||
// Convert data URI to binary data
|
||||
$imageBlob = base64_decode(explode(",", $uri)[1]);
|
||||
|
||||
// Give Imagick a filename with the correct extension to stop it from attempting
|
||||
// to identify the format itself (this avoids CVE-2016–3714)
|
||||
$imagick = new Imagick();
|
||||
$imagick->setResourceLimit(6, 1); // Prevent libgomp1 segfaults, grumble grumble.
|
||||
$imagick->readImageBlob($imageBlob, "input.png");
|
||||
|
||||
// Load Imagick straight into an EscposImage object
|
||||
$im = new ImagickEscposImage();
|
||||
$im->readImageFromImagick($imagick);
|
||||
|
||||
// Do a test print to make sure that this EscposImage object has the right data
|
||||
// (should see a tiny bullet point)
|
||||
$connector = new FilePrintConnector("php://output");
|
||||
$printer = new Printer($connector);
|
||||
$printer->bitImage($im);
|
||||
$printer->cut();
|
||||
$printer->close();
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
/*
|
||||
* Example showing how to return binary data back to the user.
|
||||
*
|
||||
* This is intended for the "Star TSP650IIcloudPRNT" printer.
|
||||
*/
|
||||
require __DIR__ . '/../../vendor/autoload.php';
|
||||
|
||||
use Zelda\EscposPhp\Printer;
|
||||
use Zelda\EscposPhp\PrintConnectors\DummyPrintConnector;
|
||||
use Zelda\EscposPhp\CapabilityProfile;
|
||||
|
||||
// Make sure you load a Star print connector or you may get gibberish.
|
||||
$connector = new DummyPrintConnector();
|
||||
$profile = CapabilityProfile::load("TSP600");
|
||||
$printer = new Printer($connector);
|
||||
$printer->text("Hello world!\n");
|
||||
$printer->cut();
|
||||
|
||||
// Get the data out as a string
|
||||
$data = $connector->getData();
|
||||
|
||||
// Return it, check the manual for specifics.
|
||||
header('Content-type: application/octet-stream');
|
||||
header('Content-Length: ' . strlen($data));
|
||||
echo $data;
|
||||
|
||||
// Close the printer when done.
|
||||
$printer->close();
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
require __DIR__ . '/../../vendor/autoload.php';
|
||||
|
||||
use Zelda\EscposPhp\CapabilityProfile;
|
||||
use Zelda\EscposPhp\Printer;
|
||||
use Zelda\EscposPhp\PrintConnectors\FilePrintConnector;
|
||||
use Zelda\EscposPhp\PrintBuffers\ImagePrintBuffer;
|
||||
|
||||
/* This example shows the printing of Latvian text on the Star TUP 592 printer */
|
||||
|
||||
$profile = CapabilityProfile::load("SP2000");
|
||||
|
||||
/* Option 1: Native character encoding */
|
||||
$connector = new FilePrintConnector("php://stdout");
|
||||
$printer = new Printer($connector, $profile);
|
||||
$printer->text("Glāžšķūņa rūķīši dzērumā čiepj Baha koncertflīģeļu vākus\n");
|
||||
$printer->cut();
|
||||
$printer->close();
|
||||
|
||||
/* Option 2: Image-based output (formatting not available using this output) */
|
||||
$buffer = new ImagePrintBuffer();
|
||||
$connector = new FilePrintConnector("php://stdout");
|
||||
$printer = new Printer($connector, $profile);
|
||||
$printer->setPrintBuffer($buffer);
|
||||
$printer->text("Glāžšķūņa rūķīši dzērumā čiepj Baha koncertflīģeļu vākus\n");
|
||||
$printer->cut();
|
||||
$printer->close();
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
require __DIR__ . '/../../vendor/autoload.php';
|
||||
|
||||
use Zelda\EscposPhp\CapabilityProfile;
|
||||
use Zelda\EscposPhp\Printer;
|
||||
use Zelda\EscposPhp\PrintConnectors\FilePrintConnector;
|
||||
|
||||
/*
|
||||
* This example shows how tok send a custom command to the printer-
|
||||
* The use case here is an Epson TM-T20II and German text.
|
||||
*
|
||||
* Background: Not all ESC/POS features are available in the driver, so sometimes
|
||||
* you might want to send a custom commnad. This is useful for testing
|
||||
* new features.
|
||||
*
|
||||
* The Escpos::text() function removes non-printable characters as a precaution,
|
||||
* so that commands cannot be injected into user input. To send raw data to
|
||||
* the printer, you need to write bytes to the underlying PrintConnector.
|
||||
*
|
||||
* If you get a new command working, please file an issue on GitHub with a code
|
||||
* snippet so that it can be incorporated into escpos-php.
|
||||
*/
|
||||
|
||||
/* Set up profile & connector */
|
||||
|
||||
$connector = new FilePrintConnector("php://output");
|
||||
$profile = CapabilityProfile::load("default"); // Works for Epson printers
|
||||
|
||||
$printer = new Printer($connector, $profile);
|
||||
$cmd = Printer::ESC . "V" . chr(1); // Try out 90-degree rotation.
|
||||
$printer->getPrintConnector()->write($cmd);
|
||||
$printer->text("Beispieltext in Deutsch\n");
|
||||
$printer->cut();
|
||||
$printer->close();
|
||||
/*
|
||||
* Hex-dump of output confirms that ESC V 1 being sent:
|
||||
*
|
||||
* 0000000 033 @ 033 V 001 B e i s p i e l t e x
|
||||
* 0000010 t i n D e u t s c h \n 035 V A
|
||||
* 0000020 003
|
||||
*/
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
/*
|
||||
* Example of printing Spanish text on SEYPOS PRP-300 thermal line printer.
|
||||
* The characters in Spanish are available in code page 437, so no special
|
||||
* code pages are needed in this case (SimpleCapabilityProfile).
|
||||
*
|
||||
* Use the hardware switch to activate "Two-byte Character Code"
|
||||
*/
|
||||
require __DIR__ . '/../../vendor/autoload.php';
|
||||
|
||||
use Zelda\EscposPhp\CapabilityProfile;
|
||||
use Zelda\EscposPhp\Printer;
|
||||
use Zelda\EscposPhp\PrintConnectors\FilePrintConnector;
|
||||
|
||||
$connector = new FilePrintConnector("php://output");
|
||||
$profile = CapabilityProfile::load("simple"); // Works for Epson printers
|
||||
$printer = new Printer($connector);
|
||||
$printer->text("El pingüino Wenceslao hizo kilómetros bajo exhaustiva lluvia y frío, añoraba a su querido cachorro.\n");
|
||||
$printer->cut();
|
||||
$printer->close();
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
/*
|
||||
* This is an example of printing chinese text. This is a bit different to other character encodings, because
|
||||
* the printer accepts a 2-byte character encoding (GBK), and formatting is handled differently while in this mode.
|
||||
*
|
||||
* At the time of writing, this is implemented separately as a textChinese() function, until chinese text
|
||||
* can be properly detected and printed alongside other encodings.
|
||||
*/
|
||||
require __DIR__ . '/../../vendor/autoload.php';
|
||||
|
||||
use Zelda\EscposPhp\CapabilityProfile;
|
||||
use Zelda\EscposPhp\Printer;
|
||||
use Zelda\EscposPhp\PrintConnectors\FilePrintConnector;
|
||||
|
||||
$connector = new FilePrintConnector("/dev/usb/lp1");
|
||||
$profile = CapabilityProfile::load("default");
|
||||
|
||||
$printer = new Printer($connector);
|
||||
|
||||
// Example text from #37
|
||||
$printer->textChinese("艾德蒙 AOC E2450SWH 23.6吋 LED液晶寬螢幕特價$ 19900\n\n");
|
||||
|
||||
// Note that on the printer tested (ZJ5890), the font only contained simplified characters.
|
||||
$printer->textChinese("示例文本打印机!\n\n");
|
||||
$printer->close();
|
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
require __DIR__ . '/../../vendor/autoload.php';
|
||||
|
||||
use Zelda\EscposPhp\CapabilityProfile;
|
||||
use Zelda\EscposPhp\Printer;
|
||||
use Zelda\EscposPhp\PrintConnectors\FilePrintConnector;
|
||||
use Zelda\EscposPhp\PrintBuffers\ImagePrintBuffer;
|
||||
|
||||
$profile = CapabilityProfile::load("default");
|
||||
// This is a quick demo of currency symbol issues in #39.
|
||||
|
||||
/* Option 1: Native ESC/POS characters, depends on printer and is buggy. */
|
||||
$connector = new FilePrintConnector("php://stdout");
|
||||
$printer = new Printer($connector, $profile);
|
||||
$printer->text("€ 9,95\n");
|
||||
$printer->text("£ 9.95\n");
|
||||
$printer->text("$ 9.95\n");
|
||||
$printer->text("¥ 9.95\n");
|
||||
$printer->cut();
|
||||
$printer->close();
|
||||
|
||||
/* Option 2: Image-based output (formatting not available using this output). */
|
||||
$buffer = new ImagePrintBuffer();
|
||||
$connector = new FilePrintConnector("php://stdout");
|
||||
$printer = new Printer($connector, $profile);
|
||||
$printer->setPrintBuffer($buffer);
|
||||
$printer->text("€ 9,95\n");
|
||||
$printer->text("£ 9.95\n");
|
||||
$printer->text("$ 9.95\n");
|
||||
$printer->text("¥ 9.95\n");
|
||||
$printer->cut();
|
||||
$printer->close();
|
||||
|
||||
/*
|
||||
Option 3: If the printer is configured to print in a specific code
|
||||
page, you can set up a CapabilityProfile which either references its
|
||||
iconv encoding name, or includes all of the available characters.
|
||||
|
||||
Here, we make use of CP858 for its inclusion of currency symbols which
|
||||
are not available in CP437. CP858 has good printer support, but is not
|
||||
included in all iconv builds.
|
||||
*/
|
||||
class CustomCapabilityProfile extends CapabilityProfile
|
||||
{
|
||||
function getCustomCodePages()
|
||||
{
|
||||
/*
|
||||
* Example to print in a specific, user-defined character set
|
||||
* on a printer which has been configured to use i
|
||||
*/
|
||||
return array(
|
||||
'CP858' => "ÇüéâäàåçêëèïîìÄÅ" .
|
||||
"ÉæÆôöòûùÿÖÜø£Ø×ƒ" .
|
||||
"áíóúñѪº¿®¬½¼¡«»" .
|
||||
"░▒▓│┤ÁÂÀ©╣║╗╝¢¥┐" .
|
||||
"└┴┬├─┼ãÃ╚╔╩╦╠═╬¤" .
|
||||
"ðÐÊËÈ€ÍÎÏ┘┌█▄¦Ì▀" .
|
||||
"ÓßÔÒõÕµþÞÚÛÙýݯ´" .
|
||||
" ±‗¾¶§÷¸°¨·¹³²■ "
|
||||
);
|
||||
}
|
||||
|
||||
function getSupportedCodePages()
|
||||
{
|
||||
return array(
|
||||
0 => 'custom:CP858'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$connector = new FilePrintConnector("php://stdout");
|
||||
$profile = CustomCapabilityProfile::getInstance();
|
||||
$printer = new Printer($connector, $profile);
|
||||
$printer->text("€ 9,95\n");
|
||||
$printer->text("£ 9.95\n");
|
||||
$printer->text("$ 9.95\n");
|
||||
$printer->text("¥ 9.95\n");
|
||||
|
||||
$printer->cut();
|
||||
$printer->close();
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
/* Example of printing the GBP pound symbol on a STAR TSP650
|
||||
*
|
||||
* In this example, it's shown how to check that your PHP files are actually being
|
||||
* saved in unicode. Sections B) and C) are identical in UTF-8, but different
|
||||
* if you are saving to a retro format like Windows-1252.
|
||||
*/
|
||||
|
||||
// Adjust these to your environment
|
||||
require __DIR__ . '/../../vendor/autoload.php';
|
||||
|
||||
use Zelda\EscposPhp\CapabilityProfile;
|
||||
use Zelda\EscposPhp\Printer;
|
||||
use Zelda\EscposPhp\PrintConnectors\FilePrintConnector;
|
||||
|
||||
$connector = new FilePrintConnector("php://stdout");
|
||||
|
||||
// Start printer
|
||||
$profile = CapabilityProfile::load("simple");
|
||||
$printer = new Printer($connector, $profile);
|
||||
|
||||
// A) Raw pound symbol
|
||||
// This is the most likely thing to work, and bypasses all the fancy stuff.
|
||||
$printer->textRaw("\x9C"); // based on position in CP437
|
||||
$printer->text(" 1.95\n");
|
||||
|
||||
// B) Manually encoded UTF8 pound symbol. Tests that the driver correctly
|
||||
// encodes this as CP437.
|
||||
$printer->text(base64_decode("wqM=") . " 2.95\n");
|
||||
|
||||
// C) Pasted in file. Tests that your files are being saved as UTF-8, which
|
||||
// escpos-php is able to convert automatically to a mix of code pages.
|
||||
$printer->text("£ 3.95\n");
|
||||
|
||||
$printer->cut();
|
||||
$printer->close();
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue