0xV3NOMx
Linux ip-172-26-7-228 5.4.0-1103-aws #111~18.04.1-Ubuntu SMP Tue May 23 20:04:10 UTC 2023 x86_64



Your IP : 3.147.46.174


Current Path : /var/www/html/collportal/src/
Upload File :
Current File : //var/www/html/collportal/src/roomsAllotmentOnQpcodeWise.php

<?php

function roomsForAllotmentOnQpcodeWise($aobj_context){
	$collcode = $aobj_context->mobj_data['collcode'];
	$univcode=$aobj_context->mobj_data['univcode'];
	$dates=$aobj_context->mobj_data['dates'];
	$year=$aobj_context->mobj_data['year'];
	$session=$aobj_context->mobj_data['session'];

	$yearmode=explode('*',$year);

	$query="SELECT s.fdoe, s.fsession, s.fdegree, s.fsubcode, s.fcsubcode, s.fqpcode,
		          s.fsubname, c.fregno, COUNT(c.fregno)AS counts, SUM(IF(IFNULL(c.fhallno,'')='', 0, 1))AS qpcount,
                  (COUNT(c.fregno) - SUM(IF(IFNULL(c.fhallno,'')='', 0, 1))) AS fremaingcount
                  FROM subject s INNER JOIN 
                  canddet c ON s.fdegree = c.fdegree AND s.fexamno = c.fexamno
                  AND s.fsubcode = c.fsubcode INNER JOIN candsum d ON c.fregno = d.fregno 
                  AND c.fcollcode = d.fcollcode
                  INNER JOIN reason r ON s.fsession=r.freasoncd 
                  WHERE s.ftheory='t' AND s.fintass='f' 
                  AND IFNULL(s.fqpcode,'')<>'' AND IFNULL(c.fpassmth,'')='' AND 
                  IFNULL(c.fpresent,'')='P' 
                  AND IFNULL(d.frecptdate,'')<>''
                  AND s.fdoe=DATE_FORMAT(STR_TO_DATE('{$dates}', '%d/%m/%Y'),'%Y-%m-%d') AND s.fsession LIKE '{$session}%' 
                  AND d.fcntrcode='{$collcode}' AND c.fyear = '{$yearmode[0]}' AND c.fexamtype = '{$yearmode[1]}'
                  GROUP BY s.fdoe,s.fsession,s.fqpcode
                  ORDER BY s.fdoe,s.fsession,s.fcsubcode,s.fqpcode,s.fsubname";

	$res = $aobj_context->mobj_db->getAll($query);

	if($res){
		echo $aobj_context->mobj_output->ToJSONEnvelope($res, 0, "success");
	} else{
		$arr['msg']="Failed to Load";
		echo $aobj_context->mobj_output->ToJSONEnvelope($arr, -1, "failure");
		return;
	}
}

function roomAllotOnQpcode($aobj_context){
	$collcode = $aobj_context->mobj_data['collcode'];
	$univcode=$aobj_context->mobj_data['univcode'];
	$dates=$aobj_context->mobj_data['date'];
	$year=$aobj_context->mobj_data['year'];
	$session=$aobj_context->mobj_data['session'];
	$qpcode=$aobj_context->mobj_data['qpcode'];

	$query0 = "select froomname as `label`,  froomno as `value` from masroom where fcollcode='{$collcode}'";
	$res0 = $aobj_context->mobj_db->GetAll($query0);

	// $query1 = "SELECT fhallno,COUNT(fregno)AS alloted,m.fbalance,m.fcapacity FROM canddet c INNER JOIN subject s
	//            ON c.fdegree=s.fdegree  AND c.fsubcode=s.fsubcode
	//            INNER JOIN masroom m ON m.froomno=c.fhallno
	//            WHERE IFNULL(fhallno,'')<>'' AND IFNULL(fqpcode1,'')<>'' 
	//            AND s.fdoe='2024-05-21' AND s.fsession='M4' AND m.fcollcode='1827'
	//            AND c.fqpcode1='13101'  GROUP BY fhallno";
	// $res1 = $aobj_context->mobj_db->GetAll($query1); 
	// if($res1){
	//     $arr['data'] = $res1;
	//     echo $aobj_context->mobj_output->ToJSONEnvelope($arr, 0, "success");
	// } else{
	//     echo $aobj_context->mobj_output->ToJSONEnvelope($res1, -1, "success"); 
	// }   

	$query = "select m.froomname as `label`, m.fcapacity, m.froomno as `value`, if(ifnull(fbalroomcnt, '')='', 
	         fcapacity, fbalroomcnt)as fbalance , 
			count(d.fregno) as fallot, count(d.fqpcode1)as qpcount from masroom m inner join candsum cs 
			on m.fcollcode = cs.fcntrcode inner join canddet d 
			on m.froomno = d.fhallno and cs.fcollcode = d.fcollcode 
			and cs.fregno = d.fregno inner join subject s 
			on d.fqpcode1 = s.fqpcode 
			and d.fdegree = s.fdegree and d.fexamno = s.fexamno
			and d.fsubcode = s.fsubcode
			where d.fqpcode1='{$qpcode}' and cs.fcntrcode='{$collcode}'
			group by d.fhallno";

		

	$res = $aobj_context->mobj_db->GetAll($query);

	if(count($res)>0){
		$arr['options'] = $res0;
		$arr['data'] = $res;
	} else{
		$obj = [
			['label' => '', 'fcapacity'=>'', 'value'=>'', 'fbalance'=>'', 'fallot'=>'', 'qpcount'=>'']
		];

		$arr['options'] = $res0;
		$arr['data'] = $obj;
	}

	echo $aobj_context->mobj_output->ToJSONEnvelope($arr, 0, "success");
}

