190 lines
5.5 KiB
PHP
190 lines
5.5 KiB
PHP
<?php
|
|
require FCPATH . "vendor/ripcord/ripcord.php";
|
|
require FCPATH . "vendor/ripcord/ripcord_client.php";
|
|
|
|
class Timesheet_v3 extends MY_Controller
|
|
{
|
|
var $db_odoo, $url, $username, $uid, $model, $password, $common;
|
|
var $teams;
|
|
function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->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];
|
|
}
|
|
|
|
|
|
|
|
// sismedika
|
|
// 1. Design: Inggrit, Ira, Nana, Zalfa
|
|
//2. HIS 2: Heri, Bagas,Febio, Domi, Morris, Putri
|
|
//3. App: Tb,Rajif, Pajri, Hanif, Adib
|
|
//4. Backoffice: Gifari, Ivan, Moko, Akbar, Stephen
|
|
//5. LIS: Fajri, Hanan, Fitri,Andi, Sindhu
|
|
//6. HIS 3: Suritno, Ramdhan, Fajar, Rubi
|
|
//7. Suppport : Yulius, Jafar, Ahmad fadil, Andreas, Ainun, Indra Waskito
|
|
//8. Document : Fardil, Ari Antoni, Heru
|
|
function ts_all($date = "")
|
|
{
|
|
$design_teams = [14, 36, 15, 16];
|
|
$this->ts_team("Design Timesheet", $design_teams, $date);
|
|
$hisv2_teams = [17, 24, 26, 25, 23, 11];
|
|
$this->ts_team("HISv2 Timesheet", $hisv2_teams, $date);
|
|
$app_teams = [30, 29, 32, 27, 43];
|
|
$this->ts_team("App Timesheet", $app_teams, $date);
|
|
$backoffice_teams = [19, 28, 47, 31, 44];
|
|
$this->ts_team("Backoffice Timesheet", $backoffice_teams, $date);
|
|
$lis_teams = [37, 39, 40, 41, 42];
|
|
$this->ts_team("LIS Timesheet", $lis_teams, $date);
|
|
$hisv3_teams = [18, 21, 20, 22];
|
|
$this->ts_team("HIS v3 Timesheet", $hisv3_teams, $date);
|
|
$support_teams = [5, 7, 45, 4, 9, 8, 10];
|
|
$this->ts_team("Support Timesheet", $support_teams, $date);
|
|
$doc_teams = [13, 38, 12];
|
|
$this->ts_team("Doc Timesheet", $doc_teams, $date);
|
|
}
|
|
function ts_team($title, $teams, $date = "")
|
|
{
|
|
if ($date == "") $date = date("Y-m-d");
|
|
if ($date == "ytd") {
|
|
$date = date("Y-m-d", strtotime("now - 1 day"));
|
|
}
|
|
$startDate = "$date 00:00:00";
|
|
$endDate = "$date 23:59:59";
|
|
// Define domain for search
|
|
$domain = [
|
|
"&",
|
|
['project_id', '!=', false],
|
|
"&",
|
|
['employee_id', 'in', $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 = round($r["unit_amount"], 1);
|
|
$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 .= "<HEADER--xx>\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 .= "Timesheet Date : " . $date . "\n";
|
|
$msg .= "Total Hour : " . $total_hours . "\n";
|
|
$msg .= "Total Staff: " . $total_staff . "\n";
|
|
$msg .= "---\n";
|
|
$table = str_replace("<HEADER--xx>", $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_me($url, $title);
|
|
}
|
|
// dev team wa group
|
|
// 120363267858371806
|
|
function wa_to_me(
|
|
$url,
|
|
$title
|
|
) {
|
|
$this->load->library("Wa_sas");
|
|
$hp = "120363267858371806@g.us";
|
|
$resp = $this->wa_sas->send_image(
|
|
$hp,
|
|
"$title",
|
|
$url,
|
|
"image/png",
|
|
"$title",
|
|
"png",
|
|
true
|
|
);
|
|
print_r($resp);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
}
|
|
}
|