| Server IP : 103.233.161.39 / Your IP : 216.73.216.121 Web Server : Apache System : Linux localhost.localdomain 3.10.0-1160.80.1.el7.x86_64 #1 SMP Tue Nov 8 15:48:59 UTC 2022 x86_64 User : apache ( 48) PHP Version : 7.2.34 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/html/mpc_emas/public/ |
Upload File : |
<?php
ini_set('max_execution_time', 0);
$file = 'ecuti.txt';
//Use the function is_file to check if the file already exists or not.
if(!is_file($file)){
//Some simple example content.
$contents = '';
//Save our content to the file.
file_put_contents($file, $contents);
}
$file = fopen("ecuti.txt", "r");
$text = fread($file,filesize("ecuti.txt"));
fclose($file);
if($text == ''){
$file = fopen("ecuti.txt", "w");
fwrite($file, 'Just start');
fclose($file);
}
else {
die('error1');
}
// get date start, date end
if(isset($_REQUEST['startDate'])){
$startDate = $_REQUEST['startDate'];
}
else {
$startDate = date("Y-m-d", strtotime("-1 days"));;
}
if(isset($_REQUEST['endDate'])){
$endDate = $_REQUEST['endDate'];
}
else {
$endDate = date("Y-m-d", strtotime("-1 days"));;
}
if(isset($_REQUEST['staffId'])){
if($_REQUEST['staffId'] != ""){
$staffId = " and b.users_detail_staffno = '" . $_REQUEST['staffId']. "'";
}
else {
$staffId = "";
}
}
else {
$staffId = "";
}
if(isset($_REQUEST['jabatanId'])){
if($_REQUEST['jabatanId'] != ""){
$jabatanId = " and a.jabatan_id = '" . $_REQUEST['jabatanId']. "'";
}
else {
$jabatanId = "";
}
}
else {
$jabatanId = "";
}
// get total number of days to get
$diff = date_diff(date_create($startDate), date_create($endDate));
// establish connection mysql
$mysql_skemps = new mysqli('localhost', 'root', 'password', 'mps');
$mysql_ecuti = new mysqli('10.10.4.13', 'ecuti', 'ch3ry', 'ecuti');
// Check connection
if ($mysql_skemps->connect_error) {
die("Connection failed: " . $mysql_skemps->connect_error);
}
$count_tb = 0;
$staffs = $mysql_skemps->query("select b.users_detail_staffno as staffno, a.id as id from users a inner join users_detail b on (a.id = b.user_id) where b.users_detail_staffno is not null and a.status = '1' and a.approve_status = '1' $staffId $jabatanId");
// loop through staffs
while ($staff = $staffs->fetch_assoc()) {
$staffNo = $staff['staffno'];
$staffId = $staff['id'];
$counter = $diff->format("%a");
// loop through days
while ($counter >= 0) {
$dateDown = date('Y/m/d', strtotime($startDate. ' + ' . $counter . ' days'));
$transactions = $mysql_skemps->query("select * from kedatangan_transaksi where user_id = '$staffId' and kedatangan_transaksi_date = '$dateDown'");
while ($transaction = $transactions->fetch_assoc()) {
$id = $transaction["kedatangan_transaksi_id"];
$in = $transaction["kedatangan_transaksi_waktu_masuk"];
$out = $transaction["kedatangan_transaksi_waktu_keluar"];
$startWork = date("H:i:s",strtotime($transaction['kedatangan_transaksi_masa_mula']));
if($transaction["kedatangan_transaksi_exclude_compare"] != '1'){
if($in == NULL || $out == NULL){
if($in == NULL && $out == NULL){
$status = 4;
}
else {
if($in != NULL){
if($startWork < $in){
$status = 2;
}
else {
$status = 3;
}
}
else {
$status = 3;
}
}
}
else {
if($startWork < $in){
$status = 2;
}
else {
$status = 0;
}
}
// 3 Tidak disokong
// 5 Tidak diluluskan
// 7 Dibatalkan
// 10 Pengganti Tidak Sokong
$canceled_cutis = $mysql_ecuti->query("select b.user_employeeno, a.appl_reason, c.levtyp_name from lev_user_application a inner join sys_user b on (a.user_id=b.user_id) inner join lev_type c on (a.levtyp_id=c.levtyp_id) where '$dateDown' between appl_datstart and appl_datend and b.user_employeeno = '$staffNo' and a.applstat_id in (3,5,7,10) limit 1");
while ($canceled_cuti = $canceled_cutis->fetch_assoc()) {
$qry = "update kedatangan_transaksi set kedatangan_transaksi_is_perfect = '$status', remarks_ecuti = NULL where kedatangan_transaksi_id = '$id'";
$mysql_skemps->query($qry);
}
$cutis = $mysql_ecuti->query("select b.user_employeeno, a.appl_reason, c.levtyp_name from lev_user_application a inner join sys_user b on (a.user_id=b.user_id) inner join lev_type c on (a.levtyp_id=c.levtyp_id) where '$dateDown' between appl_datstart and appl_datend and b.user_employeeno = '$staffNo' and a.applstat_id not in (3,5,7,10) limit 1");
while ($cuti = $cutis->fetch_assoc()) {
if(trim($cuti['appl_reason'], '') == ''){
$remark = $cuti['levtyp_name'];
}
else {
$remark = $cuti['levtyp_name'] . ' (' . $cuti['appl_reason'] .')';
}
$qry = "update kedatangan_transaksi set kedatangan_transaksi_is_perfect = '5', remarks_ecuti = '$remark' where kedatangan_transaksi_id = '$id'";
$mysql_skemps->query($qry);
$count_tb = $count_tb + 1;
file_put_contents('ecuti.txt', $count_tb);
}
}
}
$counter--;
}
}
// close connection
file_put_contents('ecuti.txt', '');
$mysql_skemps->close();
$mysql_ecuti->close();
die("Proses cuti selesai");