format('y'); $lastVoucher = Expense::query()->where('branch_id', $branch->id)->orderBy('created_at', 'desc')->first(); if (! $lastVoucher) { return $year.'-'.str_pad(1, 6, '0', STR_PAD_LEFT); } $voucherNumber = (int) explode('-', $lastVoucher->voucher_number)[1]; return $year.'-'.str_pad($voucherNumber + 1, 6, '0', STR_PAD_LEFT); } }