Files
kopalnia_2014/reports/rep_003_hours.php
T
2026-09-03 11:24:19 +02:00

242 lines
11 KiB
PHP

<?php session_start();?>
<?php
//require_once'../func.php';
//require_once'../dbaccess.php';
require_once'c:/Programy/xampp_old/htdocs/trzeciTestowy/func.php';
require_once'c:/Programy/xampp_old/htdocs/trzeciTestowy/dbaccess.php';
$con = mysql_connect($db_host, $db_user, $db_user_pass) or die ('cannot connect to db');
mysql_select_db($db_name);
mysql_query("SET NAMES utf8");
mysql_query("SET CHARACTER_SET utf8_general_ci");
function cdt($inDate)
{
unset($out);
$out = (float) str_replace(array('-',' ',':'), array('','',''), $inDate);
return $out;
}
function quarter($dateIn, $tbName)
{
unset($outParam); unset($fix);
if (substr($dateIn, 0,4)!=date('Y'))
{
// jeśli data jest sprzed 2014 roku
if (substr($dateIn, 0,4)<2014)
$dateIn = str_replace(substr($dateIn, 0,4), 2014, $dateIn);
if (substr($dateIn, 5,2)=='01' || substr($dateIn, 5,2)=='02' || substr($dateIn, 5,2)=='03') $fix='q1';
elseif (substr($dateIn, 5,2)=='04' || substr($dateIn, 5,2)=='05' || substr($dateIn, 5,2)=='06') $fix='q2';
elseif (substr($dateIn, 5,2)=='07' || substr($dateIn, 5,2)=='08' || substr($dateIn, 5,2)=='09') $fix='q3';
elseif (substr($dateIn, 5,2)=='10' || substr($dateIn, 5,2)=='11' || substr($dateIn, 5,2)=='12') $fix='q4';
$outParam = "softspm_his.".$tbName."_".substr($dateIn, 0,4)."_".$fix;
}
else
$outParam = $tbName;
return $outParam;
}
$newline = php_sapi_name() === 'cli' ? PHP_EOL : '<br/>';
?>
<?php
if (!empty($_GET['dep']))
{
if (strtoupper($_GET['dep'])=="B") $_POST['dep'] = 'P/Bełchatów';
elseif (strtoupper($_GET['dep'])=="D") $_POST['dep'] = 'Dębina';
else $_POST['dep'] = 'P/Szczerców';
}
$_POST['post_date'] = date('Y-m-d H:i:s');
$rap_timestmp = date('YmdHis');
echo 'post_date: '.$_POST['post_date'].''.$newline;
echo 'dep: '.$_POST['dep'].''.$newline;
$tbaName = getTableNameFrom_everyday_his($_POST['post_date']);
//2018-04-03
// warunke na nowe agregaty
// Przygotowanie danych
// ==================================== ==================================== ==================================== ====================================
mysql_query("drop temporary table if exists softspm_rep.rap_".$rap_timestmp."_1");
mysql_query("CREATE temporary TABLE softspm_rep.rap_".$rap_timestmp."_1 (WLL_ID int(11) DEFAULT NULL,DRS_ID int(11) unsigned NOT NULL DEFAULT '0',WLL_BARIERA varchar(32) DEFAULT NULL,WLL_NAME varchar(255) DEFAULT NULL,WWD_ID int(11) DEFAULT NULL,WWD_PARENT_ID int(11) DEFAULT NULL,WWD_NAME varchar(255) DEFAULT NULL,WLL_CAT_DIC_ID int(11) DEFAULT NULL,Q_H float(9,2) DEFAULT NULL,Q_MIN float(9,3) DEFAULT NULL,DRS_DEPARTMENT varchar(255) DEFAULT NULL,WLL_AUDIT_CD datetime DEFAULT NULL,PRIMARY KEY (DRS_ID)) ENGINE=InnoDB DEFAULT CHARSET=utf8");
mysql_query("drop temporary table if exists softspm_rep.rap_".$rap_timestmp."_2");
mysql_query("CREATE temporary TABLE softspm_rep.rap_".$rap_timestmp."_2 (WLL_ID int(11) DEFAULT NULL,DRS_ID int(11) unsigned NOT NULL DEFAULT '0',WLL_BARIERA varchar(32) DEFAULT NULL,WLL_NAME varchar(255) DEFAULT NULL,WLL_CAT_DIC_ID int(11) DEFAULT NULL,WI1_ID int(11) DEFAULT NULL,PT1_ID int(11) DEFAULT NULL,WI2_ID int(11) DEFAULT NULL,PT2_ID int(11) DEFAULT NULL,WI3_ID int(11) DEFAULT NULL,PT3_ID int(11) DEFAULT NULL,WI4_ID int(11) DEFAULT NULL,PT4_ID int(11) DEFAULT NULL,WI5_ID int(11) DEFAULT NULL,PT5_ID int(11) DEFAULT NULL,WI6_ID int(11) DEFAULT NULL,PT6_ID int(11) DEFAULT NULL,Q_H float(9,2) DEFAULT NULL,Q_MIN float(9,3) DEFAULT NULL,DRS_DEPARTMENT varchar(255) DEFAULT NULL,WLL_AUDIT_CD datetime DEFAULT NULL,PRIMARY KEY (DRS_ID) ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
unset($rep003Array_01);
//$rep003Array_01 = sqlGetResAsArray("select DRS_ID,WLL_ID,WLL_BARIERA,WLL_NAME,WLL_CAT_DIC_ID,WWD_ID,WWD_PARENT_ID,WWD_NAME,DRS_DEPARTMENT from seg_wells_exchanged,seg_wells left join seg_dev_resources on DRS_DEV_ID=WLL_ID left join seg_well_water_drainage on WLD_DRS_ID=DRS_ID left join seg_water_drainage on WLD_WWD_ID=WWD_ID where WLE_WLL_ID=WLL_ID and DRS_DEV_TYPE=12 and (WLE_DATE_TO is null or WLE_DATE_TO>='".$_POST['post_date']."') and WLE_DATE_FROM<='".$_POST['post_date']."' and DRS_DEPARTMENT='".$_POST['dep']."' and getValueInDate(507, DRS_ID, '".$_POST['post_date']."')='ON' order by WLL_BARIERA,WLL_NAME");
$rep003Array_01 = sqlGetResAsArray("select DRS_ID,(select WLL_ID from seg_dev_resources tb1, seg_wells tb2 where tb1.DRS_DEV_ID=tb2.WLL_ID and tb1.DRS_DEV_TYPE=12 and tb1.DRS_ID=tb3.DRS_ID limit 1) WLL_ID,(select WLL_BARIERA from seg_dev_resources tb1, seg_wells tb2 where tb1.DRS_DEV_ID=tb2.WLL_ID and tb1.DRS_DEV_TYPE=12 and tb1.DRS_ID=tb3.DRS_ID limit 1) WLL_BARIERA,(select WLL_NAME from seg_dev_resources tb1, seg_wells tb2 where tb1.DRS_DEV_ID=tb2.WLL_ID and tb1.DRS_DEV_TYPE=12 and tb1.DRS_ID=tb3.DRS_ID limit 1) WLL_NAME,(select WLL_CAT_DIC_ID from seg_dev_resources tb1, seg_wells tb2 where tb1.DRS_DEV_ID=tb2.WLL_ID and tb1.DRS_DEV_TYPE=12 and tb1.DRS_ID=tb3.DRS_ID limit 1) WLL_CAT_DIC_ID,WWD_ID,WWD_PARENT_ID,WWD_NAME,DRS_DEPARTMENT from seg_dev_resources tb3,seg_well_water_drainage left join seg_water_drainage on WLD_WWD_ID=WWD_ID where WLD_DRS_ID=tb3.DRS_ID and tb3.DRS_DEPARTMENT='".$_POST['dep']."' and getWellStatusOnOff(tb3.DRS_ID, '".$_POST['post_date']."')='ON' order by WWD_PARENT_ID,WLL_BARIERA,WLL_NAME");
for($i1=0;$i1<count($rep003Array_01);$i1++)
{
// $rep003Array_01[$i1]['WLL_ID']
unset($rep003Array_02);
$rep003Array_02 = sqlGetResAsArray("select RHD_Q_VAL, round(RHD_Q_VAL/60,3) Q_MIN from ".$tbaName." where RHD_ID=(select max(RHD_ID) from ".$tbaName." where RHD_DRS_ID=".$rep003Array_01[$i1]['DRS_ID']." and RHD_Q_VAL>0 and RHD_DATE<='".$_POST['post_date']."')");
if ($rep003Array_02[0]['RHD_Q_VAL']>0)
{
unset($wwd_id);
if ($rep003Array_01[$i1]['WWD_ID']>0 ) $wwd_id = ",WWD_ID=".$rep003Array_01[$i1]['WWD_ID'];
unset($wwd_parent_id);
if ($rep003Array_01[$i1]['WWD_PARENT_ID']>0 ) $wwd_parent_id = ",WWD_PARENT_ID=".$rep003Array_01[$i1]['WWD_PARENT_ID'];
mysql_query("INSERT INTO softspm_rep.rap_".$rap_timestmp."_1 SET WLL_ID=".$rep003Array_01[$i1]['WLL_ID'].",DRS_ID=".$rep003Array_01[$i1]['DRS_ID'].",WLL_BARIERA='".$rep003Array_01[$i1]['WLL_BARIERA']."',WLL_NAME='".$rep003Array_01[$i1]['WLL_NAME']."'".$wwd_id.$wwd_parent_id.",WWD_NAME='".$rep003Array_01[$i1]['WWD_NAME']."',WLL_CAT_DIC_ID=".$rep003Array_01[$i1]['WLL_CAT_DIC_ID'].",Q_H=".$rep003Array_02[0]['RHD_Q_VAL'].",Q_MIN=".$rep003Array_02[0]['Q_MIN'].",DRS_DEPARTMENT='".$_POST['dep']."',WLL_AUDIT_CD=now()");
}
}
unset($tbArray);
$tbArray = sqlGetResAsArray("select * from softspm_rep.rap_".$rap_timestmp."_1");
for($i=0; $i<count($tbArray); $i++)
{
unset($tb);
$tb = findTreeLevel($tbArray[$i]['WWD_ID']);
unset($query);
$query = "INSERT INTO softspm_rep.rap_".$rap_timestmp."_2 SET WLL_ID=".$tbArray[$i]['WLL_ID'].",DRS_ID=".$tbArray[$i]['DRS_ID'].",WLL_BARIERA='".$tbArray[$i]['WLL_BARIERA']."',WLL_NAME='".$tbArray[$i]['WLL_NAME']."',WLL_CAT_DIC_ID=".$tbArray[$i]['WLL_CAT_DIC_ID'];
if ($tb[0]['id']>0) $query .= ",WI1_ID=".$tb[0]['id'];
if ($tb[0]['par']>0) $query .= ",PT1_ID=".$tb[0]['par'];
if ($tb[1]['id']>0) $query .= ",WI2_ID=".$tb[1]['id'];
if ($tb[1]['par']>0) $query .= ",PT2_ID=".$tb[1]['par'];
if ($tb[2]['id']>0) $query .= ",WI3_ID=".$tb[2]['id'];
if ($tb[2]['par']>0) $query .= ",PT3_ID=".$tb[2]['par'];
if ($tb[3]['id']>0) $query .= ",WI4_ID=".$tb[3]['id'];
if ($tb[3]['par']>0) $query .= ",PT4_ID=".$tb[3]['par'];
if ($tb[4]['id']>0) $query .= ",WI5_ID=".$tb[4]['id'];
if ($tb[4]['par']>0) $query .= ",PT5_ID=".$tb[4]['par'];
if ($tb[5]['id']>0) $query .= ",WI6_ID=".$tb[5]['id'];
if ($tb[5]['par']>0) $query .= ",PT6_ID=".$tb[5]['par'];
$query .=",Q_H=".$tbArray[$i]['Q_H'].",Q_MIN=".$tbArray[$i]['Q_MIN'].",DRS_DEPARTMENT='".$tbArray[$i]['DRS_DEPARTMENT']."',WLL_AUDIT_CD=now()";
mysql_query($query);
}
// ==================================== ==================================== ==================================== ====================================
echo'
<table class="table table-bordered" >
<thead>
<tr>
<th style="width: 20%">Zrzut</th>
<th style="width: 30%"></th>
<th>[m<sup>3</sup>/min]</th>
<th>[m<sup>3</sup>/h]</th>
</tr>
</thead>
';
// dopisuje do tablicy
// =====================================================
$_SESSION['rap003_array'][] = array(
'znacznik' => 'red',
'col_1' => 'Grupa',
'col_2' => 'Bariera',
'col_3' => 'Studnia',
'col_4' => '',
'col_5' => '',
'col_6' => 'Zrzut [m3/min]',
'col_7' => 'Zrzut [m3/h]'
);
// =====================================================
// System
// ========================================================== *** ========================================================== //
echo"
<tr style='font-weight: bolder; background-color: #FF0000; color: #ffffff;'>
<td></td>
<td style='width: 15%;'>SYSTEM</td>
<td></td>
<td></td>
</tr>
";
// dopisuje do tablicy
// =====================================================
$_SESSION['rap003_array'][] = array(
'znacznik' => '',
'col_1' => 'Grupa:',
'col_2' => 'SYSTEM',
'col_3' => '',
'col_4' => '----->',
'col_5' => 'SYSTEM',
'col_6' => '',
'col_7' => ''
);
// =====================================================
$roow=0; $licz_roow=0; $licznik=0;
unset($mainArray01);
$mainArray01 = sqlGetResAsArray("select WI1_ID,sum(Q_MIN) Q_MIN,WWD_NAME from softspm_rep.rap_".$rap_timestmp."_2 left join seg_water_drainage on WI1_ID=WWD_ID group by WI1_ID");
for($i01=0; $i01<count($mainArray01); $i01++)
{
echo"
<tr>
<td></td>
<td style='font-weight: bolder; background-color: #B22222; color: #ffffff;'>".$mainArray01[$i01]['WWD_NAME']."</td>
<td style='font-weight: bolder; background-color: #B22222; color: #ffffff;'>".$mainArray01[$i01]['Q_MIN']."</td>
<td style='font-weight: bolder; background-color: #B22222; color: #ffffff;'>".($mainArray01[$i01]['Q_MIN'] * 60)."</td>
</tr>
";
// dopisuje do tablicy
// =====================================================
$_SESSION['rap003_array'][] = array(
'znacznik' => '',
'col_1' => '',
'col_2' => '',
'col_3' => $mainArray01[$i01]['WWD_NAME'],
'col_4' => '',
'col_5' => '',
'col_6' => $mainArray01[$i01]['Q_MIN'],
'col_7' => ($mainArray01[$i01]['Q_MIN'] * 60)
);
// =====================================================
$licz_roow += $mainArray01[$i01]['Q_MIN'];
}
echo'</table>';
if (count($mainArray01))
mysql_query("INSERT INTO softspm.rep_zrzut_wody SET RZW_KRASOWKA='".$mainArray01[0]['Q_MIN']."',RZW_DEPARTMENT='".$_POST['dep']."',RZW_AUDIT_USR='JOB',RZW_AUDIT_DATE='".$_POST['post_date']."'");
else
mysql_query("INSERT INTO softspm.rep_zrzut_wody SET RZW_WIDAWKA='".$mainArray01[0]['Q_MIN']."',RZW_KRASOWKA='".$mainArray01[1]['Q_MIN']."',RZW_DEPARTMENT='".$_POST['dep']."',RZW_AUDIT_USR='JOB',RZW_AUDIT_DATE='".$_POST['post_date']."'");
//mysql_query("UPDATE softspm.rep_zrzut_wody SET RZW_KRASOWKA=RZW_WIDAWKA, RZW_WIDAWKA=NULL WHERE RZW_ID IN(SELECT RZW_ID from softspm.rep_zrzut_wody WHERE RZW_WIDAWKA>0 AND (RZW_KRASOWKA=0 OR RZW_KRASOWKA IS NULL))");
mysql_query("drop temporary table if exists softspm_rep.rap_".$rap_timestmp."_1");
mysql_query("drop temporary table if exists softspm_rep.rap_".$rap_timestmp."_2");
// ==================================================================================================================================
mysql_close($con);
?>