<?php
class MyNilai {
    private $ci;
	public static function getNilai(array $value,$operatorID){
        $ci=get_instance();
        $ci->load->helper('hitungnilai');
		
		// // PAI
        // $paiK4S1 = "";
        // $paiK4S2 = "";
        // $paiK5S1 = "";
        // $paiK5S2 = "";
        // $paiK6S1 = "";
        // // PKN
        // $pknK4S1 = "";
        // $pknK4S2 = "";
        // $pknK5S1 = "";
        // $pknK5S2 = "";
        // $pknK6S1 = "";
        // // Indo
        // $indoK4S1 = "";
        // $indoK4S2 = "";
        // $indoK5S1 = "";
        // $indoK5S2 = "";
        // $indoK6S1 = "";
        // // mtk
        // $mtkK4S1 = "";
        // $mtkK4S2 = "";
        // $mtkK5S1 = "";
        // $mtkK5S2 = "";
        // $mtkK6S1 = "";
        // // ipa
        // $ipaK4S1 = "";
        // $ipaK4S2 = "";
        // $ipaK5S1 = "";
        // $ipaK5S2 = "";
        // $ipaK6S1 = "";
        // // ips
        // $ipsK4S1 = "";
        // $ipsK4S2 = "";
        // $ipsK5S1 = "";
        // $ipsK5S2 = "";
        // $ipsK6S1 = "";
        // // sbdp
        // $sbdpK4S1 = "";
        // $sbdpK4S2 = "";
        // $sbdpK5S1 = "";
        // $sbdpK5S2 = "";
        // $sbdpK6S1 = "";
        // // pjok
        // $pjokK4S1 = "";
        // $pjokK4S2 = "";
        // $pjokK5S1 = "";
        // $pjokK5S2 = "";
        // $pjokK6S1 = "";
        // // sunda
        // $sundaK4S1 = "";
        // $sundaK4S2 = "";
        // $sundaK5S1 = "";
        // $sundaK5S2 = "";
        // $sundaK6S1 = "";
		//    // PAI
                        $paiK4S1 = isset($value['D']) ? $value['D'] : 0;
                        $paiK4S2 = isset($value['M']) ? $value['M'] : 0;
                        $paiK5S1 = isset($value['V']) ? $value['V'] : 0;
                        $paiK5S2 = isset($value['AE']) ? $value['AE'] : 0;
                        $paiK6S1 = isset($value['AN']) ? $value['AN'] : 0;
                        // PKN
                        $pknK4S1 = isset($value['E']) ? $value['E'] : 0;
                        $pknK4S2 = isset($value['N']) ? $value['N'] : 0;
                        $pknK5S1 = isset($value['W']) ? $value['W'] : 0;
                        $pknK5S2 = isset($value['AF']) ? $value['AF'] : 0;
                        $pknK6S1 = isset($value['AO']) ? $value['AO'] : 0;
                        // Indo
                        $indoK4S1 = isset($value['F']) ? $value['F'] : 0;
                        $indoK4S2 = isset($value['O']) ? $value['O'] : 0;
                        $indoK5S1 = isset($value['X']) ? $value['X'] : 0;
                        $indoK5S2 = isset($value['AG']) ? $value['AG'] : 0;
                        $indoK6S1 = isset($value['AP']) ? $value['AP'] : 0;
                        // mtk
                        $mtkK4S1 = isset($value['G']) ? $value['G'] : 0;
                        $mtkK4S2 = isset($value['P']) ? $value['P'] : 0;
                        $mtkK5S1 = isset($value['Y']) ? $value['Y'] : 0;
                        $mtkK5S2 = isset($value['AH']) ? $value['AH'] : 0;
                        $mtkK6S1 = isset($value['AQ']) ? $value['AQ'] : 0;
                        // ipa
                        $ipaK4S1 = isset($value['H']) ? $value['H'] : 0;
                        $ipaK4S2 = isset($value['Q']) ? $value['Q'] : 0;
                        $ipaK5S1 = isset($value['Z']) ? $value['Z'] : 0;
                        $ipaK5S2 = isset($value['AI']) ? $value['AI'] : 0;
                        $ipaK6S1 = isset($value['AR']) ? $value['AR'] : 0;
                        // ips
                        $ipsK4S1 = isset($value['I']) ? $value['I'] : 0;
                        $ipsK4S2 = isset($value['R']) ? $value['R'] : 0;
                        $ipsK5S1 = isset($value['AA']) ? $value['AA'] : 0;
                        $ipsK5S2 = isset($value['AJ']) ? $value['AJ'] : 0;
                        $ipsK6S1 = isset($value['AS']) ? $value['AS'] : 0;
                        // sbdp
                        $sbdpK4S1 = isset($value['J']) ? $value['J'] : 0;
                        $sbdpK4S2 = isset($value['S']) ? $value['S'] : 0;
                        $sbdpK5S1 = isset($value['AB']) ? $value['AB'] : 0;
                        $sbdpK5S2 = isset($value['AK']) ? $value['AK'] : 0;
                        $sbdpK6S1 = isset($value['AT']) ? $value['AT'] : 0;
                        // pjok
                        $pjokK4S1 = isset($value['K']) ? $value['K'] : 0;
                        $pjokK4S2 = isset($value['T']) ? $value['T'] : 0;
                        $pjokK5S1 = isset($value['AC']) ? $value['AC'] : 0;
                        $pjokK5S2 = isset($value['AL']) ? $value['AL'] : 0;
                        $pjokK6S1 = isset($value['AU']) ? $value['AU'] : 0;
                        // sunda
                        $sundaK4S1 = isset($value['L']) ? $value['L'] : 0;
                        $sundaK4S2 = isset($value['U']) ? $value['U'] : 0;
                        $sundaK5S1 = isset($value['AD']) ? $value['AD'] : 0;
                        $sundaK5S2 = isset($value['AM']) ? $value['AM'] : 0;
                        $sundaK6S1 = isset($value['AV']) ? $value['AV'] : 0;

        $totalPai = MyHitungNilai::sumNilai($paiK4S1, $paiK4S2, $paiK5S1, $paiK5S2, $paiK6S1);
        $totalPkn = MyHitungNilai::sumNilai($pknK4S1, $pknK4S2, $pknK5S1, $pknK5S2, $pknK6S1);
        $totalIndo = MyHitungNilai::sumNilai($indoK4S1, $indoK4S2, $indoK5S1, $indoK5S2, $indoK6S1);
        $totalMtk = MyHitungNilai::sumNilai($mtkK4S1, $mtkK4S2, $mtkK5S1, $mtkK5S2, $mtkK6S1);
        $totalIpa = MyHitungNilai::sumNilai($ipaK4S1, $ipaK4S2, $ipaK5S1, $ipaK5S2, $ipaK6S1);
        $totalIps = MyHitungNilai::sumNilai($ipsK4S1, $ipsK4S2, $ipsK5S1, $ipsK5S2, $ipsK6S1);
        $totalSbdp = MyHitungNilai::sumNilai($sbdpK4S1, $sbdpK4S2, $sbdpK5S1, $sbdpK5S2, $sbdpK6S1);
        $totalPjok = MyHitungNilai::sumNilai($pjokK4S1, $pjokK4S2, $pjokK5S1, $pjokK5S2, $pjokK6S1);
        $totalSunda = MyHitungNilai::sumNilai($sundaK4S1, $sundaK4S2, $sundaK5S1, $sundaK5S2, $sundaK6S1);
        $total = MyHitungNilai::sumRataRata($totalPai, $totalPkn, $totalIndo, $totalMtk, $totalIpa, $totalIps, $totalSbdp, $totalPjok + $totalSunda); 

                        // prepare data upload

                        // data siap simpan atau update
                        $data = [
                            'nisn' => $value['B'],
                            'noOps' =>$operatorID,
                            'recordNilaiNama' => $value['C'],
                            'paiK4S1' => $paiK4S1,
                            'paiK4S2' => $paiK4S2,
                            'paiK5S1' => $paiK5S1,
                            'paiK5S2' => $paiK5S2,
                            'paiK6S1' => $paiK6S1,

                            'pknK4S1' => $pknK4S1,
                            'pknK4S2' => $pknK4S2,
                            'pknK5S1' => $pknK5S1,
                            'pknK5S2' => $pknK5S2,
                            'pknK6S1' => $pknK6S1,

                            'indoK4S1' => $indoK4S1,
                            'indoK4S2' => $indoK4S2,
                            'indoK5S1' => $indoK5S1,
                            'indoK5S2' => $indoK5S2,
                            'indoK6S1' => $indoK6S1,

                            'mtkK4S1' => $mtkK4S1,
                            'mtkK4S2' => $mtkK4S2,
                            'mtkK5S1' => $mtkK5S1,
                            'mtkK5S2' => $mtkK5S2,
                            'mtkK6S1' => $mtkK6S1,

                            'ipaK4S1' => $ipaK4S1,
                            'ipaK4S2' => $ipaK4S2,
                            'ipaK5S1' => $ipaK5S1,
                            'ipaK5S2' => $ipaK5S2,
                            'ipaK6S1' => $ipaK6S1,

                            'ipsK4S1' => $ipsK4S1,
                            'ipsK4S2' => $ipsK4S2,
                            'ipsK5S1' => $ipsK5S1,
                            'ipsK5S2' => $ipsK5S2,
                            'ipsK6S1' => $ipsK6S1,

                            'sbdpK4S1' => $sbdpK4S1,
                            'sbdpK4S2' => $sbdpK4S2,
                            'sbdpK5S1' => $sbdpK5S1,
                            'sbdpK5S2' => $sbdpK5S2,
                            'sbdpK6S1' => $sbdpK6S1,

                            'pjokK4S1' => $pjokK4S1,
                            'pjokK4S2' => $pjokK4S2,
                            'pjokK5S1' => $pjokK5S1,
                            'pjokK5S2' => $pjokK5S2,
                            'pjokK6S1' => $pjokK6S1,

                            'sundaK4S1' => $sundaK4S1,
                            'sundaK4S2' => $sundaK4S2,
                            'sundaK5S1' => $sundaK5S1,
                            'sundaK5S2' => $sundaK5S2,
                            'sundaK6S1' => $sundaK6S1,
                            'total' => $total,
                            'totalSkor'=>$total
                        ];


						return $data;
	}
}
