<?php
include "model/viewnomer.php";
class proses{
    function tanggal($tgl){
        $tanggal = substr($tgl,3,2);
	$bulan = substr($tgl,0,2);
	$tahun = substr($tgl,6,4);
        
	return $tahun.'-'.$bulan.'-'.$tanggal;
    }
    
    function tgl_berlaku($tgl){
        $tanggal = substr($tgl,3,2);
	$bulan = substr($tgl,0,2);
	$tahun = substr($tgl,6,4);
        
	$tahun = $tahun + 1;
        
        return $tahun.'-'.$bulan.'-'.$tanggal;
    }
    
    function tgl_pemeriksaan(){
        $besok = mktime (0,0,0, date("m"), date("d")+1,date("Y"));
        
        $tgl = date('d-m-Y', $besok);
        
        return $tgl;
    }
    
    function sampling($jml_kemasan_besar,$jml_inner,$berat_inner){
        $lot = $jml_kemasan_besar * $jml_inner;
        
        if($berat_inner<=1){
            if($lot<=4800){
                $hasil = 3;
            }
            elseif($lot>4800&&$lot<=24000){
                $hasil = 3;
            }
            elseif($lot>24000&&$lot<=48000){
                $hasil = 5;
            }
            elseif($lot>48000&&$lot<=84000){
                $hasil = 6;
            }
        }
        elseif($berat_inner>1&&$berat_inner<=4.5){
            if($lot<=2400){
                $hasil = 3;
            }
            elseif($lot>2400&&$lot<=15000){
                $hasil = 3;
            }
            elseif($lot>15000&&$lot<=24000){
                $hasil = 5;
            }
            elseif($lot>24000&&$lot<=42000){
                $hasil = 6;
            }
        }
        elseif($berat_inner>=4.5){
            if($lot<=600){
                $hasil = 3;
            }
            elseif($lot>600&&$lot<=2000){
                $hasil = 3;
            }
            elseif($lot>2000&&$lot<=7200){
                $hasil = 5;
            }
            elseif($lot>7200&&$lot<=15000){
                $hasil = 6;
            }
        }
        
        return $hasil;
    }
    
    function nopermohonan(){
        
        $nomer = new viewnomer();
        
        $hari = date('d');
        $bulan = date('m');
        $tahun = date('y');
        
        //$nop = $d[nomer];
        
        if($hari=='01'){
            $nop = 1;
        }else{
            $nop = $nomer->nomer();
        }
        
        $no = $nop + 1;
        
        $nomer->editnomer($no);
        
        if($nop>0&&$nop<=9){
            $nol = '000';
        }
        elseif($nop>9&&$nop<=99){
            $nol = '00';
        }
        elseif($nop>99&&$nop<=999){
            $nol = '0';
        }
        elseif($nop>999&&$nop<=9999){
            $nol = '';
        }
        
        return $tahun.$bulan.$nol.$nop;
    }
    
    function nolab(){
        
        $nomer = new viewnomer();
        
        $hari = date('d');
        $bulan = date('m');
        $tahun = date('y');
        
        $d = $nomer->nomerlab();
        
        if($hari==$d[tgl]){
            $nop = $d[nomer];
        }else{
            $nop = 1;
        }
        
        $no = $nop + 1;
        
        $nomer->editnomerlab($no,$hari);
        
        $acak = rand(1,99);
        
        if($nop>0&&$nop<=9){
            $nol = '000';
        }
        elseif($nop>9&&$nop<=99){
            $nol = '00';
        }
        elseif($nop>99&&$nop<=999){
            $nol = '0';
        }
        elseif($nop>999&&$nop<=9999){
            $nol = '';
        }
        
        return $tahun.$bulan.$acak.$nol.$nop;
    }
}

