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.145.36.252


Current Path : /proc/thread-self/root/var/www/html/univadmin_bkp/univadmin/src/
Upload File :
Current File : //proc/thread-self/root/var/www/html/univadmin_bkp/univadmin/src/paymentReport.php

<?php

function uploadPaymentReport($aobj_context){

  ini_set('max_execution_time', 600);

	$aobj_context->mobj_db->SetFetchMode(ADODB_FETCH_ASSOC); 
	session_start();
	require_once dirname(__FILE__) . '/../PHPExcel/Classes/PHPExcel/IOFactory.php';

  $univcode = $aobj_context->mobj_data["univcode"];
  $filename = $aobj_context->mobj_data["gfilename"];

  $date = date("dmYhis");
  $folderpath = $aobj_context->main_src."PaymentReports/".$univcode.'/'; 
// var_dump($folderpath);
  $temp_path = $aobj_context->main_src."upload/".$filename;

	if(!file_exists($temp_path))
	{
		$data = "Please login and try again";
		echo $aobj_context->mobj_output->ToJSONEnvelope($data,-1,"failure"); 
		return;
	}
  // var_dump($temp_path);
  if(!file_exists($folderpath))
  {
      mkdir($folderpath);
  }
  $inputFileName = $temp_path;
  $inputFileType = 'Excel2007';

  ///////////////////// Code To convert xlsx to csv \\\\\\\\\\\\\
  $objReader = PHPExcel_IOFactory::createReader($inputFileType);
  $objPHPExcelReader = $objReader->load($inputFileName);

  $loadedSheetNames = $objPHPExcelReader->getSheetNames();
// var_dump($loadedSheetNames);
  $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcelReader, 'CSV');

  $i = 0;
  foreach($loadedSheetNames as $sheetIndex => $loadedSheetName) 
  {
    if($i != 0)
        break;
    $objWriter->setSheetIndex($sheetIndex);
    $csvFile = $folderpath.$date.$loadedSheetName.'.csv';    
    $objWriter->setUseBOM(true);
    $objWriter->save($csvFile);

    $table_name = "paymentReport_{$univcode}";

    $drop_query = "DROP TABLE IF EXISTS {$table_name}";
    //var_dump($drop_query);
    $results = $aobj_context->mobj_db->Execute($drop_query);
    // var_dump($results);
    $create_query = "CREATE TABLE {$table_name} (
        `fappno` varchar(13) NOT NULL,
        `fregno` varchar(8) DEFAULT NULL,
        `fname` varchar(100) DEFAULT NULL,
        `ftranid` varchar(200) DEFAULT NULL,
        PRIMARY KEY (`fappno`)
      ) ENGINE=InnoDB DEFAULT CHARSET=latin1";
    //var_dump($create_query);
    // var_dump($csvfile);

    $results = $aobj_context->mobj_db->Execute($create_query);
    //return;
    $query = "LOAD DATA LOCAL INFILE '{$csvFile}'
    INTO TABLE {$table_name}
    FIELDS TERMINATED BY \",\"
    OPTIONALLY ENCLOSED BY '\"' 
    LINES TERMINATED BY '\n' 
    (fappno,fregno, ftranid, fname)";
    //var_dump($query);  
    $results = $aobj_context->mobj_db->Execute($query);



    
    $rows_affected = $aobj_context->mobj_db->affected_rows();
    
    if(!$results)
    {
        $data = "Upload failure. Error while loading excel data to database";
        echo $aobj_context->mobj_output->ToJSONEnvelope($data,-1,"failure"); 
        return;
    }
    // Delete All the blank values from table
    $query = "delete from {$table_name} where fappno = ''";
    $results = $aobj_context->mobj_db->Execute($query);
    
    $query = "select fdbname,ffolder from dbname where funivcode = '{$univcode}'";
    $results = $aobj_context->mobj_db->GetRow($query);

    $db = $results['fdbname'];
    $univshort = $results['ffolder'];
    // var_dump($db);
    $query = "insert ignore into {$db}.pg_txn(fappno, fregno, ftranid, fname)
    select fappno, fregno, replace(ftranid,'\'','') as ftranid, fname from {$table_name}";
    // var_dump($query);
    // die();
    $results = $aobj_context->mobj_db->Execute($query);
    
    $rows_affectedi = $aobj_context->mobj_db->affected_rows();

  }

  if($results)
  {
    $data = $univshort;
    echo $aobj_context->mobj_output->ToJSONEnvelope($data,0,"success"); 
    return;	
  }
  else
  {
    $data = "Error while updating";
    echo $aobj_context->mobj_output->ToJSONEnvelope($data,-1,"error"); 
    return;
  }
}

?>