function roomCapacityOnQpcode($aobj_context){
	$collcode = $aobj_context->mobj_data['collcode'];
	$univcode = $aobj_context->mobj_data['univcode'];
	$roomno = $aobj_context->mobj_data['roomno'];
	
	$query = "SELECT ifnull(froomname,'')as froomname, ifnull(fcapacity,'')as fcapacity, ifnull(froomno,'')as froomno,
	          ifnull(fallot,'')fallot,ifnull(fbalroomcnt,'') as fbalroomcnt  FROM masroom    
              WHERE fcollcode='{$collcode}' AND froomno='{$roomno}'";
	
			
	$res = $aobj_context->mobj_db->GetRow($query);
   if($res){
	echo $aobj_context->mobj_output->ToJSONEnvelope($res, 0, "success");
   }else{
	$arr['msg']="Failed to Load";
	echo $aobj_context->mobj_output->ToJSONEnvelope($arr, -1, "failure");
	return;
   }

}

function resetroomAllotmentQpwise($aobj_context){
	$collcode = $aobj_context->mobj_data['collcode'];
	$univcode = $aobj_context->mobj_data['univcode'];
	$date = $aobj_context->mobj_data['date'];
	$session = $aobj_context->mobj_data['session'];
	$qpcode = $aobj_context->mobj_data['qpcode'];
	$subcode = $aobj_context->mobj_data['subcode'];
	$count = $aobj_context->mobj_data['count'];

	$query = "SELECT fhallno,COUNT(fhallno)AS cnt FROM canddet WHERE fqpcode1='{$qpcode}' and fcollcode='{$collcode}' GROUP BY fhallno";

        $res1 = $aobj_context->mobj_db->GetAll($query);
		
         foreach ($res1 as $value) {
            $query="select ifnull(fbalroomcnt,0) as fbalance, ifnull(fallot,0) as fallot 
			        from masroom where froomno='{$value['fhallno']}' and fcollcode='{$collcode}'";
					
            $res = $aobj_context->mobj_db->GetRow($query);

            $remainAllot = max(0,intval($res['fallot']) - intval($value['cnt']));
            $addBalance = intval($res['fbalance']) + intval($value['cnt']);
			

            $query=" UPDATE masroom
                    SET fallot = '{$remainAllot}', fbalroomcnt = '{$addBalance}'
                    WHERE froomno='{$value['fhallno']}' AND fcollcode='{$collcode}'";
				
         
	
            $res = $aobj_context->mobj_db->Execute($query);

            if($res){
                $qry = "update canddet set fhallno = '',fslno = '' where fqpcode1='{$qpcode}' and fhallno='{$value['fhallno']}'";
			
                $result = $aobj_context->mobj_db->Execute($qry);
            }

         }
		  if ($res) {
                    $arr['msg']='Reset Successfully';
                    echo $aobj_context->mobj_output->ToJSONEnvelope($arr, 0, "success");
                } else {
                    $arr['msg']='Reset Failed';
                    echo $aobj_context->mobj_output->ToJSONEnvelope($arr, -1, "failure");
                    return;
                }

}

