174 lines
6.6 KiB
PHP
174 lines
6.6 KiB
PHP
<?php
|
|
include('includes/config/config.php');
|
|
include('includes/functions.php');
|
|
//$conn = mysqli_connect("localhost","root","","phpsamples");
|
|
require_once('excel/vendor/php-excel-reader/excel_reader2.php');
|
|
require_once('excel/vendor/SpreadsheetReader.php');
|
|
|
|
$inter_usage_id=array();
|
|
|
|
$response_array = array();
|
|
$response_mssages = "";
|
|
|
|
begin();
|
|
|
|
|
|
$allowedFileType = ['application/vnd.ms-excel', 'text/xls', 'text/xlsx', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'];
|
|
|
|
if (in_array($_FILES["file"]["type"], $allowedFileType)) {
|
|
|
|
$targetPath = 'excel/uploads/' . $_FILES['file']['name'];
|
|
move_uploaded_file($_FILES['file']['tmp_name'], $targetPath);
|
|
|
|
$Reader = new SpreadsheetReader($targetPath);
|
|
|
|
$sheetCount = count($Reader->sheets());
|
|
|
|
for ($i = 0; $i < 1; $i++) {
|
|
|
|
$Reader->ChangeSheet($i);
|
|
$j = 0;
|
|
foreach ($Reader as $Row) {
|
|
if ($j == 0) {
|
|
$j = 1;
|
|
continue;
|
|
}
|
|
|
|
error_log("again here");
|
|
|
|
// echo "shu".$Row[0];
|
|
$usage_date = "";
|
|
if (isset($Row[0])) {
|
|
$usage_date = mysqli_real_escape_string($conn, $Row[0]);
|
|
}
|
|
|
|
$ambulance_id = "";
|
|
if (isset($Row[1])) {
|
|
$ambulance_id = mysqli_real_escape_string($conn, $Row[1]);
|
|
}
|
|
$driver_id = "";
|
|
if (isset($Row[2])) {
|
|
$driver_id = mysqli_real_escape_string($conn, $Row[2]);
|
|
}
|
|
$client_id = "";
|
|
if (isset($Row[3])) {
|
|
$client_id = mysqli_real_escape_string($conn, $Row[3]);
|
|
}
|
|
$client_location_id = "";
|
|
if (isset($Row[4])) {
|
|
$client_location_id = mysqli_real_escape_string($conn, $Row[4]);
|
|
}
|
|
$patient_id = "";
|
|
if (isset($Row[5])) {
|
|
$patient_id = mysqli_real_escape_string($conn, $Row[5]);
|
|
}
|
|
$duty_id = "";
|
|
if (isset($Row[6])) {
|
|
$duty_id = mysqli_real_escape_string($conn, $Row[6]);
|
|
}
|
|
$ambulance_from = "";
|
|
if (isset($Row[7])) {
|
|
$ambulance_from = mysqli_real_escape_string($conn, $Row[7]);
|
|
}
|
|
|
|
$ambulance_to = "";
|
|
if (isset($Row[8])) {
|
|
$ambulance_to = mysqli_real_escape_string($conn, $Row[8]);
|
|
}
|
|
|
|
$ambulance_out_km = "";
|
|
if (isset($Row[9])) {
|
|
$ambulance_out_km = mysqli_real_escape_string($conn, $Row[9]);
|
|
}
|
|
|
|
$ambulance_in_km = "";
|
|
if (isset($Row[10])) {
|
|
$ambulance_in_km = mysqli_real_escape_string($conn, $Row[10]);
|
|
}
|
|
$ambulance_total_km = "";
|
|
if (isset($Row[11])) {
|
|
$ambulance_total_km = mysqli_real_escape_string($conn, $Row[11]);
|
|
}
|
|
$ambulance_out_time = "";
|
|
if (isset($Row[12])) {
|
|
$ambulance_out_time = mysqli_real_escape_string($conn, $Row[12]);
|
|
}
|
|
|
|
$ambulance_in_time = "";
|
|
if (isset($Row[13])) {
|
|
$ambulance_in_time = mysqli_real_escape_string($conn, $Row[13]);
|
|
}
|
|
|
|
$ambulance_details = "";
|
|
if (isset($Row[14])) {
|
|
$ambulance_details = mysqli_real_escape_string($conn, $Row[14]);
|
|
}
|
|
|
|
$ohc_id = $_SESSION['current_ohcttype'];
|
|
$patient_check = getFieldFromTable('id' , 'patient_master' , 'patient_name' , $patient_id);
|
|
error_log("DDMMDDMM ".$patient_id);
|
|
if (empty($patient_check) || $patient_check == "" || $patient_check == null) {
|
|
if ($patient_id !='') {
|
|
$sqlInsert = "INSERT INTO `patient_master`( `patient_name`)VALUES('$patient_id')";
|
|
$pp = mysqli_query($conn, $sqlInsert);
|
|
}
|
|
}
|
|
if (!empty($ambulance_id) && !empty($usage_date) && !empty($patient_id) && !empty($driver_id) && !empty($ambulance_from) && !empty($ambulance_to)) {
|
|
|
|
$time1 = strtotime($usage_date);
|
|
$date=date_create($usage_date);
|
|
$usage_date = date_format($date,"Y-m-d");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$usage_id_sql = "SELECT temp_ambulance_usage_id FROM temporary_usage_table WHERE usage_date='".$usage_date."' AND ambulance_id = '".$ambulance_id."' AND patient_id = '".$patient_id."' AND driver_id = '".$driver_id."' AND ambulance_from='".$ambulance_from."' AND ambulance_to = '".$ambulance_to."' ";
|
|
error_log("UPDATE OR NOT " . $usage_id_sql);
|
|
$result_id_sql = mysqli_query($conn,$usage_id_sql);
|
|
$row_id = mysqli_fetch_array($result_id_sql);
|
|
$temp_ambulance_usage_id = $row_id['temp_ambulance_usage_id'];
|
|
|
|
error_log("interm usage::" . $temp_ambulance_usage_id);
|
|
|
|
|
|
$initquery = "";
|
|
$endquery = "";
|
|
|
|
if ($temp_ambulance_usage_id != "" && $temp_ambulance_usage_id != null) {
|
|
$initquery = "UPDATE temporary_usage_table set usage_date='" .$usage_date ."', driver_id='" . $driver_id . "',patient_id='".$patient_id."',ambulance_from='".$ambulance_from."',ambulance_to='".$ambulance_to."',ambulance_out_km='".$ambulance_out_km."',ambulance_in_km='".$ambulance_in_km."',ambulance_total_km='".$ambulance_total_km."',ambulance_out_time='".$ambulance_out_time."',ambulance_in_time='".$ambulance_in_time."',duty_type='".$duty_id."',ambulance_details='".$ambulance_details."',ambulance_id='".$ambulance_id."',client_id='".$client_id."',client_location_id='".$client_location_id."' WHERE temp_ambulance_usage_id = '" . $temp_ambulance_usage_id . "'";
|
|
$update_counter++;
|
|
} else {
|
|
$initquery = "INSERT INTO temporary_usage_table set usage_date='" .$usage_date ."', driver_id='" . $driver_id . "',patient_id='".$patient_id."',ambulance_from='".$ambulance_from."',ambulance_to='".$ambulance_to."',ambulance_out_km='".$ambulance_out_km."',ambulance_in_km='".$ambulance_in_km."',ambulance_total_km='".$ambulance_total_km."',ambulance_out_time='".$ambulance_out_time."',ambulance_in_time='".$ambulance_in_time."',duty_type='".$duty_id."',ambulance_details='".$ambulance_details."',ambulance_id='".$ambulance_id."',client_id='".$client_id."',client_location_id='".$client_location_id."'";
|
|
$endquery = "";
|
|
$insert_counter++;
|
|
}
|
|
$query_temp = $initquery ;
|
|
error_log("TEMP QUERY::" . $query_temp);
|
|
$result1 = mysqli_query($conn, $query_temp);
|
|
if ($temp_ambulance_usage_id == null or $temp_ambulance_usage_id == "")
|
|
$temp_ambulance_usage_id = mysqli_insert_id($conn);
|
|
|
|
array_push($inter_usage_id,$temp_ambulance_usage_id);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
$type='';
|
|
if (!empty($result1) ) {
|
|
$ids=array_unique($inter_usage_id);
|
|
error_log('iidd'.max(array_keys($ids)).'iidd'.print_r($ids,true));
|
|
for($i=0; $i<=max(array_keys($ids)) ;$i++){
|
|
|
|
if($ids[$i]!=null || $ids[$i]!='' || $ids[$i]!=0){
|
|
$type.= $ids[$i].',' ;}
|
|
}
|
|
//$message = "Excel Data Imported Into the Database";
|
|
} else {
|
|
$type = "error";
|
|
//$message = "Problem In Importing Excel Data";
|
|
}
|
|
commit();
|
|
error_log('datas===='.$type);
|
|
echo json_encode($type); |