ID); $r = oci_execute($sqlarr); oci_fetch_all($sqlarr, $rows_main, null, null, OCI_FETCHSTATEMENT_BY_ROW); if (!$r) { $e = oci_error($sqlarr); $errorMsg = json_encode($e['message']); goto finalStep; } //Update the stage $sql = "UPDATE ytycustom.ple_header SET approval_pos = :APPROVAL_POS WHERE ID = :ID"; $sqlarr = oci_parse($dbcon , $sql); oci_bind_by_name($sqlarr, ':ID', $data->ID); oci_bind_by_name($sqlarr, ':APPROVAL_POS', $rows_main[0]["STAGE"]); $r = oci_execute($sqlarr, OCI_NO_AUTO_COMMIT); if (!$r) { $e = oci_error($sqlarr); $errorMsg = json_encode($e['message']); goto finalStep; } //Insert Submitter $sql = "INSERT INTO ytycustom.ple_approval_stages (header_id, stage_pos, approver, action, action_date) VALUES (:HEADER_ID, :STAGE_POS, :APPROVER, 'SUBMITTED', sysdate)"; $sqlarr = oci_parse($dbcon , $sql); oci_bind_by_name($sqlarr, ':HEADER_ID', $data->ID); oci_bind_by_name($sqlarr, ':STAGE_POS', $rows_main[0]["STAGE"]); oci_bind_by_name($sqlarr, ':APPROVER', $data->MODIFIED_BY); $r = oci_execute($sqlarr, OCI_NO_AUTO_COMMIT); if (!$r) { $e = oci_error($sqlarr); $errorMsg = json_encode($e['message']); goto finalStep; } //Get the approval master $sql = "SELECT a.approver, b.email_id FROM ytycustom.ple_approval_master a, production.employee_master b WHERE a.approver = b.emp_id AND a.stage_pos = :STAGE_POS"; $sqlarr = oci_parse($dbcon , $sql); oci_bind_by_name($sqlarr, ':STAGE_POS', $rows_main[0]["STAGE"]); $r = oci_execute($sqlarr); oci_fetch_all($sqlarr, $rows_approver, null, null, OCI_FETCHSTATEMENT_BY_ROW); if (!$r) { $e = oci_error($sqlarr); $errorMsg = json_encode($e['message']); goto finalStep; } if (!empty($rows_approver)) { foreach ($rows_approver as $dt) { $sql = "INSERT INTO ytycustom.ple_approval_stages (header_id, stage_pos, approver) VALUES (:HEADER_ID, :STAGE_POS, :APPROVER)"; $sqlarr = oci_parse($dbcon , $sql); oci_bind_by_name($sqlarr, ':HEADER_ID', $data->ID); oci_bind_by_name($sqlarr, ':STAGE_POS', $rows_main[0]["STAGE"]); oci_bind_by_name($sqlarr, ':APPROVER', $dt["APPROVER"]); $r = oci_execute($sqlarr, OCI_NO_AUTO_COMMIT); if (!$r) { $e = oci_error($sqlarr); $errorMsg = json_encode($e['message']); goto finalStep; } } //Get Submitter Email $sql = "SELECT email_id FROM production.employee_master WHERE emp_id = :EMP_ID"; $sqlarr = oci_parse($dbcon , $sql); oci_bind_by_name($sqlarr, ':EMP_ID', $data->MODIFIED_BY); $r = oci_execute($sqlarr); oci_fetch_all($sqlarr, $rows_submitter, null, null, OCI_FETCHSTATEMENT_BY_ROW); //Email $mail = new PHPMailer(true); try { //Server settings //$mail->SMTPDebug = SMTP::DEBUG_SERVER; $mail->isSMTP(); $mail->Host = 'email-smtp.us-east-1.amazonaws.com'; $mail->SMTPAuth = true; $mail->Username = 'AKIA4TM64HI4LPHXMK6L'; $mail->Password = 'BFAufGeMYsb8sgH5Ta5VaTR/0omvCn6Ev3qFp+5wG83+'; $mail->SMTPSecure = 'ssl'; //PHPMailer::ENCRYPTION_SMTPS; $mail->Port = 465; $mail->isHTML(true); $mail->setFrom('info.yty@ytygroup.com.my', 'YTY Workflow'); //Submitter //$mail->addAddress($rows_submitter[0]["EMAIL_ID"]); $mail->addAddress("reyndo.frenliedo@ytygroup.com.my"); //Approver // foreach ($rows_approver as $dt) { // $mail->addAddress($dt["EMAIL_ID"]); // } //Content $mail->Subject = 'A PLE request has been submitted on Stage '.$rows_main[0]["STAGE"].' (ID: '.$data->ID.')'; $mail->Body = '

Dear All,

A new PLE request for customer '.$rows_main[0]["CUSTOMER"].' has been submitted with the detail below:

SKU '.$rows_main[0]["SKU"].'
Colour '.$rows_main[0]["GLOVE_COLOUR"].'
Type '.$rows_main[0]["GLOVE_TYPE"].'
Target Weight (g) '.$rows_main[0]["TARGET_WEIGHT"].'
Length (mm) '.$rows_main[0]["GLOVE_LENGTH"].'
Size '.$rows_main[0]["GLOVE_SIZE"].'
Surface / Textured '.$rows_main[0]["GLOVE_SURFACE"].'
Donning '.$rows_main[0]["GLOVE_DONNING"].'
Special Features '.$rows_main[0]["SPECIAL_FEATURES"].'

This PLE currently pending for Approval on Stage '.$rows_main[0]["STAGE"].'.

Please click this link to view the PLE.


Thanks.

'; //$sendStatus = $mail->send(); } catch (Exception $e) { $errorMsg = "Email could not be sent. Mailer Error: {$mail->ErrorInfo}"; } } else { $errorMsg = "No approval has been set up for stage ".$rows_main[0]["STAGE"]; } } else { $errorMsg = "No data to save."; } finalStep: $result = []; if ($errorMsg == "") { oci_commit($dbcon); $result[] = [ "message" => "Success", "id" => $newid ]; } else { oci_rollback($dbcon); $result[] = [ "message" => $errorMsg, "id" => "" ]; } print json_encode($result); ?>