Open menu "add employee in orangeHRM" - orangehrm

please help how to open the add employee form in orangeHRM, i'm already add new record in ohrm_user_role_screen table to show it when we login as supervisor but the form add employee is not appear and on the screen display "Credentials Required".

Try this..
orangehrm\symfony\plugins\cashmanCorePlugin\lib\role\SupervisorUserRoleDecorator.php
Add some role permission data to SupervisorUserRoleDecorator.php compare AdminUserRoleDecorator.php
orangehrm\symfony\plugins\cashmanCorePlugin\lib\role\AdminUserRoleDecorator.php
Like:
Add permission link for example
const EMPLOYEE_REPORT_LINK="./symfony/web/index.php/time/displayEmployeeReportCriteria?reportId=2";
/**
* Get the employee list ( whole employees )
* #return Employee[]
*/
public function getEmployeeList() {
$employeeList = $this->getEmployeeService()->getEmployeeList('empNumber', 'ASC', true);
if ($employeeList[0]->getEmpNumber() == null) {
return null;
} else {
return $employeeList;
}
}
public function getEmployeeListForAttendanceTotalSummaryReport() {
$employeeList = $this->getEmployeeService()->getEmployeeList('empNumber', 'ASC', true);
$employee = new Employee();
$employee->setEmpNumber('-1');
$employee->setFirstName("All");
if ($employeeList[0]->getEmpNumber() == null) {
$employeeList->add($employee);
return $employeeList;
} else {
$employeeList->add($employee);
return $employeeList;
}
}

Related

How can I select only the children attributes with querybuilder using symfony 4?

I have a class named "insured object" that have two children "car" and "house" and this "insured object" has a one to one relation to "contract". The idea is when the user wants to add a contract he must specify its type whether it's a car or a house and add it to the database according to its type. So while working on the APIs (the editing one) a problem occurred, which is when i want to select a car to edit it shows me this error the error when i execute the API
this is the car editing API.
/**
* #Route("/api/editVoiture/{id}", name="editVoiture", methods={"PUT"})
*/
public function editVoiture($id, Request $request, EntityManagerInterface $em,ObjetAssureRepository $objetAssureRepository, VoitureRepository $voitureRepo)
{
$request = Request::createFromGlobals();
$jsonRecu = $request->getContent();
try {
$donnees = json_decode($jsonRecu);
$voiture = $voitureRepo->findVoitureById($id);
if($voiture != null){
$voiture->setDateAcquisition($donnees->dateAcquisition);
$voiture->setDateProduction($donnees->dateProduction);
$voiture->setMarque($donnees->marque);
$voiture->setNumChassis($donnees->numChassis);
$voiture->setPuissance($donnees->puissance);
$voiture->setModele($donnees->modele);
$em->persist($voiture);
$em->flush();
$objAss = $objetAssureRepository->findObjet($voiture->getId(),"voiture");
$objAss->setDateAcquisition($donnees->dateAcquisition);
$objAss->setDateProduction($donnees->dateProduction);
$em->persist($objAss);
$em->flush();
return new Response('ok', 200);
} else {
return new Response('does not exist',404);
}
} catch (UniqueConstraintViolationException $e) {
return $this->json([
'status' => 400,
'message' => $e->getMessage(),
], 400);
}
}
and this is the repository code
/**
* #return Voiture
*/
public function findVoitureById($id): ?Voiture
{
return $this->createQueryBuilder('v')
->andWhere('v.id = :id')
->setParameter('id',$id)
->getQuery()
->getOneOrNullResult()
;
}

Salesforce Apex Test Class Failing on saving of an account

