url = "http://odoo.sismedika.com:8070"; $this->db_odoo = "odoo16_sismedika"; $this->username = "admin@sismedika.com"; $this->password = "duD#Z36qH5ctmRRD"; $this->common = ripcord::client("{$this->url}/xmlrpc/2/common"); $this->uid = $this->common->authenticate($this->db_odoo, $this->username, $this->password, array()); $this->model = ripcord::client("{$this->url}/xmlrpc/2/object"); $this->db->query("use one_support"); $this->teams = [3, 22, 18, 21, 24, 15, 49, 34]; } function external_by_date($date = "") { if ($date == "") $date = date("Y-m-d"); $startDate = "$date 00:00:00"; $endDate = "$date 23:59:59"; // Define domain for search $domain = [ "&", ['project_id', '!=', false], "&", ['project_id', '!=', "HISv3"], "&", ['employee_id', 'in', $this->teams], "&", ['date', '>=', $startDate], ['date', '<=', $endDate] ]; $kwarg = array( "limit" => 1000, "offset" => 0, "order" => "user_id", 'fields' => array( 'name', 'date', 'project_id', 'task_id', 'unit_amount', 'user_id' ) ); // Search for timesheet entries $timesheets = $this->model->execute_kw( $this->db_odoo, $this->uid, $this->password, 'account.analytic.line', 'web_search_read', array($domain), $kwarg ); $total_hours = 0; $result = []; foreach ($timesheets["records"] as $r) { $name = $r["name"]; $date = $r["date"]; $project = $r["project_id"][1]; $hour = $r["unit_amount"]; $date = $r["date"]; $user = $r["user_id"][1]; $total_hours += $hour; if (!isset($result[$user])) { $result[$user] = []; } if (!isset($result[$user][$project])) { $result[$user][$project] = $hour; } else { $result[$user][$project] += $hour; } } return $result; } function sas_one($date = "") { $sas_teams = [34, 36, 37, 38, 39, 40, 41, 42, 43, 44]; if ($date == "") $date = date("Y-m-d"); $startDate = "$date 00:00:00"; $endDate = "$date 23:59:59"; // Define domain for search $domain = [ "&", ['project_id', '!=', false], "&", ['employee_id', 'in', $sas_teams], "&", ['date', '>=', $startDate], ['date', '<=', $endDate] ]; $kwarg = array( "limit" => 1000, "offset" => 0, "order" => "user_id", 'fields' => array( 'name', 'date', 'project_id', 'task_id', 'unit_amount', 'user_id' ) ); // Search for timesheet entries $timesheets = $this->model->execute_kw( $this->db_odoo, $this->uid, $this->password, 'account.analytic.line', 'web_search_read', array($domain), $kwarg ); $total_hours = 0; $result = []; foreach ($timesheets["records"] as $r) { $name = $r["name"]; $date = $r["date"]; $project = $r["project_id"][1]; $task = $r["task_id"][1]; $hour = $r["unit_amount"]; $date = $r["date"]; $user = $r["user_id"][1]; $total_hours += $hour; $total_hours += $hour; $result[$user][] = [ "project" => $project, "task" => $task, "date" => $date, "desc" => $name, "hour" => $hour ]; } $table = "@startuml\n "; $total_staff = 0; $prev_user = ""; $table .= "object Timesheet { \n"; $table .= "\n"; foreach ($result as $user => $data) { if ($prev_user != $user) { $table .= "$user\n"; $table .= "<#lightblue,#black>|= Project |= Task |= Desc |= Hour |\n"; $total_staff++; $prev_user = $user; } foreach ($data as $d) { $xdesc = $d["desc"]; if (strlen($xdesc) > 30) { $xdesc = substr($xdesc, 0, 26) . "..."; } $table .= "<#white>| {$d["project"]}| {$d["task"]}| {$xdesc}| {$d["hour"]}|\n"; } } $msg = "Collection Date : " . date("Y-m-d H:i:s") . "\n"; $msg .= "Total Hour : " . $total_hours . "\n"; $msg .= "Total Staff: " . $total_staff . "\n"; $msg .= "---\n"; $table = str_replace("", $msg, $table); if ($prev_user != "") { $table .= "}\n\n"; } $table .= "@enduml"; $img = $this->puml_post($table); $url = "https://puml.sismedika.online/png/$img"; $this->wa_to_sasone($url); } function by_project_date($project, $date = "") { if ($date == "") $date = date("Y-m-d"); $startDate = "$date 00:00:00"; $endDate = "$date 23:59:59"; // Define domain for search $domain = [ "&", ['project_id', '!=', false], "&", ['project_id', 'ilike', "$project"], "&", ['date', '>=', $startDate], ['date', '<=', $endDate] ]; $kwarg = array( "limit" => 1000, "offset" => 0, "order" => "user_id", 'fields' => array( 'name', 'date', 'task_id', 'unit_amount', 'user_id' ) ); // Search for timesheet entries $timesheets = $this->model->execute_kw( $this->db_odoo, $this->uid, $this->password, 'account.analytic.line', 'web_search_read', array($domain), $kwarg ); $total_hours = 0; $result = []; foreach ($timesheets["records"] as $r) { $name = $r["name"]; $date = $r["date"]; $task = $r["task_id"][1]; $hour = $r["unit_amount"]; $date = $r["date"]; $user = $r["user_id"][1]; $total_hours += $hour; $result[$user][] = [ "task" => $task, "date" => $date, "desc" => $name, "hour" => $hour ]; } $table = "@startuml\n "; $msg = "Collection Date : " . date("Y-m-d H:i:s") . "\n"; $msg .= "Total Hour : " . $total_hours . "\n"; $total_staff = 0; $prev_user = ""; $table .= "object Timesheet { \n"; $table .= "\n"; foreach ($result as $user => $data) { if ($prev_user != $user) { $table .= "$user\n"; $table .= "<#lightblue,#black>|= Date |= Task |= Desc |= Hour |\n"; $total_staff++; $prev_user = $user; } foreach ($data as $d) { $xdesc = $d["desc"]; if (strlen($xdesc) > 50) { $xdesc = substr($xdesc, 0, 46) . "..."; } $table .= "<#white>| {$d["date"]}| {$d["task"]}| {$xdesc}| {$d["hour"]}|\n"; } } $msg .= "Total Staff: " . $total_staff . "\n"; $msg .= "---\n"; $table = str_replace("", $msg, $table); $result = $this->external_by_date($date); $have_ext = false; if (count($result) > 0) { $have_ext = true; $table .= "\n\n\n"; $table .= "Non HIS V3\n"; $table .= "<#lightblue,#black>|= User|= Project|= Hour |\n"; $total_hours = 0; foreach ($result as $u => $r) { foreach ($r as $prj => $hour) { $table .= "<#white>| {$u}| {$prj}| {$hour}|\n"; $total_hours += $hour; } } echo "\n"; $table .= "Total Hour: " . $total_hours . "\n"; } if ($prev_user != "" || $have_ext) { $table .= "}\n\n"; } $table .= "@enduml"; $img = $this->puml_post($table); $url = "https://puml.sismedika.online/png/$img"; //echo $url; $this->wa_to_group($url); } function wa_to_sasone( $url ) { $this->load->library("Wa_sas"); $hp = "6282113702602-1584412485@g.us"; $resp = $this->wa_sas->send_image( $hp, "Timesheet Summary", $url, "image/png", "sasone-status", "png", true ); print_r($resp); } function wa_to_group( $url ) { $this->load->library("Wa_sas"); //$hp = "6287823783747"; //group set to true $hp = "120363194169273747@g.us"; //$resp = $this->wa_sas->send_message($hp, $msg,true); // print_r($resp); $resp = $this->wa_sas->send_image( $hp, "Timesheet Summary", $url, "image/png", "hisv3-status", "png", true ); print_r($resp); } function wa_to_sasone_done( $msg ) { $this->load->library("Wa_sas"); $hp = "6287823783747"; //$hp="6282113702602-1584412485@g.us"; //bisone supporter //$hp = "6281328282909-1583223560@g.us"; $resp = $this->wa_sas->send_message($hp, $msg, true); } function puml_post($data) { $url = "https://puml.sismedika.online/coder"; $ch = curl_init($url); $payload = $data; curl_setopt($ch, CURLOPT_POSTFIELDS, $payload); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/plain')); # Return response instead of printing. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); # Send request. $result = curl_exec($ch); curl_close($ch); return $result; } function bool_day($inp_dow) { $dow = strtolower(date("D", strtotime("now"))); if ($inp_dow == $dow) return true; return false; } }