Perbarui cetak dan stok barcode

This commit is contained in:
Dwi Swandhana
2026-03-13 12:24:10 +07:00
parent 52ee41e50c
commit 6fb3f5a629
11 changed files with 2239 additions and 191 deletions
@@ -4,10 +4,12 @@ namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use App\XFiles;
use App\SIMBHPJenis;
use App\SIMBHPReport;
use App\User;
use App\Services\SimbhpStockService;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use Validator;
@@ -25,7 +27,9 @@ class GudangController extends Controller
$cdatane = SIMBHPJenis::all();
$cjenis = count($cdatane);
if ($cjenis == 0){
$tasks['jjenis'][0]['id'] = null;
$tasks['jjenis'][0]['jenis'] = 'Belum Ada Jenis Barang';
$tasks['jjenis'][0]['kodejenis'] = '';
$tasks['jjenis'][0]['satuan'] = '';
$tasks['jjenis'][0]['satuan_kecil'] = '';
$tasks['jjenis'][0]['konversi_kecil'] = 1;
@@ -33,7 +37,9 @@ class GudangController extends Controller
} else {
$i = 0;
foreach($cdatane as $rdata){
$tasks['jjenis'][$i]['id'] = $rdata->id;
$tasks['jjenis'][$i]['jenis'] = $rdata->jenis;
$tasks['jjenis'][$i]['kodejenis'] = $rdata->kodejenis ?? '';
$tasks['jjenis'][$i]['satuan'] = $rdata->satuan;
$tasks['jjenis'][$i]['satuan_kecil'] = $rdata->satuan_kecil ?? '';
$tasks['jjenis'][$i]['konversi_kecil'] = $rdata->konversi_kecil ?? 1;
@@ -99,6 +105,63 @@ class GudangController extends Controller
echo json_encode($arraysurat);
}
public function jsonSnapshot()
{
if (Session::get('previlage') == '') {
return response()->json(['message' => 'Unauthorized'], 401);
}
$jjenis = [];
$cdatane = SIMBHPJenis::orderBy('jenis', 'ASC')->get();
if ($cdatane->count() == 0) {
$jjenis[] = [
'id' => null,
'jenis' => 'Belum Ada Jenis Barang',
'kodejenis' => '',
'satuan' => '',
'satuan_kecil' => '',
'konversi_kecil' => 1,
'stok_minimum' => 0,
];
} else {
foreach ($cdatane as $rdata) {
$jjenis[] = [
'id' => $rdata->id,
'jenis' => $rdata->jenis,
'kodejenis' => $rdata->kodejenis ?? '',
'satuan' => $rdata->satuan,
'satuan_kecil' => $rdata->satuan_kecil ?? '',
'konversi_kecil' => $rdata->konversi_kecil ?? 1,
'stok_minimum' => $rdata->stok_minimum ?? 0,
];
}
}
return response()->json([
'jjenis' => $jjenis,
'jenisRows' => $this->getJenisRows(),
'warningstok' => $this->getLowStockWarnings(),
'expiringSoon' => $this->getExpiringSoonItems(),
'stat' => [
'harian' => [
'masuk' => $this->getAggregateBaseQty('pemasukan', 'harian'),
'keluar' => $this->getAggregateBaseQty('pengeluaran', 'harian'),
'perjenis' => $this->getUsagePerJenis('harian'),
],
'bulanan' => [
'masuk' => $this->getAggregateBaseQty('pemasukan', 'bulanan'),
'keluar' => $this->getAggregateBaseQty('pengeluaran', 'bulanan'),
'perjenis' => $this->getUsagePerJenis('bulanan'),
],
'tahunan' => [
'masuk' => $this->getAggregateBaseQty('pemasukan', 'tahunan'),
'keluar' => $this->getAggregateBaseQty('pengeluaran', 'tahunan'),
'perjenis' => $this->getUsagePerJenis('tahunan'),
],
],
]);
}
public function jsonReportbhp(Request $request) {
$bulan = $request->input('val01');
$tahun = $request->input('val02');
@@ -293,7 +356,7 @@ class GudangController extends Controller
$tanggal = $request->input('set03');
$jumlah = $request->input('set04');
$jenis = $request->input('set05');
$postujuan = $request->input('set06');
$postujuan = $request->input('set06'); // also used as kodejenis when $jenis == 'jenis'
$alasan = $request->input('set07');
$set08 = $request->input('set08');
$set09 = $request->input('set09');
@@ -310,6 +373,7 @@ class GudangController extends Controller
$jenis = $request->input('set02');
$satuan = $request->input('set03');
$idne = $request->input('set01');
$kodeInput = trim((string) $request->input('set06'));
$satuanKecil = trim((string) $set08);
$konversiKecil = (int) $set09;
if ($konversiKecil <= 0){ $konversiKecil = 1; }
@@ -320,7 +384,21 @@ class GudangController extends Controller
} elseif ($konversiKecil <= 1) {
return response()->json(['icon' => 'error', 'warna' => '#bf441d', 'status' => 'Gagal', 'message' => 'Jika memakai satuan kecil, konversi harus lebih dari 1']);
}
$kodejenis = preg_replace('/\s+/', '', $jenis);
if ($kodeInput !== '') {
$kodejenis = strtoupper($kodeInput);
$kodejenis = preg_replace('/\s+/', '', $kodejenis);
$kodejenis = preg_replace('/[^A-Z0-9._-]/', '', $kodejenis);
} else {
$kodejenis = strtoupper((string) $jenis);
$kodejenis = preg_replace('/\s+/', '', $kodejenis);
$kodejenis = preg_replace('/[^A-Z0-9._-]/', '', $kodejenis);
}
if ($kodejenis === '' || strlen($kodejenis) < 2 || strlen($kodejenis) > 40) {
return response()->json(['icon' => 'error', 'warna' => '#bf441d', 'status' => 'Gagal', 'message' => 'Kode barang wajib (2-40 karakter). Gunakan huruf/angka dan simbol - _ .']);
}
if ($idne == 'new' OR $idne == ''){
$ceksudah = SIMBHPJenis::where('kodejenis', $kodejenis)->where('satuan', $satuan)->count();
if ($ceksudah != 0){
@@ -335,6 +413,14 @@ class GudangController extends Controller
'stok_minimum' => $stokMinimum,
]);
if ($input){
if (Schema::hasColumn('simbhpjenis', 'barcode_besar')) {
$service = app(SimbhpStockService::class);
$setting = $service->getUnitSetting($input);
$input->update([
'barcode_besar' => $service->makeBarcodeValue((int) $input->id, 'besar'),
'barcode_kecil' => ($setting['has_breakdown'] ?? false) ? $service->makeBarcodeValue((int) $input->id, 'kecil') : null,
]);
}
return response()->json(['status' => 'Success', 'message' => 'Data '.$jenis.' Sukses Ditambahkan']);
} else {
return response()->json(['icon' => 'error', 'warna' => '#bf441d', 'status' => 'Gagal', 'message' => $jenis.' Gagal di masukkan, silahkan ulangi beberapa saat lagi']);
@@ -354,6 +440,16 @@ class GudangController extends Controller
'stok_minimum' => $stokMinimum,
]);
if ($input){
if (Schema::hasColumn('simbhpjenis', 'barcode_besar')) {
$row = SIMBHPJenis::find($idne);
if ($row) {
$service = app(SimbhpStockService::class);
$setting = $service->getUnitSetting($row);
$row->barcode_besar = $service->makeBarcodeValue((int) $row->id, 'besar');
$row->barcode_kecil = ($setting['has_breakdown'] ?? false) ? $service->makeBarcodeValue((int) $row->id, 'kecil') : null;
$row->save();
}
}
return response()->json(['status' => 'Success', 'message' => 'Data '.$jenis.' Sukses Diupdate']);
} else {
return response()->json(['icon' => 'error', 'warna' => '#bf441d', 'status' => 'Gagal', 'message' => $jenis.' Gagal di masukkan, silahkan ulangi beberapa saat lagi']);
@@ -794,6 +890,7 @@ class GudangController extends Controller
if ($konversi <= 0) { $konversi = 1; }
$rows[] = [
'id' => $item->id,
'kodejenis' => $item->kodejenis ?? '',
'jenis' => $item->jenis,
'satuan' => $item->satuan,
'satuan_kecil' => $item->satuan_kecil ?? '',