having a little trouble figuring out why my test class is returning System.DmlException: Upsert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Name]: [Name]
I have required field Name on the Account object in SFDC, but Since I'm mocking the Account with a Name attribute shouldn't my test class save function work?
Below is my Apex Class
public with sharing class QuoteAccountController {
// Define VariableType and VariableName
public ApexPages.StandardController standardContactController;
public Account Account{get;set;}
public Contact Contact{get;set;}
public Account selectedAccount{get;set;}
public Boolean displayProjectInformation{get;set;}
public Boolean projectNameError{get;set;}
public Boolean projectValidationsPassed{get;set;}
//Page Constructor/Initializer
public QuoteAccountController(ApexPages.StandardController StandardController) {
Account = new Account();
Contact = new Contact();
displayProjectInformation = true;
projectNameError = false;
projectValidationsPassed = true;
}
public pageReference save() {
projectValidations();
if (projectValidationsPassed) {
upsert Account;
Contact.accountId = Account.id;
upsert Contact;
Contact = new Contact();
Account = new Account();
ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.CONFIRM,'Record Created Successfully.Thank you!'));
return null;
} else {
return null;
}
}
public void projectValidations(){
if (Account.Subscription_Type__c == 'Project' && String.isBlank(Account.Project_Name__c)) {
projectValidationsPassed = false;
ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Project Name is required field'));
} else if (Account.Subscription_Type__c == 'Project' && String.isBlank(Account.Project_Type__c)) {
projectValidationsPassed = false;
ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Project Type is required field'));
} else if (Account.Subscription_Type__c == 'Project' && Account.Project_Start_Date__c == null) {
projectValidationsPassed = false;
ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Project Start Date is required field'));
} else if (Account.Subscription_Type__c == 'Project' && Account.Project_End_Date__c == null){
projectValidationsPassed = false;
ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Project End Date is required field'));
} else {
projectValidationsPassed = true;
}
}
Below is my Apex Test Class
#isTest
public class QuoteAccountControllerTest {
private static testmethod void testSave() {
Quote quote = new Quote();
Account testAcc = new Account();
Contact con = new Contact();
ApexPages.StandardController stdCont = new ApexPages.StandardController(testAcc);
QuoteAccountController quoteAccCont = new QuoteAccountController(stdCont);
PageReference page = new PageReference('/apex/zqu_QuoteAccount?quoteType=Subscription&stepNumber=1');
Test.setCurrentPage(page);
testAcc.Project_Name__c = 'Project Name';
testAcc.Name = 'Test Account';
testAcc.Project_Start_Date__c = Date.today();
testAcc.Project_End_Date__c = Date.today().addDays(2);
testAcc.Project_Type__c = 'Convention Center';
testAcc.Region__c = 'US';
testAcc.Subscription_Type__c = 'User';
Test.startTest();
quoteAccCont.save();
Test.stopTest();
}
}
Thanks!
Edit: Error message below.
System.DmlException: Upsert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Name]: [Name]
I don't have too much background in Salesforce but I believe that you need to insert the objects that you are creating with new before Test.startTest();
If this fails too, try to use System.debug() in your Apex Test class and use the Salesforce developer console and their logs to follow your error. Maybe this helps. Good luck!
You are trying to upsert an account. Upsert(Update/Insert) call would look for Id in the account you are upserting. If Id is found Upsert would work fine else it would Insert. So in your case it is trying to insert not update. That is why Name is mandatory.
Figured out solution. Need to assign the Account and Contact to the Controller. See modified code below.
#isTest
public class QuoteAccountControllerTest {
private static testmethod void testSave() {
Quote quote = new Quote();
ApexPages.StandardController stdCont = new ApexPages.StandardController(testAcc);
QuoteAccountController quoteAccCont = new QuoteAccountController(stdCont);
quoteAccCont.Account = new Account(ATTRIBUTES_HERE);
quoteAccCont.Contact = new Contact(ATTRIBUTES_HERE
PageReference page = new PageReference('/apex/zqu_QuoteAccount?quoteType=Subscription&stepNumber=1');
Test.setCurrentPage(page);
Test.startTest();
quoteAccCont.save();
Test.stopTest();
}
}

Cakephp 3 and Authentication

Is there an easy way like in Cakephp 3 to work with roles
APP Controller
public function isAuthorized($user)
{
// Admin can access every action
if (isset($user['role']) && $user['role'] === 'admin') {
return true;
}
// Default deny
return false;
}
POSTS Contoller
public function isAuthorized($user) {
// All registered users can add posts
if ($this->action === 'edit') {
return true;
}
return parent::isAuthorized($user);
}
I know from http://book.cakephp.org/3.0/en/controllers/components/authentication.html#testing-actions-protected-by-authcomponent that
$this->auth->deny('add');
Is doing it, but how can I add the user/admin ?
I have used ACL authentication in very simple way with isAuthorised() method. I hope it would be help you.
AppController.php
you can make have to define property
/**
* ACCESS CONTROL LIST BASED ON METHODS OF CLASS FOR USER ROLES
*/
var $accessControllList = array();
Define private method
private function _checkAccessControll() {
if ($this->Auth->user('id')) {
if (!isset($this->accessControllList) || empty($this->accessControllList)) {
return true;
}
$action_name = $this->request->params['action'];
$user_role = $this->Auth->user('role');
if (isset($this->accessControllList['allowed']) && !empty($this->accessControllList['allowed']) && in_array($action_name, $this->accessControllList['allowed'])) {
return true;
} else if (isset($this->accessControllList['role_base'][$user_role]) && !empty($this->accessControllList['role_base'][$user_role]) && in_array($action_name, $this->accessControllList['role_base'][$user_role])) {
return true;
}
throw new \Cake\Network\Exception\ForbiddenException(__('You not have access for this page'));
}
return true;
}
in isAuthorized() add below line.
$this->_checkAccessControll();
In any controller, you need to mapping your ACL with roles. For you PostsController.php file something as below
/**
* List of all accessible Action from URL
* #var array
*/
var $accessControllList = array(
'allowed' => array('view','index'), // allowed for any role.
'role_base' => array(
'administrator' => array('delete', 'approve'), //specially allowed for administrator only
'publisher' => array('view','create','index','replyComment'), // specially allowed for publisher only
'reader' => array('postComment','replyComment') // specially allowed for reader
)
);

Checking for record existence in column sql

I am trying to check if the user select (u.userId) is not in the column (urid) then only return true and run the other function. If the user selected data already exists, then return false. I get it with return void.. what happens? I'm still new in asp.net, hoping for some help. Thanks.
public string URID { get; set; }
public void urid_existence(User u)
{
DBHandler dbh = new DBHandler();
dbh.OpenConnection();
string sql = "select urid from FCS_COUGRP";
if (u.UserID != u.URID)
{
userH.changeUrserGroup(u);
return true;
}
else
{
return false;
}
}
void means that the method does not return anything, but you want to return a bool. So this is the correct signature:
public bool urid_existence(User u)
{
// ...
if (u.UserID != u.URID)
{
userH.changeUrserGroup(u);
return true;
}
else
{
return false;
}
}

Edit profile page with 3 tables - Yii frameworks

I am new on Yii framework, so please i need some help where to start.
What i need is, action and module to display a form to a user, which his will be able to edit is own profile (with profile picture), so i have 3 table
user_account || user_personal || user_general
how can i build a form that insert and update those 3 table at once?
i try this:
This is what i did, but its still not saving the data even into 1 table.
public function actionUpdate() {
$model = new ProfileUpdate();
if(isset($_POST['ProfileUpdate']))
{
$model->attributes = $_POST['ProfileUpdate'];
if($model->validate())
{
$account = new Profile();
$account->userid = Yii::app()->user->id;
$account->name = $model->name;
$account->website = $model->website;
$account->category = $model->category;
$account->save();
$this->redirect('profile');
}
}
model:
class Profile extends CActiveRecord
{
public $userid;
public $name;
public $website;
public $category;
public static function model()
{
return parent::model(__CLASS__);
}
public function tableName()
{
return 'userinfo';
}
public function primaryKey()
{
return 'id';
}
public static function userExists($user)
{
return self::model()->countByAttributes( array('username'=>$user) ) > 0;
}
}
You can use all three models in a single function
for example:
In create function
$model_account = new user_account;
$model_personal= new user_personal;
$model_general = new user_general;
$this->render('create',array(
'model_account'=>$model_account, 'model_personal' => $model_personal, 'model_general' => $model_general
));
here the all three models pass by render to create page.
in form page you can use the every model attributes as fields
Like this
echo $form->textField($model_account,'account_name');
echo $form->textField($model_personal,'email');
echo $form->textField($model_general,'address');
In create function / Update function
$model_account->attributes = $_POST['user_account'];
$model_personal->attributes = $_POST['user_personal'];
$model_general->attributes = $_POST['user_general'];
if($model_account->validate() && $model_personal->validate() && $model_general->validate())
{
$model_account->save();
$model_personal->save();
$model_general->save();
}