function saveRoomAllotmentQpwiseData($aobj_context){
	$data = json_decode($aobj_context->mobj_data["data"], true);
	$date = $aobj_context->mobj_data["date"];
	$qpcode = $aobj_context->mobj_data["qpcode"];
	$collcode = $aobj_context->mobj_data['collcode'];

	foreach ($data as $key => $value) { 
		if($value['froomno']==""){
			$roomno=$value['value'];
		}else{
			$roomno=$value['froomno'];
		}
	
		
		$query6 = "drop table if exists temp_fregno";
		$res6 = $aobj_context->mobj_db->Execute($query6);
	
		$query3 = "create table temp_fregno as
				   select distinct cd.fregno from canddet cd  inner join subject s on 
				   s.fdegree = cd.fdegree and s.fexamno = cd.fexamno and s.fsubcode = cd.fsubcode
				   inner join candsum cs on cd.fregno = cs.fregno
				   and cd.fcollcode = cs.fcollcode
				   left join absent ab on ab.fregno = cd.fregno where 
				   s.fdoe =  date_format(STR_TO_DATE('{$date}', '%d/%m/%Y'),'%Y-%m-%d') and ifnull(cd.fpassmth, '') = ''
				   and cd.fpresent='P' and cs.fcntrcode = '{$collcode}'
				   and s.fqpcode = '{$qpcode}' and ifnull(cd.fhallno, '') = ''
				   and ifnull(s.fqpcode,'')<>'' and s.fintass='F' 
				   and ifnull(frecptdate, '') <> '' order by cd.fregno asc
				   limit {$value['allot']}";
				  
		$res3 = $aobj_context->mobj_db->Execute($query3);
			
		$query4 = "update canddet join temp_fregno on canddet.fregno = temp_fregno.fregno
				   inner join subject sub on sub.fdegree = canddet.fdegree 
				   and sub.fexamno = canddet.fexamno and sub.fsubcode = canddet.fsubcode 
				   set canddet.fhallno = '{$roomno}',canddet.fqpcode1 = '{$qpcode}'
				   where sub.fqpcode='{$qpcode}'
				   and ifnull(fhallno, '') = ''";
				
		$res4 = $aobj_context->mobj_db->Execute($query4);

	
		$query6 = "update canddet x, (select right(concat('000',@a:=@a+1),3) as fslno, 
				  fregno, fqpcode1, fhallno
				  from (select cd.fdegree, cd.fcollcode, 
				  cd.fregno, cd.fqpcode1, cd.fhallno from canddet cd, subject s, candsum cs
				  where s.fdegree = cd.fdegree 
				  and s.fexamno = cd.fexamno and s.fsubcode = cd.fsubcode 
				  and cd.fqpcode1 = s.fqpcode and cs.fregno = cd.fregno 
				  and cd.fcollcode = cs.fcollcode 
				  and s.fdoe = date_format(STR_TO_DATE('{$date}', '%d/%m/%Y'),'%Y-%m-%d')
				  and ifnull(cd.fpassmth,'') = '' and cd.fpresent='P'  
				  and ifnull(cs.frecptdate,'0000-00-00')<>'0000-00-00'  
				  and cd.fhallno = '{$roomno}'
				  and cs.fcntrcode = '{$collcode}'
				  and ifnull(s.fqpcode,'') <> ''
				  order by cd.fqpcode1,fregno) b, (select @a:= '000') as a) y
				  set x.fslno = y.fslno 
				  where x.fqpcode1 = y.fqpcode1
				  and x.fhallno = y.fhallno
				  and x.fregno = y.fregno";

;
		$res6 = $aobj_context->mobj_db->Execute($query6);
		
		if($res6){
			$query0 = "select if(ifnull(fbalroomcnt, '')='', fcapacity, fbalroomcnt)as fbal,
				   ifnull(fallot, '')as fallotted, ifnull(fcapacity, '')as fcapacity
				   from masroom where fcollcode = '{$collcode}' and froomno='{$roomno}'";
				
			$res0 = $aobj_context->mobj_db->GetRow($query0);
		
			$remaining =  intval($res0['fcapacity']) - (intval($res0['fallotted']) + intval($value['allot']));
	       
			$allotted = intval($res0['fallotted']) + intval($value['allot']);

			$query1 = "update masroom set fallot='{$allotted}', fbalroomcnt='{$remaining}'
					where froomno='{$roomno}' and fcollcode = '{$collcode}'";
				
					
			$res1 = $aobj_context->mobj_db->Execute($query1);
		
		}
	}

	if ($res1) {
		$arr['msg'] = "Updated successfully";
		echo $aobj_context->mobj_output->ToJSONEnvelope($arr, 0, "success");
	} else {
		$arr['msg'] = "Failed to update";
		echo $aobj_context->mobj_output->ToJSONEnvelope($arr, -1, "failure");
		return;
	}
}

?>