url = "https://odoo.sismedika.online"; $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"); } function update_task($client_id = 2) { //last 60 days $sql = "select TicketingID,TicketingDescription,TicketingCreated,TicketingNumber from one_support.ticketing where TicketingClientID = ? and TicketingCreated + interval 7 day > now() and ( TicketingOdooTaskID = 0 or TicketingDoneDate is null ) "; $qry = $this->db->query($sql, [$client_id]); if (!$qry) { print_r($this->db->error()); } $rows = $qry->result_array(); foreach ($rows as $r) { $no = $r["TicketingNumber"]; $id = $r["TicketingID"]; $desc = $r["TicketingDescription"]; $taskDate = $r["TicketingCreated"]; $taskID = $this->task_by_tag($no); echo "Get Odoo TaskID $taskDate : $no => $taskID\n"; // echo "\t$desc\n"; if ($taskID > 0) { $sql = "update one_support.ticketing set TicketingOdooTaskID = ? where TicketingID = ?"; } list($date, $staff) = $this->get_done($taskID); echo "\tDone by $staff at $date\n"; if ($date != "") { $sql = "update one_support.ticketing set TicketingOdooTaskID = ? , TicketingDoneDate = ?, TicketingDoneStaff=? where TicketingID = ?"; $qry = $this->db->query($sql, [ $taskID, $date, $staff, $id ]); } else { $qry = $this->db->query($sql, [ $taskID, $id ]); } if (!$qry) { echo "\tERR : " . print_r($this->db->error()) . "\n"; } sleep(1); $date = ""; $staff = ""; } } function task_by_tag($tag, $project_id = 123) { $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_URL, "http://odoo.sismedika.online/web/dataset/call_kw/project.task/web_search_read"); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HTTPHEADER, [ "Content-Type: application/json", "Cookie: frontend_lang=en_us; td_id=669b47846b8437b163a9c8d43a16c42cae2bc609; session_id=e1c224f95431fc75271cf484260586408c0757d4; cids=1; tz=asia/jakarta", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36" ]); $param = [ "jsonrpc" => "2.0", "method" => "call", "params" => [ "model" => "project.task", "method" => "web_search_read", "args" => [], "kwargs" => [ "limit" => 80, "offset" => 0, "order" => "", "context" => [ "lang" => "en_US", "tz" => "Asia/Jakarta", "uid" => 39, // "allowed_company_ids" => [ // 1 // ], "bin_size" => true, "active_model" => "project.project", "active_id" => $project_id, "active_ids" => [ $project_id ], "default_project_id" => $project_id, "show_project_update" => true, "create" => true, "active_test" => true ], "count_limit" => 81, "domain" => [ "&", [ "display_project_id", "=", $project_id ], "|", [ "name", "ilike", "$tag" ], [ "id", "ilike", "$tag" ] ], "fields" => [ "name", "project_id", "tag_ids" ] ] ] ]; curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($param)); $response = curl_exec($ch); $taskID = 0; if (curl_errno($ch)) { echo json_encode(["status" => "ERR", "message" => curl_error($ch)]); } else { $resp = json_decode($response, true); if ($resp["result"]["length"] > 0) { $taskID = $resp["result"]["records"][0]["id"]; } } curl_close($ch); return $taskID; } function get_done($task_id) { $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_URL, "http://odoo.sismedika.online/mail/thread/messages"); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HTTPHEADER, [ "Content-Type: application/json", "Cookie: frontend_lang=en_us; td_id=669b47846b8437b163a9c8d43a16c42cae2bc609; session_id=e1c224f95431fc75271cf484260586408c0757d4; cids=1; tz=asia/jakarta", "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36" ]); $data = [ "jsonrpc" => "2.0", "method" => "call", "params" => [ "thread_id" => $task_id, "thread_model" => "project.task", "limit" => 30 ] ]; curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); if (curl_errno($ch)) { return ["", ""]; echo json_encode(["status" => "ERR", "message" => curl_error($ch)]); } else { $resp = json_decode($response, true); $date = ""; $staff = ""; foreach ($resp["result"] as $r) { foreach ($r["trackingValues"] as $t) { if ($t["changedField"] == "Stage") { if ($t["newValue"]["value"] == "IMPLEMENTATION") { $date = $r["date"]; $staff = $r["email_from"]; break; } } if ($date != "") break; } } if ($date != "") { // echo json_encode(["status" => "OK", "date" => $date, "by" => $staff]); return [$date, $staff]; exit; } return ["", ""]; echo $response; } curl_close($ch); } function test_implementation($project_id = 70) { $sdate = "2024-07-03 00:00:00"; $edate = "2024-07-03 23:59:59"; $arg = array(); $kwarg = array( "limit" => 10, "offset" => 0, "order" => "", "count_limit" => 11, "fields" => [ "id", "name", "description", ], //"domain"=>[["stage_id","ilike","implementation"]] // "domain" ); $resp = $this->model->execute_kw( $this->db_odoo, $this->uid, $this->password, "project.task", "web_search_read", array(array( "&", ["display_project_id", "=", $project_id], "&", ["date_last_stage_update", ">=", $sdate], "&", ["date_last_stage_update", "<=", $edate], ["stage_id", "ilike", "implementation"] )), $kwarg ); echo "$sdate : $edate\n"; print_r($resp); } function get_implementation_v2($project_id = 70, $stage = "", $date = "") { if ($date == "") $date = date("Y-m-d"); $sdate = $date . " 00:00:00"; $edate = $date . " 23:59:59"; if ($stage == "") $date = "x"; if ($date == "x") { $sdate = "2024-01-01 00:00:00"; $edate = "2024-08-07 23:59:59"; } $arg = array(); $kwarg = array( "limit" => 10, "offset" => 0, "order" => "", "count_limit" => 11, "fields" => [ "id", "name", "description", ], //"domain"=>[["stage_id","ilike","implementation"]] // "domain" ); if ($stage == "") { echo "$sdate | $edate | $project_id\n"; $resp = $this->model->execute_kw( $this->db_odoo, $this->uid, $this->password, "project.task", "web_search_read", array(array( "&", ["display_project_id", "=", intval($project_id)], "&", ["date_last_stage_update", ">=", $sdate], ["date_last_stage_update", "<=", $edate] )), $kwarg ); } else { $resp = $this->model->execute_kw( $this->db_odoo, $this->uid, $this->password, "project.task", "web_search_read", array(array( "&", ["display_project_id", "=", intval($project_id)], "&", ["date_last_stage_update", ">=", $sdate], "&", ["date_last_stage_update", "<=", $edate], ["stage_id", "ilike", $stage] )), $kwarg ); } print_r($resp); exit; $arr_ticket = []; if (isset($resp["records"])) { foreach ($resp["records"] as $r) { $desc = $r["description"]; $name = $r["name"]; $id = $r["id"]; $tiket = ""; if (preg_match("/ No. Tiket : (.+)<\/b>
Cabang/", $desc, $match)) { $tiket = $match[1]; if (in_array($tiket, $arr_ticket)) { echo date("Y-m-d H:i:s") . " Ticket # $tiket duplicate \n"; continue; } $arr_ticket[] = $tiket; } if ($tiket != "") { $rec = $this->get_ticketing($tiket); if ($rec["TicketingStatus"] != "IMPLEMENTATION") { $ticketID = $rec["TicketingID"]; $sender = $rec["TicketingSender"]; $cabang = $rec["M_BranchName"]; $hasil = ""; if (preg_match("/(Hasil.*:.+)/", $desc, $match)) { $hasil = strip_tags($match[1]); $hasil = str_replace(" ", "", $hasil); } $impl_msg = " Pengirim : $sender No. Tiket : $tiket Issue : $name Cabang : $cabang Status : Selesai $hasil Silahkan di cek kembali Terima Kasih\n"; echo date("Y-m-d H:i:s") . " Done Ticket # $tiket from $sender \n"; $this->wa_to_sasone_done($impl_msg, $project_id); $this->update_ticketing($ticketID, "IMPLEMENTATION", $ticketID); sleep(2); } } } } } function get_implementation($project_id = 70, $date = "") { if ($date == "" || $date = "-") $date = date("Y-m-d"); $sdate = $date . " 00:00:00"; $edate = $date . " 23:59:59"; $arg = array(); $project_id = intval($project_id); $kwarg = array( "limit" => 10, "offset" => 0, "order" => "", "count_limit" => 11, "fields" => [ "id", "name", "description", ], //"domain"=>[["stage_id","ilike","implementation"]] // "domain" ); $resp = $this->model->execute_kw( $this->db_odoo, $this->uid, $this->password, "project.task", "web_search_read", array(array( "&", ["display_project_id", "=", $project_id], "&", ["date_last_stage_update", ">=", $sdate], "&", ["date_last_stage_update", "<=", $edate], ["stage_id", "ilike", "implementation"] )), $kwarg ); $arr_ticket = []; if (isset($resp["records"])) { foreach ($resp["records"] as $r) { $desc = $r["description"]; $name = $r["name"]; $id = $r["id"]; $tiket = ""; if (preg_match("/ No. Tiket : (.+)<\/b>
Cabang/", $desc, $match)) { $tiket = $match[1]; if (in_array($tiket, $arr_ticket)) { echo date("Y-m-d H:i:s") . " Ticket # $tiket duplicate \n"; continue; } $arr_ticket[] = $tiket; } if ($tiket != "") { $rec = $this->get_ticketing($tiket); if ($rec["TicketingStatus"] != "IMPLEMENTATION") { $ticketID = $rec["TicketingID"]; $sender = $rec["TicketingSender"]; $cabang = $rec["M_BranchName"]; $hasil = ""; if (preg_match("/(Hasil.*:.+)/", $desc, $match)) { $hasil = strip_tags($match[1]); $hasil = str_replace(" ", "", $hasil); } $impl_msg = " Pengirim : $sender No. Tiket : $tiket Issue : $name Cabang : $cabang Status : Selesai $hasil Silahkan di cek kembali Terima Kasih\n"; echo date("Y-m-d H:i:s") . " Done Ticket # $tiket from $sender \n"; $this->wa_to_sasone_done($impl_msg, $project_id); $this->update_ticketing($ticketID, "IMPLEMENTATION", $ticketID); sleep(2); } } } } } function get_message($taskID) { $arg = [ "thread_id" => $taskID, "thread_model" => "project_task", "limit" => 30 ]; $resp = $this->model->execute_kw( $this->db_odoo, $this->uid, $this->password, "mail.thread", "read", array($arg) ); print_r($resp); } function wa_to_sasone_done( $msg, $project_id = 70 ) { $this->load->library("Wa_sas"); //$hp = "6287823783747"; //$hp="6282113702602-1584412485@g.us"; //bisone supporter $hp = "6281328282909-1583223560@g.us"; if ($project_id != 70) { //sasone //6282113702602-1584412485 $hp = "6282113702602-1584412485@g.us"; if ($project_id == 123) { //hore $hp = "120363280846797029@g.us"; } } $resp = $this->wa_sas->send_message($hp, $msg, true); // print_r($resp); } function update_ticketing($ticketID, $status, $taskID) { $sql = "update ticketing set TicketingStatus = ?, TicketingOdooTaskID=? where ticketingID = ?"; $qry = $this->db->query($sql, [$status, $taskID, $taskID]); if (!$qry) { echo "Error update ticketing $ticketID\n"; exit; } echo $this->db->last_query() . "\n"; } function get_ticketing($tiket) { $sql = "select TicketingID,TicketingStatus , M_BranchName, TicketingSender from ticketing join m_branch on TicketingM_BranchCode = M_BranchCode and TicketingNumber = ? "; $qry = $this->db->query($sql, [$tiket]); if (!$qry) { echo "Error get ticketing $tiket\n"; exit; } $rows = $qry->result_array(); if (count($rows) == 0) { echo "Error get ticketing $tiket\n"; exit; } return $rows[0]; } function create_ts() { $prm = $this->sys_input; $date = $prm["date"]; $time = $prm["time"]; $employee_id = $prm["employee_id"]; $task_id = $prm["task_id"]; $project_id = $prm["project_id"]; $description = $prm["description"]; $arg = array( "name" => $description, "date" => $date, "unit_amount" => $time, "user_id" => $this->uid, "task_id" => $task_id, "project_id" => $project_id, "employee_id" => $employee_id ); $resp = $this->model->execute_kw( $this->db_odoo, $this->uid, $this->password, "account.analytic.line", "create", array($arg) ); print_r($resp); if (!is_numeric($resp)) { echo json_encode(["status" => "ERR", "message" => json_encode($resp)]); } else { echo json_encode( [ "status" => "OK", "ts_id" => $resp ] ); } } function create_task() { $prm = $this->sys_input; $title = $prm["title"]; $description = $prm["description"]; $project_id = $prm["project_id"]; if ($project_id == "") $project_id = 70; $images = $prm["images"]; if (is_array($images)) { foreach ($images as $img) { $description .= "
" . ""; } } $users = $prm["users"]; if ($users == "") { $users = [ 44, 41, 42 ]; } $arg = array( "sun" => $this->bool_day("sun"), "mon" => $this->bool_day("mon"), "tue" => $this->bool_day("tue"), "wed" => $this->bool_day("wed"), "thu" => $this->bool_day("thu"), "fri" => $this->bool_day("fri"), "sat" => $this->bool_day("sat"), "recurrence_id" => false, "parent_id" => false, "company_id" => 1, "stage_id" => 443, "personal_stage_type_id" => false, "recurrence_update" => "this", "priority" => "0", "name" => "$title", "kanban_state" => "normal", "project_id" => $project_id, "display_project_id" => false, "milestone_id" => false, "user_ids" => [ [ 6, false, $users ] ], "active" => true, "partner_id" => false, "partner_phone" => false, "date_deadline" => false, "tag_ids" => [ [ 6, false, [] ] ], "task_properties" => [], "description" => $description, "planned_hours" => 0, "timesheet_ids" => [], "child_ids" => [], ); $resp = $this->model->execute_kw( $this->db_odoo, $this->uid, $this->password, "project.task", "create", array($arg) ); if (!is_numeric($resp)) { echo json_encode(["status" => "ERR", "message" => json_encode($resp)]); } else { echo json_encode( [ "status" => "OK", "task_id" => $resp ] ); } } function bool_day($inp_dow) { $dow = strtolower(date("D", strtotime("now"))); if ($inp_dow == $dow) return true; return false; } }