<?php
namespace ApplicationBundle\Controller;
use ApplicationBundle\Constants\EmailConstant;
use ApplicationBundle\Constants\GeneralConstant;
use ApplicationBundle\Constants\ModuleConstant;
use ApplicationBundle\Entity\ApprovalSettings;
use ApplicationBundle\Entity\EmailSenderSettings;
use ApplicationBundle\Entity\SysDepartmentPosition;
use ApplicationBundle\Entity\SysDeptPositionDefaultModule;
use ApplicationBundle\Interfaces\SystemInterface;
use ApplicationBundle\Modules\Authentication\Constants\UserConstants;
use ApplicationBundle\Modules\Api\Constants\ApiConstants;
use ApplicationBundle\Modules\Inventory\Inventory;
use ApplicationBundle\Modules\Production\ProductionM;
use ApplicationBundle\Modules\System\DeleteDocument;
use ApplicationBundle\Modules\System\System;
use ApplicationBundle\Modules\User\Users;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
class SystemAdminController extends GenericController implements SystemInterface
{
public function indexAction(Request $request)
{
// ?shell=cp renders the same (cp-themed) body inside the Company
// Administration cp-shell so the sidebar persists; default = system-admin chrome.
$tpl = ($request->query->get('shell') === 'cp')
? '@System/pages/view_admin_dashboard_cp.html.twig'
: '@System/pages/dashboard.html.twig';
return $this->render($tpl, array(
'page_title' => 'Command Center',
));
}
public function addPositionAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
if ($request->isMethod('POST')) {
$find_it = $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\SysDepartmentPosition')->findOneBy(array(
'status' => GeneralConstant::ACTIVE,
'positionName' => $request->request->get('positionName'),
'departmentId' => $request->request->get('departmentId')
));
if ($find_it) {
//nothing
} else {
$new = new SysDepartmentPosition();
$parent_position = $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\SysDepartmentPosition')->findOneBy(array(
// 'status'=>GeneralConstant::ACTIVE,
// 'name'=>$request->request->get('positionName')
'positionId' => $request->request->get('parentPositionId')
));
$new->setDepartmentId($request->request->get('departmentId'));
$new->setPositionName($request->request->get('positionName'));
$new->setLevel(($parent_position) ? $parent_position->getLevel() * 1 + 1 : 0);
$new->setParentPositionId($request->request->get('parentPositionId'));
// $new->set
$new->setStatus(GeneralConstant::ACTIVE);
$em->persist($new);
$em->flush();
}
// cp-shell org page posts redirectTo so the user returns to the shell.
if ($request->request->get('redirectTo')) {
return $this->redirect($request->request->get('redirectTo'));
}
}
$positions = $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\SysDepartmentPosition')->findBy(array(
'status' => GeneralConstant::ACTIVE,
));
$pos_array = [];
$pos_obj = [];
$pos_obj_by_dept = [];
foreach ($positions as $entry) {
$dt = array(
'id' => $entry->getPositionId(),
'name' => $entry->getPositionName(),
'deptId' => $entry->getDepartmentId(),
);
$pos_array[] = $dt;
$pos_obj[$entry->getPositionId()] = $dt;
$pos_obj_by_dept[$entry->getDepartmentId()][] = $dt;
}
return $this->render('@System/pages/settings/add_position.html.twig',
array(
'page_title' => 'Dashboard',
'positions' => $positions,
'posArray' => $pos_array,
'posObj' => $pos_obj,
'posObjByDept' => $pos_obj_by_dept,
'departments' => $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\SysDepartment')->findBy(array(
'status' => GeneralConstant::ACTIVE,
))
)
);
}
public function ApprovalSettingsAction(Request $request)
{
$id = 0;
$cc_id = '';
$cc_name = '';
if ($request->isMethod('POST')) {
$em = $this->getDoctrine()->getManager();
$em->getConnection()->query('START TRANSACTION;SET FOREIGN_KEY_CHECKS=0; TRUNCATE approval_setting; SET FOREIGN_KEY_CHECKS=1; COMMIT;');
foreach ($request->request->get('settingsId', []) as $key => $value) {
//first check if it exists so we can update
$user_id_list = [];
$user_id_list = $request->request->get('userId_' . $request->request->get('rowId')[$key], []);
$new = new ApprovalSettings();
$new->setEntity($request->request->get('entity')[$key]);
$new->setEntitySub($request->request->get('subCatId')[$key]);
$new->setPositionId($request->request->get('positionId')[$key]);
$new->setSequence($request->request->get('sequence')[$key]);
$new->setUserAssignType($request->request->get('userAssignType')[$key]);
$new->setUserId(implode(',', $user_id_list));
$new->setRoleType($request->request->get('roleType')[$key]);
$new->setRequired($request->request->get('required')[$key]);
$new->setSkipPrintFlag($request->request->get('skipPrintFlag')[$key]);
$new->setSuccession($request->request->get('succession')[$key]);
$new->setSuccessionTimeout($request->request->get('successionTimeout')[$key]);
// Conditional approval layers (TODO-C) — optional; null = always applies.
$condField = $request->request->get('conditionField', []);
$condOp = $request->request->get('conditionOp', []);
$condValue = $request->request->get('conditionValue', []);
$new->setConditionField(isset($condField[$key]) && $condField[$key] !== '' ? $condField[$key] : null);
$new->setConditionOp(isset($condOp[$key]) && $condOp[$key] !== '' ? $condOp[$key] : null);
$new->setConditionValue(isset($condValue[$key]) && $condValue[$key] !== '' ? $condValue[$key] : null);
$em->persist($new);
}
$em->flush();
}
$data = $this->getDoctrine()
->getRepository('ApplicationBundle\\Entity\\ApprovalSettings')
->findAll(
[], array(
'entity' => 'ASC',
'sequence' => 'ASC',
)
);
$Entity_list = GeneralConstant::$Entity_list_details;
$positionAssignType = GeneralConstant::$positionAssignType;
$approvalAction = GeneralConstant::$approvalAction;
$approvalRequired = GeneralConstant::$approvalRequired;
// $approvalRole=GeneralConstant::$approvalRole;
$approvalRole = GeneralConstant::$approvalRole;
// $approvalRoles=GeneralConstant::$approvalRoleForPrint;
//now add additional roles form dbase
$addRoles = $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\ApprovalRole')
->findBy(
array(// 'id' => $v->getSigId()
)
);
foreach ($addRoles as $addRole) {
$approvalRole[$addRole->getIndexId()] = $addRole->getName();
}
$userList = $this->get('user_module')->showUserList();
$Positions = $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\SysDepartmentPosition')->findBy(array(
'status' => GeneralConstant::ACTIVE,
));
$positionList = [];
$Departments = $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\SysDepartment')->findBy(array(
'status' => GeneralConstant::ACTIVE,
));
$depts = [];
foreach ($Departments as $entry) {
$depts[$entry->getDepartmentId()] = array(
'id' => $entry->getDepartmentId(),
'name' => $entry->getDepartmentName(),
);
}
return $this->render('@System/pages/settings/approval_settings.html.twig',
array(
'page_title' => 'Settings',
'data' => $data,
'entity_list' => $Entity_list,
'positionAssignType' => $positionAssignType,
'approvalAction' => $approvalAction,
'approvalRequired' => $approvalRequired,
'approvalRole' => $approvalRole,
'userList' => $userList,
'positions' => $Positions,
'departments' => $depts,
)
);
}
public function ModuleAccessSettingsAction(Request $request, $id = 0)
{
$id = 0;
$cc_id = '';
$cc_name = '';
// $cur_pos=0;
$cur_pos = $id;
if ($request->isMethod('POST')) {
$em = $this->getDoctrine()->getManager();
// $em->getConnection()->query('START TRANSACTION;SET FOREIGN_KEY_CHECKS=0; TRUNCATE approval_setting; SET FOREIGN_KEY_CHECKS=1; COMMIT;');
$mod_data = [];
// foreach ($request->request->get('modules') as $d) {
// $mod_data[] = $d * 1;
// }
$modules = $request->request->get('modules');
if (is_array($modules)) {
foreach ($modules as $d) {
$mod_data[] = $d * 1;
}
}
$already_exists = $this->getDoctrine()
->getRepository('ApplicationBundle\\Entity\\SysDeptPositionDefaultModule')
->findOneBy(
array(
'positionId' => $request->request->get('position')
)
);
if ($already_exists) {
$already_exists->setModuleIds(json_encode($mod_data));
} else {
$new = new SysDeptPositionDefaultModule();
$new->setModuleIds(json_encode($mod_data));
$new->setPositionId($request->request->get('position'));
$new->setStatus(GeneralConstant::ACTIVE);
// $new->set(GeneralConstant::ACTIVE);
$em->persist($new);
}
$em->flush();
}
$cur_pos_modules = $this->getDoctrine()
->getRepository('ApplicationBundle\\Entity\\SysDeptPositionDefaultModule')
->findAll();
$modules = $this->getDoctrine()
->getRepository('ApplicationBundle\\Entity\\SysModule')
->findBy(
array(// 'level'=>[1,2]
)
);
$module_data = [];
$module_data_by_parent_id = [];
// $module_parent_id_data=[];
$module_data_array = [];
$position_modules = [];
$position_modules_by_position = [];
$position_modules_array = [];
foreach ($modules as $entry) {
$dt = array(
'id' => $entry->getModuleId(),
'name' => $entry->getModuleName(),
'parentId' => $entry->getParentId()
);
$module_data[$entry->getModuleId()] = $dt;
$module_data_by_parent_id[$entry->getParentId()] = $dt;
$module_data_array[] = $dt;
}
foreach ($cur_pos_modules as $entry) {
$dt = array(
'id' => $entry->getId(),
'positionId' => $entry->getPositionId(),
// 'dept'=>$entry->getDepartmentId(),
'data' => json_decode($entry->getModuleIds(), true)
);
$position_modules[$entry->getId()] = $dt;
$position_modules_by_position[$entry->getPositionId()] = $dt;
$position_modules_array[] = $dt;
}
// $Entity_list=GeneralConstant::$Entity_list_details;
// $positionAssignType=GeneralConstant::$positionAssignType;
// $approvalAction=GeneralConstant::$approvalAction;
// $approvalRequired=GeneralConstant::$approvalRequired;
// $approvalRole=GeneralConstant::$approvalRole;
// $userList=$this->get('user_module')->showUserList();
$Positions = $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\SysDepartmentPosition')->findBy(array(
'status' => GeneralConstant::ACTIVE,
));
$Departments = $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\SysDepartment')->findBy(array(
'status' => GeneralConstant::ACTIVE,
));
$depts = [];
foreach ($Departments as $entry) {
$depts[$entry->getDepartmentId()] = array(
'id' => $entry->getDepartmentId(),
'name' => $entry->getDepartmentName(),
);
}
return $this->render('@System/pages/settings/module_access.html.twig',
array(
'page_title' => 'Settings',
'positions' => $Positions,
'departments' => $depts,
'module_data' => $module_data,
'parent_modules' => ModuleConstant::$parentModuleList,
'module_data_by_parent_id' => $module_data_by_parent_id,
'module_data_array' => $module_data_array,
'position_modules' => $position_modules,
'position_modules_by_position' => $position_modules_by_position,
'position_modules_array' => $position_modules_array
)
);
}
public function UserListAction(Request $request)
{
$systemType = $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
$post = $request;
$globalIdsByAppIdAndUser = [];
if ($request->isMethod('POST')) {
$message = $this->get('user_module')->addNewUser(
$request->request->get('name'),
$request->request->get('email'),
$request->request->has('username') ? $request->request->get('username') : $request->request->get('email'),
$request->request->get('password'),
$request->request->get('position'),
$this->getLoggedUserLoginId($request),
$request->request->get('company'),
$request->request->get('userType'),
$request->request->get('companyIdList'),
$request->request->get('branchIdList'),
$request->request->get('supervisor'),
$request->request->get('defaultRoute'),
$request->request->has('allModuleAccessFlag') ? 1 : 0
);
$companyData = $message[2];
if ($message[0] == 'success') {
if ($systemType == '_CENTRAL_') {
} else {
$em_goc = $this->getDoctrine()->getManager('company_group');
$em_goc->getConnection()->connect();
$connected = $em_goc->getConnection()->isConnected();
$gocDataList = [];
$gocDataListByAppId = [];
$retDataDebug = array();
$appIds = $message[2]->getAppId();
$userIds = $message[3]->getUserId();
if ($connected) {
$findByQuery = array(
'active' => 1
);
if ($appIds !== '_UNSET_')
$findByQuery['appId'] = $appIds;
$gocList = $this->getDoctrine()->getManager('company_group')
->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")
->findBy($findByQuery);
foreach ($gocList as $entry) {
$d = array(
'name' => $entry->getName(),
'id' => $entry->getId(),
'image' => $entry->getImage(),
'companyGroupHash' => $entry->getCompanyGroupHash(),
'dbName' => $entry->getDbName(),
'dbUser' => $entry->getDbUser(),
'dbPass' => $entry->getDbPass(),
'dbHost' => $entry->getDbHost(),
'appId' => $entry->getAppId(),
'companyRemaining' => $entry->getCompanyRemaining(),
'companyAllowed' => $entry->getCompanyAllowed(),
);
$gocDataList[$entry->getId()] = $d;
$gocDataListByAppId[$entry->getAppId()] = $d;
}
$debugCount = 0;
foreach ($gocDataList as $gocId => $entry) {
// if($debugCount>0)
// continue;
$skipSend = 1;
$connector = $this->container->get('application_connector');
$connector->resetConnection(
'default',
$gocDataList[$gocId]['dbName'],
$gocDataList[$gocId]['dbUser'],
$gocDataList[$gocId]['dbPass'],
$gocDataList[$gocId]['dbHost'],
$reset = true);
$em = $this->getDoctrine()->getManager();
if ($userIds !== '_UNSET_')
$users = $this->getDoctrine()
->getRepository('ApplicationBundle\\Entity\\SysUser')
->findBy(
array(
'userId' => $userIds
)
);
else
$users = $this->getDoctrine()
->getRepository('ApplicationBundle\\Entity\\SysUser')
->findBy(
array()
);
$output = '';
$userData = array();
$userFiles = array();
foreach ($users as $user) {
$file = $this->container->getParameter('kernel.root_dir') . '/../web/' . $user->getImage(); //<-- Path could be relative
// $output=$file;
if ($user->getImage() != '' && $user->getImage() != null && file_exists($file)) {
// $file = new \CURLFile($this->container->getParameter('kernel.root_dir') . '/../web/uploads/CompanyImage/' . $company->getImage()); //<-- Path could be relative
$mime = mime_content_type($file);
$info = pathinfo($file);
$name = $info['basename'];
if (strpos($mime, 'image') !== false) {
$output = new \CURLFile($file, $mime, $name);
}
$skipSend = 0;
$userFiles['file_' . $user->getUserAppId() . '_' . $user->getUserId()] = $output;
} else {
// unlink($this->container->getParameter('kernel.root_dir') . '/../web'. $centralUser->getImage());
$user->setImage(null);
$userFiles['file_' . $user->getUserAppId() . '_' . $user->getUserId()] = 'pika';
$em->flush();
}
$getters = array_filter(get_class_methods($user), function ($method) {
return 'get' === substr($method, 0, 3);
});
$userDataSingle = array(// 'file'=>$output
);
foreach ($getters as $getter) {
if ($getter == 'getCreatedAt' || $getter == 'getUpdatedAt' || $getter == 'getImage')
continue;
// if(is_string($user->{$getter}())|| is_numeric($user->{$getter}()))
// {
// $userDataSingle[$getter]= $user->{$getter}();
// }
if ($user->{$getter}() instanceof \DateTime) {
$ggtd = $user->{$getter}();
$userDataSingle[$getter] = $ggtd->format('Y-m-d');
} else
$userDataSingle[$getter] = $user->{$getter}();
}
$userData[] = $userDataSingle;
}
$retDataDebug[$debugCount] = array(
'skipSend' => $skipSend
);
// if ($skipSend == 0)
{
$urlToCall = GeneralConstant::HONEYBEE_CENTRAL_SERVER . '/SyncUserToCentralUser';
$userFiles['userData'] = json_encode($userData);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_POST => 1,
CURLOPT_URL => $urlToCall,
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
// CURLOPT_SAFE_UPLOAD => false,
CURLOPT_HTTPHEADER => array(// "Accept: multipart/form-data",
),
// CURLOPT_USERAGENT => 'InnoPM',
// CURLOPT_POSTFIELDS => array(
// 'userData'=>json_encode($userData),
// 'userFiles'=>$userFiles
// ),
CURLOPT_POSTFIELDS => $userFiles
));
$retData = curl_exec($curl);
$errData = curl_error($curl);
curl_close($curl);
$retDataObj = json_decode($retData, true);
$retDataDebug[$debugCount] = $retDataObj;
if (isset($retDataObj['globalIdsData']))
foreach ($retDataObj['globalIdsData'] as $app_id => $usrList) {
$connector = $this->container->get('application_connector');
$connector->resetConnection(
'default',
$gocDataListByAppId[$app_id]['dbName'],
$gocDataListByAppId[$app_id]['dbUser'],
$gocDataListByAppId[$app_id]['dbPass'],
$gocDataListByAppId[$app_id]['dbHost'],
$reset = true);
$em = $this->getDoctrine()->getManager();
foreach ($usrList as $sys_id => $globaldata) {
$user = $this->getDoctrine()
->getRepository('ApplicationBundle\\Entity\\SysUser')
->findOneBy(
array(
'userId' => $sys_id
)
);
if ($user) {
$user->setGlobalId($globaldata['gid']);
$em->flush();
}
}
}
}
$debugCount++;
}
}
// return new JsonResponse($retDataDebug);
}
}
if ($message[0] == 'success' && GeneralConstant::EMAIL_ENABLED == 1) {
$bodyHtml = '';
$bodyTemplate = '@Application/email/user/registration.html.twig';
$bodyData = array(
'name' => $request->request->get('name'),
'companyData' => $companyData,
'userName' => $request->request->get('username'),
'password' => $request->request->get('password'),
);
$attachments = [];
// $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
$new_mail = $this->get('mail_module');
$new_mail->sendMyMail(array(
// 'senderHash' => '_USER_MANAGEMENT_',
'senderHash' => '_CUSTOM_',
'forwardToMailAddress' => $request->request->get('email'),
'subject' => 'User Registration on HoneyBee Ecosystem under Company ' . $companyData->getName(),
'fileName' => '',
'attachments' => $attachments,
'toAddress' => $request->request->get('email'),
'fromAddress' => 'registration@ourhoneybee.eu',
'userName' => 'registration@ourhoneybee.eu',
'password' => \ApplicationBundle\Helper\MailerConfig::buddybeePassword(),
'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
'encryptionMethod' => 'ssl',
'mailTemplate' => $bodyTemplate,
'templateData' => $bodyData,
'embedCompanyImage' => 1,
'companyId' => $request->request->get('company'),
'companyImagePath' => $companyData->getImage()
));
// $emailmessage = (new \Swift_Message('Registration to Entity'))
// ->setFrom('registration@entity.innobd.com')
// ->setTo($request->request->get('email'))
// ->setBody(
// $this->renderView(
// 'ApplicationBundle:email/user:registration.html.twig',
// array('name' => $request->request->get('name'),
// 'companyData' => $companyData,
// 'userName' => $request->request->get('email'),
// 'password' => $request->request->get('password'),
// )
// ),
// 'text/html'
// );
// /*
// * If you also want to include a plaintext version of the message
// ->addPart(
// $this->renderView(
// 'Emails/registration.txt.twig',
// array('name' => $name)
// ),
// 'text/plain'
// )
// */
//// ;
// $this->get('mailer')->send($emailmessage);
}
$this->addFlash(
$message[0],
$message[1]
);
// cp-shell Users page posts redirectTo so creation returns to the shell.
if ($request->request->get('redirectTo')) {
return $this->redirect($request->request->get('redirectTo'));
}
}
// Hide explicitly-retired modules (sys_module.status = 0) from the permission grid
// so users can't be granted access to outdated/old pages. status IS NULL or non-zero
// stays visible (tenants that never set the flag are unaffected).
$modules = $this->getDoctrine()
->getRepository('ApplicationBundle\\Entity\\SysModule')
->createQueryBuilder('m')
->where('m.level = 1')
->andWhere('(m.status IS NULL OR m.status <> 0)')
->getQuery()
->getResult();
$module_data = [];
$module_data_by_parent_id = [];
$module_data_array = [];
$position_modules = [];
$position_modules_by_position = [];
$position_modules_array = [];
foreach ($modules as $entry) {
$dt = array(
'id' => $entry->getModuleId(),
'name' => $entry->getModuleName(),
'route' => $entry->getModuleRoute(),
'parentId' => $entry->getParentId()
);
$module_data[$entry->getModuleId()] = $dt;
$module_data_by_parent_id[$entry->getParentId()] = $dt;
$module_data_array[] = $dt;
}
$userList = $this->get('user_module')->showUserListDesc();
return $this->render('@System/pages/user_list.html.twig',
array(
'page_title' => 'Users',
'user_list' => $userList,
'module_data_array' => $module_data_array
)
);
}
public function DocumentManagementAction(Request $request, $id)
{
$em = $this->getDoctrine()->getManager();
$errorNote = "";
if ($request->isMethod('POST')) {
$options = array(
'notification_enabled' => $this->container->getParameter('notification_enabled'),
'notification_server' => $this->container->getParameter('notification_server'),
// 'appId'=>$request->getSession()->get(UserConstants::USER_APP_ID),
// 'url'=>$this->generateUrl(
// GeneralConstant::$Entity_list_details[$request->request->get('approvalEntity')]['entity_view_route_path_name']
// )
);
$notification_enabled = 0;
$notification_server = '';
if (!empty($options)) {
$notification_enabled = $options['notification_enabled'];
$notification_server = $options['notification_server'];
// $appId =$options['appId'];
// $url = $options['url'];
}
if ($request->request->get('entityId') != '' && $request->request->get('docId') != '')
$doc = $em->getRepository('ApplicationBundle\\Entity\\' . GeneralConstant::$Entity_list[$request->request->get('entityId')])
->findOneBy(
array(
GeneralConstant::$Entity_id_field_list[$request->request->get('entityId')] => $request->request->get('docId'),
)
);
if ($request->request->get('actionId') != '') {
$action = $request->request->get('actionId'); //1:lock, 2:disable, 3:enable edit 4:enable delete 5:remove
if ($action == 1) {
$doc->setLockFlag(1);
$doc->setEditFlag(0);
$doc->setDeleteFlag(0);
// $doc->setDisabledFlag(1);
}
if ($action == 2) {
$doc->setLockFlag(1);
$doc->setEditFlag(0);
$doc->setDeleteFlag(0);
$doc->setDisabledFlag(1);
}
if ($action == 3) {
$all_seq_list = $em->getRepository('ApplicationBundle\\Entity\\Approval')
->findBy(
array(
'entity' => $request->request->get('entityId'),
'entityId' => $request->request->get('docId'),
// 'sequence' => $dt->getSequence()
)
);
foreach ($all_seq_list as $useless_data) {
//we will remove all arppovals and pendings
// if ($useless_data->getSequence() > $dt->getSequence())
{
$em->remove($useless_data);
$em->flush();
}
}
//now take revert action
$revert_doc = System::takeRevertForEditActions($em, $request->request->get('entityId'), $request->request->get('docId'));
// $doc->setLockFlag(0);
// $doc->setEditFlag(1);
// $doc->setDeleteFlag(0);
// $doc->setDisabledFlag(1);
}
if ($action == 4) {
$doc->setLockFlag(0);
// $doc->setEditFlag(0);
$doc->setDeleteFlag(1);
// $doc->setDisabledFlag(1);
}
if ($action == 5) {
$funcname = GeneralConstant::$Entity_list[$request->request->get('entityId')];
$deleteAction = DeleteDocument::$funcname($em, $request->request->get('docId'));
if ($deleteAction == false)
$errorNote = "Sorry , Could not Delete The Document. Possibly Another Dependent Document Exists";
}
}
$em->flush();
if ($request->request->has('returnJson')) {
return new JsonResponse(array(
'success' => true,
));
} else {
$this->addFlash(
'success',
'New Document Created'
);
}
}
return $this->render('@System/pages/settings/document_management.html.twig',
array(
'page_header' => 'Document Management',
'page_title' => 'Doc Management',
'page_header_sub' => 'Settings',
'errorNote' => $errorNote,
'entityList' => GeneralConstant::$Entity_list_details,
));
}
public function DocListByEntityAction(Request $request, $id = 0)
{
$em = $this->getDoctrine()->getManager();
$data = [];
$data_array = [];
if ($request->isMethod('POST')) {
$doc = $em->getRepository('ApplicationBundle\\Entity\\' . GeneralConstant::$Entity_list[$request->request->get('entityId')])
->findBy(
array(// GeneralConstant::$Entity_id_field_list[$entity] => $entity_id,
)
);
if (isset(GeneralConstant::$Entity_list_details[$request->request->get('entityId')]['entity_print_route_path_name']))
$url = $this->generateUrl(
GeneralConstant::$Entity_list_details[$request->request->get('entityId')]['entity_print_route_path_name']
);
else
$url = $this->generateUrl(
GeneralConstant::$Entity_list_details[$request->request->get('entityId')]['entity_view_route_path_name']
);
$getIdfunc = GeneralConstant::$Entity_id_get_method_list[$request->request->get('entityId')];
foreach ($doc as $entry) //doing by doc hash for now. will change to id later i guess
{
$dt = array(
// 'id'=>$data->get
'id' => $entry->$getIdfunc(),
'name' => $entry->getDocumentHash(),
// 'test'=>$entry->get('transactionId'),
'view_link' => $url . "/" . $entry->$getIdfunc()
);
$data_array[] = $dt;
$data[$entry->$getIdfunc()] = $dt;
}
if (!empty($doc))
return new JsonResponse(array("success" => true, 'dataList' => $data_array, 'dataObj' => $data));
return new JsonResponse(array("success" => false));
}
return new JsonResponse(array("success" => false));
}
public function CompanyListAction(Request $request)
{
$companies = $this->getDoctrine()
->getRepository('ApplicationBundle\\Entity\\Company')
->findBy(
array(
'active' => GeneralConstant::ACTIVE
));
return $this->render('@System/pages/company_list.html.twig',
array(
'page_header' => 'Company List',
'page_title' => 'Company List',
// 'page_header_sub'=>'Edit',
'companies' => $companies
));
}
public function EmailSenderSettingsAction(Request $request, $id)
{
// $employee= new Employee();
$companyId = $id;
$senderSettingsData = [];
$senderVarieties = EmailConstant::$EmailSenderVarieties;
$em = $this->getDoctrine()->getManager();
if ($request->query->has('returnDataByCompany')) {
$companyId = $request->query->get('companyId');
$senderSettingsDataQry = $em->getRepository('ApplicationBundle\\Entity\\EmailSenderSettings')->findBy(
array(
'CompanyId' => $companyId,
// 'valid'=>1
)
);
foreach ($senderSettingsDataQry as $item) {
$senderSettingsData[$item->getHash()] = array(
'name' => $item->getName(),
'hash' => $item->getHash(),
'email' => $item->getEmail(),
'smtpServer' => $item->getSmtpServer(),
'smtpPort' => $item->getSmtpPort(),
'encryptionMethod' => $item->getEncryptionMethod(),
'userName' => $item->getUserName(),
'password' => $item->getPassword(),
'valid' => $item->getValid(),
'CompanyId' => $item->getCompanyId(),
);
}
return new JsonResponse(
array(
'success' => true,
'companyId' => $companyId,
'senderVarieties' => $senderVarieties,
'senderSettingsData' => $senderSettingsData,
)
);
}
if ($request->isMethod('post')) {
$post = $request->request;
$settingsCompanyId = $post->get('companyId');
$hash = $post->get('hash');
$name = $post->get('name');
$userName = $post->get('userName');
$email = $post->get('email');
// $valid=$post->get('valid');
$password = $post->get('password');
$smtpServer = $post->get('smtpServer');
$smtpPort = $post->get('smtpPort');
$encryptionMethod = $post->get('encryptionMethod');
foreach ($hash as $key => $hashValue) {
$exists = 0;
$valid = 0;
$new = $em->getRepository('ApplicationBundle\\Entity\\EmailSenderSettings')->findOneBy(
array(
'CompanyId' => $settingsCompanyId,
'hash' => $hashValue
)
);
if ($new)
$exists = 1;
else
$new = new EmailSenderSettings;
$emailValue = explode(',', $email[$key])[0];
$emailValue = filter_var($emailValue, FILTER_SANITIZE_EMAIL);
$emailValue = filter_var($emailValue, FILTER_VALIDATE_EMAIL);
if ($emailValue) {
$valid = 1;
}
$new->setCompanyId($settingsCompanyId);
$new->setHash($hashValue);
$new->setValid($valid);
$new->setName($name[$key]);
$new->setEmail($emailValue);
$new->setUserName($userName[$key]);
$new->setPassword($password[$key]);
$new->setSmtpServer($smtpServer[$key]);
$new->setSmtpPort($smtpPort[$key]);
$new->setTimeStampOfForm((new \DateTime())->format('U'));
$new->setEncryptionMethod($encryptionMethod[$key]);
if (!$exists) {
$em->persist($new);
}
$em->flush();
}
// cp-shell email-settings form posts redirectTo to return to the shell.
if ($post->get('redirectTo')) {
return $this->redirect($post->get('redirectTo'));
}
}
if ($companyId == 0 || $companyId == $this->getLoggedUserCompanyId($request)) {
$companyId = $this->getLoggedUserCompanyId($request);
$company = $this->getDoctrine()
->getRepository('ApplicationBundle\\Entity\\Company')
->findOneBy(
array(
'id' => $companyId
)
);
} else {
$company = $this->getDoctrine()
->getRepository('ApplicationBundle\\Entity\\Company')
->findOneBy(
array(
'id' => $companyId
)
);
}
// var_dump($company);
// print_r($type_list);
return $this->render('@System/pages/email_sender_settings.html.twig',
array(
'page_header' => 'Email Senders',
'page_title' => 'Email Senders',
'page_header_sub' => 'Settings',
'company_list' => $this->getDoctrine()
->getRepository('ApplicationBundle\\Entity\\Company')
->findBy(
array(// 'id'=>$companyId
)
),
'companyId' => $companyId,
));
}
public function EditCompanyAction(Request $request, $id)
{
// $employee= new Employee();
if ($id == 0 || $id == $this->getLoggedUserCompanyId($request)) {
$companyId = $this->getLoggedUserCompanyId($request);
$company = $this->getDoctrine()
->getRepository('ApplicationBundle\\Entity\\Company')
->findOneBy(
array(
'id' => $companyId
)
);
} else {
$company = $this->getDoctrine()
->getRepository('ApplicationBundle\\Entity\\Company')
->findOneBy(
array(
'id' => $id
)
);
}
// var_dump($company);
// print_r($type_list);
$country_list = $this->getDoctrine()
->getRepository('ApplicationBundle\\Entity\\Countries')
->findBy(array(), array('nameEn' => 'ASC'));
return $this->render('@System/pages/edit_company.html.twig',
array(
'page_header' => 'Company Info',
'page_title' => 'Company Info',
'page_header_sub' => 'Edit',
'company_id' => $company->getId(),
'dark_vibrant' => $company->getDarkVibrant(),
'light_vibrant' => $company->getLightVibrant(),
'vibrant' => $company->getVibrant(),
'company_type' => $company->getCompanyType(),
'company_name' => $company->getName(),
'address' => $company->getAddress(),
's_address' => $company->getShippingAddress(),
'b_address' => $company->getBillingAddress(),
'company_image' => $company->getImage(),
'motto' => $company->getMotto(),
'i_footer' => $company->getInvoiceFooter(),
'g_footer' => $company->getGeneralFooter(),
'company_tin' => $company->getCompanyTin(),
'company_bin' => $company->getCompanyBin(),
'company_reg' => $company->getCompanyReg(),
'company_tl' => $company->getCompanyTl(),
'ait_certificate_no' => $company->getAitCertificateNo(),
'sms_enabled' => $company->getSmsNotificationEnabled(),
'sms_settings' => $company->getSmsSettings(),
'country_id' => $company->getCountryId(),
'country_list' => $country_list,
));
}
public function UpdateCompanyAction(Request $request)
{
// $product=new Product();
$post = $request->request;
$company = $this->getDoctrine()
->getRepository('ApplicationBundle\\Entity\\Company')
->findOneBy(
array(
'id' => $post->get('id')
)
);
// var_dump($post);
// var_dump($company);
// var_dump($company->getName);
// var_dump($post->get('name'));
$company->setName($post->get('name'));
$company->setCompanyType($post->get('company_type'));
$company->setAddress($post->get('address'));
$company->setDarkVibrant($post->get('dark_vibrant'));
$company->setLightVibrant($post->get('light_vibrant'));
$company->setVibrant($post->get('vibrant'));
$company->setShippingAddress($post->get('s_address'));
$company->setBillingAddress($post->get('b_address'));
$company->setMotto($post->get('motto'));
$company->setInvoiceFooter($post->get('i_footer'));
$company->setGeneralFooter($post->get('g_footer'));
$company->setCompanyReg($post->get('company_reg', ''));
$company->setCompanyTin($post->get('company_tin', ''));
$company->setCompanyBin($post->get('company_bin', ''));
$company->setCompanyTl($post->get('company_tl', ''));
$company->setAitCertificateNo($post->get('ait_certificate_no', ''));
// Company secretarial particulars (statutory calendar / ACRA AR).
if ($post->has('uen')) { $company->setUen($post->get('uen', '') ?: null); }
if ($post->has('ssic_code')) { $company->setSsicCode($post->get('ssic_code', '') ?: null); }
if ($post->has('financial_year_end')) { $company->setFinancialYearEnd($post->get('financial_year_end', '') ?: null); }
if ($post->has('incorporation_date')) {
$incDate = trim((string) $post->get('incorporation_date', ''));
$company->setIncorporationDate($incDate !== '' ? new \DateTime($incDate) : null);
}
$company->setSmsNotificationEnabled($post->get('sms_enabled'));
$company->setSmsSettings($post->get('sms_settings'));
$countryIdPost = $post->get('country_id', null);
$company->setCountryId(($countryIdPost === null || $countryIdPost === '') ? null : (int) $countryIdPost);
$path = "";
foreach ($request->files as $uploadedFile) {
// if($uploadedFile->getImage())
// var_dump($uploadedFile->getFile());
// var_dump($uploadedFile);
if ($uploadedFile != null) {
// $fileName = md5(uniqid()) . '.' . $uploadedFile->guessExtension();
$fileName = 'company_image' . $company->getAppId() . '.' . $uploadedFile->guessExtension();
$path = $fileName;
$upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/CompanyImage/';
if ($company->getImage() != null && $company->getImage() != '' && file_exists($this->container->getParameter('kernel.root_dir') . '/../web' . $company->getImage())) {
unlink($this->container->getParameter('kernel.root_dir') . '/../web' . $company->getImage());
}
if (!file_exists($upl_dir)) {
mkdir($upl_dir, 0777, true);
}
$file = $uploadedFile->move($upl_dir, $path);
}
}
// print_r($file);
if ($path != "")
$company->setImage('/uploads/CompanyImage/' . $path);
$em = $this->getDoctrine()->getManager();
$em->persist($company);
$em->flush();
// cp-shell company-profile form posts a redirectTo so the user lands back
// in the cp-shell; legacy form omits it and returns to the edit page.
$redirectTo = $post->get('redirectTo');
if ($redirectTo) {
return $this->redirect($redirectTo);
}
$url = $this->generateUrl('edit_company_page');
return $this->redirect($url . "/" . $post->get('id'));
}
public function UserPermissionAction(Request $request, $id)
{
$user_id = $id;
$em = $this->getDoctrine()->getManager();
$iv = '1234567812345678';
$pass = '_enc_';
$suffix = '_enpaac_';
$userId = $user_id;
if (!is_numeric($user_id)) {
if (stripos($user_id, $suffix) !== false) {
$user_id = str_ireplace($suffix, '', $user_id);
if (stripos($user_id, '_FSLASH_') !== false) {
$user_id = str_ireplace('_FSLASH_', '/', $user_id);
}
$userId = openssl_decrypt(base64_decode($user_id), "AES-128-CBC", $pass, OPENSSL_RAW_DATA, $iv);
} else {
$userId = $this->get('url_encryptor')->decrypt($user_id);
}
}
// $this->get('url_encryptor')->decrypt($user_id);
if ($request->isMethod('POST')) {
// Check if its basic info
// if ($request->query->get('post_type', '') == "basic_info")
{
$this->get('user_module')->updateUser(
$userId,
$request->request->get('name'),
$request->request->has('email') ? $request->request->get('email') : '_UNCHANGED_',
$request->request->has('username') ? $request->request->get('username') : '_UNCHANGED_',
$request->request->get('password'),
$request->request->get('status'),
$request->request->get('userType'),
$request->request->get('supervisorId'),
$request->request->get('defaultRoute'),
$request->request->get('branchIdList'),
$request->request->has('allModuleAccessFlag') ? 1 : 0,
$this->getLoggedUserLoginId($request));
$employee = $em->getRepository('ApplicationBundle\\Entity\\Employee')->findOneBy(array('userId' => $userId));
$employeeDetails = $em->getRepository('ApplicationBundle\\Entity\\EmployeeDetails')->findOneBy(array('userId' => $userId));
$superVisor = $em->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(array('userId' => $request->request->get('supervisorId', 0)));
$superVisorId = 0;
if ($superVisor)
$superVisorId = $superVisor->getUserId();
if ($employee) {
$employee->setSupervisorId($superVisorId);
$em->persist($employee);
}
if ($employeeDetails) {
$employeeDetails->setSupervisor($superVisorId);
$employeeDetails->setEmpStatus($request->request->get('status'));
$em->persist($employeeDetails);
}
$em->flush();
// Check if its permission
}
// if ($request->query->get('post_type', '') == "permission")
{
$this->get('user_module')->updateUserPosition($userId, $request->get('permission') ? $request->get('permission') : '', $this->getLoggedUserLoginId($request));
}
// if ($request->query->get('post_type', '') == "access_restriction_option")
{
$this->get('user_module')->updateUserAccessSettings($userId, $request->request, $this->getLoggedUserLoginId($request));
}
// if ($request->query->get('post_type', '') == "module_access")
{
$this->get('user_module')->updateUserModuleList($userId, $request->request->get('modules'), $request->request->get('selectionType'), $this->getLoggedUserLoginId($request));
}
// return $this->redirectToRoute("system_admin_user_permission", array("user_id"=>$user_id));
return new JsonResponse(array('success' => true));
}
$getUserInfo = $this->get('user_module')->getUserInfo($userId);
$userAccessData = Users::getUserApplicationAccessSettings($this->getDoctrine()->getManager(), $userId, 1);
if (!is_array($getUserInfo)) {
$this->addFlash(
'error',
'No user found.'
);
return $this->redirectToRoute("system_admin_user_list");
}
$userList = $this->get('user_module')->showUserList();
// Hide explicitly-retired modules (sys_module.status = 0) from the permission grid
// so users can't be granted access to outdated/old pages. status IS NULL or non-zero
// stays visible (tenants that never set the flag are unaffected).
$modules = $this->getDoctrine()
->getRepository('ApplicationBundle\\Entity\\SysModule')
->createQueryBuilder('m')
->where('m.level = 1')
->andWhere('(m.status IS NULL OR m.status <> 0)')
->getQuery()
->getResult();
$module_data = [];
$module_data_by_parent_id = [];
$module_data_array = [];
$user_modules_array = [];
$selectionType = 0;
$user_modules_array = $getUserInfo['moduleIds'];
// if($modules==null)
// $modules=[];
// if(!empty($modules))
if ($user_modules_array != null) //we will check for null rather than empty as user might have no access to anything
{
$selectionType = 1;
}
$position_modules = [];
$position_modules_by_position = [];
$position_modules_array = [];
foreach ($modules as $entry) {
$dt = array(
'id' => $entry->getModuleId(),
'name' => $entry->getModuleName(),
'route' => $entry->getModuleRoute(),
'parentId' => $entry->getParentId()
);
$module_data[$entry->getModuleId()] = $dt;
$module_data_by_parent_id[$entry->getParentId()] = $dt;
$module_data_array[] = $dt;
}
$cur_pos_modules = $this->getDoctrine()
->getRepository('ApplicationBundle\\Entity\\SysDeptPositionDefaultModule')
->findAll();
foreach ($cur_pos_modules as $entry) {
$dt = array(
'id' => $entry->getId(),
'positionId' => $entry->getPositionId(),
// 'dept'=>$entry->getDepartmentId(),
'data' => json_decode($entry->getModuleIds(), true)
);
$position_modules[$entry->getId()] = $dt;
$position_modules_by_position[$entry->getPositionId()] = $dt;
$position_modules_array[] = $dt;
}
$userList = $this->get('user_module')->showUserListDesc();
return $this->render('@System/pages/user_permission.html.twig',
array(
'page_title' => 'Edit User (' . $getUserInfo['name'] . ')',
'user_info' => $getUserInfo,
'user_list' => $userList,
'userAccessData' => $userAccessData,
'module_data_array' => $module_data_array,
'module_data' => $module_data,
'parent_modules' => ModuleConstant::$parentModuleList,
'module_data_by_parent_id' => $module_data_by_parent_id,
'warehouse_action_list' => Inventory::warehouse_action_list($em, $this->getLoggedUserCompanyId($request), 'object'),
'warehouse_list' => Inventory::WarehouseList($em),
'production_process_list' => ProductionM::ProcessList($this->getDoctrine()->getManager(), $this->getLoggedUserCompanyId($request)),
'position_modules' => $position_modules,
'position_modules_by_position' => $position_modules_by_position,
'position_modules_array' => $position_modules_array,
'user_modules_array' => $user_modules_array,
'selection_type' => $selectionType
)
);
}
public function ModulePositionAction(Request $request)
{
return $this->render('@System/pages/module_status.html.twig',
array(
'page_title' => 'Module',
)
);
}
}