@@ -269,13 +269,25 @@ public static function getYearFromDate($tanggal, $typeDate = true)
269269 * @param string $derajat
270270 * @return array nomor, nomor_urut, segmen
271271 */
272- public static function nomor ($ tanggal , $ jenis_naskah_id , $ unit_kerja_id , $ kode_arsip_id , $ derajat )
272+ public static function nomor ($ tanggal , $ jenis_naskah_id , $ unit_kerja_id = null , $ kode_arsip_id = null , $ derajat = null )
273273 {
274+ $ replaces = [];
274275 $ tahun = self ::getYearFromDate ($ tanggal );
276+ $ replaces ['<tahun> ' ] = $ tahun ;
275277 $ jenis_naskah = JenisNaskah::cache ()->get ('all ' )->where ('id ' , $ jenis_naskah_id )->first ();
276278 $ kode_naskah = KodeNaskah::cache ()->get ('all ' )->where ('id ' , $ jenis_naskah ->kode_naskah_id )->first ();
277- $ unit_kerja = UnitKerja::cache ()->get ('all ' )->where ('id ' , $ unit_kerja_id )->first ();
278- $ kode_arsip = KodeArsip::cache ()->get ('all ' )->where ('id ' , $ kode_arsip_id )->first ();
279+ if ($ unit_kerja_id !== null ) {
280+ $ unit_kerja = UnitKerja::cache ()->get ('all ' )->where ('id ' , $ unit_kerja_id )->first ();
281+ $ replaces ['<kode_unit_kerja> ' ] = $ unit_kerja ->kode ;
282+ }
283+ if ($ kode_arsip_id !== null ) {
284+ $ kode_arsip = KodeArsip::cache ()->get ('all ' )->where ('id ' , $ kode_arsip_id )->first ();
285+ $ replaces ['<kode_arsip> ' ] = $ kode_arsip ->kode ;
286+ }
287+ if ($ derajat !== null ) {
288+ $ replaces ['<kode_derajat> ' ] = $ derajat ;
289+ }
290+
279291 $ naskah = NaskahKeluar::where ('tahun ' , $ tahun )->where ('kode_naskah_id ' , $ kode_naskah ->id );
280292 $ max_no_urut = $ naskah ->max ('no_urut ' );
281293 $ max_tanggal = $ naskah ->max ('tanggal ' ) ?? '1970-01-01 ' ;
@@ -288,17 +300,14 @@ public static function nomor($tanggal, $jenis_naskah_id, $unit_kerja_id, $kode_a
288300 $ segmen = NaskahKeluar::where ('tahun ' , $ tahun )->where ('kode_naskah_id ' , $ kode_naskah ->id )->where ('no_urut ' , $ no_urut )->max ('segmen ' ) + 1 ;
289301 $ replaces ['<no_urut> ' ] = $ no_urut .'. ' .$ segmen ;
290302 }
291- $ format = $ jenis_naskah ->format ?? $ kode_naskah ->format ;
292- $ replaces ['<tahun> ' ] = $ tahun ;
293- $ replaces ['<kode_unit_kerja> ' ] = $ unit_kerja ->kode ;
294- $ replaces ['<kode_arsip> ' ] = $ kode_arsip ->kode ;
295- $ replaces ['<derajat> ' ] = $ derajat ;
303+ $ format = $ jenis_naskah ->format ?? $ kode_naskah ->format ;
296304 $ nomor = strtr ($ format , $ replaces );
297305
298306 return [
299307 'nomor ' => $ nomor ,
300308 'no_urut ' => $ no_urut ,
301309 'segmen ' => $ segmen ,
310+ 'kode_naskah_id ' => $ kode_naskah ->id
302311 ];
303312 }
304313
0 commit comments