src/ApplicationBundle/Controller/HumanResourceController.php line 3038

Open in your IDE?
  1. <?php
  2. namespace ApplicationBundle\Controller;
  3. use ApplicationBundle\Constants\BuddybeeConstant;
  4. use ApplicationBundle\Constants\GeneralConstant;
  5. use ApplicationBundle\Constants\HumanResourceConstant;
  6. use ApplicationBundle\Constants\MeetingSchedulingConstant;
  7. use ApplicationBundle\Entity\AttendanceAmendment;
  8. use ApplicationBundle\Entity\BankList;
  9. use ApplicationBundle\Entity\BonusPolicy;
  10. use ApplicationBundle\Entity\Branch;
  11. use ApplicationBundle\Entity\ConsultancyTopic;
  12. use ApplicationBundle\Entity\EducationQualification;
  13. use ApplicationBundle\Entity\Employee;
  14. use ApplicationBundle\Entity\EmployeeAttendance;
  15. use ApplicationBundle\Entity\EmployeeAttendanceLog;
  16. use ApplicationBundle\Entity\EmployeeDetails;
  17. use ApplicationBundle\Entity\EmployeeLeaveApplication;
  18. use ApplicationBundle\Entity\EvaluationCategory;
  19. use ApplicationBundle\Entity\HolidayCalendar;
  20. use ApplicationBundle\Entity\HolidayCalendarDates;
  21. use ApplicationBundle\Entity\IncrementPolicy;
  22. use ApplicationBundle\Entity\LeaveSettings;
  23. use ApplicationBundle\Entity\PayrollPolicy;
  24. use ApplicationBundle\Entity\PlanningItem;
  25. use ApplicationBundle\Entity\Questionnaire;
  26. use ApplicationBundle\Entity\ScheduledMeeting;
  27. use ApplicationBundle\Entity\Skill;
  28. use ApplicationBundle\Entity\SysDepartment;
  29. use ApplicationBundle\Entity\SysDepartmentPosition;
  30. use ApplicationBundle\Entity\SysUser;
  31. use ApplicationBundle\Entity\TrainingCourse;
  32. use ApplicationBundle\Entity\WorkHourPolicy;
  33. use ApplicationBundle\Helper\ResponseStructure;
  34. use ApplicationBundle\Interfaces\SessionCheckInterface;
  35. use ApplicationBundle\Modules\Accounts\Accounts;
  36. use ApplicationBundle\Modules\Authentication\Constants\UserConstants;
  37. use ApplicationBundle\Modules\Buddybee\Buddybee;
  38. use ApplicationBundle\Modules\HumanResource\HumanResource;
  39. use ApplicationBundle\Modules\HumanResource\HumanResourceHelper;
  40. use ApplicationBundle\Modules\Inventory\Inventory;
  41. use ApplicationBundle\Modules\Sales\Client;
  42. use ApplicationBundle\Modules\System\DeleteDocument;
  43. use ApplicationBundle\Modules\System\DocValidation;
  44. use ApplicationBundle\Modules\System\MiscActions;
  45. use ApplicationBundle\Modules\System\System;
  46. use ApplicationBundle\Modules\User\Company;
  47. use CompanyGroupBundle\Entity\EntityApplicantDetails;
  48. use CompanyGroupBundle\Entity\EntityCountryConsultantRequirements;
  49. use CompanyGroupBundle\Entity\EntityCreateBlog;
  50. use CompanyGroupBundle\Entity\EntityCreateDocument;
  51. use CompanyGroupBundle\Entity\EntityCreateTopic;
  52. use CompanyGroupBundle\Entity\EntityFile;
  53. use CompanyGroupBundle\Entity\EntityInvoice;
  54. use CompanyGroupBundle\Entity\EntitySkill;
  55. use CompanyGroupBundle\Entity\PromoCode;
  56. use CompanyGroupBundle\Modules\ApplicantM;
  57. use DateTime;
  58. use Ps\PdfBundle\Annotation\Pdf;
  59. use Symfony\Component\HttpFoundation\JsonResponse;
  60. use Symfony\Component\HttpFoundation\Request;
  61. use Symfony\Component\HttpFoundation\Response;
  62. use Symfony\Component\Routing\Generator\UrlGenerator;
  63. use Throwable;
  64. //use Symfony\Bundle\FrameworkBundle\Console\Application;
  65. //use Symfony\Component\Console\Input\ArrayInput;
  66. //use Symfony\Component\Console\Output\NullOutput;
  67. class HumanResourceController extends GenericController implements SessionCheckInterface
  68. {
  69. //temporary for adding session
  70.     public function CheckoutPageAction(Request $request$encData '')
  71.     {
  72.         $em $this->getDoctrine()->getManager('company_group');
  73.         $em_goc $this->getDoctrine()->getManager('company_group');
  74.         $sandBoxMode $this->container->hasParameter('sand_box_mode') ? $this->container->getParameter('sand_box_mode') : 0;
  75.         $systemType $this->container->getParameter('system_type') ?: '_CENTRAL_';
  76.         $invoiceId $request->request->get('invoiceId'$request->query->get('invoiceId'0));
  77.         if ($encData != "") {
  78.             $encryptedData json_decode($this->get('url_encryptor')->decrypt($encData), true);
  79.             if ($encryptedData == null$encryptedData = [];
  80.             if (isset($encryptedData['invoiceId'])) $invoiceId $encryptedData['invoiceId'];
  81.         }
  82.         $session $request->getSession();
  83.         $currencyForGateway 'eur';
  84.         $gatewayInvoice null;
  85.         if ($invoiceId != 0)
  86.             $gatewayInvoice $em->getRepository(EntityInvoice::class)->find($invoiceId);
  87.         $paymentGateway $request->request->get('paymentGateway''stripe'); //aamarpay,bkash
  88.         $paymentType $request->request->get('paymentType''credit');
  89.         $retailerId $request->request->get('retailerId'0);
  90.         if ($request->query->has('currency'))
  91.             $currencyForGateway $request->query->get('currency');
  92.         else
  93.             $currencyForGateway $request->request->get('currency''eur');
  94. //        {
  95. //            if ($request->query->has('meetingSessionId'))
  96. //                $id = $request->query->get('meetingSessionId');
  97. //        }
  98.         $currentUserBalance 0;
  99.         $currentUserCoinBalance 0;
  100.         $gatewayAmount 0;
  101.         $redeemedAmount 0;
  102.         $redeemedSessionCount 0;
  103.         $toConsumeSessionCount 0;
  104.         $invoiceSessionCount 0;
  105.         $payableAmount 0;
  106.         $promoClaimedAmount 0;
  107.         $promoCodeId 0;
  108.         $promoClaimedSession 0;
  109.         $bookingExpireTime null;
  110.         $bookingExpireTs 0;
  111.         $imageBySessionCount = [
  112.             => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  113.             100 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  114.             200 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  115.             300 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  116.             400 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  117.             500 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  118.             600 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  119.             700 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  120.             800 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  121.             900 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  122.             1000 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  123.             1100 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  124.             1200 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  125.             1300 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  126.             1400 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  127.             1500 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  128.             1600 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  129.             1700 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  130.             1800 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  131.             1900 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  132.             2000 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  133.             2100 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  134.             2200 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  135.             2300 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  136.             2400 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  137.             2500 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  138.             2600 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  139.             2700 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  140.             2800 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  141.             2900 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  142.             3000 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  143.             3100 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  144.             3200 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  145.             3300 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  146.             3400 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  147.             3500 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  148.             3600 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  149.             3700 => "https://www.buddybee.eu/buddybee_assets/ADULT-BEE.png",
  150.         ];
  151.         if (!$gatewayInvoice) {
  152.             if ($request->isMethod('POST')) {
  153.                 $totalAmount 0;
  154.                 $totalSessionCount 0;
  155.                 $consumedAmount 0;
  156.                 $consumedSessionCount 0;
  157.                 $bookedById 0;
  158.                 $bookingRefererId 0;
  159.                 if ($session->get(UserConstants::USER_ID)) {
  160.                     $bookedById $session->get(UserConstants::USER_ID);
  161.                     $bookingRefererId 0;
  162. //                    $toConsumeSessionCount = 1 * $request->request->get('meetingSessionConsumeCount', 0);
  163.                     $invoiceSessionCount * ($request->request->get('sessionCount'0) == '' $request->request->get('sessionCount'0));
  164.                     //1st do the necessary
  165.                     $extMeeting null;
  166.                     $meetingSessionId 0;
  167.                     if ($request->request->has('purchasePackage')) {
  168.                         //1. check if any bee card if yes try to claim it , modify current balance then
  169.                         $beeCodeSerial $request->request->get('beeCodeSerial''');
  170.                         $promoCode $request->request->get('promoCode''');
  171.                         $beeCodePin $request->request->get('beeCodePin''');
  172.                         $userId $request->request->get('userId'$session->get(UserConstants::USER_ID));
  173.                         $studentDetails null;
  174.                         $studentDetails $em_goc->getRepository(EntityApplicantDetails::class)->find($userId);
  175.                         if ($studentDetails) {
  176.                             $currentUserBalance $studentDetails->getAccountBalance();
  177.                         }
  178.                         if ($beeCodeSerial != '' && $beeCodePin != '') {
  179.                             $claimData MiscActions::ClaimBeeCode($em,
  180.                                 [
  181.                                     'claimFlag' => 1,
  182.                                     'pin' => $beeCodePin,
  183.                                     'serial' => $beeCodeSerial,
  184.                                     'userId' => $userId,
  185.                                 ]);
  186.                             if ($userId == $session->get(UserConstants::USER_ID)) {
  187.                                 MiscActions::RefreshBuddybeeBalanceOnSession($em$request->getSession());
  188.                                 $claimData['newCoinBalance'] = $session->get('BUDDYBEE_COIN_BALANCE');
  189.                                 $claimData['newBalance'] = $session->get('BUDDYBEE_BALANCE');
  190.                             }
  191.                             $redeemedAmount $claimData['data']['claimedAmount'];
  192.                             $redeemedSessionCount $claimData['data']['claimedCoin'];
  193.                         } else
  194.                             if ($userId == $session->get(UserConstants::USER_ID)) {
  195.                                 MiscActions::RefreshBuddybeeBalanceOnSession($em$request->getSession());
  196.                             }
  197.                         $payableAmount round($request->request->get('payableAmount'0), 0);
  198.                         $totalAmountWoDiscount round($request->request->get('totalAmountWoDiscount'0), 0);
  199.                         //now claim and process promocode
  200.                         if ($promoCode != '') {
  201.                             $claimData MiscActions::ClaimPromoCode($em,
  202.                                 [
  203.                                     'claimFlag' => 1,
  204.                                     'promoCode' => $promoCode,
  205.                                     'decryptedPromoCodeData' => json_decode($this->get('url_encryptor')->decrypt($promoCode), true),
  206.                                     'orderValue' => $totalAmountWoDiscount,
  207.                                     'currency' => $currencyForGateway,
  208.                                     'orderCoin' => $invoiceSessionCount,
  209.                                     'userId' => $userId,
  210.                                 ]);
  211.                             $promoClaimedAmount 0;
  212. //                            $promoClaimedAmount = $claimData['data']['claimedAmount']*(BuddybeeConstant::$convMultFromTo['eur'][$currencyForGateway]);
  213.                             $promoCodeId $claimData['promoCodeId'];
  214.                             $promoClaimedSession $claimData['data']['claimedCoin'];
  215.                         }
  216.                         if ($userId == $session->get(UserConstants::USER_ID)) {
  217.                             MiscActions::RefreshBuddybeeBalanceOnSession($em$request->getSession());
  218.                             $currentUserBalance $session->get('BUDDYBEE_BALANCE');
  219.                             $currentUserCoinBalance $session->get('BUDDYBEE_COIN_BALANCE');
  220.                         } else {
  221.                             if ($bookingRefererId == 0)
  222.                                 $bookingRefererId $session->get(UserConstants::USER_ID);
  223.                             $studentDetails $em_goc->getRepository(EntityApplicantDetails::class)->find($userId);
  224.                             if ($studentDetails) {
  225.                                 $currentUserBalance $studentDetails->getAccountBalance();
  226.                                 $currentUserCoinBalance $studentDetails->getSessionCountBalance();
  227.                                 if ($bookingRefererId != $userId && $bookingRefererId != 0) {
  228.                                     $bookingReferer $em_goc->getRepository(EntityApplicantDetails::class)->find($bookingRefererId);
  229.                                     if ($bookingReferer)
  230.                                         if ($bookingReferer->getIsAdmin()) {
  231.                                             $studentDetails->setAssignedSalesRepresentativeId($bookingRefererId);
  232.                                             $em_goc->flush();
  233.                                         }
  234.                                 }
  235.                             }
  236.                         }
  237.                         //2. check if any promo code  if yes add it to promo discount
  238.                         //3. check if scheule is still temporarily booked if not return that you cannot book it
  239.                         Buddybee::ExpireAnyMeetingSessionIfNeeded($em);
  240.                         Buddybee::ExpireAnyEntityInvoiceIfNeeded($em);
  241. //                        if ($request->request->get('autoAssignMeetingSession', 0) == 1
  242. //                            && $request->request->get('consultancyScheduleId', 0) != 0
  243. //                            && $request->request->get('consultancyScheduleId', 0) != ''
  244. //                        )
  245.                         {
  246.                             //1st check if a meeting session exxists with same TS, student id , consultant id
  247. //                            $scheduledStartTime = new \DateTime('@' . $request->request->get('consultancyScheduleId', ''));
  248. //                            $extMeeting = $em->getRepository('CompanyGroupBundle:EntityMeetingSession')
  249. //                                ->findOneBy(
  250. //                                    array(
  251. //                                        'scheduledTimeTs' => $scheduledStartTime->format('U'),
  252. //                                        'consultantId' => $request->request->get('consultantId', 0),
  253. //                                        'studentId' => $request->request->get('studentId', 0),
  254. //                                        'durationAllowedMin' => $request->request->get('meetingSessionScheduledDuration', BuddybeeConstant::PER_SESSION_MINUTE),
  255. //                                    )
  256. //                                );
  257. //                            if ($extMeeting) {
  258. //                                $new = $extMeeting;
  259. //                                $meetingSessionId = $new->getSessionId();
  260. //                                $periodMarker = $scheduledStartTime->format('Ym');
  261. //
  262. //                            }
  263. //                            else {
  264. //
  265. //
  266. //                                $scheduleValidity = MiscActions::CheckIfScheduleCanBeConfirmed(
  267. //                                    $em,
  268. //                                    $request->request->get('consultantId', 0),
  269. //                                    $request->request->get('studentId', 0),
  270. //                                    $scheduledStartTime->format('U'),
  271. //                                    $request->request->get('meetingSessionScheduledDuration', BuddybeeConstant::PER_SESSION_MINUTE),
  272. //                                    1
  273. //                                );
  274. //
  275. //                                if (!$scheduleValidity) {
  276. //                                    $url = $this->generateUrl(
  277. //                                        'consultant_profile'
  278. //                                    );
  279. //                                    $output = [
  280. //
  281. //                                        'proceedToCheckout' => 0,
  282. //                                        'message' => 'Session Booking Expired or not Found!',
  283. //                                        'errorFlag' => 1,
  284. //                                        'redirectUrl' => $url . '/' . $request->request->get('consultantId', 0)
  285. //                                    ];
  286. //                                    return new JsonResponse($output);
  287. //                                }
  288. //                                $new = new EntityMeetingSession();
  289. //
  290. //                                $new->setTopicId($request->request->get('consultancyTopic', 0));
  291. //                                $new->setConsultantId($request->request->get('consultantId', 0));
  292. //                                $new->setStudentId($request->request->get('studentId', 0));
  293. //                                $consultancyTopic = $em_goc->getRepository(EntityCreateTopic::class)->find($request->request->get('consultancyTopic', 0));
  294. //                                $new->setMeetingType($consultancyTopic ? $consultancyTopic->getMeetingType() : 0);
  295. //                                $new->setConsultantCanUpload($consultancyTopic ? $consultancyTopic->getConsultantCanUpload() : 0);
  296. //
  297. //
  298. //                                $scheduledEndTime = new \DateTime($request->request->get('scheduledTime', ''));
  299. //                                $scheduledEndTime = $scheduledEndTime->modify('+' . $request->request->get('meetingSessionScheduledDuration', 30) . ' minute');
  300. //
  301. //                                //$new->setScheduledTime($request->request->get('setScheduledTime'));
  302. //                                $new->setScheduledTime($scheduledStartTime);
  303. //                                $new->setDurationAllowedMin($request->request->get('meetingSessionScheduledDuration', 30));
  304. //                                $new->setDurationLeftMin($request->request->get('meetingSessionScheduledDuration', 30));
  305. //                                $new->setSessionExpireDate($scheduledEndTime);
  306. //                                $new->setSessionExpireDateTs($scheduledEndTime->format('U'));
  307. //                                $new->setEquivalentSessionCount($request->request->get('meetingSessionConsumeCount', 0));
  308. //                                $new->setMeetingSpecificNote($request->request->get('meetingSpecificNote', ''));
  309. //
  310. //                                $new->setUsableSessionCount($request->request->get('meetingSessionConsumeCount', 0));
  311. //                                $new->setRedeemSessionCount($request->request->get('meetingSessionConsumeCount', 0));
  312. //                                $new->setMeetingActionFlag(0);// no action waiting for meeting
  313. //                                $new->setScheduledTime($scheduledStartTime);
  314. //                                $new->setScheduledTimeTs($scheduledStartTime->format('U'));
  315. //                                $new->setPayableAmount($request->request->get('payableAmount', 0));
  316. //                                $new->setDueAmount($request->request->get('dueAmount', 0));
  317. //                                //$new->setScheduledTime(new \DateTime($request->get('setScheduledTime')));
  318. //                                //$new->setPcakageDetails(json_encode(($request->request->get('packageData'))));
  319. //                                $new->setPackageName(($request->request->get('packageName', '')));
  320. //                                $new->setPcakageDetails(($request->request->get('packageData', '')));
  321. //                                $new->setScheduleId(($request->request->get('consultancyScheduleId', 0)));
  322. //                                $currentUnixTime = new \DateTime();
  323. //                                $currentUnixTimeStamp = $currentUnixTime->format('U');
  324. //                                $studentId = $request->request->get('studentId', 0);
  325. //                                $consultantId = $request->request->get('consultantId', 0);
  326. //                                $new->setMeetingRoomId(str_pad($consultantId, 4, STR_PAD_LEFT) . $currentUnixTimeStamp . str_pad($studentId, 4, STR_PAD_LEFT));
  327. //                                $new->setSessionValue(($request->request->get('sessionValue', 0)));
  328. ////                        $new->setIsPayment(0);
  329. //                                $new->setConsultantIsPaidFull(0);
  330. //
  331. //                                if ($bookingExpireTs == 0) {
  332. //
  333. //                                    $bookingExpireTime = new \DateTime();
  334. //                                    $currTime = new \DateTime();
  335. //                                    $currTimeTs = $currTime->format('U');
  336. //                                    $bookingExpireTs = (1 * $scheduledStartTime->format('U')) - (24 * 3600);
  337. //                                    if ($bookingExpireTs < $currTimeTs) {
  338. //                                        if ((1 * $scheduledStartTime->format('U')) - $currTimeTs > (12 * 3600))
  339. //                                            $bookingExpireTs = (1 * $scheduledStartTime->format('U')) - (2 * 3600);
  340. //                                        else
  341. //                                            $bookingExpireTs = (1 * $scheduledStartTime->format('U'));
  342. //                                    }
  343. //
  344. ////                                    $bookingExpireTs = $bookingExpireTime->format('U');
  345. //                                }
  346. //
  347. //                                $new->setPaidSessionCount(0);
  348. //                                $new->setBookedById($bookedById);
  349. //                                $new->setBookingRefererId($bookingRefererId);
  350. //                                $new->setDueSessionCount($request->request->get('meetingSessionConsumeCount', 0));
  351. //                                $new->setExpireIfUnpaidTs($bookingExpireTs);
  352. //                                $new->setBookingExpireTs($bookingExpireTs);
  353. //                                $new->setConfirmationExpireTs($bookingExpireTs);
  354. //                                $new->setIsPaidFull(0);
  355. //                                $new->setIsExpired(0);
  356. //
  357. //
  358. //                                $em_goc->persist($new);
  359. //                                $em_goc->flush();
  360. //                                $meetingSessionId = $new->getSessionId();
  361. //                                $periodMarker = $scheduledStartTime->format('Ym');
  362. //                                MiscActions::UpdateSchedulingRestrictions($em_goc, $consultantId, $periodMarker, (($request->request->get('meetingSessionScheduledDuration', 30)) / 60), -(($request->request->get('meetingSessionScheduledDuration', 30)) / 60));
  363. //                            }
  364.                         }
  365.                         //4. if after all this stages passed then calcualte gateway payable
  366.                         if ($request->request->get('isRecharge'0) == 1) {
  367.                             if (($redeemedAmount $promoClaimedAmount) >= $payableAmount) {
  368.                                 $payableAmount = ($redeemedAmount $promoClaimedAmount);
  369.                                 $gatewayAmount 0;
  370.                             } else
  371.                                 $gatewayAmount $payableAmount - ($redeemedAmount $promoClaimedAmount);
  372.                         } else {
  373.                             if ($toConsumeSessionCount <= $currentUserCoinBalance && $invoiceSessionCount <= $toConsumeSessionCount) {
  374.                                 $payableAmount 0;
  375.                                 $gatewayAmount 0;
  376.                             } else if (($redeemedAmount $promoClaimedAmount) >= $payableAmount) {
  377.                                 $payableAmount = ($redeemedAmount $promoClaimedAmount);
  378.                                 $gatewayAmount 0;
  379.                             } else
  380.                                 $gatewayAmount $payableAmount <= ($currentUserBalance + ($redeemedAmount $promoClaimedAmount)) ? : ($payableAmount $currentUserBalance - ($redeemedAmount $promoClaimedAmount));
  381.                         }
  382.                         $gatewayAmount round($gatewayAmount2);
  383.                         $dueAmount round($request->request->get('dueAmount'$payableAmount), 0);
  384.                         if ($request->request->has('gatewayProductData'))
  385.                             $gatewayProductData $request->request->get('gatewayProductData');
  386.                         $gatewayProductData = [[
  387.                             'price_data' => [
  388.                                 'currency' => $currencyForGateway,
  389.                                 'unit_amount' => $gatewayAmount != ? ((100 $gatewayAmount) / ($invoiceSessionCount != $invoiceSessionCount 1)) : 200000,
  390.                                 'product_data' => [
  391. //                            'name' => $request->request->has('packageName') ? $request->request->get('packageName') : 'Advanced Consultancy Package',
  392.                                     'name' => 'Bee Coins',
  393.                                     'images' => [$imageBySessionCount[0]],
  394.                                 ],
  395.                             ],
  396.                             'quantity' => $invoiceSessionCount != $invoiceSessionCount 1,
  397.                         ]];
  398.                         $new_invoice null;
  399.                         if ($extMeeting) {
  400.                             $new_invoice $em->getRepository('CompanyGroupBundle:EntityInvoice')
  401.                                 ->findOneBy(
  402.                                     array(
  403.                                         'invoiceType' => $request->request->get('invoiceType'BuddybeeConstant::ENTITY_INVOICE_TYPE_PAYMENT_TO_HONEYBEE),
  404.                                         'meetingId' => $extMeeting->getSessionId(),
  405.                                     )
  406.                                 );
  407.                         }
  408.                         if ($new_invoice) {
  409.                         } else {
  410.                             $new_invoice = new EntityInvoice();
  411.                             $invoiceDate = new \DateTime();
  412.                             $new_invoice->setInvoiceDate($invoiceDate);
  413.                             $new_invoice->setInvoiceDateTs($invoiceDate->format('U'));
  414.                             $new_invoice->setStudentId($userId);
  415.                             $new_invoice->setBillerId($retailerId == $retailerId);
  416.                             $new_invoice->setRetailerId($retailerId);
  417.                             $new_invoice->setBillToId($userId);
  418.                             $new_invoice->setAmountTransferGateWayHash($paymentGateway);
  419.                             $new_invoice->setAmountCurrency($currencyForGateway);
  420.                             $cardIds $request->request->get('cardIds', []);
  421.                             $new_invoice->setMeetingId($meetingSessionId);
  422.                             $new_invoice->setGatewayBillAmount($gatewayAmount);
  423.                             $new_invoice->setRedeemedAmount($redeemedAmount);
  424.                             $new_invoice->setPromoDiscountAmount($promoClaimedAmount);
  425.                             $new_invoice->setPromoCodeId($promoCodeId);
  426.                             $new_invoice->setRedeemedSessionCount($redeemedSessionCount);
  427.                             $new_invoice->setPaidAmount($payableAmount $dueAmount);
  428.                             $new_invoice->setProductDataForPaymentGateway(json_encode($gatewayProductData));
  429.                             $new_invoice->setDueAmount($dueAmount);
  430.                             $new_invoice->setInvoiceType($request->request->get('invoiceType'BuddybeeConstant::ENTITY_INVOICE_TYPE_PAYMENT_TO_HONEYBEE));
  431.                             $new_invoice->setDocumentHash(MiscActions::GenerateRandomCrypto('BEI' microtime(true)));
  432.                             $new_invoice->setCardIds(json_encode($cardIds));
  433.                             $new_invoice->setAmountType($request->request->get('amountType'1));
  434.                             $new_invoice->setAmount($payableAmount);
  435.                             $new_invoice->setConsumeAmount($payableAmount);
  436.                             $new_invoice->setSessionCount($invoiceSessionCount);
  437.                             $new_invoice->setConsumeSessionCount($toConsumeSessionCount);
  438.                             $new_invoice->setIsPaidfull(0);
  439.                             $new_invoice->setIsProcessed(0);
  440.                             $new_invoice->setApplicantId($userId);
  441.                             $new_invoice->setBookedById($bookedById);
  442.                             $new_invoice->setBookingRefererId($bookingRefererId);
  443.                             $new_invoice->setIsRecharge($request->request->get('isRecharge'0));
  444.                             $new_invoice->setAutoConfirmTaggedMeeting($request->request->get('autoConfirmTaggedMeeting'0));
  445.                             $new_invoice->setAutoConfirmOtherMeeting($request->request->get('autoConfirmOtherMeeting'0));
  446.                             $new_invoice->setAutoClaimPurchasedCards($request->request->get('autoClaimPurchasedCards'0));
  447.                             $new_invoice->setIsPayment(0); //0 means receive
  448.                             $new_invoice->setStatus(GeneralConstant::ACTIVE); //0 means receive
  449.                             $new_invoice->setStage(BuddybeeConstant::ENTITY_INVOICE_STAGE_INITIATED); //0 means receive
  450.                             if ($bookingExpireTs == 0) {
  451.                                 $bookingExpireTime = new \DateTime();
  452.                                 $bookingExpireTime->modify('+30 day');
  453.                                 $bookingExpireTs $bookingExpireTime->format('U');
  454.                             }
  455.                             $new_invoice->setExpireIfUnpaidTs($bookingExpireTs);
  456.                             $new_invoice->setBookingExpireTs($bookingExpireTs);
  457.                             $new_invoice->setConfirmationExpireTs($bookingExpireTs);
  458. //            $new_invoice->setStatus($request->request->get(0));
  459.                             $em_goc->persist($new_invoice);
  460.                             $em_goc->flush();
  461.                         }
  462.                         $invoiceId $new_invoice->getId();
  463.                         $gatewayInvoice $new_invoice;
  464.                         if ($request->request->get('isRecharge'0) == 1) {
  465.                         } else {
  466.                             if ($gatewayAmount <= 0) {
  467.                                 $meetingId 0;
  468.                                 if ($invoiceId != 0) {
  469.                                     $retData Buddybee::ProcessEntityInvoice($em_goc$invoiceId, ['stage' => BuddybeeConstant::ENTITY_INVOICE_STAGE_COMPLETED], false,
  470.                                         $this->container->getParameter('notification_enabled'),
  471.                                         $this->container->getParameter('notification_server')
  472.                                     );
  473.                                     $meetingId $retData['meetingId'];
  474.                                 }
  475.                                 MiscActions::RefreshBuddybeeBalanceOnSession($em$request->getSession());
  476.                                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  477.                                     $billerDetails = [];
  478.                                     $billToDetails = [];
  479.                                     $invoice $gatewayInvoice;
  480.                                     if ($invoice) {
  481.                                         $billerDetails $em->getRepository('CompanyGroupBundle:EntityApplicantDetails')
  482.                                             ->findOneBy(
  483.                                                 array(
  484.                                                     'applicantId' => $invoice->getBillerId(),
  485.                                                 )
  486.                                             );
  487.                                         $billToDetails $em->getRepository('CompanyGroupBundle:EntityApplicantDetails')
  488.                                             ->findOneBy(
  489.                                                 array(
  490.                                                     'applicantId' => $invoice->getBillToId(),
  491.                                                 )
  492.                                             );
  493.                                     }
  494.                                     $bodyTemplate 'ApplicationBundle:email/templates:buddybeeInvoiceEmail.html.twig';
  495.                                     $bodyData = array(
  496.                                         'page_title' => 'Invoice',
  497. //            'studentDetails' => $student,
  498.                                         'billerDetails' => $billerDetails,
  499.                                         'billToDetails' => $billToDetails,
  500.                                         'invoice' => $invoice,
  501.                                         'currencyList' => BuddybeeConstant::$currency_List,
  502.                                         'currencyListByMarker' => BuddybeeConstant::$currency_List_by_marker,
  503.                                     );
  504.                                     $attachments = [];
  505.                                     $forwardToMailAddress $billToDetails->getOAuthEmail();
  506. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  507.                                     $new_mail $this->get('mail_module');
  508.                                     $new_mail->sendMyMail(array(
  509.                                         'senderHash' => '_CUSTOM_',
  510.                                         //                        'senderHash'=>'_CUSTOM_',
  511.                                         'forwardToMailAddress' => $forwardToMailAddress,
  512.                                         'subject' => 'YourInvoice #' 'D' str_pad('BB'5'0'STR_PAD_LEFT) . str_pad('76'2'0'STR_PAD_LEFT) . str_pad($invoice->getId(), 8"0"STR_PAD_LEFT) . ' from BuddyBee ',
  513. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  514.                                         'attachments' => $attachments,
  515.                                         'toAddress' => $forwardToMailAddress,
  516.                                         'fromAddress' => 'no-reply@buddybee.eu',
  517.                                         'userName' => 'no-reply@buddybee.eu',
  518.                                         'password' => 'Honeybee@0112',
  519.                                         'smtpServer' => 'smtp.hostinger.com',
  520.                                         'smtpPort' => 465,
  521. //                            'emailBody' => $bodyHtml,
  522.                                         'mailTemplate' => $bodyTemplate,
  523.                                         'templateData' => $bodyData,
  524.                                         'embedCompanyImage' => 0,
  525.                                         'companyId' => 0,
  526.                                         'companyImagePath' => ''
  527. //                        'embedCompanyImage' => 1,
  528. //                        'companyId' => $companyId,
  529. //                        'companyImagePath' => $company_data->getImage()
  530.                                     ));
  531.                                 }
  532.                                 if ($meetingId != 0) {
  533.                                     $url $this->generateUrl(
  534.                                         'consultancy_session'
  535.                                     );
  536.                                     $output = [
  537.                                         'invoiceId' => $gatewayInvoice->getId(),
  538.                                         'meetingId' => $meetingId,
  539.                                         'proceedToCheckout' => 0,
  540.                                         'redirectUrl' => $url '/' $meetingId
  541.                                     ];
  542.                                 } else {
  543.                                     $url $this->generateUrl(
  544.                                         $systemType == '_BUDDYBEE_' 'buddybee_dashboard' 'central_landing'
  545.                                     );
  546.                                     $output = [
  547.                                         'invoiceId' => $gatewayInvoice->getId(),
  548.                                         'meetingId' => 0,
  549.                                         'proceedToCheckout' => 0,
  550.                                         'redirectUrl' => $url
  551.                                     ];
  552.                                 }
  553.                                 return new JsonResponse($output);
  554. //                return $this->redirect($url);
  555.                             } else {
  556.                             }
  557. //                $url = $this->generateUrl(
  558. //                    'checkout_page'
  559. //                );
  560. //
  561. //                return $this->redirect($url."?meetingSessionId=".$new->getSessionId().'&invoiceId='.$invoiceId);
  562.                         }
  563.                     }
  564.                 } else {
  565.                     $url $this->generateUrl(
  566.                         'user_login'
  567.                     );
  568.                     $session->set('LAST_REQUEST_URI_BEFORE_LOGIN'$this->generateUrl(
  569.                         'pricing_plan_page', [
  570.                         'autoRedirected' => 1
  571.                     ],
  572.                         UrlGenerator::ABSOLUTE_URL
  573.                     ));
  574.                     $output = [
  575.                         'proceedToCheckout' => 0,
  576.                         'redirectUrl' => $url,
  577.                         'clearLs' => 0
  578.                     ];
  579.                     return new JsonResponse($output);
  580.                 }
  581.                 //now proceed to checkout page if the user has lower balance or recharging
  582.                 //$invoiceDetails = $em->getRepository('CompanyGroupBundle:EntityInvoice')->
  583.             }
  584.         }
  585.         if ($gatewayInvoice) {
  586.             $gatewayProductData json_decode($gatewayInvoice->getProductDataForPaymentGateway(), true);
  587.             if ($gatewayProductData == null$gatewayProductData = [];
  588.             if (empty($gatewayProductData))
  589.                 $gatewayProductData = [
  590.                     [
  591.                         'price_data' => [
  592.                             'currency' => 'eur',
  593.                             'unit_amount' => $gatewayAmount != ? (100 $gatewayAmount) : 200000,
  594.                             'product_data' => [
  595. //                            'name' => $request->request->has('packageName') ? $request->request->get('packageName') : 'Advanced Consultancy Package',
  596.                                 'name' => 'Bee Coins',
  597.                                 'images' => [$imageBySessionCount[0]],
  598.                             ],
  599.                         ],
  600.                         'quantity' => 1,
  601.                     ]
  602.                 ];
  603.             $productDescStr '';
  604.             $productDescArr = [];
  605.             foreach ($gatewayProductData as $gpd) {
  606.                 $productDescArr[] = $gpd['price_data']['product_data']['name'];
  607.             }
  608.             $productDescStr implode(','$productDescArr);
  609.             $paymentGatewayFromInvoice $gatewayInvoice->getAmountTransferGateWayHash();
  610. //            return new JsonResponse(
  611. //                [
  612. //                    'paymentGateway' => $paymentGatewayFromInvoice,
  613. //                    'gateWayData' => $gatewayProductData[0]
  614. //                ]
  615. //            );
  616.             if ($paymentGateway == null$paymentGatewayFromInvoice 'stripe';
  617.             if ($paymentGatewayFromInvoice == 'stripe' || $paymentGatewayFromInvoice == 'aamarpay' || $paymentGatewayFromInvoice == 'bkash') {
  618.                 if (GeneralConstant::EMAIL_ENABLED == 1) {
  619.                     $billerDetails = [];
  620.                     $billToDetails = [];
  621.                     $invoice $gatewayInvoice;
  622.                     if ($invoice) {
  623.                         $billerDetails $em->getRepository('CompanyGroupBundle:EntityApplicantDetails')
  624.                             ->findOneBy(
  625.                                 array(
  626.                                     'applicantId' => $invoice->getBillerId(),
  627.                                 )
  628.                             );
  629.                         $billToDetails $em->getRepository('CompanyGroupBundle:EntityApplicantDetails')
  630.                             ->findOneBy(
  631.                                 array(
  632.                                     'applicantId' => $invoice->getBillToId(),
  633.                                 )
  634.                             );
  635.                     }
  636.                     $bodyTemplate 'ApplicationBundle:email/templates:buddybeeInvoiceEmail.html.twig';
  637.                     $bodyData = array(
  638.                         'page_title' => 'Invoice',
  639. //            'studentDetails' => $student,
  640.                         'billerDetails' => $billerDetails,
  641.                         'billToDetails' => $billToDetails,
  642.                         'invoice' => $invoice,
  643.                         'currencyList' => BuddybeeConstant::$currency_List,
  644.                         'currencyListByMarker' => BuddybeeConstant::$currency_List_by_marker,
  645.                     );
  646.                     $attachments = [];
  647.                     $forwardToMailAddress $billToDetails->getOAuthEmail();
  648. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  649.                     $new_mail $this->get('mail_module');
  650.                     $new_mail->sendMyMail(array(
  651.                         'senderHash' => '_CUSTOM_',
  652.                         //                        'senderHash'=>'_CUSTOM_',
  653.                         'forwardToMailAddress' => $forwardToMailAddress,
  654.                         'subject' => 'YourInvoice #' 'D' str_pad('BB'5'0'STR_PAD_LEFT) . str_pad('76'2'0'STR_PAD_LEFT) . str_pad($invoice->getId(), 8"0"STR_PAD_LEFT) . ' from BuddyBee ',
  655. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  656.                         'attachments' => $attachments,
  657.                         'toAddress' => $forwardToMailAddress,
  658.                         'fromAddress' => 'no-reply@buddybee.eu',
  659.                         'userName' => 'no-reply@buddybee.eu',
  660.                         'password' => 'Honeybee@0112',
  661.                         'smtpServer' => 'smtp.hostinger.com',
  662.                         'smtpPort' => 465,
  663. //                            'emailBody' => $bodyHtml,
  664.                         'mailTemplate' => $bodyTemplate,
  665.                         'templateData' => $bodyData,
  666.                         'embedCompanyImage' => 0,
  667.                         'companyId' => 0,
  668.                         'companyImagePath' => ''
  669. //                        'embedCompanyImage' => 1,
  670. //                        'companyId' => $companyId,
  671. //                        'companyImagePath' => $company_data->getImage()
  672.                     ));
  673.                 }
  674.             }
  675.             if ($paymentGatewayFromInvoice == 'stripe') {
  676.                 $stripe = new \Stripe\Stripe();
  677.                 \Stripe\Stripe::setApiKey('sk_test_51IxYTAJXs21fVb0QMop2Nb0E7u9Da4LwGrym1nGHUHqaSNtT3p9HBgHd7YyDsTKHscgPPECPQniTy79Ab8Sgxfbm00JF2AndUz');
  678.                 $stripe::setApiKey('sk_test_51IxYTAJXs21fVb0QMop2Nb0E7u9Da4LwGrym1nGHUHqaSNtT3p9HBgHd7YyDsTKHscgPPECPQniTy79Ab8Sgxfbm00JF2AndUz');
  679.                 {
  680.                     if ($request->query->has('meetingSessionId'))
  681.                         $id $request->query->get('meetingSessionId');
  682.                 }
  683.                 $paymentIntent = [
  684.                     "id" => "pi_1DoWjK2eZvKYlo2Csy9J3BHs",
  685.                     "object" => "payment_intent",
  686.                     "amount" => 3000,
  687.                     "amount_capturable" => 0,
  688.                     "amount_received" => 0,
  689.                     "application" => null,
  690.                     "application_fee_amount" => null,
  691.                     "canceled_at" => null,
  692.                     "cancellation_reason" => null,
  693.                     "capture_method" => "automatic",
  694.                     "charges" => [
  695.                         "object" => "list",
  696.                         "data" => [],
  697.                         "has_more" => false,
  698.                         "url" => "/v1/charges?payment_intent=pi_1DoWjK2eZvKYlo2Csy9J3BHs"
  699.                     ],
  700.                     "client_secret" => "pi_1DoWjK2eZvKYlo2Csy9J3BHs_secret_vmxAcWZxo2kt1XhpWtZtnjDtd",
  701.                     "confirmation_method" => "automatic",
  702.                     "created" => 1546523966,
  703.                     "currency" => $currencyForGateway,
  704.                     "customer" => null,
  705.                     "description" => null,
  706.                     "invoice" => null,
  707.                     "last_payment_error" => null,
  708.                     "livemode" => false,
  709.                     "metadata" => [],
  710.                     "next_action" => null,
  711.                     "on_behalf_of" => null,
  712.                     "payment_method" => null,
  713.                     "payment_method_options" => [],
  714.                     "payment_method_types" => [
  715.                         "card"
  716.                     ],
  717.                     "receipt_email" => null,
  718.                     "review" => null,
  719.                     "setup_future_usage" => null,
  720.                     "shipping" => null,
  721.                     "statement_descriptor" => null,
  722.                     "statement_descriptor_suffix" => null,
  723.                     "status" => "requires_payment_method",
  724.                     "transfer_data" => null,
  725.                     "transfer_group" => null
  726.                 ];
  727.                 $checkout_session = \Stripe\Checkout\Session::create([
  728.                     'payment_method_types' => ['card'],
  729.                     'line_items' => $gatewayProductData,
  730.                     'mode' => 'payment',
  731.                     'success_url' => $this->generateUrl(
  732.                         'payment_gateway_success',
  733.                         ['encData' => $this->get('url_encryptor')->encrypt(json_encode(array(
  734.                             'invoiceId' => $invoiceId'autoRedirect' => $request->request->get('autoRedirect'1)
  735.                         ))), 'hbeeSessionToken' => $session->get('token'0)], UrlGenerator::ABSOLUTE_URL
  736.                     ),
  737.                     'cancel_url' => $this->generateUrl(
  738.                         'payment_gateway_cancel', ['invoiceId' => $invoiceId'autoRedirect' => $request->request->get('autoRedirect'1), 'hbeeSessionToken' => $session->get('token'0)], UrlGenerator::ABSOLUTE_URL
  739.                     ),
  740.                 ]);
  741.                 $output = [
  742.                     'clientSecret' => $paymentIntent['client_secret'],
  743.                     'id' => $checkout_session->id,
  744.                     'paymentGateway' => $paymentGatewayFromInvoice,
  745.                     'proceedToCheckout' => 1
  746.                 ];
  747.                 return new JsonResponse($output);
  748.             }
  749.             if ($paymentGatewayFromInvoice == 'aamarpay') {
  750.                 $studentDetails $em_goc->getRepository(EntityApplicantDetails::class)->find($gatewayInvoice->getBillToId());
  751.                 $url $sandBoxMode == 'https://sandbox.aamarpay.com/request.php' 'https://secure.aamarpay.com/request.php';
  752.                 $fields = array(
  753. //                    'store_id' => 'aamarpaytest', //store id will be aamarpay,  contact integration@aamarpay.com for test/live id
  754.                     'store_id' => $sandBoxMode == 'aamarpaytest' 'buddybee'//store id will be aamarpay,  contact integration@aamarpay.com for test/live id
  755.                     'amount' => $gatewayInvoice->getGateWayBillamount(), //transaction amount
  756.                     'payment_type' => 'VISA'//no need to change
  757.                     'currency' => strtoupper($currencyForGateway),  //currenct will be USD/BDT
  758.                     'tran_id' => $gatewayInvoice->getDocumentHash(), //transaction id must be unique from your end
  759.                     'cus_name' => $studentDetails->getFirstname() . ' ' $studentDetails->getLastName(),  //customer name
  760.                     'cus_email' => $studentDetails->getEmail(), //customer email address
  761.                     'cus_add1' => $studentDetails->getCurrAddr(),  //customer address
  762.                     'cus_add2' => $studentDetails->getCurrAddrCity(), //customer address
  763.                     'cus_city' => $studentDetails->getCurrAddrCity(),  //customer city
  764.                     'cus_state' => $studentDetails->getCurrAddrState(),  //state
  765.                     'cus_postcode' => $studentDetails->getCurrAddrZip(), //postcode or zipcode
  766.                     'cus_country' => 'Bangladesh',  //country
  767.                     'cus_phone' => ($studentDetails->getPhone() == null || $studentDetails->getPhone() == '') ? '+8801911706483' $studentDetails->getPhone(), //customer phone number
  768.                     'cus_fax' => '',  //fax
  769.                     'ship_name' => ''//ship name
  770.                     'ship_add1' => '',  //ship address
  771.                     'ship_add2' => '',
  772.                     'ship_city' => '',
  773.                     'ship_state' => '',
  774.                     'ship_postcode' => '',
  775.                     'ship_country' => 'Bangladesh',
  776.                     'desc' => $productDescStr,
  777.                     'success_url' => $this->generateUrl(
  778.                         'payment_gateway_success',
  779.                         ['encData' => $this->get('url_encryptor')->encrypt(json_encode(array(
  780.                             'invoiceId' => $invoiceId'autoRedirect' => $request->request->get('autoRedirect'1)
  781.                         ))), 'hbeeSessionToken' => $session->get('token'0)], UrlGenerator::ABSOLUTE_URL
  782.                     ),
  783.                     'fail_url' => $this->generateUrl(
  784.                         'payment_gateway_cancel', ['invoiceId' => $invoiceId'autoRedirect' => $request->request->get('autoRedirect'1), 'hbeeSessionToken' => $session->get('token'0)], UrlGenerator::ABSOLUTE_URL
  785.                     ),
  786.                     'cancel_url' => $this->generateUrl(
  787.                         'payment_gateway_cancel', ['invoiceId' => $invoiceId'autoRedirect' => $request->request->get('autoRedirect'1), 'hbeeSessionToken' => $session->get('token'0)], UrlGenerator::ABSOLUTE_URL
  788.                     ),
  789. //                    'opt_a' => 'Reshad',  //optional paramter
  790. //                    'opt_b' => 'Akil',
  791. //                    'opt_c' => 'Liza',
  792. //                    'opt_d' => 'Sohel',
  793. //                    'signature_key' => 'dbb74894e82415a2f7ff0ec3a97e4183',  //sandbox
  794.                     'signature_key' => $sandBoxMode == 'dbb74894e82415a2f7ff0ec3a97e4183' 'b7304a40e21fe15af3be9a948307f524'  //live
  795.                 ); //signature key will provided aamarpay, contact integration@aamarpay.com for test/live signature key
  796.                 $fields_string http_build_query($fields);
  797. //                $ch = curl_init();
  798. //                curl_setopt($ch, CURLOPT_VERBOSE, true);
  799. //                curl_setopt($ch, CURLOPT_URL, $url);
  800. //
  801. //                curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
  802. //                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  803. //                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  804. //                $url_forward = str_replace('"', '', stripslashes(curl_exec($ch)));
  805. //                curl_close($ch);
  806. //                $this->redirect_to_merchant($url_forward);
  807.                 $output = [
  808. //
  809. //                    'redirectUrl' => ($sandBoxMode == 1 ? 'https://sandbox.aamarpay.com/' : 'https://secure.aamarpay.com/') . $url_forward, //keeping it off temporarily
  810. //                    'fields'=>$fields,
  811. //                    'fields_string'=>$fields_string,
  812. //                    'redirectUrl' => $this->generateUrl(
  813. //                        'payment_gateway_success',
  814. //                        ['encData' => $this->get('url_encryptor')->encrypt(json_encode(array(
  815. //                            'invoiceId' => $invoiceId, 'autoRedirect' => $request->request->get('autoRedirect', 1)
  816. //                        ))), 'hbeeSessionToken' => $request->request->get('token', 0)], UrlGenerator::ABSOLUTE_URL
  817. //                    ),
  818.                     'paymentGateway' => $paymentGatewayFromInvoice,
  819.                     'proceedToCheckout' => 1,
  820.                     'data' => $fields
  821.                 ];
  822.                 return new JsonResponse($output);
  823.             } else if ($paymentGatewayFromInvoice == 'bkash') {
  824.                 $studentDetails $em_goc->getRepository(EntityApplicantDetails::class)->find($gatewayInvoice->getBillToId());
  825.                 $baseUrl = ($sandBoxMode == 1) ? 'https://tokenized.sandbox.bka.sh/v1.2.0-beta' 'https://tokenized.pay.bka.sh/v1.2.0-beta';
  826.                 $username_value = ($sandBoxMode == 1) ? 'sandboxTokenizedUser02' '01891962953';
  827.                 $password_value = ($sandBoxMode == 1) ? 'sandboxTokenizedUser02@12345' ',a&kPV4deq&';
  828.                 $app_key_value = ($sandBoxMode == 1) ? '4f6o0cjiki2rfm34kfdadl1eqq' '2ueVHdwz5gH3nxx7xn8wotlztc';
  829.                 $app_secret_value = ($sandBoxMode == 1) ? '2is7hdktrekvrbljjh44ll3d9l1dtjo4pasmjvs5vl5qr3fug4b' '49Ay3h3wWJMBFD7WF5CassyLrtA1jt6ONhspqjqFx5hTjhqh5dHU';
  830.                 $request_data = array(
  831.                     'app_key' => $app_key_value,
  832.                     'app_secret' => $app_secret_value
  833.                 );
  834.                 $url curl_init($baseUrl '/tokenized/checkout/token/grant');
  835.                 $request_data_json json_encode($request_data);
  836.                 $header = array(
  837.                     'Content-Type:application/json',
  838.                     'username:' $username_value,
  839.                     'password:' $password_value
  840.                 );
  841.                 curl_setopt($urlCURLOPT_HTTPHEADER$header);
  842.                 curl_setopt($urlCURLOPT_CUSTOMREQUEST"POST");
  843.                 curl_setopt($urlCURLOPT_RETURNTRANSFERtrue);
  844.                 curl_setopt($urlCURLOPT_POSTFIELDS$request_data_json);
  845.                 curl_setopt($urlCURLOPT_FOLLOWLOCATION1);
  846.                 curl_setopt($urlCURLOPT_IPRESOLVECURL_IPRESOLVE_V4);
  847.                 $tokenData json_decode(curl_exec($url), true);
  848.                 curl_close($url);
  849.                 $id_token $tokenData['id_token'];
  850.                 $goToBkashPage 0;
  851.                 if ($tokenData['statusCode'] == '0000') {
  852.                     $auth $id_token;
  853.                     $requestbody = array(
  854.                         "mode" => "0011",
  855. //                        "payerReference" => "01723888888",
  856.                         "payerReference" => $invoiceDate->format('U'),
  857.                         "callbackURL" => $this->generateUrl(
  858.                             'bkash_callback', [], UrlGenerator::ABSOLUTE_URL
  859.                         ),
  860. //                    "merchantAssociationInfo" => "MI05MID54RF09123456One",
  861.                         "amount" => number_format($gatewayInvoice->getGateWayBillamount(), 2'.'''),
  862.                         "currency" => "BDT",
  863.                         "intent" => "sale",
  864.                         "merchantInvoiceNumber" => $invoiceId
  865.                     );
  866.                     $url curl_init($baseUrl '/tokenized/checkout/create');
  867.                     $requestbodyJson json_encode($requestbody);
  868.                     $header = array(
  869.                         'Content-Type:application/json',
  870.                         'Authorization:' $auth,
  871.                         'X-APP-Key:' $app_key_value
  872.                     );
  873.                     curl_setopt($urlCURLOPT_HTTPHEADER$header);
  874.                     curl_setopt($urlCURLOPT_CUSTOMREQUEST"POST");
  875.                     curl_setopt($urlCURLOPT_RETURNTRANSFERtrue);
  876.                     curl_setopt($urlCURLOPT_POSTFIELDS$requestbodyJson);
  877.                     curl_setopt($urlCURLOPT_FOLLOWLOCATION1);
  878.                     curl_setopt($urlCURLOPT_IPRESOLVECURL_IPRESOLVE_V4);
  879.                     $resultdata curl_exec($url);
  880. //                    curl_close($url);
  881. //                    echo $resultdata;
  882.                     $obj json_decode($resultdatatrue);
  883.                     $goToBkashPage 1;
  884.                     $justNow = new \DateTime();
  885.                     $justNow->modify('+' $tokenData['expires_in'] . ' second');
  886.                     $gatewayInvoice->setGatewayIdTokenExpireTs($justNow->format('U'));
  887.                     $gatewayInvoice->setGatewayIdToken($tokenData['id_token']);
  888.                     $gatewayInvoice->setGatewayPaymentId($obj['paymentID']);
  889.                     $gatewayInvoice->setGatewayIdRefreshToken($tokenData['refresh_token']);
  890.                     $em->flush();
  891.                     $output = [
  892. //                        'redirectUrl' => $obj['bkashURL'],
  893.                         'paymentGateway' => $paymentGatewayFromInvoice,
  894.                         'proceedToCheckout' => $goToBkashPage,
  895.                         'tokenData' => $tokenData,
  896.                         'obj' => $obj,
  897.                         'id_token' => $tokenData['id_token'],
  898.                         'data' => [
  899.                             'amount' => $gatewayInvoice->getGateWayBillamount(), //transaction amount
  900. //                            'payment_type' => 'VISA', //no need to change
  901.                             'currency' => strtoupper($currencyForGateway),  //currenct will be USD/BDT
  902.                             'tran_id' => $gatewayInvoice->getDocumentHash(), //transaction id must be unique from your end
  903.                             'cus_name' => $studentDetails->getFirstname() . ' ' $studentDetails->getLastName(),  //customer name
  904.                             'cus_email' => $studentDetails->getEmail(), //customer email address
  905.                             'cus_add1' => $studentDetails->getCurrAddr(),  //customer address
  906.                             'cus_add2' => $studentDetails->getCurrAddrCity(), //customer address
  907.                             'cus_city' => $studentDetails->getCurrAddrCity(),  //customer city
  908.                             'cus_state' => $studentDetails->getCurrAddrState(),  //state
  909.                             'cus_postcode' => $studentDetails->getCurrAddrZip(), //postcode or zipcode
  910.                             'cus_country' => 'Bangladesh',  //country
  911.                             'cus_phone' => ($studentDetails->getPhone() == null || $studentDetails->getPhone() == '') ? '+8801911706483' $studentDetails->getPhone(), //customer phone number
  912.                             'cus_fax' => '',  //fax
  913.                             'ship_name' => ''//ship name
  914.                             'ship_add1' => '',  //ship address
  915.                             'ship_add2' => '',
  916.                             'ship_city' => '',
  917.                             'ship_state' => '',
  918.                             'ship_postcode' => '',
  919.                             'ship_country' => 'Bangladesh',
  920.                             'desc' => $productDescStr,
  921.                         ]
  922.                     ];
  923.                     return new JsonResponse($output);
  924.                 }
  925. //                $fields = array(
  926. //
  927. //                    "mode" => "0011",
  928. //                    "payerReference" => "01723888888",
  929. //                    "callbackURL" => $this->generateUrl(
  930. //                        'payment_gateway_success',
  931. //                        ['encData' => $this->get('url_encryptor')->encrypt(json_encode(array(
  932. //                            'invoiceId' => $invoiceId, 'autoRedirect' => $request->request->get('autoRedirect', 1)
  933. //                        ))), 'hbeeSessionToken' => $session->get('token', 0)], UrlGenerator::ABSOLUTE_URL
  934. //                    ),
  935. //                    "merchantAssociationInfo" => "MI05MID54RF09123456One",
  936. //                    "amount" => 1*number_format($gatewayInvoice->getGateWayBillamount(),2,'.',''),,
  937. //                    "currency" => "BDT",
  938. //                    "intent" => "sale",
  939. //                    "merchantInvoiceNumber" => 'BEI' . str_pad($gatewayInvoice->getBillerId(), 3, '0', STR_PAD_LEFT) . str_pad($gatewayInvoice->getBillToId(), 5, '0', STR_PAD_LEFT) . str_pad($gatewayInvoice->getId(), 4, '0', STR_PAD_LEFT)
  940. //
  941. //                );
  942. //                $fields = array(
  943. ////                    'store_id' => 'aamarpaytest', //store id will be aamarpay,  contact integration@aamarpay.com for test/live id
  944. //                    'store_id' => $sandBoxMode == 1 ? 'aamarpaytest' : 'buddybee', //store id will be aamarpay,  contact integration@aamarpay.com for test/live id
  945. //                    'amount' => 1*number_format($gatewayInvoice->getGateWayBillamount(),2,'.',''),, //transaction amount
  946. //                    'payment_type' => 'VISA', //no need to change
  947. //                    'currency' => strtoupper($currencyForGateway),  //currenct will be USD/BDT
  948. //                    'tran_id' => 'BEI' . str_pad($gatewayInvoice->getBillerId(), 3, '0', STR_PAD_LEFT) . str_pad($gatewayInvoice->getBillToId(), 5, '0', STR_PAD_LEFT) . str_pad($gatewayInvoice->getId(), 4, '0', STR_PAD_LEFT), //transaction id must be unique from your end
  949. //                    'cus_name' => $studentDetails->getFirstname() . ' ' . $studentDetails->getLastName(),  //customer name
  950. //                    'cus_email' => $studentDetails->getEmail(), //customer email address
  951. //                    'cus_add1' => $studentDetails->getCurrAddr(),  //customer address
  952. //                    'cus_add2' => $studentDetails->getCurrAddrCity(), //customer address
  953. //                    'cus_city' => $studentDetails->getCurrAddrCity(),  //customer city
  954. //                    'cus_state' => $studentDetails->getCurrAddrState(),  //state
  955. //                    'cus_postcode' => $studentDetails->getCurrAddrZip(), //postcode or zipcode
  956. //                    'cus_country' => 'Bangladesh',  //country
  957. //                    'cus_phone' => ($studentDetails->getPhone() == null || $studentDetails->getPhone() == '') ? ' + 8801911706483' : $studentDetails->getPhone(), //customer phone number
  958. //                    'cus_fax' => '',  //fax
  959. //                    'ship_name' => '', //ship name
  960. //                    'ship_add1' => '',  //ship address
  961. //                    'ship_add2' => '',
  962. //                    'ship_city' => '',
  963. //                    'ship_state' => '',
  964. //                    'ship_postcode' => '',
  965. //                    'ship_country' => 'Bangladesh',
  966. //                    'desc' => $productDescStr,
  967. //                    'success_url' => $this->generateUrl(
  968. //                        'payment_gateway_success',
  969. //                        ['encData' => $this->get('url_encryptor')->encrypt(json_encode(array(
  970. //                            'invoiceId' => $invoiceId, 'autoRedirect' => $request->request->get('autoRedirect', 1)
  971. //                        ))), 'hbeeSessionToken' => $session->get('token', 0)], UrlGenerator::ABSOLUTE_URL
  972. //                    ),
  973. //                    'fail_url' => $this->generateUrl(
  974. //                        'payment_gateway_cancel', ['invoiceId' => $invoiceId, 'autoRedirect' => $request->request->get('autoRedirect', 1), 'hbeeSessionToken' => $session->get('token', 0)], UrlGenerator::ABSOLUTE_URL
  975. //                    ),
  976. //                    'cancel_url' => $this->generateUrl(
  977. //                        'payment_gateway_cancel', ['invoiceId' => $invoiceId, 'autoRedirect' => $request->request->get('autoRedirect', 1), 'hbeeSessionToken' => $session->get('token', 0)], UrlGenerator::ABSOLUTE_URL
  978. //                    ),
  979. ////                    'opt_a' => 'Reshad',  //optional paramter
  980. ////                    'opt_b' => 'Akil',
  981. ////                    'opt_c' => 'Liza',
  982. ////                    'opt_d' => 'Sohel',
  983. ////                    'signature_key' => 'dbb74894e82415a2f7ff0ec3a97e4183',  //sandbox
  984. //                    'signature_key' => $sandBoxMode == 1 ? 'dbb74894e82415a2f7ff0ec3a97e4183' : 'b7304a40e21fe15af3be9a948307f524'  //live
  985. //
  986. //                ); //signature key will provided aamarpay, contact integration@aamarpay.com for test/live signature key
  987. //
  988. //                $fields_string = http_build_query($fields);
  989. //
  990. //                $ch = curl_init();
  991. //                curl_setopt($ch, CURLOPT_VERBOSE, true);
  992. //                curl_setopt($ch, CURLOPT_URL, $url);
  993. //
  994. //                curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
  995. //                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  996. //                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  997. //                $url_forward = str_replace('"', '', stripslashes(curl_exec($ch)));
  998. //                curl_close($ch);
  999. //                $this->redirect_to_merchant($url_forward);
  1000.             } else if ($paymentGatewayFromInvoice == 'onsite_pos' || $paymentGatewayFromInvoice == 'onsite_cash' || $paymentGatewayFromInvoice == 'onsite_bkash') {
  1001.                 $meetingId 0;
  1002.                 if ($gatewayInvoice->getId() != 0) {
  1003.                     if ($gatewayInvoice->getDueAmount() <= 0) {
  1004.                         $retData Buddybee::ProcessEntityInvoice($em_goc$gatewayInvoice->getId(), ['stage' => BuddybeeConstant::ENTITY_INVOICE_STAGE_COMPLETED], false,
  1005.                             $this->container->getParameter('notification_enabled'),
  1006.                             $this->container->getParameter('notification_server')
  1007.                         );
  1008.                         $meetingId $retData['meetingId'];
  1009.                     }
  1010.                     if (GeneralConstant::EMAIL_ENABLED == 1) {
  1011.                         $billerDetails = [];
  1012.                         $billToDetails = [];
  1013.                         $invoice $gatewayInvoice;
  1014.                         if ($invoice) {
  1015.                             $billerDetails $em->getRepository('CompanyGroupBundle:EntityApplicantDetails')
  1016.                                 ->findOneBy(
  1017.                                     array(
  1018.                                         'applicantId' => $invoice->getBillerId(),
  1019.                                     )
  1020.                                 );
  1021.                             $billToDetails $em->getRepository('CompanyGroupBundle:EntityApplicantDetails')
  1022.                                 ->findOneBy(
  1023.                                     array(
  1024.                                         'applicantId' => $invoice->getBillToId(),
  1025.                                     )
  1026.                                 );
  1027.                         }
  1028.                         $bodyTemplate 'ApplicationBundle:email/templates:buddybeeInvoiceEmail.html.twig';
  1029.                         $bodyData = array(
  1030.                             'page_title' => 'Invoice',
  1031. //            'studentDetails' => $student,
  1032.                             'billerDetails' => $billerDetails,
  1033.                             'billToDetails' => $billToDetails,
  1034.                             'invoice' => $invoice,
  1035.                             'currencyList' => BuddybeeConstant::$currency_List,
  1036.                             'currencyListByMarker' => BuddybeeConstant::$currency_List_by_marker,
  1037.                         );
  1038.                         $attachments = [];
  1039.                         $forwardToMailAddress $billToDetails->getOAuthEmail();
  1040. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  1041.                         $new_mail $this->get('mail_module');
  1042.                         $new_mail->sendMyMail(array(
  1043.                             'senderHash' => '_CUSTOM_',
  1044.                             //                        'senderHash'=>'_CUSTOM_',
  1045.                             'forwardToMailAddress' => $forwardToMailAddress,
  1046.                             'subject' => 'YourInvoice #' 'D' str_pad('BB'5'0'STR_PAD_LEFT) . str_pad('76'2'0'STR_PAD_LEFT) . str_pad($invoice->getId(), 8"0"STR_PAD_LEFT) . ' from BuddyBee ',
  1047. //                        'fileName' => 'Order#' . str_pad($id, 8, '0', STR_PAD_LEFT) . '.pdf',
  1048.                             'attachments' => $attachments,
  1049.                             'toAddress' => $forwardToMailAddress,
  1050.                             'fromAddress' => 'no-reply@buddybee.eu',
  1051.                             'userName' => 'no-reply@buddybee.eu',
  1052.                             'password' => 'Honeybee@0112',
  1053.                             'smtpServer' => 'smtp.hostinger.com',
  1054.                             'smtpPort' => 465,
  1055. //                            'emailBody' => $bodyHtml,
  1056.                             'mailTemplate' => $bodyTemplate,
  1057.                             'templateData' => $bodyData,
  1058.                             'embedCompanyImage' => 0,
  1059.                             'companyId' => 0,
  1060.                             'companyImagePath' => ''
  1061. //                        'embedCompanyImage' => 1,
  1062. //                        'companyId' => $companyId,
  1063. //                        'companyImagePath' => $company_data->getImage()
  1064.                         ));
  1065.                     }
  1066.                 }
  1067.                 MiscActions::RefreshBuddybeeBalanceOnSession($em$request->getSession());
  1068.                 if ($meetingId != 0) {
  1069.                     $url $this->generateUrl(
  1070.                         'consultancy_session'
  1071.                     );
  1072.                     $output = [
  1073.                         'proceedToCheckout' => 0,
  1074.                         'invoiceId' => $gatewayInvoice->getId(),
  1075.                         'meetingId' => $meetingId,
  1076.                         'redirectUrl' => $url '/' $meetingId
  1077.                     ];
  1078.                 } else {
  1079.                     $url $this->generateUrl(
  1080.                         'buddybee_dashboard'
  1081.                     );
  1082.                     $output = [
  1083.                         'proceedToCheckout' => 0,
  1084.                         'invoiceId' => $gatewayInvoice->getId(),
  1085.                         'meetingId' => $meetingId,
  1086.                         'redirectUrl' => $url
  1087.                     ];
  1088.                 }
  1089.                 return new JsonResponse($output);
  1090.             }
  1091.         }
  1092.         $output = [
  1093.             'clientSecret' => 0,
  1094.             'id' => 0,
  1095.             'proceedToCheckout' => 0
  1096.         ];
  1097.         return new JsonResponse($output);
  1098. //        return $this->render('ApplicationBundle:pages/stripe:checkout.html.twig', array(
  1099. //            'page_title' => 'Checkout',
  1100. ////            'stripe' => $stripe,
  1101. //            'stripe' => null,
  1102. ////            'PaymentIntent' => $paymentIntent,
  1103. //
  1104. ////            'consultantDetail' => $consultantDetail,
  1105. ////            'consultantDetails'=> $consultantDetails,
  1106. ////
  1107. ////            'meetingSession' => $meetingSession,
  1108. ////            'packageDetails' => json_decode($meetingSession->getPcakageDetails(),true),
  1109. ////            'packageName' => json_decode($meetingSession->getPackageName(),true),
  1110. ////            'pay' => $payableAmount,
  1111. ////            'balance' => $currStudentBal
  1112. //        ));
  1113.     }
  1114.     //changes dev
  1115.     public function AddEmployeeAction(Request $data$id 0)
  1116.     {
  1117.         $em $this->getDoctrine()->getManager();
  1118.         $connection $em->getConnection();
  1119.         $connection->beginTransaction();
  1120.         $skills $em->getRepository(Skill::class)->findAll();
  1121.         $session $data->getSession();
  1122.         $ownOnly 0;
  1123.         $consultancyLevel HumanResourceConstant::$consultantLevel;
  1124.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  1125.         $banks $em->getRepository(BankList::class)->findAll();
  1126.         $bankListObj = [];
  1127.         $id $data->request->get('employeeId'$id);
  1128.         foreach ($banks as $bank) {
  1129.             $bankListObj[$bank->getBankId()] = $bank->getName();
  1130.         }
  1131.         if ($id === "my") {
  1132.             $id $session->get(UserConstants::USER_EMPLOYEE_ID);
  1133.             $ownOnly 1;
  1134.             if ($id == || $id == null) {
  1135.                 return $this->redirectToRoute('permission_denied_page');
  1136.             }
  1137.         }
  1138.         if ($id) {
  1139.             if ($data->isMethod('GET')) {
  1140.                 $Employee $this->getDoctrine()->getRepository(EmployeeDetails::class)->find($id);
  1141.                 if (!$Employee) {
  1142.                     $this->addFlash(
  1143.                         'error',
  1144.                         'Invalid User ID!'
  1145.                     );
  1146.                     return $this->redirectToRoute('add_employee');
  1147.                 } else {
  1148.                     $EmployeeRes HumanResource::TwigDataForAddEmployee($em$id);
  1149.                     $Employee $EmployeeRes['employee'];
  1150.                     $EmployeeMain $EmployeeRes['employeeMain'];
  1151.                     $sysUserId $EmployeeRes['sysId'];
  1152.                     $existingSysUser $sysUserId $em->getRepository('ApplicationBundle:SysUser')->find($sysUserId) : [];
  1153.                     $regionIdsArray json_decode($EmployeeMain->getRegionIds(), true) ?: [];
  1154.                     $regionLeaderFlagsArray json_decode($EmployeeMain->getRegionLeaderFlags(), true) ?: [];
  1155.                     $existingRegionAssociations = [];
  1156.                     if (!empty($regionIdsArray)) {
  1157.                         $regionRepo $this->getDoctrine()->getRepository('ApplicationBundle:Region');
  1158.                         $regions $regionRepo->findBy(['id' => $regionIdsArray]);
  1159.                         $regionMap = [];
  1160.                         foreach ($regions as $region) {
  1161.                             $regionMap[$region->getId()] = $region;
  1162.                         }
  1163.                         foreach ($regionIdsArray as $index => $regionId) {
  1164.                             if (!isset($regionMap[$regionId])) continue;
  1165.                             $region $regionMap[$regionId];
  1166.                             $existingRegionAssociations[] = [
  1167.                                 'regionLevelId' => $region->getRegionLevelId(),
  1168.                                 'regionId' => $region->getId(),
  1169.                                 'isLeader' => isset($regionLeaderFlagsArray[$index]) ? (int)$regionLeaderFlagsArray[$index] : 0
  1170.                             ];
  1171.                         }
  1172.                     }
  1173.                     $TwigData HumanResource::TwigDataForAddEmployee($em0);
  1174.                     return $this->render(
  1175.                         'ApplicationBundle:pages/human_resource/input_forms:add_employee.html.twig',
  1176.                         array(
  1177.                             'page_title' => 'Update Employee',
  1178.                             'ownOnly' => $ownOnly,
  1179.                             'branches' => $TwigData['branches'],
  1180.                             'bankListObj' => $bankListObj,
  1181.                             'heads' => Accounts::getLedgerHeadsWithParents($em),
  1182.                             'departments' => $TwigData['departments'],
  1183.                             'departmentPositions' => $TwigData['departmentPositions'],
  1184.                             'regions' => $TwigData['regions'],
  1185.                             'supervisors' => $TwigData['supervisors'],
  1186.                             'sysUsers' => $TwigData['sysUser'],
  1187.                             'EmploymentStatus' => $TwigData['EmploymentStatus'],
  1188.                             'sex' => $TwigData['sex'],
  1189.                             'BloodGroup' => $TwigData['BloodGroup'],
  1190.                             'days' => $TwigData['days'],
  1191.                             'employeeMain' => $EmployeeMain,
  1192.                             'employee' => $Employee,
  1193.                             'skills' => $skills,
  1194.                             'existingSysUser' => $existingSysUser,
  1195.                             'id' => $id,
  1196.                             'default_route' => $EmployeeRes['defaultRoute'],
  1197.                             'user_type' => $EmployeeRes['userType'],
  1198.                             'user_type_data' => HumanResourceConstant::$userType,
  1199.                             'AccountTypes' => $TwigData['AccountType'],
  1200.                             'weekends' => explode(','$Employee->getWeeklyHoliday()),
  1201.                             'consultancyLevel' => $consultancyLevel,
  1202.                             'module_data_array' => $TwigData['module_data_array'],
  1203.                             'HasUpdateMode' => true,
  1204.                             'brand_list' => Inventory::GetBrandList($em$this->getLoggedUserCompanyId($data)),
  1205.                             'branch_list' => Client::BranchList($this->getDoctrine()->getManager(), $this->getLoggedUserCompanyId($data)),
  1206.                             'region_data' => Client::RegionList($this->getDoctrine()->getManager(), $this->getLoggedUserCompanyId($data)),
  1207.                             'leaveSettings' => $TwigData['leaveSettings'],
  1208.                             'leaveData' => $EmployeeRes['leaveData'],
  1209.                             'positions' => $EmployeeRes['positions'],
  1210.                             'existing_region_associations' => $existingRegionAssociations
  1211.                         )
  1212.                     );
  1213.                 }
  1214.             } else {
  1215.                 $approveHash $data->request->get('approvalHash');
  1216.                 $loginId $data->getSession()->get(UserConstants::USER_LOGIN_ID);
  1217.                 $isSignatureOk DocValidation::isSignatureOk($em$loginId$approveHash);
  1218.                 $upl_dir $this->container->getParameter('kernel.root_dir') . '/../web/uploads/Users/';
  1219.                 $image $data->files->get('img');
  1220.                 $profileImage $this->uploadImage($image$data);
  1221.                 $path '';
  1222.                 if ($isSignatureOk) {
  1223.                     $CompanyId $this->getLoggedUserCompanyId($data);
  1224.                     $user $em->getRepository('ApplicationBundle:SysUser')->findOneBy(['email' => $data->get('email')]);
  1225.                     if ($user) {
  1226.                         $sysUserId $user->getUserId();
  1227.                         $message $this->get('user_module')->updateUser(
  1228.                             $sysUserId,
  1229.                             $data->request->get('firstname') . " " $data->request->get('lastname'),
  1230.                             $data->request->has('email') ? $data->request->get('email') : '_UNCHANGED_',
  1231.                             $data->request->has('username') ? $data->request->get('username') : '_UNCHANGED_',
  1232.                             $data->request->get('password'),
  1233.                             1,
  1234.                             $data->request->get('user_type''_UNCHANGED_'),
  1235.                             $data->request->get('supervisor'),
  1236.                             $data->request->get('default_route'),
  1237.                             $data->request->get('branch'),
  1238.                             $data->request->has('access_module') ? 0,
  1239.                             $data->getSession()->get(UserConstants::USER_LOGIN_ID),
  1240.                             $data->request->get('global_user_id'null),
  1241.                             $profileImage,
  1242.                             $upl_dir
  1243.                         );
  1244.                         if (isset($message[0]) && $message[0] === 'success') {
  1245.                             HumanResource::StoreDataForAddEmployee($em$data$id$CompanyId$profileImage);
  1246.                             $connection->commit();
  1247.                             if ($systemType == '_CENTRAL_') {
  1248.                             } else {
  1249.                                 $Employee $em->getRepository(Employee::class)->find($id);
  1250.                                 $EmployeeDetails $em->getRepository(EmployeeDetails::class)->findOneBy(
  1251.                                     array(
  1252.                                         'id' => $id
  1253.                                     )
  1254.                                 );
  1255.                                 $em_goc $this->getDoctrine()->getManager('company_group');
  1256.                                 $em_goc->getConnection()->connect();
  1257.                                 $connected $em_goc->getConnection()->isConnected();
  1258.                                 $gocDataList = [];
  1259.                                 $gocDataListByAppId = [];
  1260.                                 $retDataDebug = array();
  1261.                                 $appIds $message[3]->getUserAppId();
  1262.                                 $userIds $message[3]->getUserId();
  1263.                                 if ($connected) {
  1264.                                     $findByQuery = array(
  1265.                                         'active' => 1
  1266.                                     );
  1267.                                     if ($appIds !== '_UNSET_')
  1268.                                         $findByQuery['appId'] = $appIds;
  1269.                                     $gocList $this->getDoctrine()->getManager('company_group')
  1270.                                         ->getRepository("CompanyGroupBundle:CompanyGroup")
  1271.                                         ->findBy($findByQuery);
  1272.                                     foreach ($gocList as $entry) {
  1273.                                         $d = array(
  1274.                                             'name' => $entry->getName(),
  1275.                                             'id' => $entry->getId(),
  1276.                                             'image' => $entry->getImage(),
  1277.                                             'companyGroupHash' => $entry->getCompanyGroupHash(),
  1278.                                             'dbName' => $entry->getDbName(),
  1279.                                             'dbUser' => $entry->getDbUser(),
  1280.                                             'dbPass' => $entry->getDbPass(),
  1281.                                             'dbHost' => $entry->getDbHost(),
  1282.                                             'appId' => $entry->getAppId(),
  1283.                                             'companyRemaining' => $entry->getCompanyRemaining(),
  1284.                                             'companyAllowed' => $entry->getCompanyAllowed(),
  1285.                                         );
  1286.                                         $gocDataList[$entry->getId()] = $d;
  1287.                                         $gocDataListByAppId[$entry->getAppId()] = $d;
  1288.                                     }
  1289.                                     $debugCount 0;
  1290.                                     foreach ($gocDataList as $gocId => $entry) {
  1291.                                         $skipSend 1;
  1292.                                         $connector $this->container->get('application_connector');
  1293.                                         $connector->resetConnection(
  1294.                                             'default',
  1295.                                             $gocDataList[$gocId]['dbName'],
  1296.                                             $gocDataList[$gocId]['dbUser'],
  1297.                                             $gocDataList[$gocId]['dbPass'],
  1298.                                             $gocDataList[$gocId]['dbHost'],
  1299.                                             $reset true);
  1300.                                         $em $this->getDoctrine()->getManager();
  1301.                                         if ($userIds !== '_UNSET_')
  1302.                                             $users $this->getDoctrine()
  1303.                                                 ->getRepository('ApplicationBundle:SysUser')
  1304.                                                 ->findBy(
  1305.                                                     array(
  1306.                                                         'userId' => $userIds
  1307.                                                     )
  1308.                                                 );
  1309.                                         else
  1310.                                             $users $this->getDoctrine()
  1311.                                                 ->getRepository('ApplicationBundle:SysUser')
  1312.                                                 ->findBy(
  1313.                                                     array()
  1314.                                                 );
  1315.                                         $output '';
  1316.                                         $userData = array();
  1317.                                         $userFiles = array();
  1318.                                         foreach ($users as $user) {
  1319.                                             $file $this->container->getParameter('kernel.root_dir') . '/../web/' $user->getImage();
  1320.                                             if ($user->getImage() != '' && $user->getImage() != null && file_exists($file)) {
  1321.                                                 $mime mime_content_type($file);
  1322.                                                 $info pathinfo($file);
  1323.                                                 $name $info['basename'];
  1324.                                                 if (strpos($mime'image') !== false) {
  1325.                                                     $output = new \CURLFile($file$mime$name);
  1326.                                                 }
  1327.                                                 $skipSend 0;
  1328.                                                 $userFiles['file_' $user->getUserAppId() . '_' $user->getUserId()] = $output;
  1329.                                             } else {
  1330.                                                 $user->setImage(null);
  1331.                                                 $userFiles['file_' $user->getUserAppId() . '_' $user->getUserId()] = 'pika';
  1332.                                                 $em->flush();
  1333.                                             }
  1334.                                             $getters array_filter(get_class_methods($user), function ($method) {
  1335.                                                 return 'get' === substr($method03);
  1336.                                             });
  1337.                                             $userDataSingle = array();
  1338.                                             foreach ($getters as $getter) {
  1339.                                                 if ($getter == 'getCreatedAt' || $getter == 'getUpdatedAt' || $getter == 'getImage')
  1340.                                                     continue;
  1341.                                                 if ($user->{$getter}() instanceof \DateTime) {
  1342.                                                     $ggtd $user->{$getter}();
  1343.                                                     $userDataSingle[$getter] = $ggtd->format('Y-m-d');
  1344.                                                 } else
  1345.                                                     $userDataSingle[$getter] = $user->{$getter}();
  1346.                                             }
  1347.                                             $employeeGetters = array(
  1348.                                                 'getFirstname''getLastname''getImage''getIsImgLegal''getNid''getDob''getSex''getReligion''getFather',
  1349.                                                 'getMother''getSpouse''getChild1''getChild2''getBlood''getPhone''getOfficailPhone''getCurrAddr',
  1350.                                                 'getCurrAddrLat''getCurrAddrLng''getPermAddr''getEmmContact''getUsername''getEmail''getPassword',
  1351.                                                 'getUserId''getJoiningDate''getEmpValidTill''getEmpStatus''getEmpType''getEmpCode''getEmpLabel''getTin',
  1352.                                                 'getTinValidTill''getMedIns''getMedInsValidTill''getDocs''getNocApproval''getInst1''getYr1''getDur1',
  1353.                                                 'getInst2''getYr2''getDur2''getInst3''getYr3''getDur3''getEinst1''getEyr1''getEdeg1''getEinst2',
  1354.                                                 'getEyr2''getEdeg2''getEinst3''getEyr3''getEdeg3''getBankAcc''getBankAccType''getBankAccValidFrom',
  1355.                                                 'getBankAccValidTo''getRoutingCode''getSwiftCode''getEar1''getEar2''getEar3''getEar4''getEar5''getEar6',
  1356.                                                 'getEart''getDed1''getDed2''getDed3''getDed4''getDedt''getPayable''getHandCash''getBankTransfer',
  1357.                                                 'getSecDep''getSecDepSpan''getSecDepRemMon''getSecDepRemAmount''getSlQty''getSlTkn''getSlFreq''getMlQty',
  1358.                                                 'getMlTkn''getMlFreq''getElQty''getElTkn''getElFreq''getClQty''getClTkn''getClFreq''getLevt',
  1359.                                                 'getWeeklyHoliday''getFiles''getSupervisor''getDept''getDesg''getBranch''getDivision''getCreatedAt',
  1360.                                                 'getUpdatedAt''getEmployeeLevel''getSkill''getProbationaryPeriod''getDocBookedFlag''getTimeStampOfForm',
  1361.                                                 'getIsConsultant''getConsultantLevel''getApplicationText''getCurrentEmployment''getEmergencyContactNumber',
  1362.                                                 'getPostalCode''getCountry''getEducationData''getWorkExperienceData''getCertificateData''getLanguagesData',
  1363.                                                 'getBeneficiaryName''getBankName''getBranchName''getClockedIn'
  1364.                                             );
  1365.                                             foreach ($employeeGetters as $getter) {
  1366.                                                 if (!method_exists($EmployeeDetails$getter)) continue;
  1367.                                                 try {
  1368.                                                     $value $EmployeeDetails->{$getter}();
  1369.                                                     if ($value instanceof \DateTime) {
  1370.                                                         $userDataSingle[$getter] = $value->format('Y-m-d');
  1371.                                                     } elseif (is_object($value)) {
  1372.                                                         continue;
  1373.                                                     } else {
  1374.                                                         $userDataSingle[$getter] = $value;
  1375.                                                     }
  1376.                                                 } catch (\Exception $e) {
  1377.                                                     continue;
  1378.                                                 }
  1379.                                             }
  1380.                                             $userData[] = $userDataSingle;
  1381.                                         }
  1382.                                         $retDataDebug[$debugCount] = array(
  1383.                                             'skipSend' => $skipSend
  1384.                                         );
  1385.                                         {
  1386.                                             $urlToCall GeneralConstant::HONEYBEE_CENTRAL_SERVER '/SyncUserToCentralUser';
  1387.                                             $userFiles['userData'] = json_encode($userData);
  1388.                                             $curl curl_init();
  1389.                                             curl_setopt_array($curl, array(
  1390.                                                 CURLOPT_RETURNTRANSFER => 1,
  1391.                                                 CURLOPT_POST => 1,
  1392.                                                 CURLOPT_URL => $urlToCall,
  1393.                                                 CURLOPT_CONNECTTIMEOUT => 10,
  1394.                                                 CURLOPT_SSL_VERIFYPEER => false,
  1395.                                                 CURLOPT_SSL_VERIFYHOST => false,
  1396.                                                 CURLOPT_HTTPHEADER => array(),
  1397.                                                 CURLOPT_POSTFIELDS => $userFiles
  1398.                                             ));
  1399.                                             $retData curl_exec($curl);
  1400.                                             $errData curl_error($curl);
  1401.                                             curl_close($curl);
  1402.                                             $retDataObj json_decode($retDatatrue);
  1403.                                             $retDataDebug[$debugCount] = $retDataObj;
  1404.                                             if (isset($retDataObj['globalIdsData']))
  1405.                                                 foreach ($retDataObj['globalIdsData'] as $app_id => $usrList) {
  1406.                                                     $connector $this->container->get('application_connector');
  1407.                                                     $connector->resetConnection(
  1408.                                                         'default',
  1409.                                                         $gocDataListByAppId[$app_id]['dbName'],
  1410.                                                         $gocDataListByAppId[$app_id]['dbUser'],
  1411.                                                         $gocDataListByAppId[$app_id]['dbPass'],
  1412.                                                         $gocDataListByAppId[$app_id]['dbHost'],
  1413.                                                         $reset true);
  1414.                                                     $em $this->getDoctrine()->getManager();
  1415.                                                     foreach ($usrList as $sys_id => $globaldata) {
  1416.                                                         $user $this->getDoctrine()
  1417.                                                             ->getRepository('ApplicationBundle:SysUser')
  1418.                                                             ->findOneBy(
  1419.                                                                 array(
  1420.                                                                     'userId' => $sys_id
  1421.                                                                 )
  1422.                                                             );
  1423.                                                         if ($user) {
  1424.                                                             $user->setGlobalId($globaldata['gid']);
  1425.                                                             $em->flush();
  1426.                                                         }
  1427.                                                     }
  1428.                                                 }
  1429.                                         }
  1430.                                         $debugCount++;
  1431.                                     }
  1432.                                 }
  1433.                             }
  1434.                         } else {
  1435.                             $errorMsg $message['message'] ?? 'Unknown error occurred.';
  1436.                             $this->addFlash('error'$errorMsg);
  1437.                             return $this->redirectToRoute('add_employee');
  1438.                         }
  1439.                         $userType $data->getSession()->get(UserConstants::USER_TYPE);
  1440.                         $redirctUrl $this->generateUrl('employee_list', [], UrlGenerator::ABSOLUTE_URL);
  1441.                         if ($userType == 1) {
  1442.                             $redirctUrl $this->generateUrl('employee_list', [], UrlGenerator::ABSOLUTE_URL);
  1443.                         } else {
  1444.                             $redirctUrl $this->generateUrl('edit_employee', [], UrlGenerator::ABSOLUTE_URL) . '/my';
  1445.                         }
  1446.                         return new JsonResponse(array(
  1447.                             'employeeId' => $Employee->getEmployeeId(),
  1448.                             'redirectToNew' => 0,
  1449.                             'success' => true,
  1450.                             'redirectUrl' => $redirctUrl,
  1451.                         ));
  1452.                     }
  1453.                 } else {
  1454.                     $this->addFlash(
  1455.                         'error',
  1456.                         'Invalid Approval Hash!'
  1457.                     );
  1458.                     return $this->redirectToRoute('add_employee');
  1459.                 }
  1460.             }
  1461.         } else {
  1462.             if ($data->isMethod('GET')) {
  1463.                 $TwigData HumanResource::TwigDataForAddEmployee($em0);
  1464.                 $existingRegionAssociations = [];
  1465.                 return $this->render(
  1466.                     'ApplicationBundle:pages/human_resource/input_forms:add_employee.html.twig',
  1467.                     array(
  1468.                         'page_title' => 'Add Employee',
  1469.                         'ownOnly' => $ownOnly,
  1470.                         'heads' => Accounts::getLedgerHeadsWithParents($em),
  1471.                         'bankListObj' => $bankListObj,
  1472.                         'branches' => $TwigData['branches'],
  1473.                         'departments' => $TwigData['departments'],
  1474.                         'departmentPositions' => $TwigData['departmentPositions'],
  1475.                         'regions' => $TwigData['regions'],
  1476.                         'supervisors' => $TwigData['supervisors'],
  1477.                         'sysUsers' => $TwigData['sysUser'],
  1478.                         'EmploymentStatus' => $TwigData['EmploymentStatus'],
  1479.                         'sex' => $TwigData['sex'],
  1480.                         'skills' => $skills,
  1481.                         'id' => $id,
  1482.                         'consultancyLevel' => $consultancyLevel,
  1483.                         'existingSysUser' => null,
  1484.                         'BloodGroup' => $TwigData['BloodGroup'],
  1485.                         'days' => $TwigData['days'],
  1486.                         'AccountTypes' => $TwigData['AccountType'],
  1487.                         'module_data_array' => $TwigData['module_data_array'],
  1488.                         'user_type_data' => HumanResourceConstant::$userType,
  1489.                         'HasUpdateMode' => false,
  1490.                         'brand_list' => Inventory::GetBrandList($em$this->getLoggedUserCompanyId($data)),
  1491.                         'leaveSettings' => $TwigData['leaveSettings'],
  1492.                         'employee' => [],
  1493.                         'positions' => $TwigData['positions'],
  1494.                         'existing_region_associations' => $existingRegionAssociations ?? [],
  1495.                         'branch_list' => Client::BranchList($this->getDoctrine()->getManager(), $this->getLoggedUserCompanyId($data)),
  1496.                         'region_data' => Client::RegionList($this->getDoctrine()->getManager(), $this->getLoggedUserCompanyId($data)),
  1497.                     )
  1498.                 );
  1499.             } else {
  1500.                 try {
  1501.                     $approveHash $data->request->get('approvalHash');
  1502.                     $loginId $data->getSession()->get(UserConstants::USER_LOGIN_ID);
  1503.                     $CompanyId $this->getLoggedUserCompanyId($data);
  1504.                     $isSignatureOk DocValidation::isSignatureOk($em$loginId$approveHash);
  1505.                     if (!$isSignatureOk) {
  1506.                         $this->addFlash('error''Invalid Approval Hash!');
  1507.                         return $this->redirectToRoute('add_employee');
  1508.                     }
  1509.                     $message $this->get('user_module')->addNewUser(
  1510.                         $data->request->get('firstname') . " " $data->request->get('lastname'),
  1511.                         $data->request->get('email'),
  1512.                         $data->request->get('username'),
  1513.                         $data->request->get('password'),
  1514.                         $data->request->get('desg'),
  1515.                         $this->getLoggedUserLoginId($data),
  1516.                         $data->request->get('company'),
  1517.                         $data->request->get('user_type'),
  1518.                         $data->request->get('companyIdList'),
  1519.                         $data->request->get('branch'),
  1520.                         $data->request->get('supervisor'),
  1521.                         $data->request->get('default_route'),
  1522.                         $data->request->has('access_module') ? 0,
  1523.                         "",
  1524.                         $data->files->get('img'),
  1525.                         '',
  1526.                         00,
  1527.                         ''''''0''0,
  1528.                         $data->request->get('global_user_id'null)
  1529.                     );
  1530.                     if ($message[0] === 'error') {
  1531.                         $this->addFlash('error''Invalid Approval Hash!');
  1532.                         return $this->redirectToRoute('add_employee');
  1533.                     }
  1534.                     $isSuccess HumanResource::StoreDataForAddEmployee($em$datafalse$CompanyId);
  1535.                     $Employee $isSuccess;
  1536.                     $EmployeeDetails $em->getRepository(EmployeeDetails::class)->findOneBy(['id' => $id]);
  1537.                     $Employee->setUserId($message[3]->getUserId());
  1538.                     $em->persist($Employee);
  1539.                     if ($EmployeeDetails) {
  1540.                         $EmployeeDetails->setUserId($message[3]->getUserId());
  1541.                         $em->persist($EmployeeDetails);
  1542.                     }
  1543.                     $em->flush();
  1544.                     $connection->commit();
  1545.                 } catch(Throwable $e) {
  1546.                     $connection->rollBack();
  1547.                     $em->close();
  1548.                     $this->addFlash('error''Failed to save employee: ' $e->getMessage());
  1549.                     return $this->redirectToRoute('add_employee');
  1550.                 }
  1551.                 if ($systemType !== '_CENTRAL_') {
  1552.                     $em_goc $this->getDoctrine()->getManager('company_group');
  1553.                     $em_goc->getConnection()->connect();
  1554.                     $connected $em_goc->getConnection()->isConnected();
  1555.                     if ($connected) {
  1556.                         $appIds $message[2]->getAppId();
  1557.                         $userIds $message[3]->getUserId();
  1558.                         $findByQuery = ['active' => 1];
  1559.                         if ($appIds !== '_UNSET_'$findByQuery['appId'] = $appIds;
  1560.                         $gocList $em_goc->getRepository("CompanyGroupBundle:CompanyGroup")->findBy($findByQuery);
  1561.                         $gocDataList $gocDataListByAppId = [];
  1562.                         foreach ($gocList as $entry) {
  1563.                             $d = [
  1564.                                 'name' => $entry->getName(),
  1565.                                 'id' => $entry->getId(),
  1566.                                 'image' => $entry->getImage(),
  1567.                                 'companyGroupHash' => $entry->getCompanyGroupHash(),
  1568.                                 'dbName' => $entry->getDbName(),
  1569.                                 'dbUser' => $entry->getDbUser(),
  1570.                                 'dbPass' => $entry->getDbPass(),
  1571.                                 'dbHost' => $entry->getDbHost(),
  1572.                                 'appId' => $entry->getAppId(),
  1573.                                 'companyRemaining' => $entry->getCompanyRemaining(),
  1574.                                 'companyAllowed' => $entry->getCompanyAllowed(),
  1575.                             ];
  1576.                             $gocDataList[$entry->getId()] = $d;
  1577.                             $gocDataListByAppId[$entry->getAppId()] = $d;
  1578.                         }
  1579.                         $debugCount 0;
  1580.                         foreach ($gocDataList as $gocId => $entry) {
  1581.                             $skipSend 1;
  1582.                             $connector $this->container->get('application_connector');
  1583.                             $connector->resetConnection(
  1584.                                 'default',
  1585.                                 $entry['dbName'],
  1586.                                 $entry['dbUser'],
  1587.                                 $entry['dbPass'],
  1588.                                 $entry['dbHost'],
  1589.                                 $reset true
  1590.                             );
  1591.                             $em $this->getDoctrine()->getManager();
  1592.                             $users = ($userIds !== '_UNSET_')
  1593.                                 ? $this->getDoctrine()->getRepository('ApplicationBundle:SysUser')->findBy(['userId' => $userIds])
  1594.                                 : $this->getDoctrine()->getRepository('ApplicationBundle:SysUser')->findBy([]);
  1595.                             $userData $userFiles = [];
  1596.                             foreach ($users as $user) {
  1597.                                 $filePath $this->container->getParameter('kernel.root_dir') . '/../web/' $user->getImage();
  1598.                                 if ($user->getImage() && file_exists($filePath)) {
  1599.                                     $mime mime_content_type($filePath);
  1600.                                     $info pathinfo($filePath);
  1601.                                     $name $info['basename'];
  1602.                                     if (strpos($mime'image') !== false) {
  1603.                                         $userFiles['file_' $user->getUserAppId() . '_' $user->getUserId()] = new \CURLFile($filePath$mime$name);
  1604.                                         $skipSend 0;
  1605.                                     }
  1606.                                 } else {
  1607.                                     $user->setImage(null);
  1608.                                     $userFiles['file_' $user->getUserAppId() . '_' $user->getUserId()] = 'pika';
  1609.                                     $em->flush();
  1610.                                 }
  1611.                                 $getters array_filter(get_class_methods($user), function ($m) {
  1612.                                     return substr($m03) === 'get';
  1613.                                 });
  1614.                                 $userDataSingle = [];
  1615.                                 foreach ($getters as $getter) {
  1616.                                     if (in_array($getter, ['getCreatedAt''getUpdatedAt''getImage'])) continue;
  1617.                                     $val $user->{$getter}();
  1618.                                     $userDataSingle[$getter] = $val instanceof \DateTime $val->format('Y-m-d') : $val;
  1619.                                 }
  1620.                                 $employeeGetters = [
  1621.                                     'getFirstname''getLastname''getImage''getIsImgLegal''getNid''getDob''getSex''getReligion',
  1622.                                     'getFather''getMother''getSpouse''getChild1''getChild2''getBlood''getPhone''getOfficailPhone',
  1623.                                     'getCurrAddr''getCurrAddrLat''getCurrAddrLng''getPermAddr''getEmmContact''getUsername''getEmail',
  1624.                                     'getPassword''getUserId''getJoiningDate''getEmpValidTill''getEmpStatus''getEmpType''getEmpCode',
  1625.                                     'getEmpLabel''getTin''getTinValidTill''getMedIns''getMedInsValidTill''getDocs''getNocApproval',
  1626.                                     'getInst1''getYr1''getDur1''getInst2''getYr2''getDur2''getInst3''getYr3''getDur3''getEinst1',
  1627.                                     'getEyr1''getEdeg1''getEinst2''getEyr2''getEdeg2''getEinst3''getEyr3''getEdeg3''getBankAcc',
  1628.                                     'getBankAccType''getBankAccValidFrom''getBankAccValidTo''getRoutingCode''getSwiftCode''getEar1',
  1629.                                     'getEar2''getEar3''getEar4''getEar5''getEar6''getEart''getDed1''getDed2''getDed3''getDed4',
  1630.                                     'getDedt''getPayable''getHandCash''getBankTransfer''getSecDep''getSecDepSpan''getSecDepRemMon',
  1631.                                     'getSecDepRemAmount''getSlQty''getSlTkn''getSlFreq''getMlQty''getMlTkn''getMlFreq''getElQty',
  1632.                                     'getElTkn''getElFreq''getClQty''getClTkn''getClFreq''getLevt''getWeeklyHoliday''getFiles',
  1633.                                     'getSupervisor''getDept''getDesg''getBranch''getDivision''getCreatedAt''getUpdatedAt',
  1634.                                     'getEmployeeLevel''getSkill''getProbationaryPeriod''getDocBookedFlag''getTimeStampOfForm',
  1635.                                     'getIsConsultant''getConsultantLevel''getApplicationText''getCurrentEmployment''getEmergencyContactNumber',
  1636.                                     'getPostalCode''getCountry''getEducationData''getWorkExperienceData''getCertificateData''getLanguagesData',
  1637.                                     'getBeneficiaryName''getBankName''getBranchName''getClockedIn'
  1638.                                 ];
  1639.                                 foreach ($employeeGetters as $getter) {
  1640.                                     if (!method_exists($EmployeeDetails$getter)) continue;
  1641.                                     $value $EmployeeDetails->{$getter}();
  1642.                                     if ($value instanceof \DateTime$userDataSingle[$getter] = $value->format('Y-m-d');
  1643.                                     elseif (!is_object($value)) $userDataSingle[$getter] = $value;
  1644.                                 }
  1645.                                 $userData[] = $userDataSingle;
  1646.                             }
  1647.                             $retDataDebug[$debugCount] = ['skipSend' => $skipSend];
  1648.                             $urlToCall GeneralConstant::HONEYBEE_CENTRAL_SERVER '/SyncUserToCentralUser';
  1649.                             $userFiles['userData'] = json_encode($userData);
  1650.                             $curl curl_init();
  1651.                             curl_setopt_array($curl, [
  1652.                                 CURLOPT_RETURNTRANSFER => 1,
  1653.                                 CURLOPT_POST => 1,
  1654.                                 CURLOPT_URL => $urlToCall,
  1655.                                 CURLOPT_CONNECTTIMEOUT => 10,
  1656.                                 CURLOPT_SSL_VERIFYPEER => false,
  1657.                                 CURLOPT_SSL_VERIFYHOST => false,
  1658.                                 CURLOPT_POSTFIELDS => $userFiles
  1659.                             ]);
  1660.                             $retData curl_exec($curl);
  1661.                             $errData curl_error($curl);
  1662.                             curl_close($curl);
  1663.                             $retDataObj $errData ? ['status' => 'error''message' => 'cURL Error: ' $errData] : json_decode($retDatatrue);
  1664.                             $retDataDebug[$debugCount] = $retDataObj;
  1665.                             if (isset($retDataObj['globalIdsData'])) {
  1666.                                 foreach ($retDataObj['globalIdsData'] as $app_id => $usrList) {
  1667.                                     $connector->resetConnection(
  1668.                                         'default',
  1669.                                         $gocDataListByAppId[$app_id]['dbName'],
  1670.                                         $gocDataListByAppId[$app_id]['dbUser'],
  1671.                                         $gocDataListByAppId[$app_id]['dbPass'],
  1672.                                         $gocDataListByAppId[$app_id]['dbHost'],
  1673.                                         $reset true
  1674.                                     );
  1675.                                     $em $this->getDoctrine()->getManager();
  1676.                                     foreach ($usrList as $sys_id => $globaldata) {
  1677.                                         $user $this->getDoctrine()->getRepository('ApplicationBundle:SysUser')->findOneBy(['userId' => $sys_id]);
  1678.                                         if ($user) {
  1679.                                             $user->setGlobalId($globaldata['gid']);
  1680.                                             $em->persist($user);
  1681.                                             $em->flush();
  1682.                                         }
  1683.                                     }
  1684.                                 }
  1685.                             }
  1686.                             $debugCount++;
  1687.                         }
  1688.                     }
  1689.                 }
  1690.                 $companyData $message[2];
  1691.                 if ($message[0] === 'success' && GeneralConstant::EMAIL_ENABLED == 1) {
  1692.                     $bodyTemplate 'ApplicationBundle:email/user:registration.html.twig';
  1693.                     $bodyData = [
  1694.                         'name' => $data->request->get('name'),
  1695.                         'companyData' => $companyData,
  1696.                         'userName' => $data->request->get('username'),
  1697.                         'password' => $data->request->get('password'),
  1698.                     ];
  1699.                     $new_mail $this->get('mail_module');
  1700.                     $new_mail->sendMyMail([
  1701.                         'senderHash' => '_CUSTOM_',
  1702.                         'forwardToMailAddress' => $data->request->get('email'),
  1703.                         'subject' => 'User Registration on HoneyBee Ecosystem under Entity ' $companyData->getName(),
  1704.                         'fileName' => '',
  1705.                         'attachments' => [],
  1706.                         'toAddress' => $data->request->get('email'),
  1707.                         'fromAddress' => 'no-reply@ourhoneybee.eu',
  1708.                         'userName' => 'no-reply@ourhoneybee.eu',
  1709.                         'password' => 'Y41dh8g0112',
  1710.                         'smtpServer' => 'smtp.hostinger.com',
  1711.                         'smtpPort' => 465,
  1712.                         'mailTemplate' => $bodyTemplate,
  1713.                         'templateData' => $bodyData,
  1714.                         'embedCompanyImage' => 1,
  1715.                         'companyId' => $data->request->get('company'),
  1716.                         'companyImagePath' => $companyData->getImage()
  1717.                     ]);
  1718.                 }
  1719.                 $this->addFlash('success''New Employee Successfully Added!');
  1720.                 $userType $data->getSession()->get(UserConstants::USER_TYPE);
  1721.                 $redirectUrl $userType == 1
  1722.                     $this->generateUrl('employee_list', [], UrlGenerator::ABSOLUTE_URL)
  1723.                     : $this->generateUrl('add_employee', [], UrlGenerator::ABSOLUTE_URL);
  1724.                 return new JsonResponse([
  1725.                     'employeeId' => $Employee->getEmployeeId(),
  1726.                     'redirectToNew' => 1,
  1727.                     'success' => true,
  1728.                     'redirectUrl' => $redirectUrl,
  1729.                 ]);
  1730.             }
  1731.         }
  1732.     }
  1733.     public function AddNewEmployeeAction(Request $request$id)
  1734.     {
  1735.         $em $this->getDoctrine()->getManager();
  1736.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  1737.         $approveHash $request->request->get('approvalHash');
  1738.         $loginId $request->getSession()->get(UserConstants::USER_LOGIN_ID);
  1739.         $CompanyId $this->getLoggedUserCompanyId($request);
  1740.         $isSignatureOk DocValidation::isSignatureOk($em$loginId$approveHash);
  1741.         $employee HumanResource::StoreDataForAddEmployee($em$requestfalse$CompanyId);
  1742.         $isUserExist $em->getRepository(EmployeeDetails::class);
  1743.         if ($isSignatureOk) {
  1744.             if ($isUserExist) {
  1745.                 if ($employee) {
  1746.                     $message $this->get('user_module')->addNewUser(
  1747.                         $request->request->get('firstname') . " " $request->request->get('lastname'),
  1748.                         $request->request->get('email'),
  1749.                         $request->request->get('username'),
  1750.                         $request->request->get('password'),
  1751.                         $request->request->get('desg'),
  1752.                         $request->getLoggedUserLoginId($request),
  1753.                         $request->request->get('company'),
  1754.                         $request->request->get('user_type'),
  1755.                         $request->request->get('companyIdList'),
  1756.                         $request->request->get('branch'),
  1757.                         $request->request->get('supervisor'),
  1758.                         $request->request->get('default_route'),
  1759.                         $request->request->has('access_module') ? 0
  1760.                     );
  1761.                     if ($message[0] == 'success') {
  1762.                         $employee->setUserId($message[3]->getUserId());
  1763.                         $em->flush();
  1764.                         if ($systemType == '_CENTRAL_') {
  1765.                         } else {
  1766.                             $em_goc $this->getDoctrine()->getManager('company_group');
  1767.                             $em_goc->getConnection()->connect();
  1768.                             $connected $em_goc->getConnection()->isConnected();
  1769.                             $gocDataList = [];
  1770.                             $gocDataListByAppId = [];
  1771.                             $retDataDebug = array();
  1772.                             $appIds $message[2]->getAppId();
  1773.                             $userIds $message[3]->getUserId();
  1774.                             if ($connected) {
  1775.                                 $findByQuery = array(
  1776.                                     'active' => 1
  1777.                                 );
  1778.                                 if ($appIds !== '_UNSET_')
  1779.                                     $findByQuery['appId'] = $appIds;
  1780.                                 $gocList $this->getDoctrine()->getManager('company_group')
  1781.                                     ->getRepository("CompanyGroupBundle:CompanyGroup")
  1782.                                     ->findBy($findByQuery);
  1783.                                 foreach ($gocList as $entry) {
  1784.                                     $d = array(
  1785.                                         'name' => $entry->getName(),
  1786.                                         'id' => $entry->getId(),
  1787.                                         'image' => $entry->getImage(),
  1788.                                         'companyGroupHash' => $entry->getCompanyGroupHash(),
  1789.                                         'dbName' => $entry->getDbName(),
  1790.                                         'dbUser' => $entry->getDbUser(),
  1791.                                         'dbPass' => $entry->getDbPass(),
  1792.                                         'dbHost' => $entry->getDbHost(),
  1793.                                         'appId' => $entry->getAppId(),
  1794.                                         'companyRemaining' => $entry->getCompanyRemaining(),
  1795.                                         'companyAllowed' => $entry->getCompanyAllowed(),
  1796.                                     );
  1797.                                     $gocDataList[$entry->getId()] = $d;
  1798.                                     $gocDataListByAppId[$entry->getAppId()] = $d;
  1799.                                 }
  1800.                                 $debugCount 0;
  1801.                                 foreach ($gocDataList as $gocId => $entry) {
  1802.                                     $skipSend 1;
  1803.                                     $connector $this->container->get('application_connector');
  1804.                                     $connector->resetConnection(
  1805.                                         'default',
  1806.                                         $gocDataList[$gocId]['dbName'],
  1807.                                         $gocDataList[$gocId]['dbUser'],
  1808.                                         $gocDataList[$gocId]['dbPass'],
  1809.                                         $gocDataList[$gocId]['dbHost'],
  1810.                                         $reset true);
  1811.                                     $em $this->getDoctrine()->getManager();
  1812.                                     if ($userIds !== '_UNSET_')
  1813.                                         $users $this->getDoctrine()
  1814.                                             ->getRepository('ApplicationBundle:SysUser')
  1815.                                             ->findBy(
  1816.                                                 array(
  1817.                                                     'userId' => $userIds
  1818.                                                 )
  1819.                                             );
  1820.                                     else
  1821.                                         $users $this->getDoctrine()
  1822.                                             ->getRepository('ApplicationBundle:SysUser')
  1823.                                             ->findBy(
  1824.                                                 array()
  1825.                                             );
  1826.                                     $output '';
  1827.                                     $userData = array();
  1828.                                     $userFiles = array();
  1829.                                     foreach ($users as $user) {
  1830.                                         $file $this->container->getParameter('kernel.root_dir') . '/../web/' $user->getImage();
  1831.                                         if ($user->getImage() != '' && $user->getImage() != null && file_exists($file)) {
  1832.                                             $mime mime_content_type($file);
  1833.                                             $info pathinfo($file);
  1834.                                             $name $info['basename'];
  1835.                                             if (strpos($mime'image') !== false) {
  1836.                                                 $output = new \CURLFile($file$mime$name);
  1837.                                             }
  1838.                                             $skipSend 0;
  1839.                                             $userFiles['file_' $user->getUserAppId() . '_' $user->getUserId()] = $output;
  1840.                                         } else {
  1841.                                             $user->setImage(null);
  1842.                                             $userFiles['file_' $user->getUserAppId() . '_' $user->getUserId()] = 'pika';
  1843.                                             $em->flush();
  1844.                                         }
  1845.                                         $getters array_filter(get_class_methods($user), function ($method) {
  1846.                                             return 'get' === substr($method03);
  1847.                                         });
  1848.                                         $userDataSingle = array();
  1849.                                         foreach ($getters as $getter) {
  1850.                                             if ($getter == 'getCreatedAt' || $getter == 'getUpdatedAt' || $getter == 'getImage')
  1851.                                                 continue;
  1852. //                                if(is_string($user->{$getter}())|| is_numeric($user->{$getter}()))
  1853. //                                {
  1854. //                                    $userDataSingle[$getter]= $user->{$getter}();
  1855. //                                }
  1856.                                             if ($user->{$getter}() instanceof \DateTime) {
  1857.                                                 $ggtd $user->{$getter}();
  1858.                                                 $userDataSingle[$getter] = $ggtd->format('Y-m-d');
  1859.                                             } else
  1860.                                                 $userDataSingle[$getter] = $user->{$getter}();
  1861.                                         }
  1862. //                                                    $userDataSingle['getNid']=$Employee->getNid();
  1863. //                                                    $userDataSingle['getCurrAddr'] = $Employee->getCurrAddr();
  1864.                                         $userData[] = $userDataSingle;
  1865.                                     }
  1866.                                     $retDataDebug[$debugCount] = array(
  1867.                                         'skipSend' => $skipSend
  1868.                                     );
  1869.                                     {
  1870.                                         $urlToCall GeneralConstant::HONEYBEE_CENTRAL_SERVER '/SyncUserToCentralUser';
  1871.                                         $userFiles['userData'] = json_encode($userData);
  1872.                                         $curl curl_init();
  1873.                                         curl_setopt_array($curl, array(
  1874.                                             CURLOPT_RETURNTRANSFER => 1,
  1875.                                             CURLOPT_POST => 1,
  1876.                                             CURLOPT_URL => $urlToCall,
  1877.                                             CURLOPT_CONNECTTIMEOUT => 10,
  1878.                                             CURLOPT_SSL_VERIFYPEER => false,
  1879.                                             CURLOPT_SSL_VERIFYHOST => false,
  1880. //                            CURLOPT_SAFE_UPLOAD => false,
  1881.                                             CURLOPT_HTTPHEADER => array(//                                "Accept: multipart/form-data",
  1882.                                             ),
  1883.                                             //                        CURLOPT_USERAGENT => 'InnoPM',
  1884. //                            CURLOPT_POSTFIELDS => array(
  1885. //                                'userData'=>json_encode($userData),
  1886. //                                'userFiles'=>$userFiles
  1887. //                            ),
  1888.                                             CURLOPT_POSTFIELDS => $userFiles
  1889.                                         ));
  1890.                                         $retData curl_exec($curl);
  1891.                                         $errData curl_error($curl);
  1892.                                         curl_close($curl);
  1893.                                         $response = [];
  1894.                                         if ($errData) {
  1895.                                             $response['status'] = 'error';
  1896.                                             $response['message'] = 'cURL Error: ' $errData;
  1897.                                         } else {
  1898.                                             $retDataObj json_decode($retDatatrue);
  1899.                                             if (!$retDataObj) {
  1900.                                                 $response['status'] = 'error';
  1901.                                                 $response['message'] = 'Invalid response from central server';
  1902.                                                 $response['raw_response'] = $retData;
  1903.                                             } else {
  1904.                                                 $response['status'] = 'success';
  1905.                                                 $response['data'] = $retDataObj;
  1906.                                             }
  1907.                                         }
  1908. // Return JSON response
  1909. //                                                    return new JsonResponse($response);
  1910.                                         $retDataDebug[$debugCount] = $retDataObj;
  1911.                                         if (isset($retDataObj['globalIdsData']))
  1912.                                             foreach ($retDataObj['globalIdsData'] as $app_id => $usrList) {
  1913.                                                 $connector $this->container->get('application_connector');
  1914.                                                 $connector->resetConnection(
  1915.                                                     'default',
  1916.                                                     $gocDataListByAppId[$app_id]['dbName'],
  1917.                                                     $gocDataListByAppId[$app_id]['dbUser'],
  1918.                                                     $gocDataListByAppId[$app_id]['dbPass'],
  1919.                                                     $gocDataListByAppId[$app_id]['dbHost'],
  1920.                                                     $reset true);
  1921.                                                 $em $this->getDoctrine()->getManager();
  1922.                                                 foreach ($usrList as $sys_id => $globaldata) {
  1923.                                                     $user $this->getDoctrine()
  1924.                                                         ->getRepository('ApplicationBundle:SysUser')
  1925.                                                         ->findOneBy(
  1926.                                                             array(
  1927.                                                                 'userId' => $sys_id
  1928.                                                             )
  1929.                                                         );
  1930.                                                     if ($user) {
  1931.                                                         $user->setGlobalId($globaldata['gid']);
  1932.                                                         $em->persist($user);
  1933.                                                         $em->flush();
  1934.                                                     }
  1935.                                                 }
  1936.                                             }
  1937.                                     }
  1938.                                     $debugCount++;
  1939.                                 }
  1940.                             }
  1941. //                    return new JsonResponse($retDataDebug);
  1942.                         }
  1943.                     }
  1944. //                                    if($message[0]=='success'){
  1945. //                                        $SysUserRepo = $em->getRepository('ApplicationBundle:SysUser');
  1946. //                                        $SysUser = $SysUserRepo->findOneBy([
  1947. //                                            'email' => $data->request->get('email')
  1948. //                                        ]);
  1949. //
  1950. //                                        if ($SysUser === null) {
  1951. //                                            throw new \Exception("User with email " . $data->request->get('email') . " not found.");
  1952. //                                        }
  1953. //
  1954. //                                        $isSuccess->setUserId($SysUser->getUserId());
  1955. //                                        $em->persist($isSuccess);
  1956. //                                        $em->flush();
  1957. //                                    }
  1958.                     $companyData $message[2];
  1959.                     if ($message[0] == 'success' && GeneralConstant::EMAIL_ENABLED == 1) {
  1960.                         $bodyHtml '';
  1961.                         $bodyTemplate 'ApplicationBundle:email/user:registration.html.twig';
  1962.                         $bodyData = array(
  1963.                             'name' => $request->request->get('name'),
  1964.                             'companyData' => $companyData,
  1965.                             'userName' => $request->request->get('username'),
  1966.                             'password' => $request->request->get('password'),
  1967.                         );
  1968.                         $attachments = [];
  1969.                         $new_mail $this->get('mail_module');
  1970.                         $new_mail->sendMyMail(array(
  1971.                             'senderHash' => '_CUSTOM_',
  1972.                             //                        'senderHash'=>'_CUSTOM_',
  1973.                             'forwardToMailAddress' => $request->request->get('email'),
  1974.                             'fromAddress' => 'no-reply@ourhoneybee.eu',
  1975.                             'userName' => 'no-reply@ourhoneybee.eu',
  1976.                             'password' => 'Honeybee@0112',
  1977.                             'smtpServer' => 'smtp.hostinger.com',
  1978.                             'smtpPort' => 465,
  1979.                             'subject' => 'User Registration on HoneyBee Ecosystem under Entity ' $companyData->getName(),
  1980.                             'fileName' => '',
  1981.                             'attachments' => $attachments,
  1982.                             'toAddress' => $request->request->get('email'),
  1983.                             'mailTemplate' => $bodyTemplate,
  1984.                             'templateData' => $bodyData,
  1985.                             'embedCompanyImage' => 1,
  1986.                             'companyId' => $request->request->get('company'),
  1987.                             'companyImagePath' => $companyData->getImage()
  1988.                         ));
  1989.                     }
  1990.                 }
  1991.                 $this->addFlash(
  1992.                     'success',
  1993.                     'New Employee Successfully Added!'
  1994.                 );
  1995.                 return $this->redirectToRoute('add_employee');
  1996.             } else {
  1997. //                        $requiredFields = [
  1998. //                            'email', 'username', 'password', 'firstname', 'lastname', 'nid', 'dob',
  1999. //                            'sex', 'blood', 'phone', 'perm_addr', 'dept', 'desg', 'branch',
  2000. //                            'emp_type', 'tin'
  2001. //                        ];
  2002. //
  2003. //                        $missingFields = [];
  2004. //
  2005. //                        foreach ($requiredFields as $field) {
  2006. //                            if (!$data->request->get($field)) {
  2007. //                                $missingFields[] = $field;
  2008. //                            }
  2009. //                        }
  2010. //                        if (!empty($missingFields)) {
  2011. //                            $this->addFlash('error', 'Missing fields: ' . implode(', ', $missingFields));
  2012. //                            return $this->redirectToRoute('add_employee');
  2013. //                        }
  2014. //                        $password = $data->request->get('password');
  2015. //                        $passwordPattern = '/^(?=.*[A-Z])(?=.*[a-z])(?=.*\d)(?=.*[\W_]).{8,}$/';
  2016. //                        if (!preg_match($passwordPattern, $password)) {
  2017. //                            $this->addFlash('error', 'Password must be at least 8 characters long, contain at least one uppercase letter, one lowercase letter, one special character, and one number. ' . implode(', ', $missingFields));
  2018. //                            return $this->redirectToRoute('add_employee');
  2019. //                        }
  2020.                 $CompanyId $this->getLoggedUserCompanyId($request);
  2021.                 $isSuccess HumanResource::StoreDataForAddEmployee($em$requestfalse$CompanyId);
  2022.                 if ($isSuccess) {
  2023.                     if ($request->request->has('send_appointment')) {
  2024.                         $email $request->request->get('email');
  2025.                         $bodyHtml '';
  2026.                         $bodyTemplate 'ApplicationBundle:email/general:appointment_letter_test.html.twig';
  2027.                         $bodyData = [];
  2028.                         $attachments = [];
  2029.                         $forwardToMailAddress $email;
  2030.                         $new_mail $this->get('mail_module');
  2031.                         $new_mail->sendMyMail(array(
  2032.                             'senderHash' => '_CUSTOM_',
  2033.                             'forwardToMailAddress' => $forwardToMailAddress,
  2034.                             'subject' => 'Appointment Letter',
  2035.                             'attachments' => $attachments,
  2036.                             'toAddress' => $forwardToMailAddress,
  2037.                             'fromAddress' => 'no-reply@ourhoneybee.eu',
  2038.                             'userName' => 'no-reply@ourhoneybee.eu',
  2039.                             'password' => 'Honeybee@0112',
  2040.                             'smtpServer' => 'smtp.hostinger.com',
  2041.                             'smtpPort' => 465,
  2042.                             'emailBody' => $bodyHtml,
  2043.                             'mailTemplate' => $bodyTemplate,
  2044.                             'templateData' => $bodyData,
  2045.                         ));
  2046.                     }
  2047.                     // Mailer function
  2048.                     if ($request->get("send_mail") && empty($request->get('sys_user'))) {
  2049.                         $message $this->get('user_module')->addNewUser(
  2050.                             $request->request->get('firstname') . " " $request->request->get('lastname'),
  2051.                             $request->request->get('email'),
  2052.                             $request->request->get('username'),
  2053.                             $request->request->get('password'),
  2054.                             $request->request->get('desg'),
  2055.                             $request->getLoggedUserLoginId($request),
  2056.                             $request->request->get('company'),
  2057.                             $request->request->get('user_type'),
  2058.                             $request->request->get('companyIdList'),
  2059.                             $request->request->get('branch'),
  2060.                             $request->request->get('supervisor'),
  2061.                             $request->request->get('default_route'),
  2062.                             $request->request->has('access_module') ? 0
  2063.                         );
  2064.                         if ($message[0] == 'success') {
  2065.                             if ($systemType == '_CENTRAL_') {
  2066.                             } else {
  2067.                                 $em_goc $this->getDoctrine()->getManager('company_group');
  2068.                                 $em_goc->getConnection()->connect();
  2069.                                 $connected $em_goc->getConnection()->isConnected();
  2070.                                 $gocDataList = [];
  2071.                                 $gocDataListByAppId = [];
  2072.                                 $retDataDebug = array();
  2073.                                 $appIds $message[2]->getAppId();
  2074.                                 $userIds $message[3]->getUserId();
  2075.                                 if ($connected) {
  2076.                                     $findByQuery = array(
  2077.                                         'active' => 1
  2078.                                     );
  2079.                                     if ($appIds !== '_UNSET_')
  2080.                                         $findByQuery['appId'] = $appIds;
  2081.                                     $gocList $this->getDoctrine()->getManager('company_group')
  2082.                                         ->getRepository("CompanyGroupBundle:CompanyGroup")
  2083.                                         ->findBy($findByQuery);
  2084.                                     foreach ($gocList as $entry) {
  2085.                                         $d = array(
  2086.                                             'name' => $entry->getName(),
  2087.                                             'id' => $entry->getId(),
  2088.                                             'image' => $entry->getImage(),
  2089.                                             'companyGroupHash' => $entry->getCompanyGroupHash(),
  2090.                                             'dbName' => $entry->getDbName(),
  2091.                                             'dbUser' => $entry->getDbUser(),
  2092.                                             'dbPass' => $entry->getDbPass(),
  2093.                                             'dbHost' => $entry->getDbHost(),
  2094.                                             'appId' => $entry->getAppId(),
  2095.                                             'companyRemaining' => $entry->getCompanyRemaining(),
  2096.                                             'companyAllowed' => $entry->getCompanyAllowed(),
  2097.                                         );
  2098.                                         $gocDataList[$entry->getId()] = $d;
  2099.                                         $gocDataListByAppId[$entry->getAppId()] = $d;
  2100.                                     }
  2101.                                     $debugCount 0;
  2102.                                     foreach ($gocDataList as $gocId => $entry) {
  2103.                                         $skipSend 1;
  2104.                                         $connector $this->container->get('application_connector');
  2105.                                         $connector->resetConnection(
  2106.                                             'default',
  2107.                                             $gocDataList[$gocId]['dbName'],
  2108.                                             $gocDataList[$gocId]['dbUser'],
  2109.                                             $gocDataList[$gocId]['dbPass'],
  2110.                                             $gocDataList[$gocId]['dbHost'],
  2111.                                             $reset true);
  2112.                                         $em $this->getDoctrine()->getManager();
  2113.                                         if ($userIds !== '_UNSET_')
  2114.                                             $users $this->getDoctrine()
  2115.                                                 ->getRepository('ApplicationBundle:SysUser')
  2116.                                                 ->findBy(
  2117.                                                     array(
  2118.                                                         'userId' => $userIds
  2119.                                                     )
  2120.                                                 );
  2121.                                         else
  2122.                                             $users $this->getDoctrine()
  2123.                                                 ->getRepository('ApplicationBundle:SysUser')
  2124.                                                 ->findBy(
  2125.                                                     array()
  2126.                                                 );
  2127.                                         $output '';
  2128.                                         $userData = array();
  2129.                                         $userFiles = array();
  2130.                                         foreach ($users as $user) {
  2131.                                             $file $this->container->getParameter('kernel.root_dir') . '/../web/' $user->getImage();
  2132.                                             if ($user->getImage() != '' && $user->getImage() != null && file_exists($file)) {
  2133.                                                 $mime mime_content_type($file);
  2134.                                                 $info pathinfo($file);
  2135.                                                 $name $info['basename'];
  2136.                                                 if (strpos($mime'image') !== false) {
  2137.                                                     $output = new \CURLFile($file$mime$name);
  2138.                                                 }
  2139.                                                 $skipSend 0;
  2140.                                                 $userFiles['file_' $user->getUserAppId() . '_' $user->getUserId()] = $output;
  2141.                                             } else {
  2142.                                                 $user->setImage(null);
  2143.                                                 $userFiles['file_' $user->getUserAppId() . '_' $user->getUserId()] = 'pika';
  2144.                                                 $em->flush();
  2145.                                             }
  2146.                                             $getters array_filter(get_class_methods($user), function ($method) {
  2147.                                                 return 'get' === substr($method03);
  2148.                                             });
  2149.                                             $userDataSingle = array();
  2150.                                             foreach ($getters as $getter) {
  2151.                                                 if ($getter == 'getCreatedAt' || $getter == 'getUpdatedAt' || $getter == 'getImage')
  2152.                                                     continue;
  2153. //                                if(is_string($user->{$getter}())|| is_numeric($user->{$getter}()))
  2154. //                                {
  2155. //                                    $userDataSingle[$getter]= $user->{$getter}();
  2156. //                                }
  2157.                                                 if ($user->{$getter}() instanceof \DateTime) {
  2158.                                                     $ggtd $user->{$getter}();
  2159.                                                     $userDataSingle[$getter] = $ggtd->format('Y-m-d');
  2160.                                                 } else
  2161.                                                     $userDataSingle[$getter] = $user->{$getter}();
  2162.                                             }
  2163. //                                                    $userDataSingle['getNid']=$Employee->getNid();
  2164. //                                                    $userDataSingle['getCurrAddr'] = $Employee->getCurrAddr();
  2165.                                             $userData[] = $userDataSingle;
  2166.                                         }
  2167.                                         $retDataDebug[$debugCount] = array(
  2168.                                             'skipSend' => $skipSend
  2169.                                         );
  2170.                                         {
  2171.                                             $urlToCall GeneralConstant::HONEYBEE_CENTRAL_SERVER '/SyncUserToCentralUser';
  2172.                                             $userFiles['userData'] = json_encode($userData);
  2173.                                             $curl curl_init();
  2174.                                             curl_setopt_array($curl, array(
  2175.                                                 CURLOPT_RETURNTRANSFER => 1,
  2176.                                                 CURLOPT_POST => 1,
  2177.                                                 CURLOPT_URL => $urlToCall,
  2178.                                                 CURLOPT_CONNECTTIMEOUT => 10,
  2179.                                                 CURLOPT_SSL_VERIFYPEER => false,
  2180.                                                 CURLOPT_SSL_VERIFYHOST => false,
  2181. //                            CURLOPT_SAFE_UPLOAD => false,
  2182.                                                 CURLOPT_HTTPHEADER => array(//                                "Accept: multipart/form-data",
  2183.                                                 ),
  2184.                                                 //                        CURLOPT_USERAGENT => 'InnoPM',
  2185. //                            CURLOPT_POSTFIELDS => array(
  2186. //                                'userData'=>json_encode($userData),
  2187. //                                'userFiles'=>$userFiles
  2188. //                            ),
  2189.                                                 CURLOPT_POSTFIELDS => $userFiles
  2190.                                             ));
  2191.                                             $retData curl_exec($curl);
  2192.                                             $errData curl_error($curl);
  2193.                                             curl_close($curl);
  2194.                                             $response = [];
  2195.                                             if ($errData) {
  2196.                                                 $response['status'] = 'error';
  2197.                                                 $response['message'] = 'cURL Error: ' $errData;
  2198.                                             } else {
  2199.                                                 $retDataObj json_decode($retDatatrue);
  2200.                                                 if (!$retDataObj) {
  2201.                                                     $response['status'] = 'error';
  2202.                                                     $response['message'] = 'Invalid response from central server';
  2203.                                                     $response['raw_response'] = $retData;
  2204.                                                 } else {
  2205.                                                     $response['status'] = 'success';
  2206.                                                     $response['data'] = $retDataObj;
  2207.                                                 }
  2208.                                             }
  2209. // Return JSON response
  2210. //                                                    return new JsonResponse($response);
  2211.                                             $retDataDebug[$debugCount] = $retDataObj;
  2212.                                             if (isset($retDataObj['globalIdsData']))
  2213.                                                 foreach ($retDataObj['globalIdsData'] as $app_id => $usrList) {
  2214.                                                     $connector $this->container->get('application_connector');
  2215.                                                     $connector->resetConnection(
  2216.                                                         'default',
  2217.                                                         $gocDataListByAppId[$app_id]['dbName'],
  2218.                                                         $gocDataListByAppId[$app_id]['dbUser'],
  2219.                                                         $gocDataListByAppId[$app_id]['dbPass'],
  2220.                                                         $gocDataListByAppId[$app_id]['dbHost'],
  2221.                                                         $reset true);
  2222.                                                     $em $this->getDoctrine()->getManager();
  2223.                                                     foreach ($usrList as $sys_id => $globaldata) {
  2224.                                                         $user $this->getDoctrine()
  2225.                                                             ->getRepository('ApplicationBundle:SysUser')
  2226.                                                             ->findOneBy(
  2227.                                                                 array(
  2228.                                                                     'userId' => $sys_id
  2229.                                                                 )
  2230.                                                             );
  2231.                                                         if ($user) {
  2232.                                                             $user->setGlobalId($globaldata['gid']);
  2233.                                                             $em->persist($user);
  2234.                                                             $em->flush();
  2235.                                                         }
  2236.                                                     }
  2237.                                                 }
  2238.                                         }
  2239.                                         $debugCount++;
  2240.                                     }
  2241.                                 }
  2242. //                    return new JsonResponse($retDataDebug);
  2243.                             }
  2244.                         }
  2245.                         $SysUserRepo $em->getRepository(SysUser::class);
  2246.                         $SysUser $SysUserRepo->findOneBy(array(
  2247.                             'email' => $request->request->get('email')
  2248.                         ));
  2249.                         $isSuccess->setUserId($SysUser->getUserId());
  2250.                         $em->persist($isSuccess);
  2251.                         $em->flush();
  2252.                         $companyData $message[2];
  2253.                         if ($message[0] == 'success' && GeneralConstant::EMAIL_ENABLED == 1) {
  2254.                             $bodyHtml '';
  2255.                             $bodyTemplate 'ApplicationBundle:email/user:registration.html.twig';
  2256.                             $bodyData = array(
  2257.                                 'name' => $request->request->get('name'),
  2258.                                 'companyData' => $companyData,
  2259.                                 'userName' => $request->request->get('username'),
  2260.                                 'password' => $request->request->get('password'),
  2261.                             );
  2262.                             $attachments = [];
  2263. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  2264.                             $new_mail $this->get('mail_module');
  2265.                             $new_mail->sendMyMail(array(
  2266.                                 'senderHash' => '_CUSTOM_',
  2267.                                 //                        'senderHash'=>'_CUSTOM_',
  2268.                                 'forwardToMailAddress' => $request->request->get('email'),
  2269.                                 'subject' => 'User Registration on HoneyBee Ecosystem under Entity ' $companyData->getName(),
  2270.                                 'fileName' => '',
  2271.                                 'attachments' => $attachments,
  2272.                                 'toAddress' => $request->request->get('email'),
  2273.                                 'fromAddress' => 'no-reply@ourhoneybee.eu',
  2274.                                 'userName' => 'no-reply@ourhoneybee.eu',
  2275.                                 'password' => 'Y41dh8g0112',
  2276.                                 'smtpServer' => 'smtp.hostinger.com',
  2277.                                 'smtpPort' => 465,
  2278. //                        'fromAddress'=>'sales@entity.innobd.com',
  2279. //                        'userName'=>'sales@entity.innobd.com',
  2280. //                        'password'=>'Y41dh8g0112',
  2281. //                        'smtpServer'=>'smtp.hostinger.com',
  2282. //                        'smtpPort'=>587,
  2283. //                        'emailBody'=>$bodyHtml,
  2284.                                 'mailTemplate' => $bodyTemplate,
  2285.                                 'templateData' => $bodyData,
  2286.                                 'embedCompanyImage' => 1,
  2287.                                 'companyId' => $request->request->get('company'),
  2288.                                 'companyImagePath' => $companyData->getImage()
  2289.                             ));
  2290. //                  $emailmessage = (new \Swift_Message('Registration to Entity'))
  2291. //                    ->setFrom('registration@entity.innobd.com')
  2292. //                    ->setTo($data->request->get('email'))
  2293. //                    ->setBody(
  2294. //                      $this->renderView(
  2295. //                        'ApplicationBundle:email/user:registration.html.twig',
  2296. //                        array(
  2297. //                          'name' => $data->request->get('name'),
  2298. //                          'companyData' => $companyData,
  2299. //                          'userName' => $data->request->get('email'),
  2300. //                          'password' => $data->request->get('password'),
  2301. //                        )
  2302. //                      ),
  2303. //                      'text/html'
  2304. //                    );
  2305. //                  $this->get('mailer')->send($emailmessage);
  2306.                         }
  2307.                     }
  2308.                     // End Mailer function
  2309.                     $this->addFlash(
  2310.                         'success',
  2311.                         'New Employee Successfully Added!'
  2312.                     );
  2313.                     return $this->redirectToRoute('employee_list');
  2314.                 } else {
  2315.                     $this->addFlash(
  2316.                         'error',
  2317.                         'Something Went Wrong!'
  2318.                     );
  2319.                     return $this->redirectToRoute('add_employee');
  2320.                 }
  2321.             }
  2322.         } else {
  2323.             $this->addFlash(
  2324.                 'error',
  2325.                 'Invalid Approval Hash!'
  2326.             );
  2327.             return $this->redirectToRoute('add_employee');
  2328.         }
  2329.     }
  2330.     public function UpdateEmployeeAction(Request $request$id)
  2331.     {
  2332.     }
  2333.     private function uploadImage($image$request)
  2334.     {
  2335.         $upl_dir $this->container->getParameter('kernel.root_dir') . '/../web/uploads/Users/';
  2336.         $profileImage '';
  2337.         if ($image != null) {
  2338.             $fileName $request->request->get('firstname') . '.' $request->request->get('global_user_id') . '.' $image->guessExtension();
  2339.             $path $fileName;
  2340.             if (!file_exists($upl_dir)) {
  2341.                 mkdir($upl_dir0777true);
  2342.             }
  2343.             $image->move($upl_dir$path);
  2344.             $profileImage 'uploads/Users/' $path;
  2345.         }
  2346.         return $profileImage;
  2347.     }
  2348.     private function uploadMeetingFile($file$request)
  2349.     {
  2350.         $upl_dir $this->container->getParameter('kernel.root_dir') . '/../web/uploads/meeting/';
  2351.         $uploadedFilePath '';
  2352.         if ($file != null) {
  2353.             $fileName uniqid() . '.' $file->guessExtension();
  2354.             if (!file_exists($upl_dir)) {
  2355.                 mkdir($upl_dir0777true);
  2356.             }
  2357.             $file->move($upl_dir$fileName);
  2358.             $uploadedFilePath 'uploads/meeting/' $fileName;
  2359.         }
  2360.         return $uploadedFilePath;
  2361.     }
  2362.     public function OnboardEmployeeAction(Request $request)
  2363.     {
  2364.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  2365.         $email $request->request->get('email');
  2366.         $applicantId $request->request->get('applicant_id');
  2367.         $em $this->getDoctrine()->getManager();
  2368.         $session $request->getSession();
  2369.         $companyId $session->get('userCompanyId');
  2370.         $appId $session->get('userAppId');
  2371.         $urlToCall GeneralConstant::HONEYBEE_CENTRAL_SERVER '/get_applicant_data_central';
  2372.         $applicantFiles = [
  2373.             'email' => $email,
  2374.             'applicantId' => $applicantId
  2375.         ];
  2376.         $entityToken $em->getRepository('ApplicationBundle:EntityTokenStorage')
  2377.             ->findOneBy(['userId' => $applicantId]);
  2378.         $curl curl_init();
  2379.         curl_setopt_array($curl, array(
  2380.             CURLOPT_RETURNTRANSFER => 1,
  2381.             CURLOPT_POST => 1,
  2382.             CURLOPT_URL => $urlToCall,
  2383.             CURLOPT_CONNECTTIMEOUT => 10,
  2384.             CURLOPT_SSL_VERIFYPEER => false,
  2385.             CURLOPT_SSL_VERIFYHOST => false,
  2386.             CURLOPT_HTTPHEADER => array(),
  2387.             CURLOPT_POSTFIELDS => $applicantFiles
  2388.         ));
  2389.         $retData curl_exec($curl);
  2390.         $errData curl_error($curl);
  2391.         curl_close($curl);
  2392.         $retDataObj json_decode($retDatatrue);
  2393.         if (!isset($retDataObj['status']) || $retDataObj['status'] !== 'success') {
  2394.             return new JsonResponse([
  2395.                 'status' => 'error',
  2396.                 'message' => 'Failed to get applicant data from central server',
  2397.                 'response' => $retDataObj
  2398.             ]);
  2399.         }
  2400.         $centralData $retDataObj['centralData'];
  2401.         $em $this->getDoctrine()->getManager();
  2402.         $existingUser $em->getRepository('ApplicationBundle:SysUser')->findOneBy([
  2403.             'globalId' => $centralData['globalId']
  2404.         ]);
  2405.         if ($existingUser) {
  2406.             return new JsonResponse([
  2407.                 'status' => 'info',
  2408.                 'message' => 'User is already onboarded',
  2409.                 'userId' => $existingUser->getUserId(),
  2410.                 'redirectUrl' => 'dashboard'
  2411.             ]);
  2412.         }
  2413.         $sysUser = new SysUser();
  2414.         $sysUser->setGlobalId($centralData['globalId'] ?? '');
  2415.         $sysUser->setUsername($centralData['username'] ?? '');
  2416.         $sysUser->setEmail($centralData['email'] ?? '');
  2417.         $sysUser->setName($centralData['firstname'] ?? '');
  2418.         $sysUser->setUserType(1);
  2419.         $sysUser->setUserAppId($appId);
  2420.         $sysUser->setUserCompanyId($companyId);
  2421.         $sysUser->setStatus(1);
  2422.         $sysUser->setDefaultRoute('sales_dashboard');
  2423.         $em->persist($sysUser);
  2424.         $em->flush();
  2425.         $employee $em->getRepository('ApplicationBundle:Employee')
  2426.             ->findOneBy(
  2427.                 array(
  2428.                     'userId' => $sysUser->getUserId(),
  2429.                 )
  2430.             );
  2431.         if (!$employee) {
  2432.             $employee = new Employee();
  2433.             if ($sysUser->getUserId()) {
  2434.                 $employee->setEmail($sysUser->getEmail());
  2435.                 $employee->setFirstName($sysUser->getUsername());
  2436.                 $employee->setLastName($sysUser->getName());
  2437.                 $employee->setCompanyId($sysUser->getUserCompanyId());
  2438.                 $employee->setStatus(1);
  2439.                 $employee->setUserId($sysUser->getUserId());
  2440.                 $em->persist($employee);
  2441.                 $em->flush();
  2442.             } else {
  2443.                 return new JsonResponse([
  2444.                     'status' => 'error',
  2445.                     'message' => 'Missing employee data',
  2446.                 ]);
  2447.             }
  2448.         }
  2449.         $employeeDetails $em->getRepository('ApplicationBundle:EmployeeDetails')
  2450.             ->findOneBy([
  2451.                 'userId' => $sysUser->getUserId(),
  2452.             ]);
  2453.         if (!$employeeDetails) {
  2454.             $employeeDetails = new EmployeeDetails();
  2455.             if ($sysUser->getUserId() && $employee->getEmployeeId()) {
  2456.                 $employeeDetails->setId($employee->getEmployeeId());
  2457.                 $employeeDetails->setEmail($sysUser->getEmail());
  2458.                 $employeeDetails->setFirstName($sysUser->getUsername());
  2459.                 $employeeDetails->setLastName($sysUser->getName());
  2460.                 $employeeDetails->setUsername($sysUser->getUsername());
  2461.                 $employeeDetails->setUserId($sysUser->getUserId());
  2462.                 $employeeDetails->setEmpStatus(1);
  2463.                 $em->persist($employeeDetails);
  2464.                 $em->flush();
  2465.             } else {
  2466.                 return new JsonResponse([
  2467.                     'status' => 'error',
  2468.                     'message' => 'Missing employee details data',
  2469.                 ]);
  2470.             }
  2471.         }
  2472.         $company $em->getRepository('ApplicationBundle:Company')->find($companyId);
  2473.         $companyName $company $company->getName() : '';
  2474.         $newAccess = [
  2475.             'userType' => 2,
  2476.             'userTypeName' => UserConstants::$userTypeName[2],
  2477.             'globalId' => $applicantId,
  2478.             'serverId' => 1,
  2479.             'serverUrl' => $request->getSchemeAndHttpHost(),
  2480.             'serverPort' => 80,
  2481.             'systemType' => '_ERP_',
  2482.             'companyId' => 1,
  2483.             'appId' => $appId,
  2484.             'companyLogoUrl' => '/uploads/CompanyImage/company_image' $request->request->get('appId') . '.png',
  2485.             'companyName' => $companyName,
  2486.             'authenticationStr' => $this->get('url_encryptor')->encrypt(json_encode(
  2487.                     array(
  2488.                         'globalId' => $applicantId,
  2489.                         'appId' => $appId,
  2490.                         'authenticate' => 1,
  2491.                         'userType' => 2,
  2492.                         'userTypeName' => UserConstants::$userTypeName[2]
  2493.                     )
  2494.                 )
  2495.             ),
  2496.             'userCompanyList' => [],
  2497.         ];
  2498.         $urlToCall GeneralConstant::HONEYBEE_CENTRAL_SERVER '/update_token_storage';
  2499.         $curl curl_init();
  2500.         curl_setopt_array($curl, array(
  2501.             CURLOPT_RETURNTRANSFER => 1,
  2502.             CURLOPT_POST => 1,
  2503.             CURLOPT_URL => $urlToCall,
  2504.             CURLOPT_CONNECTTIMEOUT => 10,
  2505.             CURLOPT_SSL_VERIFYPEER => false,
  2506.             CURLOPT_SSL_VERIFYHOST => false,
  2507.             CURLOPT_HTTPHEADER => array(),
  2508.             CURLOPT_POSTFIELDS => json_encode($newAccess)
  2509.         ));
  2510.         $retData curl_exec($curl);
  2511.         $errData curl_error($curl);
  2512.         return new JsonResponse([
  2513.             'status' => 'success',
  2514.             'message' => 'User onboarded successfully',
  2515.             'redirectUlr' => 'dashboard',
  2516.             'returnData' => $retData,
  2517.             'errorData' => $errData
  2518.         ]);
  2519.     }
  2520.     public function DecodeQrAction(Request $request)
  2521.     {
  2522.         $applicantId $request->request->get('applicant_id');
  2523.         $urlToCall GeneralConstant::HONEYBEE_CENTRAL_SERVER '/get_applicant_data_central';
  2524.         $applicantFiles = [
  2525.             'applicantId' => $applicantId
  2526.         ];
  2527.         $curl curl_init();
  2528.         curl_setopt_array($curl, array(
  2529.             CURLOPT_RETURNTRANSFER => 1,
  2530.             CURLOPT_POST => 1,
  2531.             CURLOPT_URL => $urlToCall,
  2532.             CURLOPT_CONNECTTIMEOUT => 10,
  2533.             CURLOPT_SSL_VERIFYPEER => false,
  2534.             CURLOPT_SSL_VERIFYHOST => false,
  2535.             CURLOPT_HTTPHEADER => array(),
  2536.             CURLOPT_POSTFIELDS => $applicantFiles
  2537.         ));
  2538.         $retData curl_exec($curl);
  2539.         $errData curl_error($curl);
  2540.         curl_close($curl);
  2541.         $retDataObj json_decode($retDatatrue);
  2542.         return new JsonResponse($retDataObj['centralData']);
  2543.     }
  2544.     public function GetApplicantDataForErpAction(Request $request)
  2545.     {
  2546.         $applicantId $request->request->get('applicantId');
  2547.         if (!$applicantId) {
  2548.             return new JsonResponse([
  2549.                 'status' => 'error',
  2550.                 'message' => 'Missing applicantId in request.'
  2551.             ]);
  2552.         }
  2553.         $em_goc $this->getDoctrine()->getManager('company_group');
  2554.         $entityApplicant $em_goc->getRepository("CompanyGroupBundle:EntityApplicantDetails")
  2555.             ->findOneBy(['applicantId' => $applicantId]);
  2556.         if (!$entityApplicant) {
  2557.             return new JsonResponse([
  2558.                 'status' => 'error',
  2559.                 'message' => 'Applicant not found.'
  2560.             ]);
  2561.         }
  2562.         return new JsonResponse([
  2563.             'status' => 'success',
  2564.             'centralData' => [
  2565.                 'globalId' => $entityApplicant->getApplicantId(),
  2566.                 'username' => $entityApplicant->getUsername(),
  2567.                 'email' => $entityApplicant->getEmail(),
  2568.                 'firstname' => $entityApplicant->getFirstname(),
  2569.                 'lastname' => $entityApplicant->getLastname(),
  2570.                 'image' => $entityApplicant->getImage(),
  2571.                 'phone' => $entityApplicant->getPhone(),
  2572.                 'address' => $entityApplicant->getPermAddr()
  2573.             ]
  2574.         ]);
  2575.     }
  2576.     public function UpdateTokenStorageAction(Request $request)
  2577.     {
  2578.         $em_goc $this->getDoctrine()->getManager('company_group');
  2579.         $newAccess $request->request->all();
  2580.         $appId = isset($newAccess['appId']) ? $newAccess['appId'] : null;
  2581.         $globalId = isset($newAccess['globalId']) ? $newAccess['globalId'] : null;
  2582.         $sesssionData MiscActions::UpdateCompanyListInSession(
  2583.             $em_goc,
  2584.             $globalId,
  2585.             1,
  2586.             1,
  2587.             1,
  2588.             $newAccess
  2589.         );
  2590.         return new JsonResponse([
  2591.             'status' => 'success',
  2592.             'message' => 'Token storage updated',
  2593.             'newaccess' => $newAccess
  2594.         ]);
  2595.     }
  2596.     public function EmployeeListAction(Request $data)
  2597.     {
  2598.         $em $this->getDoctrine()->getManager();
  2599.         if ($data->isMethod('GET')) {
  2600.             return $this->render("ApplicationBundle:pages/human_resource/list:list_employee.html.twig", array(
  2601.                 'page_title' => 'Employee List',
  2602.             ));
  2603.         }
  2604.     }
  2605.     public function OrganizationChartAction()
  2606.     {
  2607.         $em $this->getDoctrine()->getManager();
  2608.         $Reponse HumanResource::TwigDataForOrgChart($em);
  2609.         return $this->render('ApplicationBundle:pages/human_resource/views:org_chart.html.twig', array(
  2610.             'page_title' => 'Organization Chart',
  2611.             'supervisors' => $Reponse['TreantJsData'],
  2612.             'alluser' => $Reponse['TreantJsInitUser']
  2613.         ));
  2614.     }
  2615.     public function EmployeeListSelectizeAjaxAction(Request $request$str '_EMPTY_')
  2616.     {
  2617.         $em $this->getDoctrine()->getManager();
  2618.         $companyId $this->getLoggedUserCompanyId($request);
  2619.         $company_data Company::getCompanyData($em$companyId);
  2620.         $data = [];
  2621.         $html '';
  2622.         $qryStrs explode(' '$str);
  2623.         $qryStrAddedForSpacedName "";
  2624.         if ($str == '_EMPTY_') {
  2625.             $query "SELECT *
  2626. from  employee  order by employee_id asc limit 10";
  2627.         } else {
  2628.             foreach ($qryStrs as $qryStr) {
  2629.                 $qryStrAddedForSpacedName .= "or first_name like '%$qryStr%' or last_name like '%$qryStr%' ";
  2630.             }
  2631.             $query "SELECT  *
  2632. from  employee  where" . (is_numeric($str) ? " employee_id =$str " " 1=0 ") . $qryStrAddedForSpacedName " or `name` like '%$str%' or employee_code like '%$str%' order by employee_id asc limit 10";
  2633.         }
  2634.         $stmt $em->getConnection()->prepare($query);
  2635.         $stmt->execute();
  2636.         $res $stmt->fetchAll();
  2637. //    if(!empty($res)) {
  2638.         foreach ($res as $i => $r) {
  2639.             $res[$i]['id_padded'] = str_pad($r['employee_id'], 8'0'STR_PAD_LEFT);
  2640.         }
  2641. //    }
  2642.         return new JsonResponse(
  2643.             array(
  2644.                 'success' => true,
  2645.                 'data' => $res,
  2646.             )
  2647.         );
  2648.     }
  2649.     public function AttendanceAction(Request $data$remoteVerify 0)
  2650.     {
  2651.         $em $this->getDoctrine()->getManager();
  2652.         $em_goc $this->getDoctrine()->getManager('company_group');
  2653.         $session $data->getSession();
  2654. //        $token = $session->get(UserConstants::USER_TOKEN);
  2655. //        $providedToken = $data->headers->get('auth-token');
  2656. //
  2657. //        if (empty($providedToken) || $providedToken !== $token) {
  2658. //            return new JsonResponse([
  2659. //                'status' => 'error',
  2660. //                'message' => 'Token not match or missing',
  2661. //            ], 401);
  2662. //        }
  2663.         $workHourPolicy $em->getRepository('ApplicationBundle:WorkHourPolicy')->findAll();
  2664.         $options = array(
  2665.             'notification_enabled' => $this->container->getParameter('notification_enabled'),
  2666.             'notification_server' => $this->container->getParameter('notification_server'),
  2667.         );
  2668.         if ($data->get('DataTable')) {
  2669.             $response HumanResource::HandelAjaxRequestForManualAttendance($em$data);
  2670.             return new JsonResponse($response);
  2671.         }
  2672.         if ($data->request->get('getAttendanceStatus')) {
  2673.             $response HumanResource::getAttendanceStatus($em$data);
  2674.             return new JsonResponse($response);
  2675.         }
  2676. //        if ($session->get('devAdminMode', 0) != 1 && $data->get('returnJson', 0) == 0)
  2677. //            return $this->redirectToRoute('permission_denied_page');
  2678.         // Auto attendance
  2679.         if ($data->get('autoAttendance') && $data->request->has('position_array')) {
  2680. //            $empId = $data->query->get('id');
  2681.             $empId $data->request->get('id'$session->get(UserConstants::USER_EMPLOYEE_ID));
  2682.             $positionsArray $data->request->get('position_array', []);
  2683.             if (is_string($positionsArray)) $positionsArray json_decode($positionsArraytrue);
  2684.             if ($positionsArray == null$positionsArray = [];
  2685.             $dataByAttId = [];
  2686.             $workPlaceType '_UNSET_';
  2687.             foreach ($positionsArray as $d) {
  2688.                 $sysUserId 0;
  2689.                 $userId 0;
  2690.                 $empId 0;
  2691.                 $dtTs 0;
  2692.                 $timeZoneStr '+0000';
  2693. //                $timeZoneStr = '+0600';
  2694.                 $token '_unset_';
  2695.                 if (isset($d['token'])) $token $d['token'];
  2696.                 if (isset($d['employeeId'])) $empId $d['employeeId'];
  2697.                 if (isset($d['userId'])) $userId $d['userId'];
  2698.                 if (isset($d['sysUserId'])) $sysUserId $d['sysUserId'];
  2699.                 if (isset($d['tsMilSec'])) {
  2700.                     $dtTs ceil(($d['tsMilSec']) / 1000);
  2701.                 }
  2702.                 if ($token != '_unset_') {
  2703.                     $sessionData MiscActions::GetSessionDataFromToken($em_goc$token)['sessionData'];
  2704.                     if (isset($sessionData[UserConstants::USER_EMPLOYEE_ID]))
  2705.                         $empId $sessionData[UserConstants::USER_EMPLOYEE_ID];
  2706.                 }
  2707.                 if ($sysUserId == 0)
  2708.                     $sysUserId $userId;
  2709.                 if ($sysUserId == 0)
  2710.                     $sysUserId $em->getRepository(Employee::class)
  2711.                         ->findOneBy(['employeeId' => $empId])->getUserId();
  2712.                 if ($dtTs == 0) {
  2713.                     $currTsTime = new \DateTime();
  2714.                     $dtTs $currTsTime->format('U');
  2715.                 } else {
  2716.                     $currTsTime = new \DateTime('@' $dtTs);
  2717.                 }
  2718.                 $currTsTime->setTimezone(new \DateTimeZone('UTC'));
  2719.                 $attDate = new \DateTime($currTsTime->format('Y-m-d') . ' 00:00:00' $timeZoneStr);
  2720.                 $EmployeeAttendance $this->getDoctrine()
  2721.                     ->getRepository(EmployeeAttendance::class)
  2722.                     ->findOneBy(array('employeeId' => $empId'date' => $attDate));
  2723.                 if (!$EmployeeAttendance)
  2724.                     $EmployeeAttendance = new EmployeeAttendance;
  2725.                 $attendanceInfo HumanResource::StoreAttendance($em$empId$sysUserId$data$EmployeeAttendance$attDate$dtTs$timeZoneStr$d['markerId']);
  2726.                 if ($d['markerId'] == HumanResourceConstant::ATTENDANCE_MARKER_CLOCK_IN) {
  2727.                     if ($empId == 24)
  2728.                         $workPlaceType '_HYBRID_';
  2729.                     else
  2730.                         $workPlaceType '_STATIC_';
  2731.                 }
  2732.                 if (!isset($dataByAttId[$attendanceInfo->getId()]))
  2733.                     $dataByAttId[$attendanceInfo->getId()] = array(
  2734.                         'attendanceInfo' => $attendanceInfo,
  2735.                         'empId' => $empId,
  2736.                         'lat' => 0,
  2737.                         'lng' => 0,
  2738.                         'address' => 0,
  2739.                         'sysUserId' => $sysUserId,
  2740.                         'companyId' => $data->getSession()->get(UserConstants::USER_COMPANY_ID),
  2741.                         'appId' => $data->getSession()->get(UserConstants::USER_APP_ID),
  2742.                         'positionArray' => []
  2743.                     );
  2744.                 $posData = array(
  2745.                     'ts' => $dtTs,
  2746.                     'lat' => $d['lat'],
  2747.                     'lng' => $d['lng'],
  2748.                     'marker' => $d['markerId'],
  2749.                     'src' => 2,
  2750.                 );
  2751.                 $posDataArray = array(
  2752.                     $dtTs,
  2753.                     $d['lat'],
  2754.                     $d['lng'],
  2755.                     $d['markerId'],
  2756.                     2
  2757.                 );
  2758.                 $dataByAttId[$attendanceInfo->getId()]['markerId'] = $d['markerId'];
  2759.                 //this markerId will be calclulted and modified to check if user is in our out of office/workplace later
  2760.                 $dataByAttId[$attendanceInfo->getId()]['attendanceInfo'] = $attendanceInfo;
  2761.                 $dataByAttId[$attendanceInfo->getId()]['positionArray'][] = $posData;
  2762.                 $dataByAttId[$attendanceInfo->getId()]['lat'] = $d['lat'];  //for last lat lng etc
  2763.                 $dataByAttId[$attendanceInfo->getId()]['lng'] = $d['lng'];  //for last lat lng etc
  2764.                 if (isset($d['address']))
  2765.                     $dataByAttId[$attendanceInfo->getId()]['address'] = $d['address'];  //for last lat lng etc
  2766. //                $dataByAttId[$attendanceInfo->getId()]['positionArray'][]=$posDataArray;
  2767.             }
  2768.             $response = array(
  2769.                 'success' => true,
  2770.             );
  2771.             foreach ($dataByAttId as $attInfoId => $d) {
  2772.                 $response HumanResource::setAttendanceLogFlutterApp($em,
  2773.                     $d['empId'],
  2774.                     $d['sysUserId'],
  2775.                     $d['companyId'],
  2776.                     $d['appId'],
  2777.                     $data,
  2778.                     $d['attendanceInfo'],
  2779.                     $options,
  2780.                     $d['positionArray'],
  2781.                     $d['lat'],
  2782.                     $d['lng'],
  2783.                     $d['address'],
  2784.                     $d['markerId']
  2785.                 );
  2786.             }
  2787.             if ($data->request->get('requestFromMobile')) {
  2788.                 $today = new \DateTime(date('y-m-d'));
  2789.                 $repository $this->getDoctrine()->getRepository(EmployeeAttendance::class);
  2790.                 $ActivitiesTemplate HumanResource::getCurrentStatusFromDb($repository$empId$today);
  2791.                 return new JsonResponse(array(
  2792.                     'success' => $response['success'] == true true false,
  2793.                     'msg' => $response['success'] == true 'Employee activities successfully updated.' 'Action Failed',
  2794.                     'workPlaceType' => $workPlaceType,
  2795.                     'data' => $ActivitiesTemplate
  2796.                 ));
  2797.             }
  2798.             return new JsonResponse(
  2799.                 array(
  2800.                     'success' => true,
  2801.                     'msg' => 'Employee activities successfully updated.',
  2802.                     'workPlaceType' => $workPlaceType,
  2803.                 )
  2804.             );
  2805.         } else if ($data->get('autoAttendance')) {
  2806.             $sysUserId 0;
  2807.             $userId 0;
  2808.             $empId 0;
  2809.             $dtTs 0;
  2810. //            $timeZoneStr = '+0600';
  2811.             $timeZoneStr '+0000';
  2812.             if ($data->request->get('requestFromMobile')) {
  2813.                 $empId $data->request->get('employeeId');
  2814.                 $userId $data->request->get('userId'0);
  2815.                 $sysUserId $data->request->get('id'0);
  2816. //        $empId = $em->getRepository(Employee::class)
  2817. //            ->findOneBy(['userId' => $userId])->getEmployeeId();
  2818.             } else {
  2819.                 $empId $data->request->get('employeeId'0);
  2820.                 $sysUserId $data->request->get('userId'0);
  2821.             }
  2822.             $dtTs $data->request->get('timeTs'0);
  2823.             if ($sysUserId == 0)
  2824.                 $sysUserId $userId;
  2825.             if ($sysUserId == 0)
  2826.                 $sysUserId $em->getRepository(Employee::class)
  2827.                     ->findOneBy(['employeeId' => $empId])->getUserId();
  2828.             if ($dtTs == 0) {
  2829.                 $currTsTime = new \DateTime();
  2830.                 $dtTs $currTsTime->format('U');
  2831.             } else {
  2832.                 $currTsTime = new \DateTime('@' $dtTs);
  2833.             }
  2834.             if ($sysUserId == 0)
  2835.                 $sysUserId $userId;
  2836.             if ($sysUserId == 0)
  2837.                 $sysUserId $em->getRepository(Employee::class)
  2838.                     ->findOneBy(['employeeId' => $empId])->getUserId();
  2839.             $today = new \DateTime(date('y-m-d'));
  2840.             $currTsTime->setTimezone(new \DateTimeZone('UTC'));
  2841.             $attDate = new \DateTime($currTsTime->format('Y-m-d') . ' 00:00:00' $timeZoneStr);
  2842.             $EmployeeAttendance $this->getDoctrine()
  2843.                 ->getRepository(EmployeeAttendance::class)
  2844.                 ->findOneBy(array('employeeId' => $empId'date' => $attDate));
  2845.             if (!$EmployeeAttendance)
  2846.                 $EmployeeAttendance = new EmployeeAttendance;
  2847. //            return new JsonResponse(["success" => true, "data" => $ActivitiesTemplate]);
  2848. //            $attendanceInfo = HumanResource::StoreAttendance($em, $empId, $sysUserId, $data, $EmployeeAttendance, $customTime);
  2849.             $attendanceInfo HumanResource::StoreAttendance($em$empId$sysUserId$data$EmployeeAttendance$attDate$dtTs$timeZoneStrHumanResourceConstant::ATTENDANCE_MARKER_START_WORKING_FORCED);
  2850.             if (!isset($dataByAttId[$attendanceInfo->getId()]))
  2851.                 $dataByAttId[$attendanceInfo->getId()] = array(
  2852.                     'attendanceInfo' => $attendanceInfo,
  2853.                     'empId' => $empId,
  2854.                     'lat' => 0,
  2855.                     'lng' => 0,
  2856.                     'address' => 0,
  2857.                     'sysUserId' => $sysUserId,
  2858.                     'companyId' => $data->getSession()->get(UserConstants::USER_COMPANY_ID),
  2859.                     'appId' => $data->getSession()->get(UserConstants::USER_APP_ID),
  2860.                     'positionArray' => []
  2861.                 );
  2862.             $posData = array(
  2863.                 'ts' => $dtTs,
  2864.                 'lat' => 0,
  2865.                 'lng' => 0,
  2866.                 'marker' => HumanResourceConstant::ATTENDANCE_MARKER_START_WORKING_FORCED,
  2867.                 'src' => 1,
  2868.             );
  2869.             $posDataArray = array(
  2870.                 $dtTs,
  2871.                 0,
  2872.                 0,
  2873.                 HumanResourceConstant::ATTENDANCE_MARKER_START_WORKING_FORCED,
  2874.                 1
  2875.             );
  2876.             $dataByAttId[$attendanceInfo->getId()]['markerId'] = HumanResourceConstant::ATTENDANCE_MARKER_START_WORKING_FORCED;
  2877.             //this markerId will be calclulted and modified to check if user is in our out of office/workplace later
  2878.             $dataByAttId[$attendanceInfo->getId()]['attendanceInfo'] = $attendanceInfo;
  2879.             $dataByAttId[$attendanceInfo->getId()]['positionArray'][] = $posData;
  2880.             $dataByAttId[$attendanceInfo->getId()]['lat'] = 0;  //for last lat lng etc
  2881.             $dataByAttId[$attendanceInfo->getId()]['lng'] = 0;  //for last lat lng etc
  2882.             if (isset($d['address']))
  2883.                 $dataByAttId[$attendanceInfo->getId()]['address'] = '';  //for last lat lng etc
  2884.             $response = array(
  2885.                 'success' => true
  2886.             );
  2887.             foreach ($dataByAttId as $attInfoId => $d) {
  2888.                 $response HumanResource::setAttendanceLogFlutterApp($em,
  2889.                     $d['empId'],
  2890.                     $d['sysUserId'],
  2891.                     $d['companyId'],
  2892.                     $d['appId'],
  2893.                     $data,
  2894.                     $d['attendanceInfo'],
  2895.                     $options,
  2896.                     $d['positionArray'],
  2897.                     $d['lat'],
  2898.                     $d['lng'],
  2899.                     $d['address'],
  2900.                     $d['markerId']
  2901.                 );
  2902.             }
  2903.             if ($data->request->get('requestFromMobile')) {
  2904.                 return new JsonResponse(array(
  2905.                     'success' => $response['success'] == true true false,
  2906.                     'msg' => $response['success'] == true 'Employee activities successfully updated.' 'Action Failed',
  2907.                 ));
  2908.             }
  2909.             return new JsonResponse(
  2910.                 array(
  2911.                     'success' => true,
  2912.                     'dtTs' => $dtTs,
  2913.                     'attDate' => $attDate->format(DATE_RFC822),
  2914.                     'currTsTime' => $currTsTime->format(DATE_RFC822),
  2915.                     'msg' => 'Employee activities successfully updated.',
  2916.                 )
  2917.             );
  2918. //
  2919. //
  2920. //            $response = HumanResource::setAttendanceLog($em, $empId, $sysUserId,
  2921. //                $data->getSession()->get(UserConstants::USER_COMPANY_ID),
  2922. //                $data->getSession()->get(UserConstants::USER_APP_ID),
  2923. //                $data, $attendanceInfo, $options);
  2924. //
  2925. //            if ($data->request->get('requestFromMobile')) {
  2926. //                return new JsonResponse($response);
  2927. //            }
  2928. //
  2929. //            return new JsonResponse(
  2930. //                array(
  2931. //                    'success' => true,
  2932. //                    'msg' => 'Employee activities successfully updated.'
  2933. //                )
  2934. //            );
  2935.             // }
  2936.             // else {
  2937.             //   return new JsonResponse(
  2938.             //     array(
  2939.             //       'success' => false,
  2940.             //       'msg' => "Invalid employee ID"
  2941.             //     )
  2942.             //   );
  2943.             // }
  2944.         } else {
  2945.             if ($data->get('manualAttendance')) {
  2946.                 return $this->render(
  2947.                     'ApplicationBundle:pages/human_resource/input_forms:manual_attendance.html.twig',
  2948.                     array(
  2949.                         'page_title' => 'Manual Attendance',
  2950.                         'workPolicy' => $workHourPolicy,
  2951. //                        'workTime' => json_decode($workHourPolicy->getRepeatationData()),
  2952. //                        'workTime' => json_decode($workHourPolicy->getRepeatationData()),
  2953. //                        'workTime' => json_decode($workHourPolicy->getEmployeeTypeIds(),true),
  2954.                     )
  2955.                 );
  2956.             }
  2957.             // Show all matching employee list during ajax request
  2958.             // Show current location according to id
  2959.             if ($data->get('getCurrLocById')) {
  2960.                 $Id $data->get("id");
  2961.                 $options = array(
  2962.                     'employeeId' => $Id,
  2963.                     'entityDbaseName' => 'work_hour_policy',
  2964.                     'entityDbaseIdField' => 'id',
  2965.                     'entityDbaseEmployeeIdsField' => 'employeeIds',
  2966.                     'entityDesignationIdsField' => 'designationIds',
  2967.                     'entityDepartmentIdsField' => 'departmentIds',
  2968.                     'entityEmployeeTypeIdsField' => 'employee_types',
  2969.                     'limit' => 1,
  2970.                     'single' => 1,
  2971.                 );
  2972.                 $workHourPolicyData HumanResource::getApplicableSettingsDataForEmployee($em$options);
  2973.                 $today = new \DateTime(date('y-m-d'));
  2974.                 $repository $this->getDoctrine()->getRepository(EmployeeAttendance::class);
  2975.                 $ActivitiesTemplate HumanResource::getActivitiesTemplate($repository$Id$today);
  2976.                 return new JsonResponse(["success" => true"workHourPolicyData" => $workHourPolicyData"template" => $ActivitiesTemplate]);
  2977.             }
  2978.         }
  2979.     }
  2980.     public function AttendanceForAppAction(Request $data$remoteVerify 0)
  2981.     {
  2982.         $em $this->getDoctrine()->getManager();
  2983.         $em_goc $this->getDoctrine()->getManager('company_group');
  2984.         $session $data->getSession();
  2985.         $token $session->get(UserConstants::USER_TOKEN);
  2986.         $providedToken $data->headers->get('auth-token');
  2987.         if (empty($providedToken) || $providedToken !== $token) {
  2988.             return new JsonResponse([
  2989.                 'status' => 'error',
  2990.                 'message' => 'Token not match or missing',
  2991.             ], 401);
  2992.         }
  2993.         $workHourPolicy $em->getRepository('ApplicationBundle:WorkHourPolicy')->findAll();
  2994.         $options = array(
  2995.             'notification_enabled' => $this->container->getParameter('notification_enabled'),
  2996.             'notification_server' => $this->container->getParameter('notification_server'),
  2997.         );
  2998.         if ($data->get('DataTable')) {
  2999.             $response HumanResource::HandelAjaxRequestForManualAttendance($em$data);
  3000.             return new JsonResponse($response);
  3001.         }
  3002.         if ($data->request->get('getAttendanceStatus')) {
  3003.             $response HumanResource::getAttendanceStatus($em$data);
  3004.             return new JsonResponse($response);
  3005.         }
  3006. //        if ($session->get('devAdminMode', 0) != 1 && $data->get('returnJson', 0) == 0)
  3007. //            return $this->redirectToRoute('permission_denied_page');
  3008.         // Auto attendance
  3009.         if ($data->get('autoAttendance') && $data->request->has('position_array')) {
  3010. //            $empId = $data->query->get('id');
  3011.             $empId $data->request->get('id'$session->get(UserConstants::USER_EMPLOYEE_ID));
  3012.             $positionsArray $data->request->get('position_array', []);
  3013.             if (is_string($positionsArray)) $positionsArray json_decode($positionsArraytrue);
  3014.             if ($positionsArray == null$positionsArray = [];
  3015.             $dataByAttId = [];
  3016.             $workPlaceType '_UNSET_';
  3017.             foreach ($positionsArray as $d) {
  3018.                 $sysUserId 0;
  3019.                 $userId 0;
  3020.                 $empId 0;
  3021.                 $dtTs 0;
  3022.                 $timeZoneStr '+0000';
  3023. //                $timeZoneStr = '+0600';
  3024.                 $token '_unset_';
  3025.                 if (isset($d['token'])) $token $d['token'];
  3026.                 if (isset($d['employeeId'])) $empId $d['employeeId'];
  3027.                 if (isset($d['userId'])) $userId $d['userId'];
  3028.                 if (isset($d['sysUserId'])) $sysUserId $d['sysUserId'];
  3029.                 if (isset($d['tsMilSec'])) {
  3030.                     $dtTs ceil(($d['tsMilSec']) / 1000);
  3031.                 }
  3032.                 if ($token != '_unset_') {
  3033.                     $sessionData MiscActions::GetSessionDataFromToken($em_goc$token)['sessionData'];
  3034.                     if (isset($sessionData[UserConstants::USER_EMPLOYEE_ID]))
  3035.                         $empId $sessionData[UserConstants::USER_EMPLOYEE_ID];
  3036.                 }
  3037.                 if ($sysUserId == 0)
  3038.                     $sysUserId $userId;
  3039.                 if ($sysUserId == 0)
  3040.                     $sysUserId $em->getRepository(Employee::class)
  3041.                         ->findOneBy(['employeeId' => $empId])->getUserId();
  3042.                 if ($dtTs == 0) {
  3043.                     $currTsTime = new \DateTime();
  3044.                     $dtTs $currTsTime->format('U');
  3045.                 } else {
  3046.                     $currTsTime = new \DateTime('@' $dtTs);
  3047.                 }
  3048.                 $currTsTime->setTimezone(new \DateTimeZone('UTC'));
  3049.                 $attDate = new \DateTime($currTsTime->format('Y-m-d') . ' 00:00:00' $timeZoneStr);
  3050.                 $EmployeeAttendance $this->getDoctrine()
  3051.                     ->getRepository(EmployeeAttendance::class)
  3052.                     ->findOneBy(array('employeeId' => $empId'date' => $attDate));
  3053.                 if (!$EmployeeAttendance)
  3054.                     $EmployeeAttendance = new EmployeeAttendance;
  3055.                 $attendanceInfo HumanResource::StoreAttendance($em$empId$sysUserId$data$EmployeeAttendance$attDate$dtTs$timeZoneStr$d['markerId']);
  3056.                 if ($d['markerId'] == HumanResourceConstant::ATTENDANCE_MARKER_CLOCK_IN) {
  3057.                     if ($empId == 24)
  3058.                         $workPlaceType '_HYBRID_';
  3059.                     else
  3060.                         $workPlaceType '_STATIC_';
  3061.                 }
  3062.                 if (!isset($dataByAttId[$attendanceInfo->getId()]))
  3063.                     $dataByAttId[$attendanceInfo->getId()] = array(
  3064.                         'attendanceInfo' => $attendanceInfo,
  3065.                         'empId' => $empId,
  3066.                         'lat' => 0,
  3067.                         'lng' => 0,
  3068.                         'address' => 0,
  3069.                         'sysUserId' => $sysUserId,
  3070.                         'companyId' => $data->getSession()->get(UserConstants::USER_COMPANY_ID),
  3071.                         'appId' => $data->getSession()->get(UserConstants::USER_APP_ID),
  3072.                         'positionArray' => []
  3073.                     );
  3074.                 $posData = array(
  3075.                     'ts' => $dtTs,
  3076.                     'lat' => $d['lat'],
  3077.                     'lng' => $d['lng'],
  3078.                     'marker' => $d['markerId'],
  3079.                     'src' => 2,
  3080.                 );
  3081.                 $posDataArray = array(
  3082.                     $dtTs,
  3083.                     $d['lat'],
  3084.                     $d['lng'],
  3085.                     $d['markerId'],
  3086.                     2
  3087.                 );
  3088.                 $dataByAttId[$attendanceInfo->getId()]['markerId'] = $d['markerId'];
  3089.                 //this markerId will be calclulted and modified to check if user is in our out of office/workplace later
  3090.                 $dataByAttId[$attendanceInfo->getId()]['attendanceInfo'] = $attendanceInfo;
  3091.                 $dataByAttId[$attendanceInfo->getId()]['positionArray'][] = $posData;
  3092.                 $dataByAttId[$attendanceInfo->getId()]['lat'] = $d['lat'];  //for last lat lng etc
  3093.                 $dataByAttId[$attendanceInfo->getId()]['lng'] = $d['lng'];  //for last lat lng etc
  3094.                 if (isset($d['address']))
  3095.                     $dataByAttId[$attendanceInfo->getId()]['address'] = $d['address'];  //for last lat lng etc
  3096. //                $dataByAttId[$attendanceInfo->getId()]['positionArray'][]=$posDataArray;
  3097.             }
  3098.             $response = array(
  3099.                 'success' => true,
  3100.             );
  3101.             foreach ($dataByAttId as $attInfoId => $d) {
  3102.                 $response HumanResource::setAttendanceLogFlutterApp($em,
  3103.                     $d['empId'],
  3104.                     $d['sysUserId'],
  3105.                     $d['companyId'],
  3106.                     $d['appId'],
  3107.                     $data,
  3108.                     $d['attendanceInfo'],
  3109.                     $options,
  3110.                     $d['positionArray'],
  3111.                     $d['lat'],
  3112.                     $d['lng'],
  3113.                     $d['address'],
  3114.                     $d['markerId']
  3115.                 );
  3116.             }
  3117.             if ($data->request->get('requestFromMobile')) {
  3118.                 $today = new \DateTime(date('y-m-d'));
  3119.                 $repository $this->getDoctrine()->getRepository(EmployeeAttendance::class);
  3120.                 $ActivitiesTemplate HumanResource::getCurrentStatusFromDb($repository$empId$today);
  3121.                 return new JsonResponse(array(
  3122.                     'success' => $response['success'] == true true false,
  3123.                     'msg' => $response['success'] == true 'Employee activities successfully updated.' 'Action Failed',
  3124.                     'workPlaceType' => $workPlaceType,
  3125.                     'data' => $ActivitiesTemplate
  3126.                 ));
  3127.             }
  3128.             return new JsonResponse(
  3129.                 array(
  3130.                     'success' => true,
  3131.                     'msg' => 'Employee activities successfully updated.',
  3132.                     'workPlaceType' => $workPlaceType,
  3133.                 )
  3134.             );
  3135.         } else if ($data->get('autoAttendance')) {
  3136.             $sysUserId 0;
  3137.             $userId 0;
  3138.             $empId 0;
  3139.             $dtTs 0;
  3140. //            $timeZoneStr = '+0600';
  3141.             $timeZoneStr '+0000';
  3142.             if ($data->request->get('requestFromMobile')) {
  3143.                 $empId $data->request->get('employeeId');
  3144.                 $userId $data->request->get('userId'0);
  3145.                 $sysUserId $data->request->get('id'0);
  3146. //        $empId = $em->getRepository(Employee::class)
  3147. //            ->findOneBy(['userId' => $userId])->getEmployeeId();
  3148.             } else {
  3149.                 $empId $data->request->get('employeeId'0);
  3150.                 $sysUserId $data->request->get('userId'0);
  3151.             }
  3152.             $dtTs $data->request->get('timeTs'0);
  3153.             if ($sysUserId == 0)
  3154.                 $sysUserId $userId;
  3155.             if ($sysUserId == 0)
  3156.                 $sysUserId $em->getRepository(Employee::class)
  3157.                     ->findOneBy(['employeeId' => $empId])->getUserId();
  3158.             if ($dtTs == 0) {
  3159.                 $currTsTime = new \DateTime();
  3160.                 $dtTs $currTsTime->format('U');
  3161.             } else {
  3162.                 $currTsTime = new \DateTime('@' $dtTs);
  3163.             }
  3164.             if ($sysUserId == 0)
  3165.                 $sysUserId $userId;
  3166.             if ($sysUserId == 0)
  3167.                 $sysUserId $em->getRepository(Employee::class)
  3168.                     ->findOneBy(['employeeId' => $empId])->getUserId();
  3169.             $today = new \DateTime(date('y-m-d'));
  3170.             $currTsTime->setTimezone(new \DateTimeZone('UTC'));
  3171.             $attDate = new \DateTime($currTsTime->format('Y-m-d') . ' 00:00:00' $timeZoneStr);
  3172.             $EmployeeAttendance $this->getDoctrine()
  3173.                 ->getRepository(EmployeeAttendance::class)
  3174.                 ->findOneBy(array('employeeId' => $empId'date' => $attDate));
  3175.             if (!$EmployeeAttendance)
  3176.                 $EmployeeAttendance = new EmployeeAttendance;
  3177. //            return new JsonResponse(["success" => true, "data" => $ActivitiesTemplate]);
  3178. //            $attendanceInfo = HumanResource::StoreAttendance($em, $empId, $sysUserId, $data, $EmployeeAttendance, $customTime);
  3179.             $attendanceInfo HumanResource::StoreAttendance($em$empId$sysUserId$data$EmployeeAttendance$attDate$dtTs$timeZoneStrHumanResourceConstant::ATTENDANCE_MARKER_START_WORKING_FORCED);
  3180.             if (!isset($dataByAttId[$attendanceInfo->getId()]))
  3181.                 $dataByAttId[$attendanceInfo->getId()] = array(
  3182.                     'attendanceInfo' => $attendanceInfo,
  3183.                     'empId' => $empId,
  3184.                     'lat' => 0,
  3185.                     'lng' => 0,
  3186.                     'address' => 0,
  3187.                     'sysUserId' => $sysUserId,
  3188.                     'companyId' => $data->getSession()->get(UserConstants::USER_COMPANY_ID),
  3189.                     'appId' => $data->getSession()->get(UserConstants::USER_APP_ID),
  3190.                     'positionArray' => []
  3191.                 );
  3192.             $posData = array(
  3193.                 'ts' => $dtTs,
  3194.                 'lat' => 0,
  3195.                 'lng' => 0,
  3196.                 'marker' => HumanResourceConstant::ATTENDANCE_MARKER_START_WORKING_FORCED,
  3197.                 'src' => 1,
  3198.             );
  3199.             $posDataArray = array(
  3200.                 $dtTs,
  3201.                 0,
  3202.                 0,
  3203.                 HumanResourceConstant::ATTENDANCE_MARKER_START_WORKING_FORCED,
  3204.                 1
  3205.             );
  3206.             $dataByAttId[$attendanceInfo->getId()]['markerId'] = HumanResourceConstant::ATTENDANCE_MARKER_START_WORKING_FORCED;
  3207.             //this markerId will be calclulted and modified to check if user is in our out of office/workplace later
  3208.             $dataByAttId[$attendanceInfo->getId()]['attendanceInfo'] = $attendanceInfo;
  3209.             $dataByAttId[$attendanceInfo->getId()]['positionArray'][] = $posData;
  3210.             $dataByAttId[$attendanceInfo->getId()]['lat'] = 0;  //for last lat lng etc
  3211.             $dataByAttId[$attendanceInfo->getId()]['lng'] = 0;  //for last lat lng etc
  3212.             if (isset($d['address']))
  3213.                 $dataByAttId[$attendanceInfo->getId()]['address'] = '';  //for last lat lng etc
  3214.             $response = array(
  3215.                 'success' => true
  3216.             );
  3217.             foreach ($dataByAttId as $attInfoId => $d) {
  3218.                 $response HumanResource::setAttendanceLogFlutterApp($em,
  3219.                     $d['empId'],
  3220.                     $d['sysUserId'],
  3221.                     $d['companyId'],
  3222.                     $d['appId'],
  3223.                     $data,
  3224.                     $d['attendanceInfo'],
  3225.                     $options,
  3226.                     $d['positionArray'],
  3227.                     $d['lat'],
  3228.                     $d['lng'],
  3229.                     $d['address'],
  3230.                     $d['markerId']
  3231.                 );
  3232.             }
  3233.             if ($data->request->get('requestFromMobile')) {
  3234.                 return new JsonResponse(array(
  3235.                     'success' => $response['success'] == true true false,
  3236.                     'msg' => $response['success'] == true 'Employee activities successfully updated.' 'Action Failed',
  3237.                 ));
  3238.             }
  3239.             return new JsonResponse(
  3240.                 array(
  3241.                     'success' => true,
  3242.                     'dtTs' => $dtTs,
  3243.                     'attDate' => $attDate->format(DATE_RFC822),
  3244.                     'currTsTime' => $currTsTime->format(DATE_RFC822),
  3245.                     'msg' => 'Employee activities successfully updated.',
  3246.                 )
  3247.             );
  3248. //
  3249. //
  3250. //            $response = HumanResource::setAttendanceLog($em, $empId, $sysUserId,
  3251. //                $data->getSession()->get(UserConstants::USER_COMPANY_ID),
  3252. //                $data->getSession()->get(UserConstants::USER_APP_ID),
  3253. //                $data, $attendanceInfo, $options);
  3254. //
  3255. //            if ($data->request->get('requestFromMobile')) {
  3256. //                return new JsonResponse($response);
  3257. //            }
  3258. //
  3259. //            return new JsonResponse(
  3260. //                array(
  3261. //                    'success' => true,
  3262. //                    'msg' => 'Employee activities successfully updated.'
  3263. //                )
  3264. //            );
  3265.             // }
  3266.             // else {
  3267.             //   return new JsonResponse(
  3268.             //     array(
  3269.             //       'success' => false,
  3270.             //       'msg' => "Invalid employee ID"
  3271.             //     )
  3272.             //   );
  3273.             // }
  3274.         } else {
  3275.             if ($data->get('manualAttendance')) {
  3276.                 return $this->render(
  3277.                     'ApplicationBundle:pages/human_resource/input_forms:manual_attendance.html.twig',
  3278.                     array(
  3279.                         'page_title' => 'Manual Attendance',
  3280.                         'workPolicy' => $workHourPolicy,
  3281. //                        'workTime' => json_decode($workHourPolicy->getRepeatationData()),
  3282. //                        'workTime' => json_decode($workHourPolicy->getRepeatationData()),
  3283. //                        'workTime' => json_decode($workHourPolicy->getEmployeeTypeIds(),true),
  3284.                     )
  3285.                 );
  3286.             }
  3287.             // Show all matching employee list during ajax request
  3288.             // Show current location according to id
  3289.             if ($data->get('getCurrLocById')) {
  3290.                 $Id $data->get("id");
  3291.                 $options = array(
  3292.                     'employeeId' => $Id,
  3293.                     'entityDbaseName' => 'work_hour_policy',
  3294.                     'entityDbaseIdField' => 'id',
  3295.                     'entityDbaseEmployeeIdsField' => 'employeeIds',
  3296.                     'entityDesignationIdsField' => 'designationIds',
  3297.                     'entityDepartmentIdsField' => 'departmentIds',
  3298.                     'entityEmployeeTypeIdsField' => 'employee_types',
  3299.                     'limit' => 1,
  3300.                     'single' => 1,
  3301.                 );
  3302.                 $workHourPolicyData HumanResource::getApplicableSettingsDataForEmployee($em$options);
  3303.                 $today = new \DateTime(date('y-m-d'));
  3304.                 $repository $this->getDoctrine()->getRepository(EmployeeAttendance::class);
  3305.                 $ActivitiesTemplate HumanResource::getActivitiesTemplate($repository$Id$today);
  3306.                 return new JsonResponse(["success" => true"workHourPolicyData" => $workHourPolicyData"template" => $ActivitiesTemplate]);
  3307.             }
  3308.         }
  3309.     }
  3310.     public function getCurrentStatusAction($id)
  3311.     {
  3312.         $today = new \DateTime(date('y-m-d'));
  3313.         $repository $this->getDoctrine()->getRepository(EmployeeAttendance::class);
  3314.         $ActivitiesTemplate HumanResource::getCurrentStatusFromDb($repository$id$today);
  3315.         return new JsonResponse(["success" => true"data" => $ActivitiesTemplate]);
  3316.     }
  3317.     public function CurrentAttendanceAction(Request $data)
  3318.     {
  3319.         $em $this->getDoctrine()->getManager();
  3320.         $options = array(
  3321.             'notification_enabled' => $this->container->getParameter('notification_enabled'),
  3322.             'notification_server' => $this->container->getParameter('notification_server'),
  3323.         );
  3324.         if ($data->get('DataTable')) {
  3325.             $response HumanResource::HandelAjaxRequestForManualAttendance($em$data);
  3326.             return new JsonResponse($response);
  3327.         }
  3328.         if ($data->request->get('getAttendanceStatus')) {
  3329.             $response HumanResource::getAttendanceStatus($em$data);
  3330.             return new JsonResponse($response);
  3331.         }
  3332.         // Auto attendance
  3333.         if ($data->get('autoAttendance')) {
  3334.             $empId $data->query->get('id');
  3335.             $sysUserId 0;
  3336.             if ($data->get('requestFromMobile')) {
  3337.                 $sysUserId $data->request->get('id');
  3338.                 $empId $em->getRepository(Employee::class)
  3339.                     ->findOneBy(['userId' => $sysUserId])->getEmployeeId();
  3340.             } else {
  3341.                 $sysUserId $em->getRepository(Employee::class)
  3342.                     ->findOneBy(['employeeId' => $empId])->getUserId();
  3343.             }
  3344.             $customTime $data->get('time');
  3345.             $today = new \DateTime(date('y-m-d'));
  3346.             $EmployeeAttendance $this->getDoctrine()
  3347.                 ->getRepository(EmployeeAttendance::class)
  3348.                 ->findOneBy(array('employeeId' => $empId'date' => $today));
  3349.             if (!$EmployeeAttendance)
  3350.                 $EmployeeAttendance = new EmployeeAttendance;
  3351.             $attendanceInfo HumanResource::StoreAttendance($em$empId$sysUserId$data$EmployeeAttendance$customTime);
  3352.             $response HumanResource::setAttendanceLog($em$empId$sysUserId,
  3353.                 $data->getSession()->get(UserConstants::USER_COMPANY_ID),
  3354.                 $data->getSession()->get(UserConstants::USER_APP_ID),
  3355.                 $data$attendanceInfo$options);
  3356.             if ($data->get('requestFromMobile')) {
  3357.                 return new JsonResponse([$response]);
  3358.             }
  3359.             return new JsonResponse(
  3360.                 array(
  3361.                     'success' => true,
  3362.                     'msg' => 'Employee activities successfully updated.'
  3363.                 )
  3364.             );
  3365.             // }
  3366.             // else {
  3367.             //   return new JsonResponse(
  3368.             //     array(
  3369.             //       'success' => false,
  3370.             //       'msg' => "Invalid employee ID"
  3371.             //     )
  3372.             //   );
  3373.             // }
  3374.         } else {
  3375.             if ($data->get('manualAttendance')) {
  3376.                 return $this->render(
  3377.                     'ApplicationBundle:pages/human_resource/report:current_attendance.html.twig',
  3378.                     array(
  3379.                         'page_title' => 'Current Attendance Status',
  3380.                     )
  3381.                 );
  3382.             }
  3383.             // Show all matching employee list during ajax request
  3384.             // Show current location according to id
  3385.             if ($data->get('getCurrLocById')) {
  3386.                 $Id $data->get("id");
  3387.                 $today = new \DateTime(date('y-m-d'));
  3388.                 $repository $this->getDoctrine()->getRepository(EmployeeAttendance::class);
  3389.                 $ActivitiesTemplate HumanResource::getActivitiesTemplate($repository$Id$today);
  3390.                 return new JsonResponse(["success" => true"template" => $ActivitiesTemplate]);
  3391.             }
  3392.         }
  3393.     }
  3394.     public function EmployeeLeaveAction(Request $data$id 0)
  3395.     {
  3396.         $em $this->getDoctrine()->getManager();
  3397.         $request $data;
  3398.         if (!$id) {
  3399.             if ($data->isMethod('GET')) {
  3400.                 $EmpID $data->query->get('id');
  3401.                 $LeaveType $data->query->get('leaveType');
  3402.                 if ($data->query->has('id') && $data->query->has('leaveType')) {
  3403.                     $response HumanResource::HandelAjaxRequestForLeaveApp($em$EmpID$LeaveType);
  3404.                     return new JsonResponse($response);
  3405.                 }
  3406.                 if ($data->query->has('id')) {
  3407.                     $Response HumanResource::HandelAjaxRequestForLeaveApp($em$EmpID);
  3408.                     return new JsonResponse($Response);
  3409.                 }
  3410.                 $TemplateData HumanResource::TwigDataForLeaveApp($emFalse);
  3411.                 return $this->render(
  3412.                     'ApplicationBundle:pages/human_resource/input_forms:employee_leave.html.twig',
  3413.                     array(
  3414.                         'page_title' => $TemplateData['Title'],
  3415.                         'EmployeeList' => $TemplateData['EmployeeList'],
  3416.                         'DesignationList' => $TemplateData['DesignationList'],
  3417.                         'HasUpdateMode' => false
  3418.                     )
  3419.                 );
  3420.             } else {
  3421.                 $CompanyId $this->getLoggedUserCompanyId($data);
  3422.                 $Response HumanResource::StoreDataForLeaveApplication($em$id$datafalse$CompanyId);
  3423.                 if ($Response['HasErr']) {
  3424.                     $this->addFlash('error'$Response['msg']);
  3425.                     if ($data->request->has('returnJson')) {
  3426.                         return new JsonResponse(array(
  3427.                             'success' => false,
  3428.                             'errorStr' => $Response['msg'],
  3429.                         ));
  3430.                     } else {
  3431.                         return $this->redirectToRoute('employee_leave');
  3432.                     }
  3433.                 }
  3434.                 $applicationId $Response['applicationId'];
  3435.                 $em_goc $this->getDoctrine()->getManager('company_group');
  3436.                 $file_path_list = [];
  3437.                 if ($applicationId != 0) {
  3438.                     if (!empty($request->files)) {
  3439.                         MiscActions::RemoveFilesForEntityDoc($em_goc'EmployeeLeaveApplication'$applicationId);
  3440.                         $storePath 'uploads/LeaveDoc/';
  3441.                         $path "";
  3442.                         $file_path "";
  3443.                         $session $request->getSession();
  3444.                         MiscActions::RemoveExpiredFiles($em_goc);
  3445.                         foreach ($request->files as $uploadedFileGG) {
  3446.                             //            if($uploadedFile->getImage())
  3447.                             //                var_dump($uploadedFile->getFile());
  3448.                             //                var_dump($uploadedFile);
  3449.                             $tempD $uploadedFileGG;
  3450.                             if (!is_array($uploadedFileGG)) {
  3451.                                 $uploadedFileGG = array();
  3452.                                 $uploadedFileGG[] = $tempD;
  3453.                             }
  3454.                             foreach ($uploadedFileGG as $uploadedFile) {
  3455.                                 if ($uploadedFile != null) {
  3456.                                     $extension $uploadedFile->guessExtension();
  3457.                                     $size $uploadedFile->getSize();
  3458.                                     $fileName 'LDOC_' $applicationId '_' . (md5(uniqid())) . '.' $uploadedFile->guessExtension();
  3459.                                     $path $fileName;
  3460.                                     $upl_dir $this->container->getParameter('kernel.root_dir') . '/../web/' $storePath;
  3461.                                     if (!file_exists($upl_dir)) {
  3462.                                         mkdir($upl_dir0777true);
  3463.                                     }
  3464.                                     if (file_exists($upl_dir '' $path)) {
  3465.                                         chmod($upl_dir '' $path0755);
  3466.                                         unlink($upl_dir '' $path);
  3467.                                     }
  3468.                                     $file $uploadedFile->move($upl_dir$path);
  3469.                                     $expireNever 1;
  3470.                                     $expireTs 0;
  3471.                                     $EntityFile = new EntityFile();
  3472.                                     $EntityFile->setPath($this->container->getParameter('kernel.root_dir') . '/../web/' $storePath $path);
  3473.                                     $EntityFile->setMarker('_GEN_');
  3474.                                     $EntityFile->setExtension($extension);
  3475.                                     $EntityFile->setExpireTs($expireTs);
  3476.                                     $EntityFile->setSize($size);
  3477.                                     $EntityFile->setRelativePath($storePath $path);
  3478.                                     $EntityFile->setEntityName('EmployeeLeaveApplication');
  3479.                                     $EntityFile->setEntityBundle('EmployeeLeaveApplication');
  3480.                                     $EntityFile->setEntityId($applicationId);
  3481.                                     $EntityFile->setEntityIdField('employeeLeaveApplicationId');
  3482.                                     $EntityFile->setModifyFieldSetter('setFiles');
  3483.                                     $EntityFile->setDocIdForApplicant(0);
  3484.                                     $EntityFile->setUserId($session->get(UserConstants::USER_ID0));
  3485.                                     $EntityFile->setAppId($session->get(UserConstants::USER_APP_ID0));
  3486.                                     $EntityFile->setEmployeeId($session->get(UserConstants::USER_EMPLOYEE_ID0));
  3487.                                     $EntityFile->setUserType($session->get(UserConstants::USER_TYPE0));
  3488.                                     $em_goc->persist($EntityFile);
  3489.                                     $em_goc->flush();
  3490.                                     $EntityFileId $EntityFile->getId();
  3491.                                 }
  3492.                                 if ($path != "")
  3493.                                     $file_path_list[] = ($storePath $path);
  3494.                             }
  3495.                         }
  3496.                         $g_path $this->container->getParameter('kernel.root_dir') . '/../web/' $storePath $path;
  3497.                         $v $em->getRepository('ApplicationBundle:EmployeeLeaveApplication')->findOneBy(array(
  3498.                             'employeeLeaveApplicationId' => $applicationId,
  3499.                         ));
  3500.                         if ($v) {
  3501.                             $v->setFiles(implode(','$file_path_list));
  3502.                             $em->flush();
  3503.                         } else {
  3504.                         }
  3505.                     }
  3506.                 }
  3507.                 // $this->addFlash('success', 'Application submitted successfully!');
  3508.                 // return $this->redirectToRoute('leave_application_list');
  3509.                 if ($data->request->has('returnJson')) {
  3510.                     return new JsonResponse(array(
  3511.                         'success' => true,
  3512.                     ));
  3513.                 } else {
  3514.                     return $this->redirectToRoute('view_employee_leave_application', array('id' => $applicationId));
  3515.                 }
  3516.             }
  3517.         } else {
  3518.             if ($data->isMethod('GET')) {
  3519.                 $ApplicationRepo $em->getRepository(EmployeeLeaveApplication::class);
  3520.                 $OldData $ApplicationRepo->find(array('employeeLeaveApplicationId' => $id));
  3521.                 $TemplateData HumanResource::TwigDataForLeaveApp($em$OldData);
  3522.                 return $this->render(
  3523.                     'ApplicationBundle:pages/human_resource/input_forms:employee_leave.html.twig',
  3524.                     array(
  3525.                         'page_title' => $TemplateData['Title'],
  3526.                         'EmployeeList' => $TemplateData['EmployeeList'],
  3527.                         'DesignationList' => $TemplateData['DesignationList'],
  3528.                         'OldData' => $TemplateData['OldData'],
  3529.                         'AvailableLeave' => $TemplateData['AvailableLeave'],
  3530.                         'HasUpdateMode' => true
  3531.                     )
  3532.                 );
  3533.             } else {
  3534.                 $CompanyId $this->getLoggedUserCompanyId($data);
  3535.                 $Response HumanResource::StoreDataForLeaveApplication($em$id$datatrue$CompanyId);
  3536.                 if ($Response['HasErr']) {
  3537.                     $this->addFlash('error'$Response['msg']);
  3538.                     return $this->redirectToRoute('employee_leave');
  3539.                 }
  3540.                 $this->addFlash('success'"Application updated successfully!");
  3541.                 return $this->redirectToRoute('leave_application_list');
  3542.             }
  3543.         }
  3544.     }
  3545.     public function ViewLeaveApplicationAction(Request $request$id)
  3546.     {
  3547.         $em $this->getDoctrine()->getManager();
  3548.         if ($id) {
  3549.             $TwigData HumanResource::TwigDataForViewLeaveApplication($em$request$id);
  3550.             if ($TwigData['HasErr']) {
  3551.                 return new JsonResponse(array(
  3552.                     'success' => false,
  3553.                     'msg' => $TwigData['Msg']
  3554.                 ));
  3555.             }
  3556.             return $this->render(
  3557.                 'ApplicationBundle:pages/human_resource/views:leave_application_view.html.twig',
  3558.                 array(
  3559.                     'page_title' => 'View Leave Application',
  3560.                     'Applicant' => $TwigData['Applicant'],
  3561.                     'Application' => $TwigData['Application'],
  3562.                     'LeaveType' => $TwigData['LeaveType'],
  3563.                     'LeaveCategory' => $TwigData['LeaveCategory'],
  3564.                     'leaveDataArray' => $TwigData['leaveDataArray'],
  3565.                     'FrwdEmp' => $TwigData['FrwdEmp'],
  3566.                     'ApplicantDesg' => $TwigData['ApplicantDesg'],
  3567.                     'approval_status' => $TwigData['approval_status'],
  3568.                     'approval_data' => $TwigData['approval_data'],
  3569.                     'document_log' => $TwigData['document_log'],
  3570.                     'auto_created' => 0,
  3571.                 )
  3572.             );
  3573.         }
  3574.         return new JsonResponse(array(
  3575.             'success' => false,
  3576.             'msg' => 'Wrong URL format! Please try with application ID'
  3577.         ));
  3578.     }
  3579.     public function PrintLeaveApplicationAction(Request $request$id)
  3580.     {
  3581.         if ($id) {
  3582.             $em $this->getDoctrine()->getManager();
  3583.             $company_data Company::getCompanyData($em1);
  3584.             $Authorizations System::getSignatureListForDocumentPrint($emarray_flip(GeneralConstant::$Entity_list)['EmployeeLeaveApplication'], $id);
  3585.             $TwigData HumanResource::TwigDataForViewLeaveApplication($em$request$id);
  3586.             if ($TwigData['HasErr']) {
  3587.                 return new JsonResponse(array(
  3588.                     'success' => false,
  3589.                     'msg' => $TwigData['Msg']
  3590.                 ));
  3591.             }
  3592.             $ApplicationCategory $TwigData['Application']->getLeaveCategory();
  3593.             $ApplicationType = ($ApplicationCategory != && $ApplicationCategory != 2) ? $TwigData['LeaveType']: '';
  3594.             return $this->render(
  3595.                 'ApplicationBundle:pages/human_resource/print:leave_application_print.html.twig',
  3596.                 array(
  3597.                     'page_title' => 'Print Leave Application',
  3598.                     'export' => 'pdf,print',
  3599.                     'company_name' => $company_data->getName(),
  3600.                     'company_data' => $company_data,
  3601.                     'company_address' => $company_data->getAddress(),
  3602.                     'company_image' => $company_data->getImage(),
  3603.                     'Authorizations' => $Authorizations,
  3604.                     'ApplicationType' => $ApplicationType,
  3605.                     'ApplicationCategory' => $ApplicationCategory,
  3606.                     'Applicant' => $TwigData['Applicant'],
  3607.                     'Application' => $TwigData['Application'],
  3608.                     'LeaveType' => $TwigData['LeaveType'],
  3609.                     'LeaveCategory' => $TwigData['LeaveCategory'],
  3610.                     'leaveDataArray' => $TwigData['leaveDataArray'],
  3611.                     'FrwdEmp' => $TwigData['FrwdEmp'],
  3612.                     'ApplicantDesg' => $TwigData['ApplicantDesg'],
  3613.                     'approval_status' => $TwigData['approval_status'],
  3614.                     'approval_data' => $TwigData['approval_data'],
  3615.                     'document_log' => $TwigData['document_log'],
  3616.                     'red' => 0,
  3617.                     'invoice_footer' => 0
  3618.                 )
  3619.             );
  3620.         }
  3621.         return new JsonResponse(array(
  3622.             'success' => false,
  3623.             'msg' => 'Wrong URL format! Please try with application ID'
  3624.         ));
  3625.     }
  3626.     public function LeaveApplicationListAction(Request $request)
  3627.     {
  3628.         $em $this->getDoctrine()->getManager();
  3629.         $response HumanResource::GetEmployeeLeaveApplicationList($em$request);
  3630.         if ($request->isMethod('GET')) {
  3631.             return $this->render("ApplicationBundle:pages/human_resource/list:leave_application_list.html.twig", array(
  3632.                 'page_title' => 'Leave Application List',
  3633.                 'application_data' => $response,
  3634.             ));
  3635.         }
  3636.     }
  3637.     public function PayrollPolicySettingsAction(Request $request$id)
  3638.     {
  3639.         $em $this->getDoctrine()->getManager();
  3640.         $CompanyId $this->getLoggedUserCompanyId($request);
  3641.         if ($id) {
  3642.             if ($request->isMethod('GET')) {
  3643.                 $Row $em->getRepository(PayrollPolicy::class)->find($id);
  3644.                 if (!$Row) {
  3645.                     $this->addFlash('error''Invalid Payroll Policy Id');
  3646.                     return $this->redirectToRoute('payroll_policy_settings');
  3647.                 }
  3648.                 $TwigData HumanResource::GetPayrollPolicyTwigData($em);
  3649.                 $OldData HumanResource::GetPayrollPolicyTwigData($em$id);
  3650.                 return $this->render('ApplicationBundle:pages/human_resource/input_forms:payroll_policy_settings.html.twig', array(
  3651.                     'page_title' => 'Update Payroll Policy Settings',
  3652.                     'EmployeeIds' => $TwigData['EmployeeIds'],
  3653.                     'EmployeeType' => $TwigData['EmployeeType'],//
  3654.                     'department' => $TwigData['department'],
  3655.                     'Designation' => $TwigData['Designation'],
  3656.                     'WorkingDays' => $TwigData['WorkingDays'],
  3657.                     'OldData' => $OldData['Row'],
  3658.                     'earningAspects' => HumanResourceConstant::$earningAspectsForPayrollPolicy,
  3659.                     'leaveTypes' => HumanResourceConstant::$LeaveTypeForPayrollPolicy,
  3660.                     'leaveTypesArray' => HumanResourceConstant::$LeaveTypeArrayForPayrollPolicy,
  3661.                     'deductionAspects' => HumanResourceConstant::$deductionAspects,
  3662.                     'deductionCondition' => json_decode($Row->getDeductionCondition(), true),
  3663.                     'HasUpdateMode' => true,
  3664.                 ));
  3665.             } else {
  3666.                 $Response HumanResource::StorePayrollPolicyData($em$id$CompanyId$request);
  3667.                 if ($Response['HasErr']) {
  3668.                     $this->addFlash('error'$Response['msg']);
  3669.                     return $this->redirectToRoute('payroll_policy_settings');
  3670.                 }
  3671.                 return $this->redirectToRoute('payroll_policy_settings');
  3672. //        if ($Response['isSuccess']) {
  3673. //          return new JsonResponse(array('success' => true, 'msg' => 'don\'t forget to redirect'));
  3674. //        }
  3675. //        return new JsonResponse(array('success' => false, 'msg' => 'Sorry something went wrong'));
  3676.             }
  3677.         } else {
  3678.             if ($request->isMethod('GET')) {
  3679.                 if ($request->query->get('GetDocHash')) {
  3680.                     $Dochash HumanResource::GenerateDocHashForPayrollSettings($em$request);
  3681.                     return new JsonResponse($Dochash);
  3682.                 }
  3683.                 $TwigData HumanResource::GetPayrollPolicyTwigData($em);
  3684.                 return $this->render(
  3685.                     'ApplicationBundle:pages/human_resource/input_forms:payroll_policy_settings.html.twig',
  3686.                     array(
  3687.                         'page_title' => 'Create Payroll Policy Settings',
  3688.                         'EmployeeIds' => $TwigData['EmployeeIds'],
  3689.                         'EmployeeType' => $TwigData['EmployeeType'],
  3690.                         'WorkingDays' => $TwigData['WorkingDays'],
  3691.                         'Designation' => $TwigData['Designation'],
  3692.                         'department' => $TwigData['department'],
  3693.                         'earningAspects' => HumanResourceConstant::$earningAspectsForPayrollPolicy,
  3694.                         'leaveTypes' => HumanResourceConstant::$LeaveTypeForPayrollPolicy,
  3695.                         'leaveTypesArray' => HumanResourceConstant::$LeaveTypeArrayForPayrollPolicy,
  3696.                         'deductionAspects' => HumanResourceConstant::$deductionAspects,
  3697.                         'HasUpdateMode' => false
  3698.                     )
  3699.                 );
  3700.             } else {
  3701.                 $Response HumanResource::StorePayrollPolicyData($em$id$CompanyId$request);
  3702.                 if ($Response['HasErr']) {
  3703.                     $this->addFlash('error'$Response['msg']);
  3704.                     return $this->redirectToRoute('payroll_policy_settings');
  3705.                 }
  3706.                 return $this->redirectToRoute('payroll_policy_settings');
  3707. //        return new JsonResponse(array("success" => true, 'msg' => 'Dont forget to redirect!'));
  3708.             }
  3709.         }
  3710.     }
  3711.     public function AttendanceReportAction(Request $request$apiKey 'impose')
  3712.     {
  3713.         $em $this->getDoctrine()->getManager();
  3714.         $attendanceSource HumanResourceConstant::$attendanceSources;
  3715.         $routeName $request->attributes->get('_route');
  3716.         if ($routeName == 'app_get_attendendance_data') {
  3717.             $ReportData HumanResource::GenerateAttendanceReport($em$request$request->get('considerCurrTsIfNoOut'1));
  3718.             $newReports = [];
  3719.             foreach ($ReportData['Reports'] as $gg) {
  3720.                 foreach ($gg as $d) {
  3721.                     $newReports[] = $d;
  3722. //                if(!isset($newReports[$d['id']]))
  3723. //                    $newReports[$d['id']]=array();
  3724. //                    $newReports[$d['id']][]=$d;
  3725.                 }
  3726.             }
  3727.             return new JsonResponse (array(
  3728.                 'attendanceSource' => $attendanceSource,
  3729. //                'Reports' => $ReportData['Reports'],
  3730.                 'Reports' => $newReports,
  3731.                 'from_date' => $ReportData['from_date'],
  3732.                 'to_date' => $ReportData['to_date'],
  3733.                 'report_for' => $ReportData['generated_for'],
  3734.                 'attendance' => $ReportData['attendance'],
  3735.             ));
  3736.         } else {
  3737.             $EmployeeIds $em->getRepository(EmployeeDetails::class)->findAll();
  3738.             $Departments $em->getRepository(SysDepartment::class)->findAll();
  3739.             if ($request->isMethod('GET')) {
  3740.                 return $this->render('ApplicationBundle:pages/human_resource/report:attendance_report.html.twig', array(
  3741.                     'page_title' => 'Attendance Report',
  3742.                     'employes' => $EmployeeIds,
  3743.                     'departments' => $Departments,
  3744.                     'isMethodGet' => true,
  3745.                     'from_date' => '',
  3746.                     'to_date' => '',
  3747.                     'report_for' => '',
  3748.                     'attendance' => [],
  3749.                     'Reports' => [],
  3750.                     'qry' => ''
  3751.                 ));
  3752.             }
  3753.             $ReportData HumanResource::GenerateAttendanceReport($em$request$request->request->get('considerCurrTsIfNoOut'0));
  3754.             if ($request->request->get('returnJson'0) == 1) {
  3755.                 return new JsonResponse($ReportData);
  3756.             }
  3757.             $Qry "start_date=" $ReportData['from_date'] . '&' "end_date=" $ReportData['to_date'] . '&' "period_type=" $ReportData['period_type'] . '&' "show_all=" $ReportData['show_all'] . '&' "department=" $request->get('department') . '&' "employes=" implode(',', ($request->get('employes') ? $request->get('employes') : []));
  3758.             return $this->render('ApplicationBundle:pages/human_resource/report:attendance_report.html.twig', array(
  3759.                 'page_title' => 'Attendance Report',
  3760.                 'isMethodGet' => false,
  3761.                 'departments' => $Departments,
  3762.                 'employes' => $EmployeeIds,
  3763.                 'attendanceSource' => $attendanceSource,
  3764.                 'Reports' => $ReportData['Reports'],
  3765.                 'from_date' => $ReportData['from_date'],
  3766.                 'to_date' => $ReportData['to_date'],
  3767.                 'report_for' => $ReportData['generated_for'],
  3768.                 'attendance' => $ReportData['attendance'],
  3769.                 'qry' => $Qry
  3770.             ));
  3771.         }
  3772.     }
  3773.     public function PrintAttendanceReportAction(Request $request)
  3774.     {
  3775.         $em $this->getDoctrine()->getManager();
  3776.         $company_data Company::getCompanyData($em1);
  3777.         $ReportData HumanResource::GenerateAttendanceReport($em$request);
  3778.         return $this->render(
  3779.             'ApplicationBundle:pages/human_resource/print:print_attendance_report.html.twig',
  3780.             array(
  3781.                 'page_title' => 'Print Attendance Report',
  3782.                 'export' => 'pdf,print',
  3783.                 'company_name' => $company_data->getName(),
  3784.                 'company_data' => $company_data,
  3785.                 'company_address' => $company_data->getAddress(),
  3786.                 'company_image' => $company_data->getImage(),
  3787.                 'Reports' => $ReportData['Reports'],
  3788.                 'from_date' => $ReportData['from_date'],
  3789.                 'to_date' => $ReportData['to_date'],
  3790.                 'report_for' => $ReportData['generated_for'],
  3791.                 'attendance' => $ReportData['attendance'],
  3792.                 'red' => 0
  3793.             )
  3794.         );
  3795.     }
  3796.     public function DisburseSalaryAction(Request $request)
  3797.     {
  3798.         $em $this->getDoctrine()->getManager();
  3799.         $EmployeeIds $em->getRepository(EmployeeDetails::class)->findBy(
  3800.             array(
  3801.                 'emp_status' => 1
  3802.             )
  3803.         );
  3804.         $startDate $request->get('salary_start_date''');
  3805.         $endDate $request->get('salary_till_date''');
  3806.         $filterType $request->get('filterType'1);
  3807.         $filterBranchIds $request->get('branchIds', []);
  3808.         $filterBankIds $request->get('bankIds', []);
  3809.         $filterDepartmentIds $request->get('departmentIds', []);
  3810.         $filterEmployeeIds $request->get('employeeIds', []);
  3811.         $Departments $em->getRepository(SysDepartment::class)->findAll();
  3812.         $attendance $em->getRepository(EmployeeAttendanceLog::class)->findAll();
  3813.         $banks $em->getRepository(BankList::class)->findAll();
  3814.         $branches $em->getRepository(Branch::class)->findAll();
  3815.         if ($request->isMethod('GET')) {
  3816.             return $this->render('ApplicationBundle:pages/human_resource/report:disburse_salary.html.twig', array(
  3817.                 'page_title' => 'Disburse Salary',
  3818.                 'EmployeeIds' => $EmployeeIds,
  3819.                 'departments' => $Departments,
  3820.                 'attendance' => $attendance,
  3821.                 'branches' => $branches,
  3822.                 'banks' => $banks,
  3823.                 'SalaryReports' => [],
  3824.                 'from_date' => '',
  3825.                 'to_date' => '',
  3826.                 'Qry' => '',
  3827.                 'isMethodGet' => true,
  3828.                 'filterType' => $filterType,
  3829.                 'startDate' => $startDate,
  3830.                 'endDate' => $endDate,
  3831.                 'filterBranchIds' => $filterBranchIds,
  3832.                 'filterBankIds' => $filterBankIds,
  3833.                 'filterDepartmentIds' => $filterDepartmentIds,
  3834.                 'filterEmployeeIds' => $filterEmployeeIds,
  3835.             ));
  3836.         }
  3837.         $SalaryReports HumanResource::BasicDeduction($em$request);
  3838. //        $SalaryReportsNew = HumanResource::calculateSalary($em,
  3839. //            array(
  3840. //                'startDate' => $request->get('salary_start_date', ''),
  3841. //                'endDate' => $request->get('salary_end_date', ''),
  3842. //                'timeZone' => $request->get('time_zone', '+0600'),
  3843. //                'employeeIds' => $request->get('employeeIds', []),
  3844. //                'departmentIds' => $request->get('department', []),
  3845. //                'allFlag' => $request->get('show_all', 0),
  3846. //
  3847. //            )
  3848. //        );
  3849.         $Qry "salary_till_date=" $endDate '&' "departmentIds=" implode(','$filterDepartmentIds) . '&' "employeeIds=" implode(','$filterEmployeeIds) .
  3850.             '&' "salary_start_date=" $startDate .
  3851.             '&' "filterType=" $filterType .
  3852.             '&' "branchIds=" implode(','$filterBranchIds) .
  3853.             '&' "bankIds=" implode(','$filterBankIds);
  3854. //        if ($request->get('returnJson', 0) == 1) {
  3855.         if ($request->get('returnJson'0) == 1) {
  3856.             return new JsonResponse(array(
  3857.                 'SalaryReports' => $SalaryReports,
  3858.             ));
  3859.         } else {
  3860.             return $this->render('ApplicationBundle:pages/human_resource/report:disburse_salary.html.twig', array(
  3861.                 'page_title' => 'Disburse Salary',
  3862.                 'EmployeeIds' => $EmployeeIds,
  3863.                 'departments' => $Departments,
  3864.                 'branches' => $branches,
  3865.                 'banks' => $banks,
  3866.                 'SalaryReports' => $SalaryReports,
  3867.                 'for_month' => $SalaryReports[0]['for_month'],
  3868.                 'from_date' => $SalaryReports[0]['from_date'],
  3869.                 'to_date' => $SalaryReports[0]['to_date'],
  3870.                 'Qry' => $Qry,
  3871.                 'isMethodGet' => false,
  3872.                 'startDate' => $startDate,
  3873.                 'endDate' => $endDate,
  3874.                 'filterType' => $filterType,
  3875.                 'filterBranchIds' => $filterBranchIds,
  3876.                 'filterBankIds' => $filterBankIds,
  3877.                 'filterDepartmentIds' => $filterDepartmentIds,
  3878.                 'filterEmployeeIds' => $filterEmployeeIds,
  3879.             ));
  3880.         }
  3881.     }
  3882.     public function PrintDisburseSalaryAction(Request $Req)
  3883.     {
  3884.         $em $this->getDoctrine()->getManager();
  3885.         $company_data Company::getCompanyData($em1);
  3886.         $SalaryReports HumanResource::BasicDeduction($em$Req);
  3887.         return $this->render(
  3888.             'ApplicationBundle:pages/human_resource/print:print_disburse_salary.html.twig',
  3889.             array(
  3890.                 'page_title' => 'Print Disburse Salary',
  3891.                 'export' => 'pdf,print',
  3892.                 'company_name' => $company_data->getName(),
  3893.                 'company_data' => $company_data,
  3894.                 'company_address' => $company_data->getAddress(),
  3895.                 'company_image' => $company_data->getImage(),
  3896.                 'SalaryReports' => $SalaryReports,
  3897.                 'for_month' => $SalaryReports[0]['for_month'],
  3898.                 'from_date' => $SalaryReports[0]['from_date'],
  3899.                 'to_date' => $SalaryReports[0]['to_date'],
  3900.                 'red' => 0
  3901.             )
  3902.         );
  3903.     }
  3904.     public function SalaryReportAction(Request $request)
  3905.     {
  3906.         $em $this->getDoctrine()->getManager();
  3907.         $startDate $request->get('salary_start_date''');
  3908.         $endDate $request->get('salary_till_date''');
  3909.         $segregationType $request->get('segregationType'1);
  3910.         $filterBranchIds $request->get('branchIds', []);
  3911.         $filterBankIds $request->get('bankIds', []);
  3912.         $approvalFilterTypes $request->get('approvalFilterTypes', []);
  3913.         $filterDepartmentIds $request->get('departmentIds', []);
  3914.         $filterEmployeeIds $request->get('employeeIds', []);
  3915.         $Departments $em->getRepository(SysDepartment::class)->findAll();
  3916.         $attendance $em->getRepository(EmployeeAttendanceLog::class)->findAll();
  3917.         $banks $em->getRepository(BankList::class)->findAll();
  3918.         $branches $em->getRepository(Branch::class)->findAll();
  3919.         $SalaryReports HumanResource::GenerateSalaryReport($em$request);
  3920. //        dump($SalaryReports);
  3921.         $Qry "salary_till_date=" $endDate '&' "departmentIds=" implode(','$filterDepartmentIds) . '&' "employeeIds=" implode(','$filterEmployeeIds) .
  3922.             '&' "salary_start_date=" $startDate .
  3923.             '&' "segregationType=" $segregationType .
  3924.             '&' "branchIds=" implode(','$filterBranchIds) .
  3925.             '&' "bankIds=" implode(','$filterBankIds);
  3926. //        if ($request->get('returnJson', 0) == 1) {
  3927.         if ($request->get('returnJson'0) == 1) {
  3928.             return new JsonResponse(array(
  3929.                 'SalaryReports' => $SalaryReports,
  3930.             ));
  3931.         } else {
  3932.             return $this->render('ApplicationBundle:pages/human_resource/report:salary_report.html.twig', array(
  3933.                 'page_title' => 'Salary Report',
  3934.                 'departments' => $Departments,
  3935.                 'branches' => $branches,
  3936.                 'banks' => $banks,
  3937.                 'approvalFilterTypes' => $approvalFilterTypes,
  3938.                 'salaryInfo' => $SalaryReports,
  3939.                 'SalaryReports' => $SalaryReports,
  3940.                 'for_month' => '',
  3941.                 'from_date' => $startDate,
  3942.                 'to_date' => $endDate,
  3943.                 'Qry' => $Qry,
  3944.                 'isMethodGet' => false,
  3945.                 'startDate' => $startDate,
  3946.                 'endDate' => $endDate,
  3947.                 'segregationType' => $segregationType,
  3948.                 'filterBranchIds' => $filterBranchIds,
  3949.                 'filterBankIds' => $filterBankIds,
  3950.                 'filterDepartmentIds' => $filterDepartmentIds,
  3951.                 'filterEmployeeIds' => $filterEmployeeIds,
  3952.             ));
  3953.         }
  3954.     }
  3955.     public function createJobRecruitmentAction(Request $request$id 0)
  3956.     {
  3957.         $data = [];
  3958.         $em_goc $this->getDoctrine()->getManager('company_group');
  3959.         $skillDetails $em_goc->getRepository(EntitySkill::class)->findAll();
  3960.         $em $this->getDoctrine()->getManager();
  3961.         $companyId $this->getLoggedUserCompanyId($request);
  3962.         if ($request->isMethod('POST')) {
  3963.             $em $this->getDoctrine()->getManager();
  3964.             $entity_id array_flip(GeneralConstant::$Entity_list)['JobRecruitment']; //change
  3965.             $dochash $request->request->get('docHash'); //change
  3966.             $loginId $request->getSession()->get(UserConstants::USER_LOGIN_ID);
  3967.             $approveRole $request->request->get('approvalRole');
  3968.             $approveHash $request->request->get('approvalHash');
  3969.             if (!DocValidation::isInsertable($em$entity_id$dochash,
  3970.                 $loginId$approveRole$approveHash$id)
  3971.             ) {
  3972.                 $this->addFlash(
  3973.                     'error',
  3974.                     'Sorry Could not insert Data.'
  3975.                 );
  3976.             } else {
  3977.                 $data $request->request;
  3978.                 $docId HumanResource::createJobRecruitment($em$loginId$id$data$companyId);
  3979.                 //now add Approval info
  3980.                 $approveRole $request->request->get('approvalRole');
  3981.                 $options = array(
  3982.                     'notification_enabled' => $this->container->getParameter('notification_enabled'),
  3983.                     'notification_server' => $this->container->getParameter('notification_server'),
  3984.                     'appId' => $request->getSession()->get(UserConstants::USER_APP_ID),
  3985.                     'url' => $this->generateUrl(
  3986.                         GeneralConstant::$Entity_list_details[array_flip(GeneralConstant::$Entity_list)['JobRecruitment']]
  3987.                         ['entity_view_route_path_name']
  3988.                     )
  3989.                 );
  3990.                 System::setApprovalInfo($this->getDoctrine()->getManager(), $options,
  3991.                     array_flip(GeneralConstant::$Entity_list)['JobRecruitment'],
  3992.                     $docId,
  3993.                     $request->getSession()->get(UserConstants::USER_LOGIN_ID)    //journal voucher
  3994.                 );
  3995.                 System::createEditSignatureHash($this->getDoctrine()->getManager(), array_flip(GeneralConstant::$Entity_list)['JobRecruitment'],
  3996.                     $docId,
  3997.                     $loginId,
  3998.                     $approveRole,
  3999.                     $request->request->get('approvalHash'));
  4000.                 $this->addFlash(
  4001.                     'success',
  4002.                     'New Recruitment Document Added.'
  4003.                 );
  4004.                 $url $this->generateUrl(
  4005.                     'view_job_recruitment'
  4006.                 );
  4007.                 return $this->redirect($url "/" $docId);
  4008.             }
  4009.         }
  4010.         if ($id == 0) {
  4011.         } else {
  4012.             $extDoc $em->getRepository('ApplicationBundle:JobRecruitment')->findOneBy(
  4013.                 array(
  4014.                     'jobRecruitmentId' => $id///material
  4015.                 )
  4016.             );
  4017.             //now if its not editable, redirect to view
  4018.             if ($extDoc) {
  4019.                 if ($extDoc->getEditFlag() != 1) {
  4020.                     $url $this->generateUrl(
  4021.                         'view_job_recruitment'
  4022.                     );
  4023.                     return $this->redirect($url "/" $id);
  4024.                 }
  4025.             }
  4026.         }
  4027.         $jobType HumanResourceConstant::$employeeType;
  4028.         //$skillDetails = $em->getRepository(Skill::class)->findAll();
  4029.         $educationDetails $em->getRepository('ApplicationBundle:EducationQualification')->findAll();
  4030.         $employeeIds $em->getRepository('ApplicationBundle:Employee')->findAll();
  4031.         $location HumanResourceConstant::$location;
  4032.         $salaryPer HumanResourceConstant::$salaryPer;
  4033.         $workExperience HumanResourceConstant::$workExperience;
  4034.         $jobOpeningStatus HumanResourceConstant::$jobOpeningStatus;
  4035.         $compatibility HumanResourceConstant::$compatibility;
  4036.         return $this->render('ApplicationBundle:pages/human_resource/input_forms:create_new_job_post.html.twig', [
  4037.             'page_title' => 'Create New Job Post',
  4038.             'jobType' => $jobType,
  4039.             'skillDetails' => $skillDetails,
  4040.             'educationDetails' => $educationDetails,
  4041.             'employeeIds' => $employeeIds,
  4042.             'location' => $location,
  4043.             'salaryPer' => $salaryPer,
  4044.             'workExperience' => $workExperience,
  4045.             'jobOpeningStatus' => $jobOpeningStatus,
  4046.             'compatibility' => $compatibility
  4047.         ]);
  4048.     }
  4049.     public function viewApplicantInfoAction(Request $request$id)
  4050.     {
  4051.         $em $this->getDoctrine()->getManager('company_group');
  4052.         //$session = $request->getSession();
  4053.         $consultantDetails $em->getRepository(EntityApplicantDetails::class)->find($id);
  4054.         $skillDetails $em->getRepository('CompanyGroupBundle:EntitySkill')->findAll();
  4055.         //$companyId = $this->getLoggedUserCompanyId($request);
  4056.         $gender HumanResourceConstant::$sex;
  4057.         $blood HumanResourceConstant::$BloodGroup;
  4058.         //$userId = $session->get(UserConstants::USER_ID);
  4059.         return $this->render('ApplicationBundle:pages/human_resource/views:view_applicant_info.html.twig', [
  4060.             'page_title' => 'Applicant Information',
  4061.             'gender' => $gender,
  4062.             'blood' => $blood,
  4063.             'consultantDetails' => $consultantDetails,
  4064.             'education' => json_decode($consultantDetails->getEducationData(), true),
  4065.             'workExperience' => json_decode($consultantDetails->getWorkExperienceData(), true),
  4066.             'certificate' => json_decode($consultantDetails->getCertificateData(), true),
  4067.             'courses' => json_decode($consultantDetails->getCoursesData(), true),
  4068.             'languages' => json_decode($consultantDetails->getLanguagesData(), true),
  4069.             'skillDetails' => $skillDetails
  4070.         ]);
  4071.     }
  4072.     public function ListJobRecruitmentAction()
  4073.     {
  4074.         $em $this->getDoctrine()->getManager();
  4075.         $jobRecruitmentList = [];
  4076.         $jobRecruitments $em->getRepository('ApplicationBundle:JobRecruitment')->findAll();
  4077.         foreach ($jobRecruitments as $jobRecruitment) {
  4078.             $jobData = array(
  4079.                 'jobRecruitmentId' => $jobRecruitment->getJobRecruitmentId(),
  4080.                 'title' => $jobRecruitment->getTitle(),
  4081.                 'date' => $jobRecruitment->getDate(),
  4082.                 'jobOpeningStatus' => $jobRecruitment->getJobOpeningStatus(),
  4083.                 'applicationOpeningDate' => $jobRecruitment->getApplicationOpeningDate(),
  4084.                 'applicationClosingDate' => $jobRecruitment->getApplicationClosingDate(),
  4085.             );
  4086.             $jobRecruitmentList[] = $jobData;
  4087.         }
  4088.         return $this->render('ApplicationBundle:pages/human_resource/list:job_recruitment_list.html.twig', [
  4089.             'page_title' => 'Job RecruitmentAction List',
  4090.             'jobRecruitments' => $jobRecruitmentList
  4091.         ]);
  4092.     }
  4093.     public function ViewJobRecruitmentAction(Request $request$id 0)
  4094.     {
  4095.         $em_goc $this->getDoctrine()->getManager('company_group');
  4096.         $skillDetails $em_goc->getRepository('CompanyGroupBundle:EntitySkill')->findAll();
  4097.         $em $this->getDoctrine()->getManager();
  4098.         $companyId $this->getLoggedUserCompanyId($request);
  4099.         $company_data Company::getCompanyData($em$companyId);
  4100. //        return new JsonResponse($encryptedDataArray);
  4101.         $location HumanResourceConstant::$location;
  4102.         $salaryPer HumanResourceConstant::$salaryPer;
  4103.         $workExperience HumanResourceConstant::$workExperience;
  4104.         $jobOpeningStatus HumanResourceConstant::$jobOpeningStatus;
  4105.         $compatibility HumanResourceConstant::$compatibility;
  4106.         $jobType HumanResourceConstant::$employeeType;
  4107.         $educationDetail $em->getRepository(EducationQualification::class)->findAll();
  4108.         $jobRecruitments $em->getRepository('ApplicationBundle:JobRecruitment')->find($id);
  4109.         $em_goc $this->getDoctrine()->getManager('company_group');
  4110.         $applicantApplicationList $em_goc->getRepository("CompanyGroupBundle:EntityApplicantApplicationList")->findBy(
  4111.             array(
  4112.                 'jobPostId' => $id,
  4113.                 'CompanyId' => $companyId,
  4114.                 'appId' => $company_data->getAppId()
  4115.             )
  4116.         );
  4117.         $applicantIdList = [];
  4118.         foreach ($applicantApplicationList as $dt) {
  4119.             $applicantIdList[] = $dt->getApplicantId();
  4120.         }
  4121.         $applicantList ApplicantM::getApplicantList($em_goc$applicantIdList);
  4122.         $Approval_data = [
  4123.             'exists' => 0,
  4124.             'approvalId' => 0,
  4125.             'roleType' => 0,
  4126.             'required' => 0,
  4127.             'acted' => 0,
  4128.             'entity' => array_flip(GeneralConstant::$Entity_list)['JobRecruitment'],
  4129.             'entityId' => $id,
  4130.         ];
  4131.         if (in_array($request->getSession()->get(UserConstants::USER_TYPE), [125]))
  4132.             $Approval_data System::checkIfApprovalExists(
  4133.                 $em,
  4134.                 array_flip(GeneralConstant::$Entity_list)['JobRecruitment'],
  4135.                 $id,
  4136.                 $request->getSession()->get(UserConstants::USER_LOGIN_ID)
  4137.             );
  4138.         return $this->render('ApplicationBundle:pages/human_resource/views:view_job_recruitment.html.twig', [
  4139.             'page_title' => 'View Job RecruitmentAction',
  4140.             'jobRecruitments' => $jobRecruitments,
  4141.             'applicantApplicationList' => $applicantApplicationList,
  4142.             'applicantList' => $applicantList,
  4143. //            'encryptedData' => $encryptedData,
  4144.             'skills' => json_decode($jobRecruitments->getskills()),
  4145.             'skillDetails' => $skillDetails,
  4146.             'education' => json_decode($jobRecruitments->getEducations()),
  4147.             'educationDetails' => $educationDetail,
  4148.             'location' => $location,
  4149.             'salaryPer' => $salaryPer,
  4150.             'workExperience' => $workExperience,
  4151.             'jobType' => $jobType,
  4152.             'compatibility' => $compatibility,
  4153.             'approval_status' => $jobRecruitments->getApproved(),
  4154.             'jobOpeningStatus' => $jobOpeningStatus,
  4155.             'approval_data' => $Approval_data,
  4156.             'auto_created' => $jobRecruitments->getAutocreated(),
  4157.             'document_log' => $jobRecruitments->getAutocreated() == System::getDocumentLog(
  4158.                 $em,
  4159.                 array_flip(GeneralConstant::$Entity_list)['JobRecruitment'],
  4160.                 $id,
  4161.                 $jobRecruitments->getCreatedLoginId(),
  4162.                 $jobRecruitments->getEditedLoginId()
  4163.             ) : []
  4164.         ]);
  4165.     }
  4166.     public function ViewApplicantScheduleAction(Request $request$id 0)
  4167.     {
  4168.         $em $this->getDoctrine()->getManager();
  4169.         $companyId $this->getLoggedUserCompanyId($request);
  4170.         $company_data Company::getCompanyData($em$companyId);
  4171.         $em_goc $this->getDoctrine()->getManager('company_group');
  4172.         $applicantApplicationList $em_goc->getRepository("CompanyGroupBundle:EntityApplicantApplicationList")->findBy(
  4173.             array(
  4174.                 'jobPostId' => $id,
  4175.                 'CompanyId' => $companyId,
  4176.                 'appId' => $company_data->getAppId()
  4177.             )
  4178.         );
  4179.         $applicantIdList = [];
  4180.         foreach ($applicantApplicationList as $dt) {
  4181.             $applicantIdList[] = $dt->getApplicantId();
  4182.         }
  4183.         $applicantList ApplicantM::getApplicantList($em_goc$applicantIdList);
  4184.         return $this->render('ApplicationBundle:pages/human_resource/views:view_applicant_scheduled.html.twig', [
  4185.             'page_title' => 'View Applicant Scheduled',
  4186.             'applicantApplicationList' => $applicantApplicationList,
  4187.             'applicantList' => $applicantList,
  4188.         ]);
  4189.     }
  4190.     public function ViewApplicantReportAction(Request $request$id 0)
  4191.     {
  4192.         $em $this->getDoctrine()->getManager();
  4193.         $companyId $this->getLoggedUserCompanyId($request);
  4194.         $company_data Company::getCompanyData($em$companyId);
  4195.         $em_goc $this->getDoctrine()->getManager('company_group');
  4196.         $applicantApplicationList $em_goc->getRepository("CompanyGroupBundle:EntityApplicantApplicationList")->findBy(
  4197.             array(
  4198.                 'jobPostId' => $id,
  4199.                 'CompanyId' => $companyId,
  4200.                 'appId' => $company_data->getAppId()
  4201.             )
  4202.         );
  4203.         $applicantIdList = [];
  4204.         foreach ($applicantApplicationList as $dt) {
  4205.             $applicantIdList[] = $dt->getApplicantId();
  4206.         }
  4207.         $applicantList ApplicantM::getApplicantList($em_goc$applicantIdList);
  4208.         return $this->render('ApplicationBundle:pages/human_resource/views:view_applicant_report.html.twig', [
  4209.             'page_title' => 'View Applicant Report',
  4210.             'applicantApplicationList' => $applicantApplicationList,
  4211.             'applicantList' => $applicantList,
  4212.         ]);
  4213.     }
  4214.     public function createEmployeePerformanceEvaluationAction(Request $request$id 0)
  4215.     {
  4216.         $data = [];
  4217.         $em $this->getDoctrine()->getManager();
  4218.         $companyId $this->getLoggedUserCompanyId($request);
  4219.         if ($request->isMethod('POST')) {
  4220.             $em $this->getDoctrine()->getManager();
  4221.             $entity_id array_flip(GeneralConstant::$Entity_list)['EmployeePerformanceEvolution']; //change
  4222.             $dochash $request->request->get('docHash'); //change
  4223.             $loginId $request->getSession()->get(UserConstants::USER_LOGIN_ID);
  4224.             $approveRole $request->request->get('approvalRole');
  4225.             $approveHash $request->request->get('approvalHash');
  4226.             if (!DocValidation::isInsertable($em$entity_id$dochash,
  4227.                 $loginId$approveRole$approveHash$id)
  4228.             ) {
  4229.                 $this->addFlash(
  4230.                     'error',
  4231.                     'Sorry Could not insert Data.'
  4232.                 );
  4233.             } else {
  4234.                 $data $request->request;
  4235.                 $docId HumanResource::createEmployeePerformanceEvaluation($em$loginId$id$data$companyId);
  4236.                 //now add Approval info
  4237.                 $approveRole $request->request->get('approvalRole');
  4238.                 $options = array(
  4239.                     'notification_enabled' => $this->container->getParameter('notification_enabled'),
  4240.                     'notification_server' => $this->container->getParameter('notification_server'),
  4241.                     'appId' => $request->getSession()->get(UserConstants::USER_APP_ID),
  4242.                     'url' => $this->generateUrl(
  4243.                         GeneralConstant::$Entity_list_details[array_flip(GeneralConstant::$Entity_list)['EmployeePerformanceEvolution']]
  4244.                         ['entity_view_route_path_name']
  4245.                     )
  4246.                 );
  4247.                 System::setApprovalInfo($this->getDoctrine()->getManager(), $options,
  4248.                     array_flip(GeneralConstant::$Entity_list)['JobRecruitment'],
  4249.                     $docId,
  4250.                     $request->getSession()->get(UserConstants::USER_LOGIN_ID)    //journal voucher
  4251.                 );
  4252.                 System::createEditSignatureHash($this->getDoctrine()->getManager(), array_flip(GeneralConstant::$Entity_list)['EmployeePerformanceEvolution'],
  4253.                     $docId,
  4254.                     $loginId,
  4255.                     $approveRole,
  4256.                     $request->request->get('approvalHash'));
  4257.                 $this->addFlash(
  4258.                     'success',
  4259.                     'New Recruitment Document Added.'
  4260.                 );
  4261.                 $url $this->generateUrl(
  4262.                     'view_employee_performance_evolution'
  4263.                 );
  4264.                 return $this->redirect($url "/" $docId);
  4265.             }
  4266.         }
  4267.         $skill $em->getRepository(Skill::class)->findAll();
  4268.         $educationDetail $em->getRepository(EducationQualification::class)->findAll();
  4269.         $employeeIds $em->getRepository(EmployeeDetails::class)->findAll();
  4270.         $employeeType HumanResourceConstant::$employeeType;
  4271.         $Designation $em->getRepository(SysDepartmentPosition::class)->findAll();
  4272.         $branch $em->getRepository(Branch::class)->findAll();
  4273.         $departments $em->getRepository(SysDepartment::class)->findAll();
  4274.         $department = [];
  4275.         foreach ($departments as $entry) {
  4276.             $department[$entry->getDepartmentId()] = array(
  4277.                 'id' => $entry->getDepartmentId(),
  4278.                 'name' => $entry->getDepartmentName(),
  4279.             );
  4280.         }
  4281.         return $this->render('ApplicationBundle:pages/human_resource/input_forms:employee_performance_evolution.html.twig',
  4282.             array(
  4283.                 'page_title' => 'Create Employee Performance Evaluation',
  4284.                 'employeeIds' => $employeeIds,
  4285.                 'employeeType' => $employeeType,
  4286.                 'Designation' => $Designation,
  4287.                 'branch' => $branch,
  4288.                 'department' => $department,
  4289.                 'skill' => $skill,
  4290.                 'educationDetail' => $educationDetail
  4291.             )
  4292.         );
  4293.     }
  4294.     public function ViewIndividualReviewAction()
  4295.     {
  4296.         return $this->render('ApplicationBundle:pages/human_resource/views:individual_review.html.twig',
  4297.             array(
  4298.                 'page_title' => 'Individual Performance View',
  4299.             )
  4300.         );
  4301.     }
  4302.     public function EmployeeListBySkillPerformanceAction()
  4303.     {
  4304.         $em $this->getDoctrine()->getManager();
  4305.         $employee $em->getRepository('ApplicationBundle:EmployeeDetails')->findAll();
  4306.         $skill $em->getRepository('ApplicationBundle:Skill')->findAll();
  4307.         return $this->render('ApplicationBundle:pages/human_resource/list:employee_performance_evolution_list.html.twig',
  4308.             array(
  4309.                 'page_title' => 'Employee Skill & Performance',
  4310.                 'employee' => $employee,
  4311.                 //'employeeSkill' => json_decode($employee->getSkill(),true),
  4312.                 'skill' => $skill,
  4313.             )
  4314.         );
  4315.     }
  4316.     public function setWorkPlaceAction(Request $req)
  4317.     {
  4318.         $em $this->getDoctrine()->getManager();
  4319.         $companyId $this->getLoggedUserCompanyId($req);
  4320.         $docHash '';
  4321.         if ($req->request->has('XHRreq')) {
  4322.             $docHash HumanResource::HandelXHRreqForEmpWorkplace($em$req);
  4323.             return new JsonResponse([$docHash]);
  4324.         }
  4325.         if ($req->isMethod('GET')) {
  4326.             $TwigData HumanResource::TwigDataForEmployeeWorkplace($em);
  4327.             return $this->render(
  4328.                 'ApplicationBundle:pages/human_resource/input_forms:update_workplace.html.twig',
  4329.                 [
  4330.                     'page_title' => 'Set Workplace',
  4331.                     'employeeIds' => $TwigData['employeeIds']
  4332.                 ]
  4333.             );
  4334.         }
  4335.         if ($req->isMethod('POST')) {
  4336.             $approveHash $req->request->get('approvalHash');
  4337.             $loginId $req->getSession()->get(UserConstants::USER_LOGIN_ID);
  4338.             $isSignatureOk DocValidation::isSignatureOk($em$loginId$approveHash);
  4339.             if ($isSignatureOk) {
  4340.                 $isSuccess HumanResource::CreateOrUpdateForEmpWorkplace($em$req$companyIdfalse$docHash);
  4341.                 if ($isSuccess) {
  4342.                     $this->addFlash(
  4343.                         'success',
  4344.                         'Workplace set!'
  4345.                     );
  4346.                     return $this->redirectToRoute('set_workplace');
  4347.                 }
  4348.             } else {
  4349.                 $this->addFlash(
  4350.                     'error',
  4351.                     'Invalid Approval Hash!'
  4352.                 );
  4353.                 return $this->redirectToRoute('set_workplace');
  4354.             }
  4355.         }
  4356.     }
  4357.     public function setWorkPlaceForAppAction(Request $req)
  4358.     {
  4359.         $em $this->getDoctrine()->getManager();
  4360.         $companyId $this->getLoggedUserCompanyId($req);
  4361.         $docHash HumanResource::HandelXHRreqForEmpWorkplace($em$req);
  4362.         if ($req->isMethod('GET')) {
  4363.             $TwigData HumanResource::TwigDataForEmployeeWorkplace($em);
  4364.             return $this->render(
  4365.                 'ApplicationBundle:pages/human_resource/input_forms:update_workplace.html.twig',
  4366.                 [
  4367.                     'page_title' => 'Set Workplace',
  4368.                     'employeeIds' => $TwigData['employeeIds']
  4369.                 ]
  4370.             );
  4371.         }
  4372.         if ($req->isMethod('POST')) {
  4373.             $approveHash $req->request->get('approvalHash');
  4374.             $loginId $req->getSession()->get(UserConstants::USER_LOGIN_ID);
  4375.             $isSignatureOk DocValidation::isSignatureOk($em$loginId$approveHash);
  4376.             if ($isSignatureOk) {
  4377.                 $isSuccess HumanResource::CreateOrUpdateForEmpWorkplace($em$req$companyIdfalse$docHash);
  4378.                 if ($isSuccess) {
  4379.                     $this->addFlash(
  4380.                         'success',
  4381.                         'Workplace set!'
  4382.                     );
  4383. //                    return $this->redirectToRoute('set_workplace');
  4384.                     return new JsonResponse(array(
  4385.                         "success" => true
  4386.                     ));
  4387.                 }
  4388.             } else {
  4389.                 $this->addFlash(
  4390.                     'error',
  4391.                     'Invalid Approval Hash!'
  4392.                 );
  4393. //                return $this->redirectToRoute('set_workplace');
  4394.             }
  4395.         }
  4396.     }
  4397.     public function ViewMeetingAction(Request $req$action 0$id 0)
  4398.     {
  4399.         $em $this->getDoctrine()->getManager();
  4400.         $companyId $this->getLoggedUserCompanyId($req);
  4401.         if ($req->request->has('XHRreq')) {
  4402.             return new JsonResponse([HumanResource::HandelXHRreqForMeetingScheduling($em$req)]);
  4403.         }
  4404.         if ($action === 'view') {
  4405.             $response HumanResource::TwigDataForScheduledMeetingView($em$req$id);
  4406.             return $this->render(
  4407.                 'ApplicationBundle:pages/human_resource/views:scheduled_meeting_view.html.twig',
  4408.                 [
  4409.                     'page_title' => 'View Scheduled Meeting',
  4410.                     'duration' => $response['duration'],
  4411.                     'appId' => $response['appId'],
  4412.                     'publicView' => 0,
  4413.                     'meeting_data' => $response['meeting_data'],
  4414.                     'agenda_list' => $response['agenda_list'],
  4415.                     'id' => $req->query->get('view_meeting'),
  4416.                     'approval_data' => $response['approval_data'],
  4417.                     'document_log' => $response['document_log'],
  4418.                     'approval_status' => $response['approval_status'],
  4419.                     'created_by' => $response['created_by'],
  4420.                     'updated_at' => $response['updated_at'],
  4421.                     'auto_created' => 0,
  4422.                 ]
  4423.             );
  4424.         }
  4425.         if ($action === 'print') {
  4426.             $response HumanResource::TwigDataForScheduledMeetingView($em$req$id);
  4427. //      $id = $req->query->get('print_meeting');
  4428.             $em $this->getDoctrine()->getManager();
  4429.             $company_data Company::getCompanyData($em1);
  4430.             $Authorizations System::getSignatureListForDocumentPrint($emarray_flip(GeneralConstant::$Entity_list)['ScheduledMeeting'], $id);
  4431.             return $this->render(
  4432.                 'ApplicationBundle:pages/human_resource/print:scheduled_meeting_print.html.twig',
  4433.                 array(
  4434.                     'page_title' => 'View Scheduled Meeting',
  4435.                     'duration' => $response['duration'],
  4436.                     'meeting_data' => $response['meeting_data'],
  4437.                     'agenda_list' => $response['agenda_list'],
  4438.                     'export' => 'pdf,print',
  4439.                     'company_name' => $company_data->getName(),
  4440.                     'company_data' => $company_data,
  4441.                     'company_address' => $company_data->getAddress(),
  4442.                     'company_image' => $company_data->getImage(),
  4443.                     'Authorizations' => $Authorizations,
  4444.                     'red' => 0
  4445.                 )
  4446.             );
  4447.         }
  4448.     }
  4449.     public function UpdateMeetingMinutesAction(Request $req$action 0$id 0)
  4450.     {
  4451.         $em $this->getDoctrine()->getManager();
  4452.         $companyId $this->getLoggedUserCompanyId($req);
  4453.         $scheduleId $req->request->get('scheduleId');
  4454.         $minuteText $req->request->get('minuteText');
  4455.         $agendaKey $req->request->get('key');
  4456.         $scheduledMeeting $em->getRepository(ScheduledMeeting::class)
  4457.             ->find($scheduleId);
  4458.         $agendaList json_decode($scheduledMeeting->getAgendaList(), true);
  4459.         foreach ($agendaList as $key => $item) {
  4460.             if ($key == $agendaKey)
  4461.                 $agendaList[$key]['minutes'] = $minuteText;
  4462.         }
  4463.         $scheduledMeeting->setAgendaList(json_encode($agendaList));
  4464.         $em->flush();
  4465.         return new JsonResponse(array(
  4466.             'success' => true
  4467.         ));
  4468.     }
  4469.     public function deleteLastAttendanceAction(Request $request)
  4470.     {
  4471.         $em $this->getDoctrine()->getManager();
  4472.         $lastAttendance $em->getRepository('ApplicationBundle:EmployeeAttendance')
  4473.             ->createQueryBuilder('ea')
  4474.             ->orderBy('ea.id''DESC')
  4475.             ->setMaxResults(1)
  4476.             ->getQuery()
  4477.             ->getOneOrNullResult();
  4478.         $lastAttendanceLog $em->getRepository('ApplicationBundle:EmployeeAttendanceLog')
  4479.             ->createQueryBuilder('eal')
  4480.             ->orderBy('eal.id''DESC')
  4481.             ->setMaxResults(1)
  4482.             ->getQuery()
  4483.             ->getOneOrNullResult();
  4484.         $deletedCount 0;
  4485.         if ($lastAttendance) {
  4486.             $em->remove($lastAttendance);
  4487.             $deletedCount++;
  4488.         }
  4489.         if ($lastAttendanceLog) {
  4490.             $em->remove($lastAttendanceLog);
  4491.             $deletedCount++;
  4492.         }
  4493.         $em->flush();
  4494.         return new JsonResponse(
  4495.             [
  4496.                 'success' => true,
  4497.                 'message' => "Deleted `$deletedCount` rows from attendance tables."
  4498.             ]
  4499.         );
  4500.     }
  4501.     public function SendMeetingUpdatesAction(Request $req$action 0$id 0)
  4502.     {
  4503.         $em $this->getDoctrine()->getManager();
  4504.         $companyId $this->getLoggedUserCompanyId($req);
  4505.         $session $req->getSession();
  4506.         $companyData Company::getCompanyData($em$companyId);
  4507.         $scheduleId $req->request->get('scheduleId');
  4508.         $minuteText $req->request->get('minuteText');
  4509.         $agendaKey $req->request->get('key');
  4510.         $scheduledMeeting $em->getRepository(ScheduledMeeting::class)
  4511.             ->find($scheduleId);
  4512.         $sendEmailInvitationTo json_decode($scheduledMeeting->getAllParticipantsNameEmail(), true);
  4513.         if ($sendEmailInvitationTo == null)
  4514.             $sendEmailInvitationTo = [];
  4515.         $agendaList json_decode($scheduledMeeting->getAgendaList(), true);
  4516.         if ($agendaList == null)
  4517.             $agendaList = [];
  4518.         $EmployeeList HumanResource::GetEmployeeList($em, []);
  4519.         $meetingType MeetingSchedulingConstant::$meetingType[$scheduledMeeting->getMeetingType()];
  4520.         foreach ($sendEmailInvitationTo as $key => $email) {
  4521.             $name ucWords(str_replace("_"" "$key));
  4522.             $bodyHtml '';
  4523.             $bodyTemplate 'ApplicationBundle:email/meeting_scheduling:scheduled_meeting_update.html.twig';
  4524.             $bodyData = array(
  4525.                 'name' => $name,
  4526.                 'gocId' => $session->get(UserConstants::USER_GOC_ID),
  4527.                 'appId' => $session->get(UserConstants::USER_APP_ID),
  4528.                 'email' => $email,
  4529.                 'meetingData' => $scheduledMeeting,
  4530.                 'meeting_type' => $meetingType,
  4531.                 'agenda_list' => $agendaList,
  4532.                 'companyData' => $companyData,
  4533.                 'employeeList' => $EmployeeList,
  4534.             );
  4535.             $attachments = [];
  4536.             $new_mail $this->get('mail_module');
  4537.             $new_mail->sendMyMail(array(
  4538.                 'senderHash' => '_MEETING_',
  4539.                 'forwardToMailAddress' => $email,
  4540.                 'subject' => "Meeting Updates Arranged By - " $companyData->getName() . " on " $scheduledMeeting->getTitle() . ". ",
  4541.                 'fileName' => '',
  4542.                 'attachments' => $attachments,
  4543.                 'toAddress' => $email,
  4544.                 'mailTemplate' => $bodyTemplate,
  4545.                 'templateData' => $bodyData,
  4546.                 'embedCompanyImage' => 1,
  4547.                 'companyId' => $companyId,
  4548.                 'companyImagePath' => $companyData->getImage()
  4549.             ));
  4550.         }
  4551.         return new JsonResponse(array(
  4552.             'success' => true
  4553.         ));
  4554.     }
  4555.     public function meetingSchedulingAction(Request $req$action 0)
  4556.     {
  4557.         $em $this->getDoctrine()->getManager();
  4558.         $companyId $this->getLoggedUserCompanyId($req);
  4559.         $session $req->getSession();
  4560.         if ($req->request->has('XHRreq')) {
  4561.             return new JsonResponse([HumanResource::HandelXHRreqForMeetingScheduling($em$req)]);
  4562.         }
  4563.         if ($action === 'list') {
  4564.             $response HumanResource::TwigDataForScheduledMeetingList($em, [0null]);
  4565.             return $this->render(
  4566.                 'ApplicationBundle:pages/human_resource/list:scheduled_meeting_list.html.twig',
  4567.                 [
  4568.                     'page_title' => 'Scheduled Meeting List',
  4569.                     'list' => $response
  4570.                 ]
  4571.             );
  4572.         }
  4573.         if ($req->isMethod('GET')) {
  4574.             $response HumanResource::twigDataForMeetingScheduling($em);
  4575.             return $this->render(
  4576.                 'ApplicationBundle:pages/human_resource/input_forms:meeting_scheduling.html.twig',
  4577.                 [
  4578.                     'page_title' => 'Schedule a Meeting',
  4579.                     'employeeIds' => $response['employeeIds'],
  4580.                     'branches' => $response['branches'],
  4581.                     'asset' => $response['asset'],
  4582.                     'rooms' => $response['rooms'],
  4583.                     'sales_orders' => $response['salesOrders'],
  4584.                     'purchase_orders' => $response['purchaseOrders'],
  4585.                     'meeting_types' => $response['meetingType'],
  4586.                 ]
  4587.             );
  4588.         }
  4589.         if ($req->isMethod('POST')) {
  4590.             $approveHash $req->request->get('approvalHash');
  4591.             $approveRole $req->request->get('approvalRole');
  4592.             $loginId $req->getSession()->get(UserConstants::USER_LOGIN_ID);
  4593.             $isSignatureOk DocValidation::isSignatureOk($em$loginId$approveHash);
  4594.             $companyData Company::getCompanyData($em$companyId);
  4595.             if ($isSignatureOk) {
  4596.                 $isSuccess HumanResource::createOrUpdateDataForMeetingScheduling($em$req);
  4597.                 if ($isSuccess) {
  4598.                     $options = array(
  4599.                         'notification_enabled' => $this->container->getParameter('notification_enabled'),
  4600.                         'notification_server' => $this->container->getParameter('notification_server'),
  4601.                         'appId' => $req->getSession()->get(UserConstants::USER_APP_ID),
  4602.                         'url' => $this->generateUrl(
  4603.                             GeneralConstant::$Entity_list_details[array_flip(GeneralConstant::$Entity_list)['ScheduledMeeting']]['entity_view_route_path_name']
  4604.                         )
  4605.                     );
  4606.                     $meetingId $isSuccess[1];
  4607.                     System::setApprovalInfo(
  4608.                         $this->getDoctrine()->getManager(),
  4609.                         $options,
  4610.                         array_flip(GeneralConstant::$Entity_list)['ScheduledMeeting'],
  4611.                         $meetingId,
  4612.                         $req->getSession()->get(UserConstants::USER_LOGIN_ID),
  4613.                         0//normal meeting
  4614.                         0,
  4615.                         $this->get('mail_module')
  4616.                     );
  4617.                     System::createEditSignatureHash(
  4618.                         $this->getDoctrine()->getManager(),
  4619.                         array_flip(GeneralConstant::$Entity_list)['ScheduledMeeting'],
  4620.                         $meetingId,
  4621.                         $loginId,
  4622.                         $approveRole,
  4623.                         $req->request->get('approvalHash')
  4624.                     );
  4625.                     $url $this->generateUrl(
  4626.                         'view_scheduled_meeting'
  4627.                     );
  4628.                     return $this->redirect($url "/" $meetingId);
  4629.                 } else {
  4630.                     return new JsonResponse(array(
  4631.                         'success' => false
  4632.                     ));
  4633.                 }
  4634.             } else {
  4635.                 $this->addFlash(
  4636.                     'error',
  4637.                     'Invalid Approval Hash!'
  4638.                 );
  4639.                 return $this->redirectToRoute('meeting_scheduling');
  4640.             }
  4641.         }
  4642.         return $this->redirectToRoute('meeting_scheduling');
  4643.     }
  4644.     public function MeetingSchedulingForAppAction(Request $request): JsonResponse
  4645.     {
  4646.         $em $this->getDoctrine()->getManager();
  4647.         $session $request->getSession();
  4648.         $mailer $this->get('mail_module');
  4649.         $helper = new HumanResourceHelper($em$mailer);
  4650.         try {
  4651.             $data $request->request->all();
  4652.             $files $request->files->all();
  4653.             $companyId $this->getLoggedUserCompanyId($request);
  4654.             $meeting $helper->prepareMeeting($data$session);
  4655.             $agendaList = [];
  4656.             if (!empty($data['agendaList']) && is_array($data['agendaList'])) {
  4657.                 foreach ($data['agendaList'] as $index => $agendaData) {
  4658.                     $agenda = [
  4659.                         'title' => $agendaData['title'] ?? null,
  4660.                         'desc' => $agendaData['desc'] ?? null,
  4661.                         'notes' => $agendaData['notes'] ?? null,
  4662.                         'taggedDocuments' => $agendaData['taggedDocuments'] ?? [],
  4663.                         'otherDocuments' => [],
  4664.                     ];
  4665.                     if (!empty($files['agendaList'][$index]['otherDocuments'])) {
  4666.                         foreach ($files['agendaList'][$index]['otherDocuments'] as $uploadedFile) {
  4667.                             $uploadedFilePath $this->uploadMeetingFile($uploadedFile$request);
  4668.                             if ($uploadedFilePath) {
  4669.                                 $agenda['otherDocuments'][] = [
  4670.                                     'fileName' => basename($uploadedFilePath),
  4671.                                     'path' => $uploadedFilePath,
  4672.                                     'type' => $uploadedFile->getClientOriginalExtension(),
  4673.                                 ];
  4674.                             }
  4675.                         }
  4676.                     }
  4677.                     $agendaList[] = $agenda;
  4678.                 }
  4679.             }
  4680.             $meeting->setAgendaList(json_encode($agendaList));
  4681.             [$internalInfo$otherInfo$internalIds] = $helper->resolveParticipants(
  4682.                 $data['guests'] ?? [],
  4683.                 $session->get('userEmployeeId')
  4684.             );
  4685.             // Save **full participant objects** to DB
  4686.             $meeting->setInternalParticipantIds(!empty($internalInfo) ? json_encode($internalInfo) : null);
  4687.             $meeting->setOtherParticipantInfo(!empty($otherInfo) ? json_encode($otherInfo) : null);
  4688.             $meeting->setParticipantInfo(json_encode([
  4689.                 'internal' => $internalInfo,
  4690.                 'other' => $otherInfo,
  4691.             ]));
  4692.             // Persist the meeting
  4693.             $em->persist($meeting);
  4694.             $em->flush();
  4695.             // Send invitations
  4696.             $helper->sendInvitations($meeting$internalIds$otherInfo$companyId);
  4697.             return new JsonResponse([
  4698.                 'success' => true,
  4699.                 'message' => 'Meeting scheduled successfully',
  4700.                 'meetingId' => $meeting->getScheduleId(),
  4701.                 'documentHas' => $meeting->getDocumentHash(),
  4702.             ]);
  4703.         } catch (\Exception $e) {
  4704.             return new JsonResponse(['success' => false'error' => $e->getMessage()], 500);
  4705.         }
  4706.     }
  4707.     public function updateMeetingForAppAction(Request $requestint $meetingId): JsonResponse
  4708.     {
  4709.         $em $this->getDoctrine()->getManager();
  4710.         $session $request->getSession();
  4711.         $mailer $this->get('mail_module');
  4712.         $helper = new HumanResourceHelper($em$mailer);
  4713.         try {
  4714.             $data $request->request->all();
  4715.             $files $request->files->all();
  4716.             $meeting $em->getRepository(ScheduledMeeting::class)->find($meetingId);
  4717.             if (!$meeting) {
  4718.                 return new JsonResponse(['success' => false'error' => 'Meeting not found'], 404);
  4719.             }
  4720.             $meeting->setTitle($data['title'] ?? $meeting->getTitle());
  4721.             $meeting->setSpecialType($data['specialType'] ?? $meeting->getSpecialType());
  4722.             $meeting->setStartAt(!empty($data['startAt']) ? new \DateTime($data['startAt']) : $meeting->getStartAt());
  4723.             $meeting->setEndAt(!empty($data['endAt']) ? new \DateTime($data['endAt']) : $meeting->getEndAt());
  4724.             $meeting->setMeetingType($data['meetingType'] ?? $meeting->getMeetingType());
  4725.             $meeting->setLocation($data['location'] ?? $meeting->getLocation());
  4726.             $meeting->setRoomId($data['roomId'] ?? $meeting->getRoomId());
  4727.             $meeting->setDesc($data['desc'] ?? $meeting->getDesc());
  4728.             $meeting->setLastModifiedDate(new \DateTime());
  4729.             if (isset($data['agendaList']) && is_array($data['agendaList'])) {
  4730.                 $agendaList = [];
  4731.                 foreach ($data['agendaList'] as $index => $agendaData) {
  4732.                     $agenda = [
  4733.                         'title' => $agendaData['title'] ?? null,
  4734.                         'desc' => $agendaData['desc'] ?? null,
  4735.                         'notes' => $agendaData['notes'] ?? null,
  4736.                         'taggedDocuments' => $agendaData['taggedDocuments'] ?? [],
  4737.                         'otherDocuments' => [],
  4738.                     ];
  4739.                     if (!empty($files['agendaList'][$index]['otherDocuments'])) {
  4740.                         foreach ($files['agendaList'][$index]['otherDocuments'] as $uploadedFile) {
  4741.                             $uploadedFilePath $this->uploadMeetingFile($uploadedFile$request);
  4742.                             if ($uploadedFilePath) {
  4743.                                 $agenda['otherDocuments'][] = [
  4744.                                     'fileName' => basename($uploadedFilePath),
  4745.                                     'path' => $uploadedFilePath,
  4746.                                     'type' => $uploadedFile->getClientOriginalExtension(),
  4747.                                 ];
  4748.                             }
  4749.                         }
  4750.                     }
  4751.                     if (!empty($agendaData['otherDocumentsExisting'])) {
  4752.                         $agenda['otherDocuments'] = array_merge(
  4753.                             $agenda['otherDocuments'],
  4754.                             $agendaData['otherDocumentsExisting']
  4755.                         );
  4756.                     }
  4757.                     $agendaList[] = $agenda;
  4758.                 }
  4759.                 $meeting->setAgendaList(json_encode($agendaList));
  4760.             }
  4761.             if (isset($data['guests'])) {
  4762.                 [$internalIds$otherInfo] = $helper->resolveParticipants($data['guests'], $session->get('userEmployeeId'));
  4763.                 $meeting->setInternalParticipantIds(!empty($internalIds) ? json_encode($internalIds) : null);
  4764.                 $meeting->setOtherParticipantInfo(!empty($otherInfo) ? json_encode($otherInfo) : null);
  4765.             }
  4766.             $em->persist($meeting);
  4767.             $em->flush();
  4768.             if (isset($internalIds) || isset($otherInfo)) {
  4769.                 $helper->sendInvitations($meeting$internalIds ?? [], $otherInfo ?? [], $meeting->getCompanyId());
  4770.             }
  4771.             return new JsonResponse([
  4772.                 'success' => true,
  4773.                 'message' => 'Meeting updated successfully',
  4774.                 'meetingId' => $meeting->getScheduleId(),
  4775.                 'facilitator' => ['id' => $meeting->getFacilitatorId(), 'name' => $meeting->getFacilitatorName()],
  4776.                 'companyId' => $meeting->getCompanyId(),
  4777.                 'branchId' => $meeting->getBranchId(),
  4778.                 'internalParticipants' => json_decode($meeting->getInternalParticipantIds(), true) ?? [],
  4779.                 'otherParticipants' => json_decode($meeting->getOtherParticipantInfo(), true) ?? [],
  4780.                 'agendas' => json_decode($meeting->getAgendaList(), true) ?? [],
  4781.             ]);
  4782.         } catch (\Exception $e) {
  4783.             return new JsonResponse(['success' => false'error' => $e->getMessage()], 500);
  4784.         }
  4785.     }
  4786.     public function GetDocumentsForMeetingScheduleAppAction(Request $request): JsonResponse
  4787.     {
  4788.         $em $this->getDoctrine()->getManager();
  4789.         $hrHelper = new HumanResourceHelper($em);
  4790.         try {
  4791.             $documents $hrHelper->getAllDocumentsFromApproval($request);
  4792.             return ResponseStructure::success($documents'Documents fetched successfully');
  4793.         } catch (\Exception $e) {
  4794.             return ResponseStructure::error($e->getMessage());
  4795.         }
  4796.     }
  4797.     public function getMeetingsByDateAction(Request $request): JsonResponse
  4798.     {
  4799.         $em $this->getDoctrine()->getManager();
  4800.         $dateParam $request->query->get('date');
  4801.         $monthParam $request->query->get('month');
  4802.         $dayParam $request->query->get('day');
  4803.         $yearParam $request->query->get('year');
  4804.         $start $end null;
  4805.         try {
  4806.             if ($dateParam) {
  4807.                 if (strpos($dateParam',') !== false) {
  4808.                     [$startStr$endStr] = explode(','$dateParam);
  4809.                     $start = new \DateTime($startStr " 00:00:00");
  4810.                     $end = new \DateTime($endStr " 23:59:59");
  4811.                 } else {
  4812.                     $parts explode('-'$dateParam);
  4813.                     if (count($parts) === 3) {
  4814.                         $start = new \DateTime($dateParam " 00:00:00");
  4815.                         $end = new \DateTime($dateParam " 23:59:59");
  4816.                     } elseif (count($parts) === 2) {
  4817.                         $start = new \DateTime($dateParam "-01 00:00:00");
  4818.                         $end = (clone $start)->modify('last day of this month')->setTime(235959);
  4819.                     } else {
  4820.                         throw new \Exception("Invalid date format");
  4821.                     }
  4822.                 }
  4823.             } elseif ($monthParam) {
  4824.                 $year $yearParam ?: date('Y');
  4825.                 $monthDate = new \DateTime("first day of $monthParam $year");
  4826.                 $start = (clone $monthDate)->setTime(000);
  4827.                 $end = (clone $monthDate)->modify('last day of this month')->setTime(235959);
  4828.             } elseif ($dayParam) {
  4829.                 $year $yearParam ?: date('Y');
  4830.                 $startOfYear = new \DateTime("$year-01-01 00:00:00");
  4831.                 $endOfYear = new \DateTime("$year-12-31 23:59:59");
  4832.                 $meetings $em->getRepository(\ApplicationBundle\Entity\ScheduledMeeting::class)
  4833.                     ->createQueryBuilder('m')
  4834.                     ->where('m.startAt BETWEEN :start AND :end')
  4835.                     ->setParameter('start'$startOfYear)
  4836.                     ->setParameter('end'$endOfYear)
  4837.                     ->getQuery()
  4838.                     ->getResult();
  4839.                 $meetingType MeetingSchedulingConstant::$meetingType;
  4840.                 $data = [];
  4841.                 foreach ($meetings as $meeting) {
  4842.                     if (strtolower($meeting->getStartAt()->format('l')) === strtolower($dayParam)) {
  4843.                         $data[] = [
  4844.                             'id' => $meeting->getScheduleId(),
  4845.                             'title' => $meeting->getTitle(),
  4846.                             'desc' => $meeting->getDesc(),
  4847.                             'startAt' => $meeting->getStartAt()->format('Y-m-d H:i:s'),
  4848.                             'endAt' => $meeting->getEndAt() ? $meeting->getEndAt()->format('Y-m-d H:i:s') : null,
  4849.                             'roomId' => $meeting->getRoomId(),
  4850.                             'meetingType' => $meetingType[$meeting->getMeetingType()] ?? null,
  4851.                             'location' => $meeting->getLocation(),
  4852.                             'participant' => json_decode($meeting->getParticipantInfo()),
  4853.                             'status' => $meeting->getStatus(),
  4854.                             'approved' => (bool)$meeting->getApproved(),
  4855.                         ];
  4856.                     }
  4857.                 }
  4858.                 return new JsonResponse([
  4859.                     'success' => true,
  4860.                     'filter' => [
  4861.                         'day' => $dayParam,
  4862.                         'year' => $year
  4863.                     ],
  4864.                     'meetings' => $data
  4865.                 ]);
  4866.             } else {
  4867.                 return new JsonResponse([
  4868.                     'success' => false,
  4869.                     'error' => 'Please provide month, day, or date query parameter.'
  4870.                 ], 400);
  4871.             }
  4872.         } catch (\Exception $e) {
  4873.             return new JsonResponse([
  4874.                 'success' => false,
  4875.                 'error' => 'Invalid date format or input. ' $e->getMessage()
  4876.             ], 400);
  4877.         }
  4878.         $meetings $em->getRepository(\ApplicationBundle\Entity\ScheduledMeeting::class)
  4879.             ->createQueryBuilder('m')
  4880.             ->where('m.startAt BETWEEN :start AND :end')
  4881.             ->setParameter('start'$start)
  4882.             ->setParameter('end'$end)
  4883.             ->getQuery()
  4884.             ->getResult();
  4885.         $meetingType MeetingSchedulingConstant::$meetingType;
  4886.         $data = [];
  4887.         foreach ($meetings as $meeting) {
  4888.             $data[] = [
  4889.                 'id' => $meeting->getScheduleId(),
  4890.                 'title' => $meeting->getTitle(),
  4891.                 'desc' => $meeting->getDesc(),
  4892.                 'startAt' => $meeting->getStartAt() ? $meeting->getStartAt()->format('Y-m-d H:i:s') : null,
  4893.                 'endAt' => $meeting->getEndAt() ? $meeting->getEndAt()->format('Y-m-d H:i:s') : null,
  4894.                 'roomId' => $meeting->getRoomId(),
  4895.                 'meetingType' => $meetingType[$meeting->getMeetingType()] ?? null,
  4896.                 'location' => $meeting->getLocation(),
  4897.                 'participant' => json_decode($meeting->getParticipantInfo()),
  4898.                 'status' => $meeting->getStatus(),
  4899.                 'approved' => (bool)$meeting->getApproved(),
  4900.             ];
  4901.         }
  4902.         return new JsonResponse([
  4903.             'success' => true,
  4904.             'range' => [
  4905.                 'start' => $start->format('Y-m-d H:i:s'),
  4906.                 'end' => $end->format('Y-m-d H:i:s')
  4907.             ],
  4908.             'meetings' => $data
  4909.         ]);
  4910.     }
  4911.     public function getMeetingByYearlyAction(Request $request): JsonResponse
  4912.     {
  4913.         $em $this->getDoctrine()->getManager();
  4914.         $yearParam $request->query->get('year');
  4915.         try {
  4916.             $data HumanResourceHelper::GetMeetingByYearlyAction($em$yearParam);
  4917.             return new JsonResponse($data200);
  4918.         } catch (\Exception $e) {
  4919.             return new JsonResponse([
  4920.                 'success' => false,
  4921.                 'error' => $e->getMessage()
  4922.             ], 400);
  4923.         }
  4924.     }
  4925.     public function getMeetingByIdAction(Request $requestint $id): JsonResponse
  4926.     {
  4927.         $em $this->getDoctrine()->getManager();
  4928.         $meeting $em->getRepository(\ApplicationBundle\Entity\ScheduledMeeting::class)->find($id);
  4929.         if (!$meeting) {
  4930.             return new JsonResponse([
  4931.                 'success' => false,
  4932.                 'error' => 'Meeting not found'
  4933.             ], 404);
  4934.         }
  4935.         return new JsonResponse([
  4936.             'success' => true,
  4937.             'meeting' => [
  4938.                 'id' => $meeting->getScheduleId(),
  4939.                 'docHash' => $meeting->getDocumentHash(),
  4940.                 'title' => $meeting->getTitle(),
  4941.                 'desc' => $meeting->getDesc(),
  4942.                 'specialType' => $meeting->getSpecialType(),
  4943.                 'startAt' => $meeting->getStartAt() ? $meeting->getStartAt()->format('Y-m-d H:i:s') : null,
  4944.                 'endAt' => $meeting->getEndAt() ? $meeting->getEndAt()->format('Y-m-d H:i:s') : null,
  4945.                 'meetingType' => $meeting->getMeetingType(),
  4946.                 'location' => $meeting->getLocation(),
  4947.                 'roomId' => $meeting->getRoomId(),
  4948.                 'facilitator' => [
  4949.                     'id' => $meeting->getFacilitatorId(),
  4950.                     'name' => $meeting->getFacilitatorName()
  4951.                 ],
  4952.                 'companyId' => $meeting->getCompanyId(),
  4953.                 'branchId' => $meeting->getBranchId(),
  4954.                 'agendaList' => $meeting->getAgendaList() ? json_decode($meeting->getAgendaList(), true) : [],
  4955.                 'internalParticipants' => $meeting->getInternalParticipantIds() ? json_decode($meeting->getInternalParticipantIds(), true) : [],
  4956.                 'otherParticipants' => $meeting->getOtherParticipantInfo() ? json_decode($meeting->getOtherParticipantInfo(), true) : [],
  4957.                 'createdAt' => $meeting->getCreatedAt()->format('Y-m-d H:i:s'),
  4958.             ]
  4959.         ]);
  4960.     }
  4961.     public function updateMeetingAction(Request $requestint $id): JsonResponse
  4962.     {
  4963.         $em $this->getDoctrine()->getManager();
  4964.         $meeting $em->getRepository(\ApplicationBundle\Entity\ScheduledMeeting::class)->find($id);
  4965.         if (!$meeting) {
  4966.             return new JsonResponse(['success' => false'error' => 'Meeting not found'], 404);
  4967.         }
  4968.         $data json_decode($request->getContent(), true);
  4969.         if (!$data) {
  4970.             $data $request->request->all();
  4971.         }
  4972.         if (!$data) {
  4973.             return new JsonResponse(['success' => false'error' => 'Invalid data'], 400);
  4974.         }
  4975.         if (isset($data['title'])) $meeting->setTitle($data['title']);
  4976.         if (isset($data['desc'])) $meeting->setDesc($data['desc']);
  4977.         if (isset($data['startAt'])) $meeting->setStartAt(new \DateTime($data['startAt']));
  4978.         if (isset($data['endAt'])) $meeting->setEndAt(new \DateTime($data['endAt']));
  4979.         if (isset($data['location'])) $meeting->setLocation($data['location']);
  4980.         if (isset($data['meetingType'])) $meeting->setMeetingType($data['meetingType']);
  4981.         if (isset($data['roomId'])) $meeting->setRoomId($data['roomId']);
  4982.         if (isset($data['agendaList'])) {
  4983.             $agendaList is_array($data['agendaList']) ? $data['agendaList'] : json_decode($data['agendaList'], true);
  4984.             $meeting->setAgendaList(json_encode($agendaList));
  4985.         }
  4986.         $meeting->setLastModifiedDate(new \DateTime());
  4987.         $em->flush();
  4988.         return new JsonResponse([
  4989.             'success' => true,
  4990.             'message' => 'Meeting updated successfully',
  4991.             'meetingId' => $meeting->getScheduleId()
  4992.         ]);
  4993.     }
  4994.     public function deleteMeetingAction(Request $requestint $id): JsonResponse
  4995.     {
  4996.         $em $this->getDoctrine()->getManager();
  4997.         $meeting $em->getRepository(\ApplicationBundle\Entity\ScheduledMeeting::class)->find($id);
  4998.         if (!$meeting) {
  4999.             return new JsonResponse(['success' => false'error' => 'Meeting not found'], 404);
  5000.         }
  5001.         $em->remove($meeting);
  5002.         $em->flush();
  5003.         return new JsonResponse([
  5004.             'success' => true,
  5005.             'message' => 'Meeting deleted successfully',
  5006.             'deletedId' => $id
  5007.         ]);
  5008.     }
  5009.     public function searchParticipantByEmailAction(Request $request): JsonResponse
  5010.     {
  5011.         $em $this->getDoctrine()->getManager();
  5012.         $email trim($request->query->get('email'));
  5013.         if (empty($email)) {
  5014.             return new JsonResponse([
  5015.                 'success' => false,
  5016.                 'error' => 'Email is required'
  5017.             ], 400);
  5018.         }
  5019.         try {
  5020.             $companyId $this->getLoggedUserCompanyId($request);
  5021.             $client $em->getRepository(\ApplicationBundle\Entity\AccClients::class)
  5022.                 ->findOneBy(['email' => $email]);
  5023.             if ($client) {
  5024.                 return new JsonResponse([
  5025.                     'success' => true,
  5026.                     'type' => 'client',
  5027.                     'data' => [
  5028.                         'client_id' => $client->getClientId(),
  5029.                         'company_id' => $client->getCompanyId(),
  5030.                         'client_name' => $client->getClientName(),
  5031.                         'email' => $client->getEmail(),
  5032.                     ]
  5033.                 ]);
  5034.             }
  5035.             $employee $em->getRepository(\ApplicationBundle\Entity\Employee::class)
  5036.                 ->findOneBy(['email' => $email]);
  5037.             if ($employee) {
  5038.                 return new JsonResponse([
  5039.                     'success' => true,
  5040.                     'type' => 'employee',
  5041.                     'data' => [
  5042.                         'name' => $employee->getName(),
  5043.                         'email' => $employee->getEmail(),
  5044.                         'user_id' => $employee->getUserId(),
  5045.                         'address_contact' => $employee->getAddressContact(),
  5046.                     ]
  5047.                 ]);
  5048.             }
  5049.             return new JsonResponse([
  5050.                 'success' => false,
  5051.                 'error' => 'No client or employee found for this email'
  5052.             ], 404);
  5053.         } catch (\Exception $e) {
  5054.             return new JsonResponse([
  5055.                 'success' => false,
  5056.                 'error' => $e->getMessage()
  5057.             ], 500);
  5058.         }
  5059.     }
  5060.     public function GetRoomInformationForMeetingAction(Request $request): JsonResponse
  5061.     {
  5062.         $em $this->getDoctrine()->getManager();
  5063.         $onlyAvailable $request->query->getBoolean('onlyAvailable'false);
  5064.         $rooms HumanResourceHelper::getRooms($em$onlyAvailable);
  5065.         return new JsonResponse([
  5066.             'status' => 'success',
  5067.             'data' => $rooms
  5068.         ]);
  5069.     }
  5070.     public function MeetingTypeAction(Request $request)
  5071.     {
  5072.         return new JsonResponse([
  5073.             'success' => true,
  5074.             'data' => MeetingSchedulingConstant::$meetingType
  5075.         ]);
  5076.     }
  5077.     public function GetPriorityListAction()
  5078.     {
  5079.         $priority HumanResourceHelper::priorityList();
  5080.         return new JsonResponse([
  5081.             'success' => true,
  5082.             'data' => $priority
  5083.         ]);
  5084.     }
  5085.     public function CreateTrainingScheduleAction(Request $req$action 0)
  5086.     {
  5087.         $em $this->getDoctrine()->getManager();
  5088.         $companyId $this->getLoggedUserCompanyId($req);
  5089.         $session $req->getSession();
  5090.         if ($req->request->has('XHRreq')) {
  5091.             return new JsonResponse([HumanResource::HandelXHRreqForMeetingScheduling($em$req)]);
  5092.         }
  5093.         if ($action === 'list') {
  5094.             $response HumanResource::TwigDataForScheduledMeetingList($em, [1]);
  5095.             return $this->render(
  5096.                 'ApplicationBundle:pages/human_resource/list:scheduled_meeting_list.html.twig',
  5097.                 [
  5098.                     'page_title' => 'Training Schedule List',
  5099.                     'list' => $response
  5100.                 ]
  5101.             );
  5102.         }
  5103.         if ($req->isMethod('GET')) {
  5104.         }
  5105.         if ($req->isMethod('POST')) {
  5106.             $approveHash $req->request->get('approvalHash');
  5107.             $approveRole $req->request->get('approvalRole');
  5108.             $loginId $req->getSession()->get(UserConstants::USER_LOGIN_ID);
  5109.             $isSignatureOk DocValidation::isSignatureOk($em$loginId$approveHash);
  5110.             $companyData Company::getCompanyData($em$companyId);
  5111.             if ($isSignatureOk) {
  5112.                 $isSuccess HumanResource::createOrUpdateDataForMeetingScheduling($em$req);
  5113.                 if ($isSuccess) {
  5114.                     $options = array(
  5115.                         'notification_enabled' => $this->container->getParameter('notification_enabled'),
  5116.                         'notification_server' => $this->container->getParameter('notification_server'),
  5117.                         'appId' => $req->getSession()->get(UserConstants::USER_APP_ID),
  5118.                         'url' => $this->generateUrl(
  5119.                             GeneralConstant::$Entity_list_details[array_flip(GeneralConstant::$Entity_list)['ScheduledMeeting']]['entity_view_route_path_name']
  5120.                         )
  5121.                     );
  5122.                     $meetingId $isSuccess[1];
  5123.                     System::setApprovalInfo(
  5124.                         $this->getDoctrine()->getManager(),
  5125.                         $options,
  5126.                         array_flip(GeneralConstant::$Entity_list)['ScheduledMeeting'],
  5127.                         $meetingId,
  5128.                         $req->getSession()->get(UserConstants::USER_LOGIN_ID),
  5129.                         '',
  5130.                         0,
  5131.                         $this->get('mail_module')
  5132.                     );
  5133.                     System::createEditSignatureHash(
  5134.                         $this->getDoctrine()->getManager(),
  5135.                         array_flip(GeneralConstant::$Entity_list)['ScheduledMeeting'],
  5136.                         $meetingId,
  5137.                         $loginId,
  5138.                         $approveRole,
  5139.                         $req->request->get('approvalHash')
  5140.                     );
  5141.                     $url $this->generateUrl(
  5142.                         'view_scheduled_meeting'
  5143.                     );
  5144.                     return $this->redirect($url "/" $meetingId);
  5145.                 } else {
  5146.                     return new JsonResponse(array(
  5147.                         'success' => false
  5148.                     ));
  5149.                 }
  5150.             } else {
  5151.                 $this->addFlash(
  5152.                     'error',
  5153.                     'Invalid Approval Hash!'
  5154.                 );
  5155.                 return $this->redirectToRoute('create_training_schedule');
  5156.             }
  5157.         }
  5158.         $response HumanResource::twigDataForTrainingScheduling($em);
  5159.         return $this->render(
  5160.             'ApplicationBundle:pages/human_resource/input_forms:create_training_schedule.html.twig',
  5161.             [
  5162.                 'page_title' => 'Schedule a Training',
  5163.                 'employeeIds' => $response['employeeIds'],
  5164.                 'branches' => $response['branches'],
  5165.                 'asset' => $response['asset'],
  5166.                 'rooms' => $response['rooms'],
  5167.                 'courseList' => $response['courseList'],
  5168.                 'sales_orders' => $response['salesOrders'],
  5169.                 'purchase_orders' => $response['purchaseOrders'],
  5170.                 'meeting_types' => $response['meetingType'],
  5171.                 'skillList' => $response['skillList'],
  5172.             ]
  5173.         );
  5174.     }
  5175.     public function ScheduledTrainingListAction(Request $req$action 0)
  5176.     {
  5177.         $em $this->getDoctrine()->getManager();
  5178.         $companyId $this->getLoggedUserCompanyId($req);
  5179.         $session $req->getSession();
  5180.         $response HumanResource::TwigDataForScheduledMeetingList($em, [1]);
  5181.         return $this->render(
  5182.             'ApplicationBundle:pages/human_resource/list:scheduled_training_list.html.twig',
  5183.             [
  5184.                 'page_title' => 'Scheduled Trainings ',
  5185.                 'list' => $response
  5186.             ]
  5187.         );
  5188.     }
  5189.     public function ScheduledInterviewListAction(Request $req$action 0)
  5190.     {
  5191.         $em $this->getDoctrine()->getManager();
  5192.         $companyId $this->getLoggedUserCompanyId($req);
  5193.         $session $req->getSession();
  5194.         $response HumanResource::TwigDataForScheduledMeetingList($em, [2]);
  5195.         return $this->render(
  5196.             'ApplicationBundle:pages/human_resource/list:scheduled_interview_list.html.twig',
  5197.             [
  5198.                 'page_title' => 'Scheduled Interviews ',
  5199.                 'list' => $response
  5200.             ]
  5201.         );
  5202.     }
  5203.     public function GetFilteredQuestionsAction(Request $request$search '')
  5204.     {
  5205.         $em $this->getDoctrine()->getManager();
  5206.         $companyId $this->getLoggedUserCompanyId($request);
  5207.         if ($search == '' || $search == '_EMPTY_')
  5208.             $Query "SELECT  * FROM questionnaire WHERE 1 limit 10;";
  5209.         else
  5210.             $Query "SELECT  * FROM questionnaire WHERE question_text like '%$search%'  limit 10;";
  5211.         $stmt $em->getConnection()->prepare($Query);
  5212.         $stmt->execute();
  5213.         $queryResult $stmt->fetchAll();
  5214.         $parent_head_ids = [];
  5215.         $queryResultIndexed = [];
  5216.         foreach ($queryResult as $dt) {
  5217.             $queryResultIndexed[$dt['question_id']] = $dt;
  5218.         }
  5219.         return new JsonResponse(array(
  5220.             'data' => $queryResult,
  5221.             'queryResultIndexed' => $queryResultIndexed,
  5222.         ));
  5223.     }
  5224.     public function CreateTrainingCourseAction(Request $request$id 0)
  5225.     {
  5226.         $em $this->getDoctrine()->getManager();
  5227.         $companyId $this->getLoggedUserCompanyId($request);
  5228.         $skills $em->getRepository('ApplicationBundle:Skill')->findAll();
  5229.         $courses $em->getRepository('ApplicationBundle:TrainingCourse')->findAll();
  5230.         if ($request->isMethod('POST')) {
  5231.             $loginId $request->getSession()->get(UserConstants::USER_LOGIN_ID);
  5232.             $skill = new TrainingCourse;
  5233.             $skill->setTitle($request->request->get('name'));
  5234.             $skill->setCourseHash($request->request->get('coursehash'));
  5235.             $skill->setTrainingMaterialText($request->request->get('overview'));
  5236.             $skill->setTaggedSkillHashes(json_encode($request->request->get('skill')));
  5237.             $skill->setCompanyId($companyId);
  5238.             //$skill->setEditFlag(1); //editable usually
  5239.             $skill->setCreatedLoginId($request->getSession()->get(UserConstants::USER_LOGIN_ID));
  5240.             //$skill->setApproved(GeneralConstant::APPROVAL_STATUS_PENDING);
  5241.             //$skill->setAutocreated(0);
  5242.             $em->persist($skill);
  5243.             $em->flush();
  5244.         }
  5245.         return $this->render(
  5246.             'ApplicationBundle:pages/human_resource/input_forms:create_training_course.html.twig',
  5247.             [
  5248.                 'page_title' => 'Create Training Course',
  5249.                 'skills' => $skills,
  5250.                 'courses' => $courses
  5251.             ]
  5252.         );
  5253.     }
  5254.     public function CreateEmployeeExpenseAllowanceSettingsAction(Request $request$id 0)
  5255.     {
  5256.         $em $this->getDoctrine()->getManager();
  5257.         $companyId $this->getLoggedUserCompanyId($request);
  5258.         $extDocData = [];
  5259.         $extDetailsData = [];
  5260.         if ($request->isMethod('POST')) {
  5261.             //            Generic::debugMessage($_POST);
  5262.             $em $this->getDoctrine()->getManager();
  5263.             $entity_id array_flip(GeneralConstant::$Entity_list)['EmployeeExpenseAllowanceSettings']; //change
  5264.             $dochash $request->request->get('docHash'); //change
  5265.             $loginId $request->getSession()->get(UserConstants::USER_LOGIN_ID);
  5266.             $approveRole $request->request->get('approvalRole');
  5267.             $approveHash $request->request->get('approvalHash');
  5268.             if (!DocValidation::isInsertable(
  5269.                 $em,
  5270.                 $entity_id,
  5271.                 $dochash,
  5272.                 $loginId,
  5273.                 $approveRole,
  5274.                 $approveHash,
  5275.                 $id
  5276.             )
  5277.             ) {
  5278.                 $this->addFlash(
  5279.                     'error',
  5280.                     'Sorry Could not insert Data.'
  5281.                 );
  5282.             } else {
  5283.                 $funcname 'EmployeeExpenseAllowanceSettings';
  5284.                 DeleteDocument::$funcname($em$id0);
  5285.                 $docId HumanResource::CreateSalarySegregationPolicy($em$request$companyId0);
  5286.                 //now add Approval info
  5287.                 $loginId $request->getSession()->get(UserConstants::USER_LOGIN_ID);
  5288.                 $approveRole $request->request->get('approvalRole');
  5289.                 $options = array(
  5290.                     'notification_enabled' => $this->container->getParameter('notification_enabled'),
  5291.                     'notification_server' => $this->container->getParameter('notification_server'),
  5292.                     'appId' => $request->getSession()->get(UserConstants::USER_APP_ID),
  5293.                     'url' => $this->generateUrl(
  5294.                         GeneralConstant::$Entity_list_details[array_flip(GeneralConstant::$Entity_list)['EmployeeExpenseAllowanceSettings']]['entity_view_route_path_name']
  5295.                     )
  5296.                 );
  5297.                 System::setApprovalInfo(
  5298.                     $this->getDoctrine()->getManager(),
  5299.                     $options,
  5300.                     array_flip(GeneralConstant::$Entity_list)['EmployeeExpenseAllowanceSettings'],
  5301.                     $docId,
  5302.                     $request->getSession()->get(UserConstants::USER_LOGIN_ID)
  5303.                 );
  5304.                 System::createEditSignatureHash(
  5305.                     $this->getDoctrine()->getManager(),
  5306.                     array_flip(GeneralConstant::$Entity_list)['EmployeeExpenseAllowanceSettings'],
  5307.                     $docId,
  5308.                     $loginId,
  5309.                     $approveRole,
  5310.                     $request->request->get('approvalHash')
  5311.                 );
  5312.                 $doc_here $this->getDoctrine()
  5313.                     ->getRepository('ApplicationBundle:EmployeeExpenseAllowanceSettings')
  5314.                     ->findOneBy(
  5315.                         array(
  5316.                             'id' => $docId
  5317.                         )
  5318.                     );
  5319.                 //notify
  5320.                 $this->addFlash(
  5321.                     'success',
  5322.                     'Settings Successfully Updated.'
  5323.                 );
  5324.                 $url $this->generateUrl(
  5325.                     GeneralConstant::$Entity_list_details[array_flip(GeneralConstant::$Entity_list)['EmployeeExpenseAllowanceSettings']]['entity_view_route_path_name']
  5326.                 );
  5327.                 System::AddNewNotification(
  5328.                     $this->container->getParameter('notification_enabled'),
  5329.                     $this->container->getParameter('notification_server'),
  5330.                     $request->getSession()->get(UserConstants::USER_APP_ID),
  5331.                     $request->getSession()->get(UserConstants::USER_COMPANY_ID),
  5332.                     "Salary Segregation Policy : " $doc_here->getDocumentHash() . " Has Been Created And is Under Processing",
  5333.                     'pos',
  5334.                     System::getPositionIdsByDepartment($emGeneralConstant::HRM_DEPARTMENT),
  5335.                     'success',
  5336.                     //                    $url . "/" . $TransID,
  5337.                     $url "/" $docId,
  5338.                     "Journal"
  5339.                 );
  5340.                 return $this->redirect($url "/" $docId);
  5341.             }
  5342.         }
  5343.         //for edits
  5344.         if ($id == 0) {
  5345.         } else {
  5346.             $extDocData $em->getRepository('ApplicationBundle:EmployeeExpenseAllowanceSettings')->findOneBy(
  5347.                 array(
  5348.                     'id' => $id///material
  5349.                 )
  5350.             );
  5351.             //now if its not editable, redirect to view
  5352.             if ($extDocData) {
  5353.                 if ($extDocData->getEditFlag() != 1) {
  5354. //          $url = $this->generateUrl(
  5355. ////              'view_salary_segregation_policy'
  5356. //              'salary_segregation_policy'
  5357. //          );
  5358. //          return $this->redirect($url . "/" . $id);
  5359.                 } else {
  5360. //          $extVoucherDetailsData = Accounts::GetVoucherDataForEdit($em, $voucherId);
  5361. //          $extDetailsData = $em->getRepository('ApplicationBundle:SalarySegregationPolicy')->findOneBy(
  5362. //              array(
  5363. //                  'transactionId' => $id, ///material
  5364. //
  5365. //              )
  5366. //          );
  5367.                 }
  5368.             } else {
  5369.             }
  5370.         }
  5371.         $employeeIds $em->getRepository("ApplicationBundle:Employee")->findAll();
  5372.         $employeeType HumanResourceConstant::$employeeType;
  5373.         $employeeExpenseAllowanceTypes HumanResourceConstant::$employeeExpenseAllowanceTypes;
  5374.         $Designation $em->getRepository("ApplicationBundle:SysDepartmentPosition")->findAll();
  5375.         $branch $em->getRepository("ApplicationBundle:Branch")->findAll();
  5376.         $departments $em->getRepository("ApplicationBundle:SysDepartment")->findAll();
  5377.         $department = [];
  5378.         foreach ($departments as $entry) {
  5379.             $department[$entry->getDepartmentId()] = array(
  5380.                 'id' => $entry->getDepartmentId(),
  5381.                 'name' => $entry->getDepartmentName(),
  5382.             );
  5383.         }
  5384.         return $this->render(
  5385.             'ApplicationBundle:pages/human_resource/input_forms:create_employee_expense_allowance_settings.html.twig',
  5386.             [
  5387.                 'page_title' => 'Employee Expense Allowance Settings',
  5388.                 'employeeIds' => $employeeIds,
  5389.                 'extId' => $id,
  5390.                 'extDocData' => $extDocData,
  5391.                 'employeeType' => $employeeType,
  5392.                 'employeeExpenseAllowanceTypes' => $employeeExpenseAllowanceTypes,
  5393.                 'Designation' => $Designation,
  5394.                 'branch' => $branch,
  5395.                 'department' => $department,
  5396.             ]
  5397.         );
  5398.     }
  5399.     public function EmployeeExpenseAllowanceSettingsListAction(Request $request)
  5400.     {
  5401.         $em $this->getDoctrine()->getManager();
  5402.         $allowed_ids = [];
  5403.         $companyId $this->getLoggedUserCompanyId($request);
  5404.         $listData HumanResource::GetDataForEmployeeExpenseAllowanceSettingsListAction($em$request->isMethod('POST') ? 'POST' 'GET'$request->request$companyId);
  5405.         if ($request->isMethod('POST')) {
  5406.             if ($request->query->has('dataTableQry')) {
  5407.                 return new JsonResponse(
  5408.                     $listData
  5409.                 );
  5410.             }
  5411.         }
  5412.         return $this->render('ApplicationBundle:pages/human_resource/list:employee_expense_allowance_settings_list.html.twig',
  5413. //         return $this->render('ApplicationBundle:pages/dashboard:test_pix_invent.html.twig',
  5414.             array(
  5415.                 'page_title' => 'Expense Allowance Settings List',
  5416. //            'data' => SalesOrderM::GetClientList($em, [], $companyId),
  5417. //            'client_types' => Client::GetClientType($em, $companyId),
  5418. //            'region_list' => Client::RegionList($em, $companyId),
  5419. //            'geographical_region_list' => Client::GeographicalRegionList($em, $companyId)
  5420.             )
  5421.         );
  5422.     }
  5423.     public function salarySegAction(Request $request$id 0)
  5424.     {
  5425.         $em $this->getDoctrine()->getManager();
  5426.         $companyId $this->getLoggedUserCompanyId($request);
  5427.         $extDocData = [];
  5428.         $extDetailsData = [];
  5429.         if ($request->isMethod('POST')) {
  5430.             //            Generic::debugMessage($_POST);
  5431.             $em $this->getDoctrine()->getManager();
  5432.             $entity_id array_flip(GeneralConstant::$Entity_list)['SalarySegregationPolicy']; //change
  5433.             $dochash $request->request->get('docHash'); //change
  5434.             $loginId $request->getSession()->get(UserConstants::USER_LOGIN_ID);
  5435.             $approveRole $request->request->get('approvalRole');
  5436.             $approveHash $request->request->get('approvalHash');
  5437.             if (!DocValidation::isInsertable(
  5438.                 $em,
  5439.                 $entity_id,
  5440.                 $dochash,
  5441.                 $loginId,
  5442.                 $approveRole,
  5443.                 $approveHash,
  5444.                 $id
  5445.             )
  5446.             ) {
  5447.                 $this->addFlash(
  5448.                     'error',
  5449.                     'Sorry Couldnot insert Data.'
  5450.                 );
  5451.             } else {
  5452.                 $funcname 'SalarySegregationPolicy';
  5453.                 DeleteDocument::$funcname($em$id0);
  5454.                 $docId HumanResource::CreateSalarySegregationPolicy($em$request$companyId0);
  5455.                 //now add Approval info
  5456.                 $loginId $request->getSession()->get(UserConstants::USER_LOGIN_ID);
  5457.                 $approveRole $request->request->get('approvalRole');
  5458.                 $options = array(
  5459.                     'notification_enabled' => $this->container->getParameter('notification_enabled'),
  5460.                     'notification_server' => $this->container->getParameter('notification_server'),
  5461.                     'appId' => $request->getSession()->get(UserConstants::USER_APP_ID),
  5462.                     'url' => $this->generateUrl(
  5463.                         GeneralConstant::$Entity_list_details[array_flip(GeneralConstant::$Entity_list)['SalarySegregationPolicy']]['entity_view_route_path_name']
  5464.                     )
  5465.                 );
  5466.                 System::setApprovalInfo(
  5467.                     $this->getDoctrine()->getManager(),
  5468.                     $options,
  5469.                     array_flip(GeneralConstant::$Entity_list)['SalarySegregationPolicy'],
  5470.                     $docId,
  5471.                     $request->getSession()->get(UserConstants::USER_LOGIN_ID),
  5472.                     3    //journal voucher
  5473.                 );
  5474.                 System::createEditSignatureHash(
  5475.                     $this->getDoctrine()->getManager(),
  5476.                     array_flip(GeneralConstant::$Entity_list)['SalarySegregationPolicy'],
  5477.                     $docId,
  5478.                     $loginId,
  5479.                     $approveRole,
  5480.                     $request->request->get('approvalHash')
  5481.                 );
  5482.                 $doc_here $this->getDoctrine()
  5483.                     ->getRepository('ApplicationBundle:SalarySegregationPolicy')
  5484.                     ->findOneBy(
  5485.                         array(
  5486.                             'id' => $docId
  5487.                         )
  5488.                     );
  5489.                 //notify
  5490.                 $this->addFlash(
  5491.                     'success',
  5492.                     'Policy Successfully Updated.'
  5493.                 );
  5494.                 $url $this->generateUrl(
  5495.                     'salary_segregation_policy'
  5496.                 );
  5497.                 System::AddNewNotification(
  5498.                     $this->container->getParameter('notification_enabled'),
  5499.                     $this->container->getParameter('notification_server'),
  5500.                     $request->getSession()->get(UserConstants::USER_APP_ID),
  5501.                     $request->getSession()->get(UserConstants::USER_COMPANY_ID),
  5502.                     "Salary Segregation Policy : " $doc_here->getDocumentHash() . " Has Been Created And is Under Processing",
  5503.                     'pos',
  5504.                     System::getPositionIdsByDepartment($emGeneralConstant::HRM_DEPARTMENT),
  5505.                     'success',
  5506.                     //                    $url . "/" . $TransID,
  5507.                     $url "/" $docId,
  5508.                     "Journal"
  5509.                 );
  5510.                 return $this->redirect($url "/" $docId);
  5511.             }
  5512.         }
  5513.         //for edits
  5514.         if ($id == 0) {
  5515.         } else {
  5516.             $extDocData $em->getRepository('ApplicationBundle:SalarySegregationPolicy')->findOneBy(
  5517.                 array(
  5518.                     'id' => $id///material
  5519.                 )
  5520.             );
  5521.             //now if its not editable, redirect to view
  5522.             if ($extDocData) {
  5523.                 if ($extDocData->getEditFlag() != 1) {
  5524. //          $url = $this->generateUrl(
  5525. ////              'view_salary_segregation_policy'
  5526. //              'salary_segregation_policy'
  5527. //          );
  5528. //          return $this->redirect($url . "/" . $id);
  5529.                 } else {
  5530. //          $extVoucherDetailsData = Accounts::GetVoucherDataForEdit($em, $voucherId);
  5531. //          $extDetailsData = $em->getRepository('ApplicationBundle:SalarySegregationPolicy')->findOneBy(
  5532. //              array(
  5533. //                  'transactionId' => $id, ///material
  5534. //
  5535. //              )
  5536. //          );
  5537.                 }
  5538.             } else {
  5539.             }
  5540.         }
  5541.         $employeeIds $em->getRepository(EmployeeDetails::class)->findAll();
  5542.         $employeeType HumanResourceConstant::$employeeType;
  5543.         $Designation $em->getRepository(SysDepartmentPosition::class)->findAll();
  5544.         $branch $em->getRepository(Branch::class)->findAll();
  5545.         $departments $em->getRepository(SysDepartment::class)->findAll();
  5546.         $department = [];
  5547.         foreach ($departments as $entry) {
  5548.             $department[$entry->getDepartmentId()] = array(
  5549.                 'id' => $entry->getDepartmentId(),
  5550.                 'name' => $entry->getDepartmentName(),
  5551.             );
  5552.         }
  5553.         return $this->render(
  5554.             'ApplicationBundle:pages/human_resource/input_forms:salary_segregation_policy.html.twig',
  5555.             [
  5556.                 'page_title' => 'Salary Segregation Policy',
  5557.                 'employeeIds' => $employeeIds,
  5558.                 'extId' => $id,
  5559.                 'extDocData' => $extDocData,
  5560.                 'employeeType' => $employeeType,
  5561.                 'Designation' => $Designation,
  5562.                 'branch' => $branch,
  5563.                 'department' => $department,
  5564.             ]
  5565.         );
  5566.     }
  5567.     public function GetSalarySegregationDataForEmployeeEntryAction(Request $request)
  5568.     {
  5569.         $em $this->getDoctrine()->getManager();
  5570.         $companyId $this->getLoggedUserCompanyId($request);
  5571.         if ($request->request->has('salSagDataReq')) {
  5572.             $ajaxData HumanResource::handelXhrForSalSeg($em$request);
  5573.             return new JsonResponse($ajaxData);
  5574.         }
  5575.         return new JsonResponse(array('success' => false));
  5576.     }
  5577.     public function WorkHourPolicyAction(Request $req$id 0)
  5578.     {
  5579.         $em $this->getDoctrine()->getManager();
  5580.         $companyId $this->getLoggedUserCompanyId($req);
  5581.         $extData = [];
  5582.         if ($id != 0) {
  5583.             $extData $em->getRepository('ApplicationBundle:WorkHourPolicy')
  5584.                 ->findOneBy(
  5585.                     array(
  5586.                         'id' => $id
  5587.                     )
  5588.                 );
  5589.         }
  5590.         if ($req->isMethod('POST')) {
  5591.             $storeDataRes HumanResource::checkSignature($em$req);
  5592.             if ($storeDataRes['hasErr']) {
  5593.                 $msg $storeDataRes['msg'];
  5594.                 $this->addFlash(
  5595.                     'error',
  5596.                     $msg
  5597.                 );
  5598.                 return $this->redirectToRoute('work_hour_policy');
  5599.             } else {
  5600.                 HumanResource::storeDataForWhPolicy($em$req$companyId);
  5601.                 $this->addFlash(
  5602.                     'success',
  5603.                     'Policy Successfully Created!'
  5604.                 );
  5605.                 return $this->redirectToRoute('work_hour_policy');
  5606.             }
  5607.         }
  5608.         $twigData HumanResource::twigDataForWorkHourPolicy($em);
  5609.         $timeZonesArray = array();
  5610.         return $this->render(
  5611.             'ApplicationBundle:pages/human_resource/input_forms:work_hour_policy.html.twig',
  5612.             [
  5613.                 'page_title' => 'Work Hour Policy',
  5614.                 'extId' => $id,
  5615.                 'extData' => $extData,
  5616.                 'employeeIds' => $twigData['employeeIds'],
  5617.                 'employeeType' => $twigData['employeeType'],
  5618.                 'Designation' => $twigData['Designation'],
  5619.                 'branch' => $twigData['branch'],
  5620.                 'department' => $twigData['department'],
  5621.             ]
  5622.         );
  5623.     }
  5624.     public function WorkHourPolicyListAction(Request $request)
  5625.     {
  5626.         $em $this->getDoctrine()->getManager();
  5627.         $allowed_ids = [];
  5628.         $companyId $this->getLoggedUserCompanyId($request);
  5629.         $listData HumanResource::GetDataForWorkHourPolicyListAction($em$request->isMethod('POST') ? 'POST' 'GET'$request->request$companyId);
  5630.         if ($request->isMethod('POST')) {
  5631.             if ($request->query->has('dataTableQry')) {
  5632.                 return new JsonResponse(
  5633.                     $listData
  5634.                 );
  5635.             }
  5636.         }
  5637.         return $this->render('ApplicationBundle:pages/human_resource/list:work_hour_policy_list.html.twig',
  5638. //         return $this->render('ApplicationBundle:pages/dashboard:test_pix_invent.html.twig',
  5639.             array(
  5640.                 'page_title' => 'Work Hour Policy List',
  5641. //            'data' => SalesOrderM::GetClientList($em, [], $companyId),
  5642. //            'client_types' => Client::GetClientType($em, $companyId),
  5643. //            'region_list' => Client::RegionList($em, $companyId),
  5644. //            'geographical_region_list' => Client::GeographicalRegionList($em, $companyId)
  5645.             )
  5646.         );
  5647.     }
  5648.     public function WorkPlacePolicyListAction(Request $request)
  5649.     {
  5650.         $em $this->getDoctrine()->getManager();
  5651.         $workplacePolicyDetails $em->getRepository('ApplicationBundle:EmployeeWorkplace')->findAll();
  5652. //        $employee = $em->getRepository('ApplicationBundle:Employee')->findAll();
  5653.         return $this->render('ApplicationBundle:pages/human_resource/list:work_place_policy_list.html.twig', array(
  5654.             'page_title' => 'Work Place Policy List',
  5655.             'workplacePolicyDetails' => $workplacePolicyDetails,
  5656. //            'employee'=>$employee
  5657.         ));
  5658.     }
  5659.     public function workPlacePolicyAction(Request $data$id)
  5660.     {
  5661.         $em $this->getDoctrine()->getManager();
  5662.         $workPlacePolicy $em->getRepository('ApplicationBundle:EmployeeWorkplace')->find($id);
  5663.         $employee $em->getRepository(Employee::class)->findAll();
  5664.         $Approval_data System::checkIfApprovalExists(
  5665.             $em,
  5666.             array_flip(GeneralConstant::$Entity_list)['EmployeeWorkplace'],
  5667.             $id,
  5668.             $data->getSession()->get(UserConstants::USER_LOGIN_ID)
  5669.         );
  5670.         $ApprovalStatus GeneralConstant::$approvalStatus;
  5671.         return $this->render('ApplicationBundle:pages/human_resource/views:viewWorkPlacePolicy.html.twig', array(
  5672.             'page_title' => 'Work Place Policy  View',
  5673.             'workPlacePolicy' => $workPlacePolicy,
  5674.             'employee' => $employee,
  5675.             'approval_data' => $Approval_data,
  5676.             'approval_status' => $workPlacePolicy->getApproved(),
  5677.             'id' => $id,
  5678.         ));
  5679.     }
  5680.     public function SalarySegregationPolicyListAction(Request $request)
  5681.     {
  5682.         $em $this->getDoctrine()->getManager();
  5683.         $allowed_ids = [];
  5684.         $companyId $this->getLoggedUserCompanyId($request);
  5685.         $listData HumanResource::GetDataForSalarySegregationPolicyListAction($em$request->isMethod('POST') ? 'POST' 'GET'$request->request$companyId);
  5686.         if ($request->isMethod('POST')) {
  5687.             if ($request->query->has('dataTableQry')) {
  5688.                 return new JsonResponse(
  5689.                     $listData
  5690.                 );
  5691.             }
  5692.         }
  5693.         return $this->render('ApplicationBundle:pages/human_resource/list:salary_segregation_policy_list.html.twig',
  5694. //         return $this->render('ApplicationBundle:pages/dashboard:test_pix_invent.html.twig',
  5695.             array(
  5696.                 'page_title' => 'Salary Segregation Policy List',
  5697. //            'data' => SalesOrderM::GetClientList($em, [], $companyId),
  5698. //            'client_types' => Client::GetClientType($em, $companyId),
  5699. //            'region_list' => Client::RegionList($em, $companyId),
  5700. //            'geographical_region_list' => Client::GeographicalRegionList($em, $companyId)
  5701.             )
  5702.         );
  5703.     }
  5704.     public function HolidayCalendarListAction(Request $request)
  5705.     {
  5706.         $q $this->getDoctrine()
  5707.             ->getRepository('ApplicationBundle:HolidayCalendar')
  5708.             ->findBy(
  5709.                 array(
  5710. //                'status' => GeneralConstant::ACTIVE,
  5711.                     'CompanyId' => $this->getLoggedUserCompanyId($request)
  5712. //                    'approved' =>  GeneralConstant::APPROVED,
  5713.                 )
  5714.             );
  5715.         $stage_list = array(
  5716.             => 'Pending',
  5717.             => 'Pending',
  5718.             => 'Complete',
  5719.             => 'Partial',
  5720.         );
  5721.         $data = [];
  5722.         foreach ($q as $entry) {
  5723.             $data[] = array(
  5724. //          'doc_date' => $entry->getSalesReplacementDate(),
  5725.                 'id' => $entry->getHolidayCalendarId(),
  5726.                 'title' => $entry->getHoliDayTitle(),
  5727.                 'approval_status' => GeneralConstant::$approvalStatus[$entry->getApproved()],
  5728. //          'stage' => $stage_list[$entry->getStage()]
  5729.             );
  5730.         }
  5731.         return $this->render('ApplicationBundle:pages/human_resource/list:holiday_calendar_list.html.twig',
  5732.             array(
  5733.                 'page_title' => 'Holiday Calendar List',
  5734.                 'data' => $data
  5735.             )
  5736.         );
  5737.     }
  5738.     public function PayrollPolicyListAction(Request $request)
  5739.     {
  5740.         $em $this->getDoctrine()->getManager();
  5741.         $allowed_ids = [];
  5742.         $companyId $this->getLoggedUserCompanyId($request);
  5743.         $listData HumanResource::GetDataForPayrollPolicyListAction($em$request->isMethod('POST') ? 'POST' 'GET'$request->request$companyId);
  5744.         if ($request->isMethod('POST')) {
  5745.             if ($request->query->has('dataTableQry')) {
  5746.                 return new JsonResponse(
  5747.                     $listData
  5748.                 );
  5749.             }
  5750.         }
  5751.         return $this->render('ApplicationBundle:pages/human_resource/list:payroll_policy_list.html.twig',
  5752. //         return $this->render('ApplicationBundle:pages/dashboard:test_pix_invent.html.twig',
  5753.             array(
  5754.                 'page_title' => 'Payroll Policy List',
  5755. //            'data' => SalesOrderM::GetClientList($em, [], $companyId),
  5756. //            'client_types' => Client::GetClientType($em, $companyId),
  5757. //            'region_list' => Client::RegionList($em, $companyId),
  5758. //            'geographical_region_list' => Client::GeographicalRegionList($em, $companyId)
  5759.             )
  5760.         );
  5761.     }
  5762.     public function payslipAction(Request $req$action 0$id 0)
  5763.     {
  5764.         $em $this->getDoctrine()->getManager();
  5765.         $attendanceSource HumanResourceConstant::$attendanceSources;
  5766.         if ($action === 'list') {
  5767.             $response HumanResource::twigDataForPayslipList($em);
  5768.             $approval_status GeneralConstant::$approvalAction;
  5769.             return $this->render(
  5770.                 'ApplicationBundle:pages/human_resource/list:payslip_list.html.twig',
  5771.                 [
  5772.                     'page_title' => 'Payslip List',
  5773.                     'reports' => $response,
  5774.                     'approval_status' => $approval_status
  5775.                 ]
  5776.             );
  5777.         }
  5778.         if ($action === 'view') {
  5779.             $response HumanResource::twigDataForPayslipViewAndPrint($em$req$id);
  5780.             return $this->render(
  5781.                 'ApplicationBundle:pages/human_resource/views:payslip_view.html.twig',
  5782.                 [
  5783.                     'page_title' => 'View Payslip',
  5784.                     'approval_data' => $response['approval_data'],
  5785.                     'payslip' => $response['payslip'],
  5786.                     'bankAccount' => $response['bankAccount'],
  5787.                     'tin' => $response['tin'],
  5788.                     'employeeCode' => $response['employeeCode'],
  5789.                     'earningValues' => $response['earningValues'],
  5790.                     'facilityValues' => $response['facilityValues'],
  5791.                     'deductionValues' => $response['deductionValues'],
  5792.                     'document_log' => $response['document_log'],
  5793.                     'approval_status' => $response['approval_status'],
  5794.                     'created_by' => $response['created_by'],
  5795.                     'updated_at' => $response['updated_at'],
  5796.                     'employeeId' => $response['employeeId'],
  5797.                     'totalAttendance' => $response['totalPresent'],
  5798.                     'leaveList' => HumanResourceConstant::$LeaveType,
  5799.                     'AttReportData' => $response['AttReportData'],
  5800. //                    'attendanceLog' => $response['attendanceLog'],
  5801.                     'attendanceSource' => $attendanceSource,
  5802.                     'auto_created' => 0,
  5803.                 ]
  5804.             );
  5805.         }
  5806.         if ($action === 'print') {
  5807.             $em $this->getDoctrine()->getManager();
  5808.             $company_data Company::getCompanyData($em1);
  5809.             $Authorizations System::getSignatureListForDocumentPrint($emarray_flip(GeneralConstant::$Entity_list)['Payslip'], $id);
  5810.             $response HumanResource::twigDataForPayslipViewAndPrint($em$req$id);
  5811.             return $this->render(
  5812.                 'ApplicationBundle:pages/human_resource/print:payslip_print.html.twig',
  5813.                 array(
  5814.                     'page_title' => 'Print Payslip',
  5815.                     'export' => 'pdf,print',
  5816.                     'payslip' => $response['payslip'],
  5817.                     'bankAccount' => $response['bankAccount'],
  5818.                     'tin' => $response['tin'],
  5819.                     'employeeCode' => $response['employeeCode'],
  5820.                     'earningValues' => $response['earningValues'],
  5821.                     'facilityValues' => $response['facilityValues'],
  5822.                     'deductionValues' => $response['deductionValues'],
  5823.                     'company_name' => $company_data->getName(),
  5824.                     'company_data' => $company_data,
  5825.                     'company_address' => $company_data->getAddress(),
  5826.                     'company_image' => $company_data->getImage(),
  5827.                     'Authorizations' => $Authorizations,
  5828.                     'totalAttendance' => $response['totalPresent'],
  5829.                     'leaveList' => HumanResourceConstant::$LeaveType,
  5830.                     'AttReportData' => $response['AttReportData'],
  5831.                     'attendanceSource' => $attendanceSource,
  5832.                     'red' => 0
  5833.                 )
  5834.             );
  5835.         }
  5836.         if ($req->isMethod('POST')) {
  5837.             $sigRes HumanResource::checkSignature($em$req);
  5838.             if ($sigRes['hasErr']) {
  5839.                 $msg $sigRes['msg'];
  5840.                 return new JsonResponse(['success' => false'msg' => $msg]);
  5841.             }
  5842.             HumanResource::storeDataForPayslip($em$req);
  5843.             return new JsonResponse(['success' => true]);
  5844.         }
  5845.     }
  5846.     public function applicantInfoAction(Request $request$id)
  5847.     {
  5848.         $em $this->getDoctrine()->getManager('company_group');
  5849.         $session $request->getSession();
  5850.         $consultantDetails $em->getRepository(EntityApplicantDetails::class)->find($session->get(UserConstants::USER_ID));
  5851.         $skillDetails $em->getRepository(EntitySkill::class)->findAll();
  5852.         $companyId $this->getLoggedUserCompanyId($request);
  5853.         $gender HumanResourceConstant::$sex;
  5854.         $blood HumanResourceConstant::$BloodGroup;
  5855.         $userId $session->get(UserConstants::USER_ID);
  5856.         $encData $request->query->has('ref') ? $request->query->get('ref') : '';
  5857.         $education = array(
  5858.             'instituteName' => $request->get('instituteName'),
  5859.             'courseOfStudy' => $request->get('courseOfStudy'),
  5860.             'courseStartDate' => $request->get('courseStartDate'),
  5861.             'courseEndDate' => $request->get('courseEndDate'),
  5862.             'result' => $request->get('result'),
  5863.             'grade' => $request->get('grade'),
  5864.             'degree' => $request->get('degree'),
  5865.         );
  5866.         $workExperience = array(
  5867.             'title' => $request->get('title'),
  5868.             'companyName' => $request->get('companyName'),
  5869.             'jobStartDate' => $request->get('jobStartDate'),
  5870.             'jobEndDate' => $request->get('jobEndDate'),
  5871.             'description' => $request->get('description'),
  5872.         );
  5873.         $certificate = array(
  5874.             'certificatename' => $request->get('certificatename'),
  5875.             'issuedDate' => $request->get('issuedDate'),
  5876.         );
  5877.         $courses = array(
  5878.             'courseName' => $request->get('courseName'),
  5879.             'date' => $request->get('date'),
  5880.             'duration' => $request->get('duration')
  5881.         );
  5882.         $languages = array(
  5883.             'languageName' => $request->get('languageName'),
  5884.             'writtenSkill' => $request->get('writtenSkill'),
  5885.             'verbalSkill' => $request->get('verbalSkill'),
  5886.         );
  5887.         if ($request->isMethod('POST')) {
  5888.             if ($consultantDetails)
  5889.                 $consultant $consultantDetails;
  5890.             else
  5891.                 $consultant = new EntityApplicantDetails();
  5892.             $consultant->setApplicationText($request->request->get('applicationText'));
  5893.             $consultant->setFirstname($request->request->get('firstname'));
  5894.             $consultant->setLastname($request->request->get('lastname'));
  5895.             $consultant->setIsImgLegal($request->request->get('is_img_legal'));
  5896.             $consultant->setNid($request->request->get('nid'));
  5897.             $consultant->setDob(new \DateTime($request->get('dob')));
  5898.             $consultant->setSex($request->request->get('sex'));
  5899.             $consultant->setFather($request->request->get('father'));
  5900.             $consultant->setMother($request->request->get('mother'));
  5901.             $consultant->setBlood($request->request->get('blood'));
  5902.             $consultant->setPhone($request->request->get('phone'));
  5903.             $consultant->setCountry($request->request->get('country'));
  5904.             $consultant->setPostalCode($request->request->get('postalCode'));
  5905.             $consultant->setCurrAddr($request->request->get('curr_addr'));
  5906.             $consultant->setSkill(json_encode($request->request->get('skill')));
  5907.             $consultant->setEmergencyContactNumber($request->request->get('emm_contact'));
  5908.             $consultant->setCurrentEmployment($request->request->get('currentEmployment'));
  5909.             $consultant->setTin($request->request->get('tin'));
  5910.             $consultant->setEducationData(json_encode($education));
  5911.             $consultant->setWorkExperienceData(json_encode($workExperience));
  5912.             $consultant->setCertificateData(json_encode($certificate));
  5913.             $consultant->setCoursesData(json_encode($courses));
  5914.             $consultant->setLanguagesData(json_encode($languages));
  5915.             $consultant->setWorkExperienceYear($request->request->get('workExperienceYear'));
  5916.             //$consultant->setApplyForConsultant(1);
  5917.             $em->persist($consultant);
  5918.             $em->flush();
  5919.             $path "";
  5920.             $defaultProductImage '';
  5921.             $uploadedFile null;
  5922.             $upl_dir $this->container->getParameter('kernel.root_dir') . '/../web/uploads/applicantCv/';
  5923.             $uploadedFile $request->files->get('docUpload');
  5924.             if ($uploadedFile != null) {
  5925.                 $fileName 'cv' $consultantDetails->getApplicantId() . '.' $uploadedFile->guessExtension();
  5926.                 $path $fileName;
  5927. //            $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/Products/';
  5928.                 if (!file_exists($upl_dir)) {
  5929.                     mkdir($upl_dir0777true);
  5930.                 }
  5931.                 $uploadedFile->move($upl_dir$path);
  5932.                 $defaultProductImage 'uploads/applicantCv/' $path;
  5933.                 $consultant->setDocImage($defaultProductImage);
  5934.                 $em->flush();
  5935.             }
  5936.             $this->addFlash(
  5937.                 'success',
  5938.                 'Data Updated.'
  5939.             );
  5940.             if ($encData != '') {
  5941.                 $url $this->generateUrl(
  5942.                     'applicant_job_recruitment_view'
  5943.                 );
  5944.                 return $this->redirect($url '?auto_apply=1&encData=' $encData);
  5945.             }
  5946.             $url $this->generateUrl(
  5947.                 'job_recruitment_list_applicant'
  5948.             );
  5949.             return $this->redirect($url);
  5950.         }
  5951.         return $this->render('ApplicationBundle:pages/human_resource/input_forms:applicant_info.html.twig', array(
  5952.             'page_title' => 'My Information ',
  5953.             'gender' => $gender,
  5954.             'blood' => $blood,
  5955.             'consultantDetails' => $consultantDetails,
  5956.             'education' => json_decode($consultantDetails->getEducationData(), true),
  5957.             'workExperience' => json_decode($consultantDetails->getWorkExperienceData(), true),
  5958.             'certificate' => json_decode($consultantDetails->getCertificateData(), true),
  5959.             'courses' => json_decode($consultantDetails->getCoursesData(), true),
  5960.             'languages' => json_decode($consultantDetails->getLanguagesData(), true),
  5961.             'skill' => json_decode($consultantDetails->getSkill(), true),
  5962.             'skillDetails' => $skillDetails
  5963.         ));
  5964. //        $em = $this->getDoctrine()->getManager('company_group');
  5965. //        $applicantRepo = $em->getRepository(EntityApplicantDetails::class);
  5966. //        $skillDetails = $em->getRepository(EntitySkill::class)->findAll();
  5967. //
  5968. //
  5969. //        if ($req->isMethod('POST')) {
  5970. //            $applicant = $applicantRepo->find($id);
  5971. //
  5972. //            if ($req->files->get('img')) {
  5973. //                $ImgName = HumanResource::StoreFiles($req->files->get('img'), 'Applicant');
  5974. //                $applicant->setImage($ImgName);
  5975. //            }
  5976. //
  5977. //            $applicant->setFirstname($req->request->get('firstname'));
  5978. //            $applicant->setLastname($req->request->get('lastname'));
  5979. //            $applicant->setIsImgLegal($req->request->get('is_img_legal'));
  5980. //            $applicant->setNid($req->request->get('nid'));
  5981. //            $applicant->setDob(HumanResource::StringToDate($req->request->get('dob')));
  5982. //            $applicant->setSex($req->request->get('sex'));
  5983. //            $applicant->setFather($req->request->get('father'));
  5984. //            $applicant->setMother($req->request->get('mother'));
  5985. //            $applicant->setSpouse($req->request->get('spouse'));
  5986. //            $applicant->setChild1($req->request->get('child_1'));
  5987. //            $applicant->setChild2($req->request->get('child_2'));
  5988. //            $applicant->setBlood($req->request->get('blood'));
  5989. //            $applicant->setPhone($req->request->get('phone'));
  5990. //            $applicant->setOAuthEmail($req->request->get('oauth_email'));
  5991. //            $applicant->setCurrAddr($req->request->get('curr_addr'));
  5992. //            $applicant->setPermAddr($req->request->get('perm_addr'));
  5993. //            $applicant->setEmmContact($req->request->get('emm_contact'));
  5994. //
  5995. //            $applicant->setInst1($req->request->get('inst1'));
  5996. //            $applicant->setYr1($req->request->get('yr1'));
  5997. //            $applicant->setDur1($req->request->get('dur1'));
  5998. //            $applicant->setInst2($req->request->get('inst2'));
  5999. //            $applicant->setYr2($req->request->get('yr2'));
  6000. //            $applicant->setDur2($req->request->get('dur2'));
  6001. //            $applicant->setInst3($req->request->get('inst3'));
  6002. //            $applicant->setYr3($req->request->get('yr3'));
  6003. //            $applicant->setDur3($req->request->get('dur3'));
  6004. //            $applicant->setEinst1($req->request->get('einst1'));
  6005. //            $applicant->setEyr1($req->request->get('eyr1'));
  6006. //            $applicant->setEdeg1($req->request->get('edeg1'));
  6007. //            $applicant->setEinst2($req->request->get('einst2'));
  6008. //            $applicant->setEyr2($req->request->get('eyr2'));
  6009. //            $applicant->setEdeg2($req->request->get('edeg2'));
  6010. //            $applicant->setEinst3($req->request->get('einst3'));
  6011. //            $applicant->setEyr3($req->request->get('eyr3'));
  6012. //            $applicant->setEdeg3($req->request->get('edeg3'));
  6013. //
  6014. //            $em->persist($applicant);
  6015. //            $em->flush();
  6016. //
  6017. //            return $this->render(
  6018. //                'ApplicationBundle:pages/human_resource/input_forms:applicant_info.html.twig',
  6019. //                [
  6020. //                    'page_title' => 'Applicant Info',
  6021. //                    'applicant_info' => $applicant,
  6022. //                    'blood' => HumanResourceConstant::$BloodGroup,
  6023. //                    'gender' => HumanResourceConstant::$sex,
  6024. //                    'skillDetails' => $skillDetails,
  6025. //                    'HasUpdateMode' => true,
  6026. //                ]
  6027. //            );
  6028. //        }
  6029. //
  6030. //        if ($id) {
  6031. //            $applicant = $applicantRepo->find($id);
  6032. //
  6033. //            return $this->render(
  6034. //                'ApplicationBundle:pages/human_resource/input_forms:applicant_info.html.twig',
  6035. //                [
  6036. //                    'page_title' => 'Applicant Info',
  6037. //                    'applicant_info' => $applicant,
  6038. //                    'blood' => HumanResourceConstant::$BloodGroup,
  6039. //                    'gender' => HumanResourceConstant::$sex,
  6040. //                    'skillDetails' => $skillDetails,
  6041. //                    'HasUpdateMode' => false,
  6042. //                ]
  6043. //            );
  6044. //        }
  6045. //
  6046. //        $google_client = new Google_Client();
  6047. //        $google_client->setClientId('916737688016-l2qfmb9p37cumudkaqpu8s7ndngq9una.apps.googleusercontent.com');
  6048. //        $google_client->setClientSecret('BEWpEBRvv3-hSoB4cGBrVB3z');
  6049. //        $google_client->setRedirectUri('http://localhost/applicant_info');
  6050. //        $google_client->addScope('email');
  6051. //        $google_client->addScope('profile');
  6052.     }
  6053.     public function applicantDashboardAction()
  6054.     {
  6055.         return new JsonResponse(['this is applicant dashboard']);
  6056.     }
  6057.     public function resignApplicationAction(Request $req$id)
  6058.     {
  6059.         $em $this->getDoctrine()->getManager();
  6060.         if ($req->request->has('xhrReq')) {
  6061.             $response HumanResource::HandelXhrForResignApplication($em$req);
  6062.             return new JsonResponse($response);
  6063.         }
  6064.         if ($req->isMethod('GET')) {
  6065.             $applicant $em->getRepository(EmployeeDetails::class)->findBy(['emp_status' => 1]);
  6066.             $resignReason HumanResourceConstant::$resignReason;
  6067.             return $this->render(
  6068.                 'ApplicationBundle:pages/human_resource/input_forms:resign_application.html.twig',
  6069.                 [
  6070.                     'page_title' => 'Resign Application',
  6071.                     'employeeIds' => $applicant,
  6072.                     'resignReasons' => $resignReason,
  6073.                     'HasUpdateMode' => false,
  6074.                 ]
  6075.             );
  6076.         }
  6077.         if ($req->isMethod('POST')) {
  6078.             $approveHash $req->request->get('approvalHash');
  6079.             $loginId $req->getSession()->get(UserConstants::USER_LOGIN_ID);
  6080.             $isSignatureOk DocValidation::isSignatureOk($em$loginId$approveHash);
  6081.             if ($isSignatureOk) {
  6082.                 $response HumanResource::storeResignApplicationData($em$req);
  6083.                 if ($response) {
  6084.                     return $this->redirectToRoute(
  6085.                         'view_resign_application',
  6086.                         array('id' => $response->getResignApplicationId()),
  6087.                         Response::HTTP_MOVED_PERMANENTLY
  6088.                     );
  6089.                 }
  6090.             } else {
  6091.                 $this->addFlash(
  6092.                     'error',
  6093.                     'Invalid Approval Hash!'
  6094.                 );
  6095.                 return $this->redirectToRoute('resign_application');
  6096.             }
  6097.         }
  6098.     }
  6099.     public function viewResignApplicationAction(Request $req$id 0)
  6100.     {
  6101.         $em $this->getDoctrine()->getManager();
  6102.         $response HumanResource::twigDataForResignApplicationView($em$req$id);
  6103.         return $this->render(
  6104.             'ApplicationBundle:pages/human_resource/views:resign_application_view.html.twig',
  6105.             [
  6106.                 'page_title' => 'View Resign Application',
  6107.                 'approval_data' => $response['approval_data'],
  6108.                 'application' => $response['application'],
  6109.                 'applicant' => $response['applicant'],
  6110.                 'document_log' => $response['document_log'],
  6111.                 'approval_status' => $response['approval_status'],
  6112.                 'created_by' => $response['created_by'],
  6113.                 'updated_at' => $response['updated_at'],
  6114.                 'auto_created' => 0,
  6115.             ]
  6116.         );
  6117.     }
  6118.     public function printResignApplicationAction(Request $req$id)
  6119.     {
  6120.         if ($id) {
  6121.             $em $this->getDoctrine()->getManager();
  6122.             $company_data Company::getCompanyData($em1);
  6123.             $authorizations System::getSignatureListForDocumentPrint($emarray_flip(GeneralConstant::$Entity_list)['ResignApplication'], $id);
  6124.             $response HumanResource::twigDataForResignApplicationView($em$req$id);
  6125.             return $this->render(
  6126.                 'ApplicationBundle:pages/human_resource/print:resign_application_print.html.twig',
  6127.                 array(
  6128.                     'page_title' => 'Print Resign Application',
  6129.                     'export' => 'pdf,print',
  6130.                     'company_name' => $company_data->getName(),
  6131.                     'company_data' => $company_data,
  6132.                     'company_address' => $company_data->getAddress(),
  6133.                     'company_image' => $company_data->getImage(),
  6134.                     'application' => $response['application'],
  6135.                     'applicant' => $response['applicant'],
  6136.                     'Authorizations' => $authorizations,
  6137.                     'red' => 0
  6138.                 )
  6139.             );
  6140.         }
  6141.         return new JsonResponse(array(
  6142.             'success' => false,
  6143.             'msg' => 'Wrong URL format! Please try with application ID'
  6144.         ));
  6145.     }
  6146.     public function listResignApplicationAction(Request $req)
  6147.     {
  6148.         $em $this->getDoctrine()->getManager();
  6149.         $response HumanResource::getResignApplicationList($em$req);
  6150.         return $this->render("ApplicationBundle:pages/human_resource/list:resign_application_list.html.twig", array(
  6151.             'page_title' => 'Resign Application List',
  6152.             'applications' => $response,
  6153.         ));
  6154.     }
  6155.     public function viewNocApprovalAction(Request $req$id)
  6156.     {
  6157.         $em $this->getDoctrine()->getManager();
  6158.         $response HumanResource::twigDataForNocView($em$req$id);
  6159.         return $this->render(
  6160.             'ApplicationBundle:pages/human_resource/views:noc_view.html.twig',
  6161.             [
  6162.                 'page_title' => 'View NOC',
  6163.                 'approval_data' => $response['approval_data'],
  6164.                 'noc_application' => $response['noc_application'],
  6165.                 'resign_application' => $response['resign_application'],
  6166.                 'applicant' => $response['applicant'],
  6167.                 'document_log' => $response['document_log'],
  6168.                 'approval_status' => $response['approval_status'],
  6169.                 'created_by' => $response['created_by'],
  6170.                 'updated_at' => $response['updated_at'],
  6171.                 'auto_created' => 0,
  6172.             ]
  6173.         );
  6174.     }
  6175.     public function printNocApprovalAction(Request $req$id)
  6176.     {
  6177.         $em $this->getDoctrine()->getManager();
  6178.         $company_data Company::getCompanyData($em1);
  6179.         $Authorizations System::getSignatureListForDocumentPrint($emarray_flip(GeneralConstant::$Entity_list)['NocApproval'], $id);
  6180.         $response HumanResource::twigDataForNocView($em$req$id);
  6181.         return $this->render(
  6182.             'ApplicationBundle:pages/human_resource/print:noc_print.html.twig',
  6183.             [
  6184.                 'page_title' => 'Print NOC',
  6185.                 'noc_application' => $response['noc_application'],
  6186.                 'resign_application' => $response['resign_application'],
  6187.                 'applicant' => $response['applicant'],
  6188.                 'export' => 'pdf,print',
  6189.                 'company_name' => $company_data->getName(),
  6190.                 'company_data' => $company_data,
  6191.                 'company_address' => $company_data->getAddress(),
  6192.                 'company_image' => $company_data->getImage(),
  6193.                 'Authorizations' => $Authorizations,
  6194.                 'red' => 0
  6195.             ]
  6196.         );
  6197.     }
  6198.     public function createHolidayAction(Request $request$id)
  6199.     {
  6200.         $em $this->getDoctrine()->getManager();
  6201.         $companyId $this->getLoggedUserCompanyId($request);
  6202.         if ($request->isMethod('POST')) {
  6203.             $entity_id array_flip(GeneralConstant::$Entity_list)['HolidayCalendar']; //change
  6204.             $dochash $request->request->get('doc_hash'); //change
  6205.             $loginId $request->getSession()->get(UserConstants::USER_LOGIN_ID);
  6206.             $approveRole $request->request->get('approvalRole');
  6207.             $approveHash $request->request->get('approvalHash');
  6208.             if (!DocValidation::isInsertable(
  6209.                 $em,
  6210.                 $entity_id,
  6211.                 $dochash,
  6212.                 $loginId,
  6213.                 $approveRole,
  6214.                 $approveHash,
  6215.                 $id
  6216.             )
  6217.             ) {
  6218.                 $this->addFlash(
  6219.                     'error',
  6220.                     'Sorry Couldnot insert Data.'
  6221.                 );
  6222.             } else {
  6223.                 $funcname 'HolidayCalendar';
  6224.                 $doc_id $id;
  6225.                 DeleteDocument::$funcname($em$doc_id0);
  6226.                 if ($id != 0)
  6227.                     $HolidayCalender $em->getRepository(HolidayCalendar::class)->find($id);
  6228.                 else
  6229.                     $HolidayCalender = new HolidayCalendar;
  6230.                 $HolidayCalender->setDocumentHash($request->request->get('doc_hash'));
  6231.                 $HolidayCalender->setHoliDayTitle($request->request->get('holidayCalendarTitle'));
  6232.                 $HolidayCalender->setEmployeeIds(json_encode($request->request->get('employee')));
  6233.                 $HolidayCalender->setEmployeeTypeIds(json_encode($request->request->get('emp_status')));
  6234.                 $HolidayCalender->setDesignationIds(json_encode($request->request->get('desg', [])));
  6235.                 $HolidayCalender->setDepartmentIds(json_encode($request->request->get('dept', [])));
  6236.                 $HolidayCalender->setBranchIds(json_encode($request->request->get('branch', [])));
  6237.                 $HolidayCalender->setLevelSelectionStr($request->get('levelSelectionStr'''));
  6238.                 $HolidayCalender->setLevels(json_encode(HumanResource::getLevelsFromLevelSelectionStr($request->get('levelSelectionStr'''))));
  6239.                 $HolidayCalender->setCompanyId($companyId);
  6240.                 $HolidayCalender->setTypeHash('HD');
  6241.                 $HolidayCalender->setEditFlag(1); //editable usually
  6242.                 $HolidayCalender->setPrefixHash($request->request->get('prefix'));
  6243.                 $HolidayCalender->setAssocHash($request->request->get('assoc'));
  6244.                 $HolidayCalender->setNumberHash($request->request->get('number_hash'));
  6245.                 $HolidayCalender->setCreatedLoginId($request->getSession()->get(UserConstants::USER_LOGIN_ID));
  6246.                 $HolidayCalender->setApproved(GeneralConstant::APPROVAL_STATUS_PENDING);
  6247.                 $HolidayCalender->setAutocreated(0);
  6248. //
  6249. //        $arr = [
  6250. //            'date' =>$request->request->get('start_date'),
  6251. //            'title' => $request->request->get('title'),
  6252. //        ];
  6253. //
  6254. //        $HolidayCalender->setData(json_encode($arr));
  6255.                 $em->persist($HolidayCalender);
  6256.                 $em->flush();
  6257.                 $indHolidays = [];
  6258.                 if ($request->request->has('start_date'))
  6259.                     $indHolidays $request->request->get('start_date');
  6260.                 foreach ($indHolidays as $ind => $dateRangeStr) {
  6261.                     $currRow $request->request->get('row')[$ind];//string
  6262.                     $holidayTitle $request->request->get('title')[$ind];//string
  6263.                     $currStartDate $request->request->get('start_date')[$ind];//string
  6264.                     $currEndDate $request->request->get('end_date')[$ind];//string
  6265.                     $HolidayDate = new HolidayCalendarDates();
  6266.                     $HolidayDate->setHolidayCalendarId($HolidayCalender->getHolidayCalendarId());
  6267.                     $HolidayDate->setDateRange($currStartDate '-' $currEndDate);//string
  6268.                     $HolidayDate->setStartDate(new \DateTime($currStartDate));//date
  6269.                     $HolidayDate->setEndDate(new \DateTime($currEndDate ' 23:59:59'));//date
  6270.                     $HolidayDate->setHolidayTitle($holidayTitle);
  6271. //          $HolidayDate->setIsVariableEachYearFlag($request->request->get('is_variable_each_year',null));
  6272.                     $HolidayDate->setIsVariableEachYearFlag($request->request->get('is_variable_each_year_' $currRownull));
  6273.                     $HolidayDate->setAllDayFlag($request->request->get('all_day_flag_' $currRow1));
  6274.                     $em->persist($HolidayDate);
  6275.                     $em->flush();
  6276.                 }
  6277.                 $options = [];
  6278.                 $entity array_flip(GeneralConstant::$Entity_list)['HolidayCalendar'];
  6279.                 $loginId $request->getSession()->get(UserConstants::USER_LOGIN_ID);
  6280.                 $approveRole $request->request->get('approvalRole');
  6281.                 System::setApprovalInfo(
  6282.                     $em,
  6283.                     $options,
  6284.                     $entity,
  6285.                     $HolidayCalender->getHolidayCalendarId(),
  6286.                     $request->getSession()->get(UserConstants::USER_LOGIN_ID)
  6287.                 );
  6288.                 System::createEditSignatureHash(
  6289.                     $em,
  6290.                     $entity,
  6291.                     $HolidayCalender->getHolidayCalendarId(),
  6292.                     $loginId,
  6293.                     $approveRole,
  6294.                     $request->request->get('approvalHash')
  6295.                 );
  6296.                 $url $this->generateUrl(
  6297.                     'view_holiday_calendar'
  6298.                 );
  6299.                 return $this->redirect($url "/" $HolidayCalender->getHolidayCalendarId());
  6300.             }
  6301.         }
  6302.         $em $this->getDoctrine()->getManager();
  6303.         $branches $em->getRepository(Branch::class)->findAll();
  6304.         $employee $em->getRepository(Employee::class)->findAll();
  6305.         $departments $em->getRepository(SysDepartment::class)->findAll();
  6306.         $departmentPositions $em->getRepository(SysDepartmentPosition::class)->findAll();
  6307.         $EmploymentStatus HumanResourceConstant::$employeeType;
  6308.         $em $this->getDoctrine()->getManager();
  6309.         $extDocData = [];
  6310.         if ($id != 0)
  6311.             $extDocData $em->getRepository(HolidayCalendar::class)->find($id);
  6312.         return $this->render(
  6313.             'ApplicationBundle:pages/human_resource/input_forms:create_holiday.html.twig',
  6314.             [
  6315.                 'page_title' => 'Create Holiday',
  6316.                 'branches' => $branches,
  6317.                 'id' => $id,
  6318.                 'extDocData' => $extDocData,
  6319.                 'departments' => $departments,
  6320.                 'departmentPositions' => $departmentPositions,
  6321.                 'employeeStatus' => $EmploymentStatus,
  6322.                 'employeeIds' => $employee,
  6323.                 'holidayCalendarList' => $em->getRepository('ApplicationBundle:HolidayCalendar')
  6324.                     ->findBy(array())
  6325.             ]
  6326.         );
  6327.     }
  6328.     public function HolidayViewAction(Request $request$id)
  6329.     {
  6330.         $em $this->getDoctrine()->getManager();
  6331.         $HolidaysCalendar $em->getRepository(HolidayCalendar::class)->find($id);
  6332.         $holidayCalendarDetails $em->getRepository('ApplicationBundle:HolidayCalendarDates')
  6333.             ->findBy(array(
  6334.                 'holidayCalendarId' => $id
  6335.             ));
  6336.         $Approval_data System::checkIfApprovalExists(
  6337.             $em,
  6338.             array_flip(GeneralConstant::$Entity_list)['HolidayCalendar'],
  6339.             $id,
  6340.             $request->getSession()->get(UserConstants::USER_LOGIN_ID)
  6341.         );
  6342.         return $this->render('ApplicationBundle:pages/human_resource/views:holidays_view.html.twig', array(
  6343.             'page_title' => 'View Holiday',
  6344.             'holidays' => $HolidaysCalendar,
  6345.             'holidayCalendarDetails' => $holidayCalendarDetails,
  6346.             'approval_status' => $HolidaysCalendar->getApproved(),
  6347.             'approval_data' => $Approval_data,
  6348.             'auto_created' => $HolidaysCalendar->getAutocreated(),
  6349.             'document_log' => $HolidaysCalendar->getAutocreated() == System::getDocumentLog(
  6350.                 $this->getDoctrine()->getManager(),
  6351.                 array_flip(GeneralConstant::$Entity_list)['HolidayCalendar'],
  6352.                 $id,
  6353.                 $HolidaysCalendar->getCreatedLoginId(),
  6354.                 $HolidaysCalendar->getEditedLoginId()
  6355.             ) : []
  6356.         ));
  6357.     }
  6358.     public function GetHolidayDetailsAction(Request $request$id)
  6359.     {
  6360.         $em $this->getDoctrine()->getManager();
  6361.         $holidayCalendar $em->getRepository('ApplicationBundle:HolidayCalendar')
  6362.             ->findOneBy(array(
  6363.                 'holidayCalendarId' => $id
  6364.             ));
  6365.         $holidayCalendarDetails $em->getRepository('ApplicationBundle:HolidayCalendarDates')
  6366.             ->findBy(array(
  6367.                 'holidayCalendarId' => $id
  6368.             ));
  6369.         $holidayList = [];
  6370.         foreach ($holidayCalendarDetails as $det) {
  6371.             $dateDet = array(
  6372.                 'title' => $det->getHolidayTitle(),
  6373.                 'startDate' => $det->getStartDate()->format('Y-m-d'),
  6374.                 'endDate' => $det->getEndDate()->format('Y-m-d'),
  6375.             );
  6376.             $holidayList[] = $dateDet;
  6377.         }
  6378.         return new JsonResponse(
  6379.             array(
  6380.                 'success' => true,
  6381.                 'holidayList' => $holidayList
  6382.             )
  6383.         );
  6384.     }
  6385.     public function GetHolidayListByEmployeeIdAction(Request $request$id)
  6386.     {
  6387.         $em $this->getDoctrine()->getManager();
  6388.         $options = [];
  6389.         $options['employeeId'] = $id;
  6390.         HumanResource::getFilteredHolidaysSingle($em$options);
  6391.         $holidayCalendar $em->getRepository('ApplicationBundle:HolidayCalendar')
  6392.             ->findOneBy(array(
  6393.                 'holidayCalendarId' => $id
  6394.             ));
  6395.         $holidayCalendarDetails $em->getRepository('ApplicationBundle:HolidayCalendarDates')
  6396.             ->findBy(array(
  6397.                 'holidayCalendarId' => $id
  6398.             ));
  6399.         $holidayList = [];
  6400.         foreach ($holidayCalendarDetails as $det) {
  6401.             $dateDet = array(
  6402.                 'title' => $det->getHolidayTitle(),
  6403.                 'startDate' => $det->getStartDate()->format('Y-m-d'),
  6404.                 'endDate' => $det->getEndDate()->format('Y-m-d'),
  6405.             );
  6406.             $holidayList[] = $dateDet;
  6407.         }
  6408.         return new JsonResponse(
  6409.             array(
  6410.                 'success' => true,
  6411.                 'holidayList' => $holidayList
  6412.             )
  6413.         );
  6414.     }
  6415.     public function createQuestionAction(Request $request)
  6416.     {
  6417.         $em $this->getDoctrine()->getManager();
  6418.         $em_goc $this->getDoctrine()->getManager('company_group');
  6419.         $companyId $this->getLoggedUserCompanyId($request);
  6420.         if ($request->isMethod('POST')) {
  6421.             $loginId $request->getSession()->get(UserConstants::USER_LOGIN_ID);
  6422.             $question = new Questionnaire();
  6423.             $question->setQuestionTitle($request->request->get('questionTitle'''));
  6424.             $question->setQuestionText($request->request->get('questionText'''));
  6425.             $question->setIsForPlanningItem($request->request->has('forPlanningItem') ? 0);
  6426.             $question->setIsForInterview($request->request->has('forInterview') ? 0);
  6427.             $question->setIsForMock($request->request->has('forMock') ? 0);
  6428.             $question->setIsForTraining($request->request->has('forTraining') ? 0);
  6429.             $question->setTaggedSkillHashes($request->request->get('skillHash'));
  6430.             $question->setCorrectAnswers(json_encode($request->request->get('correctAns')));
  6431.             $question->setCompanyId($companyId);
  6432.             $optionData = [];
  6433.             foreach ($request->request->get('optionText') as $key => $val) {
  6434.                 $option = array(
  6435.                     'index' => $request->request->get('optionIndex')[$key],
  6436.                     'text' => $val,
  6437.                 );
  6438.                 $optionData[] = $option;
  6439.             }
  6440.             $question->setOptions(json_encode($optionData));
  6441.             $question->setQuestionValueWeight(1);
  6442.             $question->setQuestionText($request->request->get('questionText'));
  6443.             $question->setUniqueHash('_NONE_');
  6444.             $question->setType($request->request->get('type'0));
  6445.             //$skill->setEditFlag(1); //editable usually
  6446.             $question->setCreatedLoginId($request->getSession()->get(UserConstants::USER_LOGIN_ID));
  6447.             //$skill->setApproved(GeneralConstant::APPROVAL_STATUS_PENDING);
  6448.             //$skill->setAutocreated(0);
  6449.             $em->persist($question);
  6450.             $em->flush();
  6451.             $questionId $question->getQuestionId();
  6452.             $file_path_list = [];
  6453.             if ($questionId != 0)
  6454.                 if (!empty($request->files)) {
  6455.                     MiscActions::RemoveFilesForEntityDoc($em_goc'Question'$questionId);
  6456.                     $storePath 'uploads/Questionnaire/';
  6457.                     $path "";
  6458.                     $file_path "";
  6459.                     $session $request->getSession();
  6460. //                    MiscActions::RemoveExpiredFiles($em_goc);
  6461.                     foreach ($request->files as $uploadedFileGG) {
  6462.                         //            if($uploadedFile->getImage())
  6463.                         //                var_dump($uploadedFile->getFile());
  6464.                         //                var_dump($uploadedFile);
  6465.                         $tempD $uploadedFileGG;
  6466.                         if (!is_array($uploadedFileGG)) {
  6467.                             $uploadedFileGG = array();
  6468.                             $uploadedFileGG[] = $tempD;
  6469.                         }
  6470.                         foreach ($uploadedFileGG as $uploadedFile) {
  6471.                             if ($uploadedFile != null) {
  6472.                                 $extension $uploadedFile->guessExtension();
  6473.                                 $size $uploadedFile->getSize();
  6474.                                 $fileName 'QUES_' $questionId '_' . (md5(uniqid())) . '.' $uploadedFile->guessExtension();
  6475.                                 $path $fileName;
  6476.                                 $upl_dir $this->container->getParameter('kernel.root_dir') . '/../web/' $storePath;
  6477.                                 if (!file_exists($upl_dir)) {
  6478.                                     mkdir($upl_dir0777true);
  6479.                                 }
  6480.                                 if (file_exists($upl_dir '' $path)) {
  6481.                                     chmod($upl_dir '' $path0755);
  6482.                                     unlink($upl_dir '' $path);
  6483.                                 }
  6484.                                 $file $uploadedFile->move($upl_dir$path);
  6485.                                 $expireNever 1;
  6486.                                 $expireTs 0;
  6487.                                 $EntityFile = new EntityFile();
  6488.                                 $EntityFile->setPath($this->container->getParameter('kernel.root_dir') . '/../web/' $storePath $path);
  6489.                                 $EntityFile->setMarker('_GEN_');
  6490.                                 $EntityFile->setExtension($extension);
  6491.                                 $EntityFile->setExpireTs($expireTs);
  6492.                                 $EntityFile->setSize($size);
  6493.                                 $EntityFile->setRelativePath($storePath $path);
  6494.                                 $EntityFile->setEntityName('Questionnaire');
  6495.                                 $EntityFile->setEntityBundle('ApplicationBundle');
  6496.                                 $EntityFile->setEntityId($questionId);
  6497.                                 $EntityFile->setEntityIdField('questionId');
  6498.                                 $EntityFile->setModifyFieldSetter('setFiles');
  6499.                                 $EntityFile->setDocIdForApplicant(0);
  6500.                                 $EntityFile->setUserId($session->get(UserConstants::USER_ID0));
  6501.                                 $EntityFile->setAppId($session->get(UserConstants::USER_APP_ID0));
  6502.                                 $EntityFile->setEmployeeId($session->get(UserConstants::USER_EMPLOYEE_ID0));
  6503.                                 $EntityFile->setUserType($session->get(UserConstants::USER_TYPE0));
  6504.                                 $em_goc->persist($EntityFile);
  6505.                                 $em_goc->flush();
  6506.                                 $EntityFileId $EntityFile->getId();
  6507.                             }
  6508.                             if ($path != "")
  6509.                                 $file_path_list[] = ($storePath $path);
  6510.                         }
  6511.                     }
  6512.                     $g_path $this->container->getParameter('kernel.root_dir') . '/../web/' $storePath $path;
  6513.                     $question->setFiles(implode(','$file_path_list));
  6514.                     $em->flush();
  6515.                 }
  6516.             if ($request->request->has('returnJson') || $request->query->has('returnJson')) {
  6517.                 if ($question)
  6518.                     return new JsonResponse(
  6519.                         array(
  6520.                             'id' => $questionId,
  6521.                             'value' => $questionId,
  6522.                             'question_id' => $questionId,
  6523.                             'text' => $question->getQuestionText(),
  6524.                             'question_text' => $question->getQuestionText(),
  6525.                             'question_title' => $question->getQuestionTitle(),
  6526.                             'files' => explode(','$question->getFiles()),
  6527.                             'options' => json_decode($question->getFiles(), true),
  6528.                             'answer_text' => '',
  6529.                             'success' => true
  6530.                         )
  6531.                     );
  6532.                 else
  6533.                     return new JsonResponse(
  6534.                         array(
  6535.                             'success' => false
  6536.                         )
  6537.                     );
  6538.             }
  6539.         }
  6540.         $skillDetails $em->getRepository(Skill::class)->findAll();
  6541.         $skillListObj = [];
  6542.         $skillListArray = [];
  6543.         foreach ($skillDetails as $skillDetail) {
  6544.             $dt = array(
  6545.                 'id' => $skillDetail->getSkillId(),
  6546.                 'name' => $skillDetail->getName(),
  6547.                 'hash' => $skillDetail->getUniqueHash(),
  6548.             );
  6549.             $skillListArray[] = $dt;
  6550.         }
  6551.         return $this->render('ApplicationBundle:pages/human_resource/input_forms:createQuestion.html.twig', array(
  6552.             'page_title' => 'Create Question',
  6553.             'skiillDetails' => $skillDetails,
  6554.             'skillListArray' => $skillListArray,
  6555.         ));
  6556.     }
  6557.     public function createSkillAction(Request $request)
  6558.     {
  6559.         $em $this->getDoctrine()->getManager();
  6560.         $companyId $this->getLoggedUserCompanyId($request);
  6561.         if ($request->isMethod('POST')) {
  6562.             $loginId $request->getSession()->get(UserConstants::USER_LOGIN_ID);
  6563.             $skill = new Skill;
  6564.             $skill->setName($request->request->get('skillName'));
  6565.             $skill->setParentId($request->request->get('parentName'));
  6566.             $skill->setUniqueHash($request->request->get('uniqueHash'));
  6567.             $skill->setCompanyId($companyId);
  6568.             //$skill->setEditFlag(1); //editable usually
  6569.             $skill->setCreatedLoginId($request->getSession()->get(UserConstants::USER_LOGIN_ID));
  6570.             //$skill->setApproved(GeneralConstant::APPROVAL_STATUS_PENDING);
  6571.             //$skill->setAutocreated(0);
  6572.             $em->persist($skill);
  6573.             $em->flush();
  6574.         }
  6575.         $skillDetails $em->getRepository(Skill::class)->findAll();
  6576.         return $this->render('ApplicationBundle:pages/human_resource/input_forms:createSkill.html.twig', array(
  6577.             'page_title' => 'Create Skill',
  6578.             'skiillDetails' => $skillDetails,
  6579.         ));
  6580.     }
  6581.     public function createEducationQualificationAction(Request $request)
  6582.     {
  6583.         $em $this->getDoctrine()->getManager();
  6584.         $companyId $this->getLoggedUserCompanyId($request);
  6585.         if ($request->isMethod('POST')) {
  6586.             $loginId $request->getSession()->get(UserConstants::USER_LOGIN_ID);
  6587.             $new = new EducationQualification;
  6588.             $new->setName($request->request->get('educationName'));
  6589.             $new->setParentId($request->request->get('parentName'));
  6590.             $new->setUniqueHash($request->request->get('uniqueHash'));
  6591.             $new->setCompanyId($companyId);
  6592.             //$skill->setEditFlag(1); //editable usually
  6593.             $new->setCreatedLoginId($request->getSession()->get(UserConstants::USER_LOGIN_ID));
  6594.             //$skill->setApproved(GeneralConstant::APPROVAL_STATUS_PENDING);
  6595.             //$skill->setAutocreated(0);
  6596.             $em->persist($new);
  6597.             $em->flush();
  6598.         }
  6599.         $educationDetails $em->getRepository(EducationQualification::class)->findAll();
  6600.         return $this->render('ApplicationBundle:pages/human_resource/input_forms:create_education.html.twig', array(
  6601.             'page_title' => 'Create Education',
  6602.             'educationDetails' => $educationDetails,
  6603.         ));
  6604.     }
  6605.     public function createEvaluationCategoryAction(Request $request$id 0)
  6606.     {
  6607.         $em $this->getDoctrine()->getManager();
  6608.         $companyId $this->getLoggedUserCompanyId($request);
  6609.         if ($request->isMethod('POST')) {
  6610.             $loginId $request->getSession()->get(UserConstants::USER_LOGIN_ID);
  6611.             $new = new EvaluationCategory;
  6612.             $new->setName($request->request->get('name'));
  6613.             $new->setBranch($request->request->get('branch'));
  6614.             $new->setSelectionType($request->request->get('selection_type'));
  6615.             $new->setEmployeeIds($request->request->get('selected_employeeIds'));
  6616.             $new->setEmployeeTypeIds($request->request->get('employee_types'));
  6617.             $new->setDesignationIds($request->request->get('designation'));
  6618.             $new->setDesignationIds($request->request->get('designation'));
  6619.             $new->setmark($request->request->get('mark'));
  6620.             $new->setSkills(json_encode($request->request->get('skill')));
  6621.             $new->setLevelSelectionStr($request->request->get('levelSelectionStr'));
  6622.             $new->setCompanyId($companyId);
  6623.             $new->setCreatedLoginId($request->getSession()->get(UserConstants::USER_LOGIN_ID));
  6624.             $em->persist($new);
  6625.             $em->flush();
  6626.         }
  6627.         $skill $em->getRepository(Skill::class)->findAll();
  6628.         $employeeIds $em->getRepository(EmployeeDetails::class)->findAll();
  6629.         $employeeType HumanResourceConstant::$employeeType;
  6630.         $Designation $em->getRepository(SysDepartmentPosition::class)->findAll();
  6631.         $branch $em->getRepository(Branch::class)->findAll();
  6632.         $departments $em->getRepository(SysDepartment::class)->findAll();
  6633.         $department = [];
  6634.         foreach ($departments as $entry) {
  6635.             $department[$entry->getDepartmentId()] = array(
  6636.                 'id' => $entry->getDepartmentId(),
  6637.                 'name' => $entry->getDepartmentName(),
  6638.             );
  6639.             return $this->render('ApplicationBundle:pages/human_resource/input_forms:create_evaluation_category.html.twig', array(
  6640.                 'page_title' => 'Create Evaluation Category',
  6641.                 'employeeIds' => $employeeIds,
  6642.                 'employeeType' => $employeeType,
  6643.                 'Designation' => $Designation,
  6644.                 'branch' => $branch,
  6645.                 'department' => $department,
  6646.                 'skill' => $skill,
  6647.             ));
  6648.         }
  6649.     }
  6650.     public function createWorkplaceHarassmentAction(Request $request$id 0)
  6651.     {
  6652.         $em $this->getDoctrine()->getManager();
  6653.         $employeeIds $em->getRepository(EmployeeDetails::class)->findAll();
  6654.         //$employeeType = HumanResourceConstant::$employeeType;
  6655.         $Designation $em->getRepository(SysDepartmentPosition::class)->findAll();
  6656.         $branches $em->getRepository(Branch::class)->findAll();
  6657.         $departments $em->getRepository(SysDepartment::class)->findAll();
  6658.         $harassmentType HumanResourceConstant::$harrasmentType;
  6659.         $department = [];
  6660.         foreach ($departments as $entry) {
  6661.             $department[$entry->getDepartmentId()] = array(
  6662.                 'id' => $entry->getDepartmentId(),
  6663.                 'name' => $entry->getDepartmentName(),
  6664.             );
  6665.         }
  6666.         return $this->render('ApplicationBundle:pages/human_resource/input_forms:create_workplace_harrasment.html.twig', array(
  6667.             'page_title' => 'Create Workplace Harrasment',
  6668.             'employeeIds' => $employeeIds,
  6669.             'branches' => $branches,
  6670.             'harassmentType' => $harassmentType,
  6671.             'departments' => $department,
  6672.             'designationIds' => $Designation
  6673.         ));
  6674.     }
  6675.     public function ViewHarasssmentComplainAction()
  6676.     {
  6677.         return $this->render('ApplicationBundle:pages/human_resource/views:view_harassment_compalin.html.twig', array(
  6678.             'page_title' => 'View Harassment Complain',
  6679.         ));
  6680.     }
  6681.     public function createWorkplaceViolenceAction(Request $request$id 0)
  6682.     {
  6683.         $em $this->getDoctrine()->getManager();
  6684.         $employeeIds $em->getRepository(EmployeeDetails::class)->findAll();
  6685.         //$employeeType = HumanResourceConstant::$employeeType;
  6686.         $Designation $em->getRepository(SysDepartmentPosition::class)->findAll();
  6687.         $branches $em->getRepository(Branch::class)->findAll();
  6688.         $departments $em->getRepository(SysDepartment::class)->findAll();
  6689.         $harassmentType HumanResourceConstant::$harrasmentType;
  6690.         $department = [];
  6691.         foreach ($departments as $entry) {
  6692.             $department[$entry->getDepartmentId()] = array(
  6693.                 'id' => $entry->getDepartmentId(),
  6694.                 'name' => $entry->getDepartmentName(),
  6695.             );
  6696.         }
  6697.         return $this->render('ApplicationBundle:pages/human_resource/input_forms:register_workplace_complaint.html.twig', array(
  6698.             'page_title' => 'Register Complaint',
  6699.             'employeeIds' => $employeeIds,
  6700.             'branches' => $branches,
  6701.             'harassmentType' => $harassmentType,
  6702.             'departments' => $department,
  6703.             'designationIds' => $Designation
  6704.         ));
  6705.     }
  6706.     public function createBonusPolicyAction(Request $request$id 0)
  6707.     {
  6708.         $em $this->getDoctrine()->getManager();
  6709.         $companyId $this->getLoggedUserCompanyId($request);
  6710.         $extDocData = [];
  6711.         $extDetailsData = [];
  6712.         if ($request->isMethod('POST')) {
  6713.             //            Generic::debugMessage($_POST);
  6714.             $em $this->getDoctrine()->getManager();
  6715.             $entity_id array_flip(GeneralConstant::$Entity_list)['BonusPolicy']; //change
  6716.             $dochash $request->request->get('docHash'); //change
  6717.             $loginId $request->getSession()->get(UserConstants::USER_LOGIN_ID);
  6718.             $approveRole $request->request->get('approvalRole');
  6719.             $approveHash $request->request->get('approvalHash');
  6720.             if (!DocValidation::isInsertable(
  6721.                 $em,
  6722.                 $entity_id,
  6723.                 $dochash,
  6724.                 $loginId,
  6725.                 $approveRole,
  6726.                 $approveHash,
  6727.                 $id
  6728.             )
  6729.             ) {
  6730.                 $this->addFlash(
  6731.                     'error',
  6732.                     'Sorry Couldnot insert Data.'
  6733.                 );
  6734.             } else {
  6735.                 $funcname 'BonusPolicy';
  6736.                 DeleteDocument::$funcname($em$id0);
  6737.                 $loginId $request->getSession()->get(UserConstants::USER_LOGIN_ID);
  6738.                 $docId HumanResource::createBonusPolicy($em$request$companyId$loginId0);
  6739.                 //now add Approval info
  6740.                 $approveRole $request->request->get('approvalRole');
  6741.                 $options = array(
  6742.                     'notification_enabled' => $this->container->getParameter('notification_enabled'),
  6743.                     'notification_server' => $this->container->getParameter('notification_server'),
  6744.                     'appId' => $request->getSession()->get(UserConstants::USER_APP_ID),
  6745.                     'url' => $this->generateUrl(
  6746.                         GeneralConstant::$Entity_list_details[array_flip(GeneralConstant::$Entity_list)['BonusPolicy']]['entity_view_route_path_name']
  6747.                     )
  6748.                 );
  6749.                 System::setApprovalInfo(
  6750.                     $this->getDoctrine()->getManager(),
  6751.                     $options,
  6752.                     array_flip(GeneralConstant::$Entity_list)['BonusPolicy'],
  6753.                     $docId,
  6754.                     $request->getSession()->get(UserConstants::USER_LOGIN_ID)
  6755.                 );
  6756.                 System::createEditSignatureHash(
  6757.                     $this->getDoctrine()->getManager(),
  6758.                     array_flip(GeneralConstant::$Entity_list)['BonusPolicy'],
  6759.                     $docId,
  6760.                     $loginId,
  6761.                     $approveRole,
  6762.                     $request->request->get('approvalHash')
  6763.                 );
  6764.                 $doc_here $this->getDoctrine()
  6765.                     ->getRepository('ApplicationBundle:BonusPolicy')
  6766.                     ->findOneBy(
  6767.                         array(
  6768.                             'id' => $docId
  6769.                         )
  6770.                     );
  6771.                 //notify
  6772.                 $this->addFlash(
  6773.                     'success',
  6774.                     'Policy Successfully Updated.'
  6775.                 );
  6776.                 $url $this->generateUrl(
  6777.                     'view_bonus_policy'
  6778.                 );
  6779. //                System::AddNewNotification(
  6780. //                    $this->container->getParameter('notification_enabled'),
  6781. //                    $this->container->getParameter('notification_server'),
  6782. //                    $request->getSession()->get(UserConstants::USER_APP_ID),
  6783. //                    $request->getSession()->get(UserConstants::USER_COMPANY_ID),
  6784. //                    "Salary Segregation Policy : " . $doc_here->getDocumentHash() . " Has Been Created And is Under Processing",
  6785. //                    'pos',
  6786. //                    System::getPositionIdsByDepartment($em, GeneralConstant::HRM_DEPARTMENT),
  6787. //                    'success',
  6788. //                    //                    $url . "/" . $TransID,
  6789. //                    $url . "/" . $docId,
  6790. //                    "Journal"
  6791. //
  6792. //                );
  6793.                 return $this->redirect($url "/" $docId);
  6794.             }
  6795.         }
  6796.         //for edits
  6797.         if ($id == 0) {
  6798.         } else {
  6799.             $extDocData $em->getRepository('ApplicationBundle:BonusPolicy')->findOneBy(
  6800.                 array(
  6801.                     'id' => $id///material
  6802.                 )
  6803.             );
  6804.             //now if its not editable, redirect to view
  6805.             if ($extDocData) {
  6806.                 if ($extDocData->getEditFlag() != 1) {
  6807. //          $url = $this->generateUrl(
  6808. ////              'view_salary_segregation_policy'
  6809. //              'salary_segregation_policy'
  6810. //          );
  6811. //          return $this->redirect($url . "/" . $id);
  6812.                 } else {
  6813. //          $extVoucherDetailsData = Accounts::GetVoucherDataForEdit($em, $voucherId);
  6814. //          $extDetailsData = $em->getRepository('ApplicationBundle:SalarySegregationPolicy')->findOneBy(
  6815. //              array(
  6816. //                  'transactionId' => $id, ///material
  6817. //
  6818. //              )
  6819. //          );
  6820.                 }
  6821.             } else {
  6822.             }
  6823.         }
  6824.         $employeeIds $em->getRepository(EmployeeDetails::class)->findAll();
  6825.         $employeeType HumanResourceConstant::$employeeType;
  6826.         $Designation $em->getRepository(SysDepartmentPosition::class)->findAll();
  6827.         $branch $em->getRepository(Branch::class)->findAll();
  6828.         $departments $em->getRepository(SysDepartment::class)->findAll();
  6829.         $department = [];
  6830.         foreach ($departments as $entry) {
  6831.             $department[$entry->getDepartmentId()] = array(
  6832.                 'id' => $entry->getDepartmentId(),
  6833.                 'name' => $entry->getDepartmentName(),
  6834.             );
  6835.         }
  6836.         return $this->render('ApplicationBundle:pages/human_resource/input_forms:create_bonus_policy.html.twig', array(
  6837.             'page_title' => 'Create Bonus Policy',
  6838.             'employeeIds' => $employeeIds,
  6839.             'employeeType' => $employeeType,
  6840.             'Designation' => $Designation,
  6841.             'branch' => $branch,
  6842.             'department' => $department,
  6843.         ));
  6844.     }
  6845.     public function BonusPolicyListAction()
  6846.     {
  6847.         $em $this->getDoctrine()->getManager();
  6848.         $bonusPolicy $em->getRepository(BonusPolicy::class)->findAll();
  6849.         return $this->render('ApplicationBundle:pages/human_resource/list:bonus_policy_list.html.twig', array(
  6850.             'page_title' => 'Increment Policy List',
  6851.             'bonusPolicy' => $bonusPolicy
  6852.         ));
  6853.     }
  6854.     public function createIncrementPolicyAction(Request $request$id 0)
  6855.     {
  6856.         $em $this->getDoctrine()->getManager();
  6857.         $companyId $this->getLoggedUserCompanyId($request);
  6858.         $extDocData = [];
  6859.         $extDetailsData = [];
  6860.         if ($request->isMethod('POST')) {
  6861.             //            Generic::debugMessage($_POST);
  6862.             $em $this->getDoctrine()->getManager();
  6863.             $entity_id array_flip(GeneralConstant::$Entity_list)['IncrementPolicy']; //change
  6864.             $dochash $request->request->get('docHash'); //change
  6865.             $loginId $request->getSession()->get(UserConstants::USER_LOGIN_ID);
  6866.             $approveRole $request->request->get('approvalRole');
  6867.             $approveHash $request->request->get('approvalHash');
  6868.             if (!DocValidation::isInsertable(
  6869.                 $em,
  6870.                 $entity_id,
  6871.                 $dochash,
  6872.                 $loginId,
  6873.                 $approveRole,
  6874.                 $approveHash,
  6875.                 $id
  6876.             )
  6877.             ) {
  6878.                 $this->addFlash(
  6879.                     'error',
  6880.                     'Sorry Couldnot insert Data.'
  6881.                 );
  6882.             } else {
  6883.                 $funcname 'IncrementPolicy';
  6884.                 DeleteDocument::$funcname($em$id0);
  6885.                 $docId HumanResource::createIncrementPolicy($em$request$companyId0);
  6886.                 //now add Approval info
  6887.                 $loginId $request->getSession()->get(UserConstants::USER_LOGIN_ID);
  6888.                 $approveRole $request->request->get('approvalRole');
  6889.                 $options = array(
  6890.                     'notification_enabled' => $this->container->getParameter('notification_enabled'),
  6891.                     'notification_server' => $this->container->getParameter('notification_server'),
  6892.                     'appId' => $request->getSession()->get(UserConstants::USER_APP_ID),
  6893.                     'url' => $this->generateUrl(
  6894.                         GeneralConstant::$Entity_list_details[array_flip(GeneralConstant::$Entity_list)['IncrementPolicy']]
  6895.                         ['entity_view_route_path_name']
  6896.                     )
  6897.                 );
  6898.                 System::setApprovalInfo(
  6899.                     $this->getDoctrine()->getManager(),
  6900.                     $options,
  6901.                     array_flip(GeneralConstant::$Entity_list)['IncrementPolicy'],
  6902.                     $docId,
  6903.                     $request->getSession()->get(UserConstants::USER_LOGIN_ID),
  6904.                     3    //journal voucher
  6905.                 );
  6906.                 System::createEditSignatureHash(
  6907.                     $this->getDoctrine()->getManager(),
  6908.                     array_flip(GeneralConstant::$Entity_list)['IncrementPolicy'],
  6909.                     $docId,
  6910.                     $loginId,
  6911.                     $approveRole,
  6912.                     $request->request->get('approvalHash')
  6913.                 );
  6914.                 $doc_here $this->getDoctrine()
  6915.                     ->getRepository('ApplicationBundle:IncrementPolicy')
  6916.                     ->findOneBy(
  6917.                         array(
  6918.                             'id' => $docId
  6919.                         )
  6920.                     );
  6921.                 //notify
  6922.                 $this->addFlash(
  6923.                     'success',
  6924.                     'Policy Successfully Updated.'
  6925.                 );
  6926.                 $url $this->generateUrl(
  6927.                     'view_increment_policy'
  6928.                 );
  6929.                 return $this->redirect($url "/" $docId);
  6930.             }
  6931.         }
  6932.         //for edits
  6933.         if ($id == 0) {
  6934.         } else {
  6935.             $extDocData $em->getRepository('ApplicationBundle:IncrementPolicy')->findOneBy(
  6936.                 array(
  6937.                     'id' => $id///material
  6938.                 )
  6939.             );
  6940.             //now if its not editable, redirect to view
  6941.             if ($extDocData) {
  6942.                 if ($extDocData->getEditFlag() != 1) {
  6943. //          $url = $this->generateUrl(
  6944. ////              'view_salary_segregation_policy'
  6945. //              'salary_segregation_policy'
  6946. //          );
  6947. //          return $this->redirect($url . "/" . $id);
  6948.                 } else {
  6949. //          $extVoucherDetailsData = Accounts::GetVoucherDataForEdit($em, $voucherId);
  6950. //          $extDetailsData = $em->getRepository('ApplicationBundle:SalarySegregationPolicy')->findOneBy(
  6951. //              array(
  6952. //                  'transactionId' => $id, ///material
  6953. //
  6954. //              )
  6955. //          );
  6956.                 }
  6957.             } else {
  6958.             }
  6959.         }
  6960.         //$em = $this->getDoctrine()->getManager();
  6961.         $employeeIds $em->getRepository(EmployeeDetails::class)->findAll();
  6962.         $employeeType HumanResourceConstant::$employeeType;
  6963.         $Designation $em->getRepository(SysDepartmentPosition::class)->findAll();
  6964.         $branch $em->getRepository(Branch::class)->findAll();
  6965.         $departments $em->getRepository(SysDepartment::class)->findAll();
  6966.         $department = [];
  6967.         foreach ($departments as $entry) {
  6968.             $department[$entry->getDepartmentId()] = array(
  6969.                 'id' => $entry->getDepartmentId(),
  6970.                 'name' => $entry->getDepartmentName(),
  6971.             );
  6972.         }
  6973.         return $this->render('ApplicationBundle:pages/human_resource/input_forms:create_increment_policy.html.twig', array(
  6974.             'page_title' => 'Create Increment Policy',
  6975.             'employeeIds' => $employeeIds,
  6976.             'employeeType' => $employeeType,
  6977.             'Designation' => $Designation,
  6978.             'branch' => $branch,
  6979.             'department' => $department,
  6980.         ));
  6981.     }
  6982.     public function IncrementPolicyListAction()
  6983.     {
  6984.         $em $this->getDoctrine()->getManager();
  6985.         $incrementPolicy $em->getRepository(IncrementPolicy::class)->findAll();
  6986.         return $this->render('ApplicationBundle:pages/human_resource/list:increment_policy_list.html.twig', array(
  6987.             'page_title' => 'Increment Policy List',
  6988.             'incrementPolicy' => $incrementPolicy
  6989.         ));
  6990.     }
  6991.     public function ViewIncrementPolicyAction(Request $request$id)
  6992.     {
  6993.         $em $this->getDoctrine()->getManager();
  6994.         $incrementPolicy $em->getRepository(IncrementPolicy::class)->find($id);
  6995.         $Approval_data System::checkIfApprovalExists(
  6996.             $em,
  6997.             array_flip(GeneralConstant::$Entity_list)['IncrementPolicy'],
  6998.             $id,
  6999.             $request->getSession()->get(UserConstants::USER_LOGIN_ID)
  7000.         );
  7001.         return $this->render('ApplicationBundle:pages/human_resource/views:view_increment_policy.html.twig', array(
  7002.             'page_title' => 'Increment Policy List',
  7003.             'incrementPolicy' => $incrementPolicy,
  7004.             'approval_status' => $incrementPolicy->getApproved(),
  7005.             'approval_data' => $Approval_data,
  7006.             'auto_created' => $incrementPolicy->getAutocreated(),
  7007.             'id' => $id,
  7008.             'document_log' => $incrementPolicy->getAutocreated() == System::getDocumentLog(
  7009.                 $this->getDoctrine()->getManager(),
  7010.                 array_flip(GeneralConstant::$Entity_list)['FundRequisition'],
  7011.                 $id,
  7012.                 $incrementPolicy->getCreatedLoginId(),
  7013.                 $incrementPolicy->getEditedLoginId()
  7014.             ) : []
  7015.         ));
  7016.     }
  7017.     public function createConsultancyTopicAction(Request $request$id 0)
  7018.     {
  7019.         $em $this->getDoctrine()->getManager();
  7020.         $companyId $this->getLoggedUserCompanyId($request);
  7021.         if ($request->isMethod('POST')) {
  7022.             $loginId $request->getSession()->get(UserConstants::USER_LOGIN_ID);
  7023.             $new = new ConsultancyTopic();
  7024.             $new->setTopicName($request->request->get('topicName'));
  7025.             $new->setParentTopicName($request->request->get('parentTopicName'));
  7026.             $new->setUniqueHash($request->request->get('uniqueHash'));
  7027.             $new->setCompanyId($companyId);
  7028.             $new->setTopicSlug($request->request->get('topicSlug'));
  7029.             $new->setTitle($request->request->get('title'));
  7030.             $new->setSubTitle($request->request->get('subTitle'));
  7031.             $new->setSummary($request->request->get('content'));
  7032.             $new->setVideo($request->request->get('video'));
  7033.             $new->setAuthor($request->request->get('author'));
  7034.             $new->setAuthorSummary($request->request->get('authorSummary'));
  7035.             $new->setCreatedLoginId($request->getSession()->get(UserConstants::USER_LOGIN_ID));
  7036. //            $arr = [
  7037. //                'requirement' => $request->request->get('requirement'),
  7038. //
  7039. //            ];
  7040. //            $new->setRequirementData(json_encode($arr));
  7041.             $em->persist($new);
  7042.             $em->flush();
  7043.         }
  7044. //            $data = [];
  7045. //            $em = $this->getDoctrine()->getManager();
  7046. //            $companyId = $this->getLoggedUserCompanyId($request);
  7047. //            if ($request->isMethod('POST')) {
  7048. //                $em = $this->getDoctrine()->getManager();
  7049. //                $entity_id = array_flip(GeneralConstant::$Entity_list)['ConsultancyTopic'];
  7050. //                //$dochash = $request->request->get('docHash');//change
  7051. //                $approveRole = $request->request->get('approvalRole');
  7052. //                $approveHash = $request->request->get('approvalHash');
  7053. //                $loginId = $request->getSession()->get(UserConstants::USER_LOGIN_ID);
  7054. //                if (!DocValidation::isInsertable($em, $entity_id,
  7055. //                    $loginId, $approveRole, $approveHash, $id)
  7056. //                ) {
  7057. //                    $this->addFlash(
  7058. //                        'error',
  7059. //                        'Sorry Could not insert Data.'
  7060. //                    );
  7061. //                }  else {
  7062. //                    $data = $request->request;
  7063. //                    $docId = HumanResource::createConsultancyTopic($em, $loginId, $id, $data, $companyId);
  7064. ////                    now add Approval info
  7065. //
  7066. //                    $approveRole = $request->request->get('approvalRole');
  7067. //                    $options = array(
  7068. //                        'notification_enabled' => $this->container->getParameter('notification_enabled'),
  7069. //                        'notification_server' => $this->container->getParameter('notification_server'),
  7070. //                        'appId' => $request->getSession()->get(UserConstants::USER_APP_ID),
  7071. ////                        'url' => $this->generateUrl(
  7072. ////                            GeneralConstant::$Entity_list_details[array_flip(GeneralConstant::$Entity_list)['EmployeePerformanceEvolution']]
  7073. ////                            ['entity_view_route_path_name']
  7074. ////                        )
  7075. //                    );
  7076. //                    System::setApprovalInfo($this->getDoctrine()->getManager(), $options,
  7077. //                        array_flip(GeneralConstant::$Entity_list)['ConsultancyTopic'],
  7078. //                        $docId,
  7079. //                        $request->getSession()->get(UserConstants::USER_LOGIN_ID)    //journal voucher
  7080. //                    );
  7081. //                    System::createEditSignatureHash($this->getDoctrine()->getManager(), array_flip(GeneralConstant::$Entity_list)['ConsultancyTopic'],
  7082. //                        $docId,
  7083. //                        $loginId,
  7084. //                        $request->request->get('approvalHash'));
  7085. //                    $this->addFlash(
  7086. //                        'success',
  7087. //                        'New Consultancy Topic Added.'
  7088. //                    );
  7089. ////                    $url = $this->generateUrl(
  7090. ////                        'create_consultancy_topic'
  7091. ////                    );
  7092. //                    //return $this->redirect($url);
  7093. //
  7094. //                }
  7095. //            }
  7096.         $consultancyDetails $em->getRepository('ApplicationBundle:ConsultancyTopic')->findAll();
  7097.         return $this->render('ApplicationBundle:pages/human_resource/input_forms:create_consultancy.html.twig', array(
  7098.             'page_title' => 'Consultancy Topic',
  7099.             'consultancyDetails' => $consultancyDetails,
  7100. //                'requirement' => json_decode($consultancyDetails->getRequirementData())
  7101.         ));
  7102.     }
  7103.     public function createTopicAction(Request $request$id 0)
  7104.     {
  7105.         $em $this->getDoctrine()->getManager('company_group');
  7106.         $companyId $this->getLoggedUserCompanyId($request);
  7107.         $documentQRY $em->getRepository('CompanyGroupBundle:EntityCreateDocument')->findAll();
  7108.         $topicList $em->getRepository('CompanyGroupBundle:EntityCreateTopic')->findAll();
  7109.         $topic = [];
  7110.         $sessionName BuddybeeConstant::$sessionName;
  7111.         $document = [];
  7112.         foreach ($documentQRY as $d) {
  7113.             $document[$d->getId()] = array(
  7114.                 'id' => $d->getId(),
  7115.                 'documentName' => $d->getDocumentName(),
  7116.                 'text' => $d->getDocumentName(),
  7117.             );
  7118.         }
  7119.         $topicId $id;
  7120.         if ($topicId != 0)
  7121.             $topic $em->getRepository('CompanyGroupBundle:EntityCreateTopic')->findOneBy(
  7122.                 array(
  7123.                     'id' => $topicId
  7124.                 )
  7125.             );
  7126.         if ($request->isMethod('POST')) {
  7127.             if ($request->request->has('topicId'))
  7128.                 $topicId $request->request->get('topicId');
  7129. //            $loginId = $request->getSession()->get(UserConstants::USER_LOGIN_ID);
  7130.             if ($topicId != 0)
  7131.                 $new $em->getRepository('CompanyGroupBundle:EntityCreateTopic')->findOneBy(
  7132.                     array(
  7133.                         'id' => $topicId
  7134.                     )
  7135.                 );
  7136.             else
  7137.                 $new = new EntityCreateTopic();
  7138.             $new->setTopicName($request->request->get('topicName'));
  7139.             $new->setParentTopicId($request->request->get('parentTopic'));
  7140.             if ($request->request->get('countryId') != '')
  7141.                 $new->setCountryId($request->request->get('countryId'));
  7142.             else if ($request->request->get('parentTopic') != '') {
  7143.                 $parentTopic $em->getRepository('CompanyGroupBundle:EntityCreateTopic')->findOneBy(
  7144.                     array(
  7145.                         'id' => $request->request->get('parentTopic')
  7146.                     )
  7147.                 );
  7148.                 if ($parentTopic)
  7149.                     $new->setCountryId($parentTopic->getCountryId());
  7150.             }
  7151.             $new->setTimeSlotMultipliers($request->request->get('timeSlotMultipliers'));
  7152.             $new->setOnlyBookableByAdmin($request->request->get('onlyBookableByAdmin'0));
  7153.             $new->setMeetingType($request->request->get('meetingType'0));
  7154.             $new->setConsultantCanUpload($request->request->get('consultantCanUpload'0));
  7155.             $new->setTopicMarker($request->request->get('topicMarker'));
  7156.             $new->setCoinMultiplierValue($request->request->get('coinMultiplierValue'1));
  7157.             $new->setMinLifetimeCoinsBalance($request->request->get('minLifetimeCoinsBalance'0));
  7158.             $new->setMapEmbedIframe($request->request->get('mapEmbedIframe'''));
  7159.             $new->setTopicSummary($request->request->get('topicSummary'));
  7160.             $new->setAddress($request->request->get('address'));
  7161.             $new->setLocationString($request->request->get('locationString'));
  7162.             $new->setLocationLat($request->request->get('locationLat'));
  7163.             $new->setLocationLong($request->request->get('locationLong'));
  7164.             $new->setUniversityRanking($request->request->get('universityRanking'));
  7165.             $new->setIsParent($request->request->get('isParent'));
  7166.             $new->setIsEvent($request->request->get('isEvent'));
  7167.             $new->setConsultancyEnabled($request->request->get('consultancyEnabled'0));
  7168.             $new->setEventExpired($request->request->get('eventExpired'0));
  7169.             $new->setEventDesc($request->request->get('eventDesc'0));
  7170.             $eventStartDate = new \DateTime($request->request->get('eventStartDate'));
  7171.             $eventEndDate = new \DateTime($request->request->get('eventStartDate'));
  7172.             $new->setEventStartDate($eventStartDate);
  7173.             $new->setEventStartDateTs($eventStartDate->format('U'));
  7174.             $new->setEventEndDate($eventEndDate);
  7175.             $new->setEventStartDateTs($eventEndDate->format('U'));
  7176.             $new->setCreatedLoginId($request->getSession()->get(UserConstants::USER_LOGIN_ID));
  7177.             $checkListStringArray = [];
  7178.             if ($request->request->has('checkList'))
  7179.                 foreach ($request->request->get('checkList') as $value) {
  7180.                     $checkListStringArray [] = explode(","$value);
  7181.                 }
  7182.             $docData = [];
  7183.             foreach ($request->request->get('document', []) as $key => $value)
  7184.                 $docData[] = [
  7185.                     'document' => $request->request->get('document')[$key],
  7186.                     'expDays' => $request->request->get('expDays')[$key],
  7187.                     'stage' => $request->request->get('stage')[$key],
  7188.                     'generalProcessingDays' => $request->request->get('generalProcessingDays')[$key],
  7189.                     'emergencyProcessingDays' => $request->request->get('emergencyProcessingDays')[$key],
  7190.                     'thresholdDaysOffset' => $request->request->get('thresholdDaysOffset')[$key],
  7191.                     'checklist' => explode(","$request->request->get('checkList')[$key])
  7192.                 ];
  7193.             $coursePlanData = [];
  7194.             foreach ($request->request->get('coursePlanSessionNo', []) as $key => $value)
  7195.                 if ($request->request->get('coursePlanSessionNo')[$key] != '' and $request->request->get('coursePlanSessionNo')[$key] != null) {
  7196.                     if (!isset($coursePlanData[$request->request->get('coursePlanSessionNo')[$key]]))
  7197.                         $coursePlanData[$request->request->get('coursePlanSessionNo')[$key]] = [];
  7198.                     $coursePlanData[$request->request->get('coursePlanSessionNo')[$key]][] = [
  7199.                         'sessionNo' => $request->request->get('coursePlanSessionNo')[$key],
  7200.                         'subject' => $request->request->get('coursePlanSubject')[$key],
  7201.                         'details' => $request->request->get('coursePlanDetails')[$key],
  7202.                         'optimumMin' => $request->request->get('coursePlanOptimumMin')[$key],
  7203.                     ];
  7204.                 }
  7205.             $routineData = [];
  7206.             foreach ($request->request->get('routine_sequence', []) as $key => $value) {
  7207.                 $routineData[] = [
  7208.                     'sequence' => $request->request->get('routine_sequence')[$key],
  7209.                     'topicId' => $request->request->get('routine_topic_id')[$key],
  7210.                     'topicName' => $request->request->get('routine_topic_name')[$key],
  7211.                     'meetingType' => $request->request->get('routine_topic_meeting_type')[$key],
  7212.                     'duration' => $request->request->get('routine_duration')[$key],
  7213.                     'offset' => $request->request->get('routine_offset')[$key],
  7214.                     'coins' => $request->request->get('routine_coins')[$key],
  7215.                     'nextSequenceStart' => $request->request->has('routine_next_sequence_start_' $value) ? 0,
  7216.                     'modifiable' => $request->request->has('routine_modifiable_' $value) ? 0,
  7217.                 ];
  7218.             }
  7219.             $sessionData = [];
  7220.             foreach ($request->request->get('sessionId', []) as $key => $value)
  7221.                 $sessionData[] = [
  7222.                     'sessionId' => $request->request->get('sessionId')[$key],
  7223.                     'sessionYear' => $request->request->get('year')[$key],
  7224.                     'threshold' => $request->request->get('threshold')[$key],
  7225.                     'sessionStart' => $request->request->get('sessionStart')[$key],
  7226.                     'applicationStartDate' => $request->request->get('applicationStartDate')[$key],
  7227.                 ];
  7228.             $coursesData = [];
  7229.             foreach ($request->request->get('courseName', []) as $key => $value)
  7230.                 $coursesData[] = [
  7231.                     'courseName' => $request->request->get('courseName')[$key],
  7232.                 ];
  7233.             $departmentData = [];
  7234.             foreach ($request->request->get('departmentName', []) as $key => $value)
  7235.                 $departmentData[] = [
  7236.                     'departmentName' => $request->request->get('departmentName')[$key],
  7237.                 ];
  7238.             $benefitsData = [];
  7239.             foreach ($request->request->get('benefit', []) as $key => $value)
  7240.                 $benefitsData[] = [
  7241.                     'benefit' => $request->request->get('benefit')[$key],
  7242.                 ];
  7243.             $new->setRoutineData(json_encode($routineData));
  7244.             $new->setDocumentData(json_encode($docData));
  7245.             $new->setCoursePlanData(json_encode($coursePlanData));
  7246.             $new->setSessionData(json_encode($sessionData));
  7247.             $new->setCourses(json_encode($coursesData));
  7248.             $new->setDepartments(json_encode($departmentData));
  7249.             $new->setBenefits(json_encode($benefitsData));
  7250.             $otherDataObj = [];
  7251.             foreach (BuddybeeConstant::$otherDataByHash as $ohash => $otherDataGroup)
  7252.                 foreach ($otherDataGroup as $otherData) {
  7253.                     $fieldExists $request->request->has($ohash '_' $otherData['field']);
  7254.                     if ($fieldExists) {
  7255.                         $fieldValue $request->request->get($ohash '_' $otherData['field'], '');
  7256.                         $otherDataObj[$ohash '_' $otherData['field']] = $fieldValue;
  7257.                     }
  7258.                 }
  7259.             $new->setOtherData(json_encode($otherDataObj));
  7260.             $new->setBenefits(json_encode($benefitsData));
  7261.             $em->persist($new);
  7262.             $em->flush();
  7263.             $path "";
  7264.             $defaultProductImage '';
  7265.             $uploadedFile null;
  7266.             $upl_dir $this->container->getParameter('kernel.root_dir') . '/../web/uploads/topicImage/';
  7267.             $uploadedFile $request->files->get('topicSummaryImage');
  7268.             if ($uploadedFile != null) {
  7269.                 $fileName 'TSI' $new->getId() . '.' $uploadedFile->guessExtension();
  7270.                 $path $fileName;
  7271. //            $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/Products/';
  7272.                 if (!file_exists($upl_dir)) {
  7273.                     mkdir($upl_dir0777true);
  7274.                 }
  7275.                 $uploadedFile->move($upl_dir$path);
  7276.                 $defaultProductImage 'uploads/topicImage/' $path;
  7277.                 $new->setTopicSummaryImage($defaultProductImage);
  7278.                 $em->flush();
  7279.             }
  7280.             $path "";
  7281.             $defaultProductImage '';
  7282.             $uploadedFile null;
  7283.             $upl_dir $this->container->getParameter('kernel.root_dir') . '/../web/uploads/topicImage/';
  7284.             $uploadedFile $request->files->get('topicImage');
  7285.             if ($uploadedFile != null) {
  7286.                 $fileName 'TI' $new->getId() . '.' $uploadedFile->guessExtension();
  7287.                 $path $fileName;
  7288. //            $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/Products/';
  7289.                 if (!file_exists($upl_dir)) {
  7290.                     mkdir($upl_dir0777true);
  7291.                 }
  7292.                 $uploadedFile->move($upl_dir$path);
  7293.                 $defaultProductImage 'uploads/topicImage/' $path;
  7294.                 $new->setTopicImage($defaultProductImage);
  7295.                 $em->flush();
  7296.             }
  7297.             $this->addFlash(
  7298.                 'success',
  7299.                 'Topic Added.'
  7300.             );
  7301.         }
  7302.         return $this->render('ApplicationBundle:pages/human_resource/input_forms:create_topic.html.twig', array(
  7303.             'page_title' => 'Create Topic',
  7304.             'defaultCoursePlan' => BuddybeeConstant::$defaultCoursePlan,
  7305.             'coursePlanSessionTitle' => BuddybeeConstant::$coursePlanSessionTitle,
  7306.             'coursePlanSessionTitleShort' => BuddybeeConstant::$coursePlanSessionTitleShort,
  7307.             'document' => $document,
  7308.             'topic' => $topic,
  7309.             'otherDataByHash' => BuddybeeConstant::$otherDataByHash,
  7310.             'topicId' => $topicId,
  7311.             'topicList' => $topicList,
  7312.             'topicMarker' => BuddybeeConstant::$topicMarkup,
  7313.             'sessionName' => $sessionName,
  7314.         ));
  7315.     }
  7316.     public function ConsultancyRequirementSettingsAction(Request $request$id 0)
  7317.     {
  7318.         $em $this->getDoctrine()->getManager('company_group');
  7319.         $entityList $em->getRepository('CompanyGroupBundle:EntityCountryConsultantRequirements')->findAll();
  7320.         $documentQRY $em->getRepository('CompanyGroupBundle:EntityCreateDocument')->findAll();
  7321.         $entity = [];
  7322.         $sessionName BuddybeeConstant::$sessionName;
  7323.         $document = [];
  7324.         foreach ($documentQRY as $d) {
  7325.             $document[$d->getId()] = array(
  7326.                 'id' => $d->getId(),
  7327.                 'documentName' => $d->getDocumentName(),
  7328.                 'text' => $d->getDocumentName(),
  7329.             );
  7330.         }
  7331.         $countryId $id;
  7332.         if ($countryId != 0)
  7333.             $entity $em->getRepository('CompanyGroupBundle:EntityCountryConsultantRequirements')->findOneBy(
  7334.                 array(
  7335.                     'countryId' => $countryId
  7336.                 )
  7337.             );
  7338.         if ($request->isMethod('POST')) {
  7339.             if ($request->request->has('countryId'))
  7340.                 $countryId $request->request->get('countryId');
  7341. //            $loginId = $request->getSession()->get(UserConstants::USER_LOGIN_ID);
  7342.             if ($countryId != 0) {
  7343.                 $new $em->getRepository('CompanyGroupBundle:EntityCountryConsultantRequirements')->findOneBy(
  7344.                     array(
  7345.                         'countryId' => $countryId
  7346.                     )
  7347.                 );
  7348.                 if (!$new)
  7349.                     $new = new EntityCountryConsultantRequirements();
  7350.             } else
  7351.                 $new = new EntityCountryConsultantRequirements();
  7352.             $new->setCountryId($request->request->get('countryId'));
  7353.             $new->setContractLetterHtml($request->request->get('contractLetterHtml'));
  7354.             $new->setRequiredFields($request->request->get('requiredFields'));
  7355.             $new->setAllowedWorkingHoursPerDay($request->request->get('allowedWorkingHoursPerDay'));
  7356.             $new->setAllowedWorkingHoursPerMonth($request->request->get('allowedWorkingHoursPerMonth'));
  7357.             $new->setAllowedWorkingHoursPerWeek($request->request->get('allowedWorkingHoursPerWeek'));
  7358.             $new->setAllowedWorkingHoursPerYear($request->request->get('allowedWorkingHoursPerYear'));
  7359.             $new->setAllowedEarningPerDay($request->request->get('allowedEarningPerDay'));
  7360.             $new->setAllowedEarningPerMonth($request->request->get('allowedEarningPerMonth'));
  7361.             $new->setAllowedEarningPerWeek($request->request->get('allowedEarningPerWeek'));
  7362.             $new->setAllowedEarningPerYear($request->request->get('allowedEarningPerYear'));
  7363.             $new->setRevenuePercentagePerSession($request->request->get('revenuePercentagePerSession'));
  7364.             $docData = [];
  7365.             foreach ($request->request->get('document', []) as $key => $value)
  7366.                 $docData[] = [
  7367.                     'document' => $request->request->get('document')[$key],
  7368.                     'expDays' => $request->request->get('expDays')[$key],
  7369.                     'stage' => $request->request->get('stage')[$key],
  7370.                     'generalProcessingDays' => $request->request->get('generalProcessingDays')[$key],
  7371.                     'emergencyProcessingDays' => $request->request->get('emergencyProcessingDays')[$key],
  7372.                     'thresholdDaysOffset' => $request->request->get('thresholdDaysOffset')[$key],
  7373.                     'checklist' => explode(","$request->request->get('checkList')[$key])
  7374.                 ];
  7375.             $new->setDocumentList(json_encode($docData));
  7376.             $em->persist($new);
  7377.             $em->flush();
  7378.             $this->addFlash(
  7379.                 'success',
  7380.                 'Restriction Updated.'
  7381.             );
  7382.         }
  7383.         return $this->render('@Buddybee/pages/create_consultancy_requirements.html.twig', array(
  7384.             'page_title' => 'Create Requirements',
  7385.             'defaultCoursePlan' => BuddybeeConstant::$defaultCoursePlan,
  7386.             'coursePlanSessionTitle' => BuddybeeConstant::$coursePlanSessionTitle,
  7387.             'coursePlanSessionTitleShort' => BuddybeeConstant::$coursePlanSessionTitleShort,
  7388.             'document' => $document,
  7389.             'entity' => $entity,
  7390.             'otherDataByHash' => BuddybeeConstant::$otherDataByHash,
  7391.             'countryId' => $countryId,
  7392.             'entityList' => $entityList,
  7393.             'topicMarker' => BuddybeeConstant::$topicMarkup,
  7394.             'sessionName' => $sessionName,
  7395.         ));
  7396.     }
  7397.     public function PromoCodeSettingsAction(Request $request$id 0)
  7398.     {
  7399.         $em $this->getDoctrine()->getManager('company_group');
  7400.         $entityList $em->getRepository('CompanyGroupBundle:PromoCode')->findAll();
  7401.         $applicantList $em->getRepository('CompanyGroupBundle:EntityApplicantDetails')->findAll();
  7402.         $promoCodeId $id;
  7403.         $entity = [];
  7404.         if ($promoCodeId != 0)
  7405.             $entity $em->getRepository('CompanyGroupBundle:PromoCode')->findOneBy(
  7406.                 array(
  7407.                     'id' => $promoCodeId
  7408.                 )
  7409.             );
  7410.         if ($request->isMethod('POST')) {
  7411.             if ($request->request->has('promoCodeId'))
  7412.                 $promoCodeId $request->request->get('promoCodeId');
  7413. //            $loginId = $request->getSession()->get(UserConstants::USER_LOGIN_ID);
  7414.             if ($promoCodeId != 0) {
  7415.                 $new $em->getRepository('CompanyGroupBundle:PromoCode')->findOneBy(
  7416.                     array(
  7417.                         'id' => $promoCodeId
  7418.                     )
  7419.                 );
  7420.                 if (!$new)
  7421.                     $new = new PromoCode();
  7422.             } else
  7423.                 $new = new PromoCode();
  7424. //            $new->setCountryId($request->request->get('countryId'));
  7425.             $new->setCode($request->request->get('code'''));
  7426.             $new->setPromoType($request->request->get('promoType'1));
  7427.             $new->setPromoCodeType($request->request->get('promoCodeType'1));
  7428.             $new->setPromoValue($request->request->get('promoValue'0));
  7429.             $new->setPerpetual($request->request->get('perpetual'0));
  7430.             $new->setMaxDiscountAmount($request->request->get('maxDiscountAmount', -1));
  7431.             $new->setMaxCoinAddition($request->request->get('maxCoinAddition', -1));
  7432.             $new->setMinAmountForApplication($request->request->get('minAmountForApplication'0));
  7433.             $new->setMinCoinForApplication($request->request->get('minCoinForApplication'0));
  7434.             $new->setNextApplicationEachCoinCount($request->request->get('nextApplicationEachCoinCount', -1));
  7435.             $new->setMaxUseCount($request->request->get('maxUseCount', -1));
  7436.             $new->setMaxUseCountPerUser($request->request->get('maxUseCountPerUser', -1));
  7437.             $new->setUseCountBalance($request->request->get('useCountBalance', -1));
  7438.             $new->setReferralApplicantId($request->request->get('referralApplicantId'0));
  7439.             $new->setMaxReferralCommissionCount($request->request->get('maxReferralCommissionCount'0));
  7440.             $new->setReferralCommissionCountBalance($request->request->get('referralCommissionCountBalance'0));
  7441.             $new->setReferralCommissionType($request->request->get('referralCommissionType'1));
  7442.             $new->setReferralAmount($request->request->get('referralAmount'0));
  7443.             $startsAt = new \DateTime($request->request->get('startsAt'''));
  7444.             $expiresAt = new \DateTime($request->request->get('expiresAt'''));
  7445.             $new->setStartsAtTs($startsAt->format('U'));
  7446.             $new->setExpiresAtTs($expiresAt->format('U'));
  7447. //
  7448. //        startsAtTs:
  7449. //            type: integer
  7450. //            nullable: true
  7451. //        expiresAtTs:
  7452. //            type: integer
  7453. //            nullable: true
  7454.             $em->persist($new);
  7455.             $em->flush();
  7456.             $this->addFlash(
  7457.                 'success',
  7458.                 'Promo Code Updated.'
  7459.             );
  7460.         }
  7461.         return $this->render('@Buddybee/pages/buddybee_promo_code_settings.html.twig', array(
  7462.             'page_title' => 'Promo Codes',
  7463.             'entity' => $entity,
  7464.             'promoCodeId' => $promoCodeId,
  7465.             'entityList' => $entityList,
  7466.             'applicantList' => $applicantList,
  7467.         ));
  7468.     }
  7469.     public function createDocumentAction(Request $request$id 0)
  7470.     {
  7471.         $em $this->getDoctrine()->getManager('company_group');
  7472.         $companyId $this->getLoggedUserCompanyId($request);
  7473.         $document $em->getRepository('CompanyGroupBundle:EntityCreateDocument')->findAll();
  7474.         $thisDoc = [];
  7475.         if ($id != 0)
  7476.             $thisDoc $em->getRepository('CompanyGroupBundle:EntityCreateDocument')->findOneBy(
  7477.                 array(
  7478.                     'Id' => $id
  7479.                 )
  7480.             );
  7481.         if ($request->isMethod('POST')) {
  7482.             if ($id != 0)
  7483.                 $new $thisDoc;
  7484.             else
  7485.                 $new = new EntityCreateDocument();
  7486.             $new->setDocumentName($request->request->get('docName'));
  7487.             $new->setExpiryDays($request->request->get('expDays'));
  7488.             $new->setProcessingDays($request->request->get('processingDays'));
  7489.             $new->setEmergencyProcessingDays($request->request->get('emergencyProcessingDays'));
  7490.             $new->setDocVideo($request->request->get('docVideoLink'));
  7491.             $new->setRequiredDocument(json_encode($request->request->get('requiredDoc')));
  7492.             $new->setCreatedLoginId($request->getSession()->get(UserConstants::USER_LOGIN_ID));
  7493.             $arr = [
  7494.                 'checkListName' => $request->request->get('checkListName'),
  7495.             ];
  7496.             $new->setCheckList(json_encode($arr));
  7497.             $em->persist($new);
  7498.             $em->flush();
  7499.         }
  7500.         $this->addFlash(
  7501.             'Document Added',
  7502.             'Topic Added.'
  7503.         );
  7504.         return $this->render('ApplicationBundle:pages/human_resource/input_forms:create_document.html.twig', array(
  7505.             'page_title' => 'Create Document',
  7506.             'document' => $document,
  7507.             'thisDoc' => $thisDoc
  7508.         ));
  7509.     }
  7510.     public function getIndividualDocumentAction(Request $request$id)
  7511.     {
  7512.         $em $this->getDoctrine()->getManager('company_group');
  7513.         if ($id == 0) {
  7514.             if ($request->request->has('documentId'))
  7515.                 $id $request->request->get('documentId');
  7516.         }
  7517.         $document $em->getRepository('CompanyGroupBundle:EntityCreateDocument')->find($id);
  7518.         return new JsonResponse(
  7519.             array(
  7520.                 'success' => true,
  7521.                 'rowId' => $request->request->get('rowId'),
  7522.                 'expiryDays' => $document->getExpiryDays(),
  7523.                 'processingDays' => $document->getProcessingDays(),
  7524.                 'emergencyProcessing' => $document->getEmergencyProcessingDays(),
  7525.                 'checklist' => json_decode($document->getCheckList()),
  7526.             )
  7527.         );
  7528.     }
  7529.     public function createBlogAction(Request $request$id)
  7530.     {
  7531.         if (!$id) {
  7532.             if ($request->isMethod('POST')) {
  7533.                 $em $this->getDoctrine()->getManager('company_group');
  7534.                 $loginId $request->getSession()->get(UserConstants::USER_LOGIN_ID);
  7535.                 $new = new EntityCreateBlog();
  7536.                 $new->setTopicId($request->request->get('topicId'));
  7537.                 $new->setTitle($request->request->get('title'));
  7538.                 $new->setSubtitle($request->request->get('subTitle'));
  7539.                 $new->setContent($request->request->get('content'));
  7540.                 $new->setVideoLink($request->request->get('videoLink'));
  7541.                 $new->setAuthorName($request->request->get('authorName'));
  7542.                 $new->setAuthorSummary($request->request->get('authorSummary'));
  7543.                 $new->setIsPrimaryBlog($request->request->get('checkPrimaryBlog'));
  7544.                 $em->persist($new);
  7545.                 $em->flush();
  7546.                 //$fileName = 'cv' . $consultantDetails->getApplicantId() . '.' . $uploadedFile->guessExtension();
  7547.                 $path "";
  7548.                 $defaultProductImage '';
  7549.                 $uploadedFile null;
  7550.                 $upl_dir $this->container->getParameter('kernel.root_dir') . '/../web/uploads/authorImage/';
  7551.                 $uploadedFile $request->files->get('authorImage');
  7552.                 if ($uploadedFile != null) {
  7553.                     $fileName 'authorImage' $new->getId() . '.' $uploadedFile->guessExtension();
  7554.                     $path $fileName;
  7555. //            $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/Products/';
  7556.                     if (!file_exists($upl_dir)) {
  7557.                         mkdir($upl_dir0777true);
  7558.                     }
  7559.                     $uploadedFile->move($upl_dir$path);
  7560.                     $defaultProductImage 'uploads/authorImage/' $path;
  7561.                     $new->setAuthorImage($defaultProductImage);
  7562.                     $em->flush();
  7563.                 }
  7564.                 $path "";
  7565.                 $defaultProductImage '';
  7566.                 $uploadedFile null;
  7567.                 $upl_dir $this->container->getParameter('kernel.root_dir') . '/../web/uploads/mainImage/';
  7568.                 $uploadedFile $request->files->get('main_img');
  7569.                 if ($uploadedFile != null) {
  7570.                     $fileName 'mainImage' $new->getId() . '.' $uploadedFile->guessExtension();
  7571.                     $path $fileName;
  7572. //            $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/Products/';
  7573.                     if (!file_exists($upl_dir)) {
  7574.                         mkdir($upl_dir0777true);
  7575.                     }
  7576.                     $uploadedFile->move($upl_dir$path);
  7577.                     $defaultProductImage 'uploads/mainImage/' $path;
  7578.                     $new->setMainImage($defaultProductImage);
  7579.                     $em->flush();
  7580.                 }
  7581.                 $topicDetails $em->getRepository('CompanyGroupBundle:EntityCreateTopic')->findOneBy(
  7582.                     array(
  7583.                         'id' => $request->request->get('topicId')
  7584.                     )
  7585.                 );
  7586.                 if ($new->getIsPrimaryBlog() == 1) {
  7587.                     if ($topicDetails)
  7588.                         $topic $topicDetails;
  7589.                     else
  7590.                         $topic = new EntityCreateTopic();
  7591.                     $topic->setPrimaryBlogId($new->getId());
  7592.                     $em->flush();
  7593.                 }
  7594.                 $this->addFlash(
  7595.                     'success',
  7596.                     'Blog Added.'
  7597.                 );
  7598.             } else {
  7599.                 $em $this->getDoctrine()->getManager('company_group');
  7600.                 $topic $em->getRepository('CompanyGroupBundle:EntityCreateTopic')->findAll();
  7601.                 $applicant $em->getRepository('CompanyGroupBundle:EntityApplicantDetails')->findAll();
  7602.                 $blogs $em->getRepository('CompanyGroupBundle:EntityCreateBlog')->findAll();
  7603.                 $topicIds = [];
  7604.                 foreach ($blogs as $blog) {
  7605.                     $topicIds [] = $blog->getTopicId();
  7606.                 }
  7607. //                $topic = $em->getRepository('CompanyGroupBundle:EntityCreateTopic')->findBy(
  7608. //                    array(
  7609. //                        'id' => $topicIds
  7610. //                    )
  7611. //                );
  7612.                 return $this->render('ApplicationBundle:pages/human_resource/input_forms:create_blog.html.twig', array(
  7613.                     'page_title' => 'Create Blog',
  7614.                     'topic' => $topic,
  7615.                     'applicant' => $applicant,
  7616.                     'blog' => $blogs,
  7617.                     'id' => $id,
  7618.                 ));
  7619.             }
  7620.         } else {
  7621.             if ($request->isMethod('GET')) {
  7622.                 $em $this->getDoctrine()->getManager('company_group');
  7623.                 $topic $em->getRepository('CompanyGroupBundle:EntityCreateTopic')->findAll();
  7624.                 $applicant $em->getRepository('CompanyGroupBundle:EntityApplicantDetails')->findAll();
  7625.                 $blogs $em->getRepository('CompanyGroupBundle:EntityCreateBlog')->find($id);
  7626.                 return $this->render('ApplicationBundle:pages/human_resource/input_forms:create_blog.html.twig', array(
  7627.                     'page_title' => 'Create Blog',
  7628.                     'topic' => $topic,
  7629.                     'applicant' => $applicant,
  7630.                     'blog' => $blogs,
  7631.                     'id' => $id,
  7632.                 ));
  7633.             } else {
  7634.                 $em $this->getDoctrine()->getManager('company_group');
  7635.                 $new = new EntityCreateBlog();
  7636.                 $new->setTopicId($request->request->get('topicId'));
  7637.                 $new->setTitle($request->request->get('title'));
  7638.                 $new->setSubtitle($request->request->get('subTitle'));
  7639.                 $new->setContent($request->request->get('content'));
  7640.                 $new->setVideoLink($request->request->get('videoLink'));
  7641.                 $new->setAuthorName($request->request->get('authorName'));
  7642.                 $new->setAuthorSummary($request->request->get('authorSummary'));
  7643.                 //$em->persist($new);
  7644.                 $em->flush();
  7645.                 $path "";
  7646.                 $defaultProductImage '';
  7647.                 $uploadedFile null;
  7648.                 $upl_dir $this->container->getParameter('kernel.root_dir') . '/../web/uploads/authorImage/';
  7649.                 $uploadedFile $request->files->get('authorImage');
  7650.                 if ($uploadedFile != null) {
  7651.                     $fileName 'authorImage' '.' $uploadedFile->guessExtension();
  7652.                     $path $fileName;
  7653. //            $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/Products/';
  7654.                     if (!file_exists($upl_dir)) {
  7655.                         mkdir($upl_dir0777true);
  7656.                     }
  7657.                     $uploadedFile->move($upl_dir$path);
  7658.                     $defaultProductImage 'uploads/authorImage/' $path;
  7659.                     $new->setAuthorImage($defaultProductImage);
  7660.                     $em->flush();
  7661.                 }
  7662.                 $this->addFlash(
  7663.                     'success',
  7664.                     'Blog Updated.'
  7665.                 );
  7666.             }
  7667.         }
  7668.         return new JsonResponse(
  7669.             array(
  7670.                 'success' => true,
  7671.             )
  7672.         );
  7673. //        if ($request->isMethod('POST')) {
  7674. //            $loginId = $request->getSession()->get(UserConstants::USER_LOGIN_ID);
  7675. //
  7676. //            $new = new EntityCreateBlog();
  7677. //
  7678. //            $new->setTopicId($request->request->get('topicId'));
  7679. //            $new->setTitle($request->request->get('title'));
  7680. //            $new->setSubtitle($request->request->get('subTitle'));
  7681. //            $new->setContent($request->request->get('content'));
  7682. //            $new->setVideoLink($request->request->get('videoLink'));
  7683. //            $new->setAuthorName($request->request->get('authorName'));
  7684. //            $new->setAuthorSummary($request->request->get('authorSummary'));
  7685. //
  7686. //            $em->persist($new);
  7687. //            $em->flush();
  7688. //
  7689. //
  7690. //            $path = "";
  7691. //            $defaultProductImage = '';
  7692. //            $uploadedFile = null;
  7693. //            $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/authorImage/';
  7694. //            $uploadedFile=  $request->files->get('authorImage');
  7695. //
  7696. //            if ($uploadedFile != null) {
  7697. //
  7698. //                $fileName = 'authorImage' .'.' . $uploadedFile->guessExtension();
  7699. //                $path = $fileName;
  7700. ////            $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/Products/';
  7701. //                if (!file_exists($upl_dir)) {
  7702. //                    mkdir($upl_dir, 0777, true);
  7703. //                }
  7704. //                $uploadedFile->move($upl_dir, $path);
  7705. //                $defaultProductImage = 'uploads/authorImage/' . $path;
  7706. //                $new->setAuthorImage($defaultProductImage);
  7707. //                $em->flush();
  7708. //
  7709. //            }
  7710. //            $this->addFlash(
  7711. //                'success',
  7712. //                'Blog Added.'
  7713. //            );
  7714. //        }
  7715. //        return $this->render('ApplicationBundle:pages/human_resource/input_forms:create_blog.html.twig', array(
  7716. //            'page_title' => 'Create Blog',
  7717. //            'topic'=> $topic,
  7718. //            'applicant' => $applicant,
  7719. //            'blog' => $blogs
  7720. //        ));
  7721.     }
  7722.     public function applicantConsultancyAction()
  7723.     {
  7724.         return $this->render('ApplicationBundle:pages/human_resource/input_forms:consultancy.html.twig', array(
  7725.             'page_title' => 'Consultancy',
  7726.         ));
  7727.     }
  7728.     public function viewConsultantDetailsAction(Request $request$id 0)
  7729.     {
  7730.         $gocEnabled 1;
  7731.         $currAppId 4;
  7732.         $honeybeeAppId 1;
  7733.         $buddybeeAppId 4;
  7734.         $em_goc $this->getDoctrine()->getManager('company_group');
  7735.         $em $this->getDoctrine()->getManager();
  7736.         $option = [];
  7737.         $option['appId'] = $currAppId//honeybee
  7738.         $option['departmentId'] = 18//consultancy
  7739.         $option['designationId'] = 50;
  7740. //        $dataToConnect = System::changeDoctrineManagerByAppId(
  7741. //            $this->getDoctrine()->getManager('company_group'),
  7742. //            $gocEnabled,
  7743. //            $currAppId
  7744. //        );
  7745. //        if (!empty($dataToConnect)) {
  7746. //            $connector = $this->container->get('application_connector');
  7747. //            $connector->resetConnection(
  7748. //                'default',
  7749. //                $dataToConnect['dbName'],
  7750. //                $dataToConnect['dbUser'],
  7751. //                $dataToConnect['dbPass'],
  7752. //                $dataToConnect['dbHost'],
  7753. //                $reset = true
  7754. //            );
  7755. //            $em = $this->getDoctrine()->getManager();
  7756. //        } else {
  7757. //            $currAppId = $honeybeeAppId;
  7758. //            $dataToConnectAgain = System::changeDoctrineManagerByAppId(
  7759. //                $this->getDoctrine()->getManager('company_group'),
  7760. //                $gocEnabled,
  7761. //                $currAppId
  7762. //            );
  7763. //            if (!empty($dataToConnectAgain)) {
  7764. //                $connector = $this->container->get('application_connector');
  7765. //                $connector->resetConnection(
  7766. //                    'default',
  7767. //                    $dataToConnect['dbName'],
  7768. //                    $dataToConnect['dbUser'],
  7769. //                    $dataToConnect['dbPass'],
  7770. //                    $dataToConnect['dbHost'],
  7771. //                    $reset = true
  7772. //                );
  7773. //                $em = $this->getDoctrine()->getManager();
  7774. //            }
  7775. //
  7776. //        }
  7777.         $consultantDetails $em_goc->getRepository(EntityApplicantDetails::class)->find($id);
  7778.         $skill $em_goc->getRepository(EntitySkill::class)->findAll();
  7779.         $gender HumanResourceConstant::$sex;
  7780.         $blood HumanResourceConstant::$BloodGroup;
  7781.         $consultantLevel HumanResourceConstant::$consultantLevel;
  7782.         $companyId $this->getLoggedUserCompanyId($request);
  7783.         $designation $em->getRepository("ApplicationBundle:SysDepartmentPosition")->findAll();
  7784.         $departments $em->getRepository("ApplicationBundle:SysDepartment")->findAll();
  7785.         $companyData Company::getCompanyData($em$companyId);
  7786.         $currDate = new \DateTime();
  7787.         if ($request->isMethod('POST')) {
  7788.             //for consultant only
  7789.             $convertToConsultant HumanResource::convertToConsultant($em_goc$em$id$option$request->request);
  7790.             if ($request->request->get('confirmStatus'0) == 1) {
  7791.                 $bodyTemplate 'ApplicationBundle:email/templates:consultantApprovalEmail.html.twig';
  7792.                 $contractLetterHtml '';
  7793.                 $bodyData = array(
  7794.                     'name' => $consultantDetails->getFirstname() . ' ' $consultantDetails->getLastname(),
  7795.                     'companyData' => $companyData,
  7796.                     'contractLetterHtml' => $contractLetterHtml,
  7797.                     'commentText' => $request->request->get('commentText'),
  7798.                 );
  7799.                 $new_mail $this->get('mail_module');
  7800.                 $new_mail->sendMyMail(array(
  7801.                     'senderHash' => '_CUSTOM_',
  7802.                     'encryptionMethod' => 'ssl',
  7803.                     'userName' => 'management@buddybee.eu',
  7804.                     'fromAddress' => 'management@buddybee.eu',
  7805.                     'password' => 'Eco@0112',
  7806.                     'smtpServer' => 'smtp.hostinger.com',
  7807.                     'smtpPort' => '465',
  7808.                     'forwardToMailAddress' => $consultantDetails->getEmail(),
  7809.                     'subject' => 'Consultant Contract Letter Of ' $consultantDetails->getFirstName(),
  7810.                     'fileName' => '',
  7811.                     //'attachments' => $attachments,
  7812.                     'toAddress' => $consultantDetails->getEmail(),
  7813.                     'mailTemplate' => $bodyTemplate,
  7814.                     'templateData' => $bodyData,
  7815.                     'embedCompanyImage' => 1,
  7816.                     'companyId' => $companyId,
  7817.                     'companyImagePath' => ""
  7818.                 ));
  7819.             }
  7820.             if ($request->request->get('confirmStatus'0) == 0) {
  7821.                 $bodyTemplate 'ApplicationBundle:email/templates:consultantRejectionEmail.html.twig';
  7822.                 $contractLetterHtml '';
  7823.                 $bodyData = array(
  7824.                     'name' => $consultantDetails->getFirstname() . ' ' $consultantDetails->getLastname(),
  7825.                     'companyData' => $companyData,
  7826.                     'contractLetterHtml' => $contractLetterHtml,
  7827.                     'commentText' => $request->request->get('commentText'),
  7828.                 );
  7829.                 $new_mail $this->get('mail_module');
  7830.                 $new_mail->sendMyMail(array(
  7831.                     'senderHash' => '_CUSTOM_',
  7832.                     'encryptionMethod' => 'ssl',
  7833.                     'userName' => 'management@buddybee.eu',
  7834.                     'fromAddress' => 'management@buddybee.eu',
  7835.                     'password' => 'Eco@0112',
  7836.                     'smtpServer' => 'smtp.hostinger.com',
  7837.                     'smtpPort' => '465',
  7838.                     'forwardToMailAddress' => $consultantDetails->getEmail(),
  7839.                     'subject' => 'Rejection Letter Of ' $consultantDetails->getFirstName(),
  7840.                     'fileName' => '',
  7841.                     //'attachments' => $attachments,
  7842.                     'toAddress' => $consultantDetails->getEmail(),
  7843.                     'mailTemplate' => $bodyTemplate,
  7844.                     'templateData' => $bodyData,
  7845.                     'embedCompanyImage' => 1,
  7846.                     'companyId' => $companyId,
  7847.                     'companyImagePath' => ""
  7848.                 ));
  7849.             }
  7850.         }
  7851.         $docList MiscActions::GetDocumentDataForBuddybeeConsultantApply($em_goc,
  7852.             $id,
  7853.             $consultantDetails->getCurrentCountryId()
  7854.         );
  7855.         return $this->render('ApplicationBundle:pages/human_resource/views:viewConsultantDetails.html.twig', array(
  7856.             'page_title' => 'Consultant Details',
  7857.             'applicantId' => $id,
  7858.             'consultantDetails' => $consultantDetails,
  7859.             'education' => json_decode($consultantDetails->getEducationData(), true),
  7860.             'workExperience' => json_decode($consultantDetails->getWorkExperienceData(), true),
  7861.             'certificate' => json_decode($consultantDetails->getCertificateData(), true),
  7862.             'gender' => $gender,
  7863.             'blood' => $blood,
  7864.             'skill' => $skill,
  7865.             'docList' => $docList,
  7866.             'countryId' => $consultantDetails->getCurrentCountryId(),
  7867.             'consultantLevel' => $consultantLevel,
  7868.             'designation' => $designation,
  7869.             'department' => $departments
  7870.         ));
  7871.     }
  7872.     public function ApplicableEmployeSettingsAction()
  7873.     {
  7874.         $em $this->getDoctrine()->getManager();
  7875.         $employeeIds $em->getRepository(Employee::class)->findAll();
  7876.         return $this->render('ApplicationBundle:pages/human_resource/input_forms:applicable_employee_settings.html.twig', array(
  7877.             'page_title' => 'Applicable Employee Settings',
  7878.             'employeeIds' => $employeeIds
  7879.         ));
  7880.     }
  7881.     public function GetApplicableSettingsForSingleEmployeeAction($id)
  7882.     {
  7883.         $em $this->getDoctrine()->getManager();
  7884.         $bankLists $em->getRepository(WorkHourPolicy::class)->findAll();
  7885.         if (json_decode($bankLists->getEmployeeIds()) == $id) {
  7886.             return new JsonResponse(
  7887.                 array(
  7888.                     'success' => true,
  7889.                     'msg' => 'employee found'
  7890.                 )
  7891.             );
  7892.         } else {
  7893.             return new JsonResponse(
  7894.                 array(
  7895.                     'success' => true,
  7896.                     'msg' => 'employee not found'
  7897.                 )
  7898.             );
  7899.         }
  7900.     }
  7901. //    public function  getEmployeeDataAction(){
  7902. //        $em = $this->getDoctrine()->getManager();
  7903. //        $emplyeeDetails =  $em->getRepository('ApplicationBundle:EmployeeDeatils')->findAll();
  7904. //        $days = HumanResourceConstant::$days;
  7905. //        $holidays = ;
  7906. //        $workHourPolicies = ;
  7907. //
  7908. //    }
  7909.     public function meetingSchedulingForTabAction()
  7910.     {
  7911.         $em $this->getDoctrine()->getManager();
  7912.         $date date('Y-m-d');
  7913.         $month date('m');
  7914.         $year date('Y');
  7915.         $monthName date("F"mktime(000$month));
  7916.         $totalDayOfMonth cal_days_in_month(CAL_GREGORIAN$month$year);
  7917.         $fromdt date('Y-m-01 'strtotime("First Day Of  $monthName $year"));
  7918. //        echo "Start Date : $fromdt" . "<br>";
  7919.         $todt date('Y-m-d 'strtotime("Last Day of $monthName $year"));
  7920. //        echo "End Date : $todt" . "<br>";
  7921.         $num_friday '';
  7922.         for ($i 0$i < ((strtotime($todt) - strtotime($fromdt)) / 86400); $i++) {
  7923.             if (date('l'strtotime($fromdt) + ($i 86400)) == 'Friday') {
  7924.                 $num_friday++;
  7925.             }
  7926.         }
  7927.         $num_saturday '';
  7928.         for ($i 0$i < ((strtotime($todt) - strtotime($fromdt)) / 86400); $i++) {
  7929.             if (date('l'strtotime($fromdt) + ($i 86400)) == 'Saturday') {
  7930.                 $num_saturday++;
  7931.             }
  7932.         }
  7933.         $totalWeekends $num_saturday $num_friday;
  7934.         $totalCompanyWorkingDay $totalDayOfMonth $totalWeekends;
  7935. //        $attendanceData=$em->getRepository('ApplicationBundle:EmployeeAttendanceLog')->findOneBy(
  7936. //            array(
  7937. //                'employeeId' => 3
  7938. //            )
  7939. //        );
  7940.         $DateRange = [];
  7941.         $holidayDates $em->getRepository('ApplicationBundle:HolidayCalendarDates')->findAll();
  7942.         foreach ($holidayDates as $holiday) {
  7943.             $holidaayData = array(
  7944.                 'startDate' => $holiday->getStartDate(),
  7945.                 'endDate' => $holiday->getEndDate(),
  7946.             );
  7947.             $DateRange $holidaayData;
  7948.         }
  7949.         $employeeDataDetail = [];
  7950.         $employeeDetail $em->getRepository('ApplicationBundle:EmployeeDetails')->findOneBy(
  7951.             array(
  7952.                 'id' => 3
  7953.             )
  7954.         );
  7955. //        foreach($employeeDetail as $employee){
  7956.         $employeeData = array(
  7957.             'firstName' => $employeeDetail->getFirstname(),
  7958.             'basic' => $employeeDetail->getEar1(),
  7959.             'dearness' => $employeeDetail->getEar2(),
  7960.             'houseRent' => $employeeDetail->getEar3(),
  7961.             'medical' => $employeeDetail->getEar4(),
  7962.             'leaveTravel' => $employeeDetail->getEar5(),
  7963.             'childEducation' => $employeeDetail->getEar6(),
  7964.             'totalEarning' => $employeeDetail->getEart(),
  7965.         );
  7966.         $employeeDataDetail $employeeData;
  7967. //        }
  7968.         $attendanceData $em->getRepository(EmployeeAttendanceLog::class);
  7969. //        $employeeId = $attendanceData->getEmployeeId();
  7970. //        $countId = count($employeeId);
  7971.         $totalPresent $attendanceData->createQueryBuilder('a')
  7972.             // Filter by some parameter if you want
  7973.             ->where('a.employeeId = 3')
  7974.             ->andWhere('a.isPresent = 1')
  7975.             ->select('a.isPresent')
  7976.             ->getQuery()
  7977.             ->getResult();
  7978. //        $countAt = 0;
  7979.         $count count($totalPresent);
  7980. //        $count = $countAt+$count;
  7981.         //get holiday
  7982.         $holidayStartDate $DateRange['startDate']->format('Y-m-d');
  7983.         $holidayEndDate $DateRange['endDate']->format('Y-m-d');
  7984.         $dates HumanResource::getBetweenDates($holidayStartDate$holidayEndDate);
  7985.         $dateCount count($dates);
  7986.         $totalOffDay $totalWeekends $dateCount;
  7987.         $totalCompanyWorkingDay $totalDayOfMonth $totalOffDay;
  7988.         $totalAbsent $totalCompanyWorkingDay $count;
  7989. //        foreach($dates as $compDate ){
  7990. //
  7991. //
  7992. //
  7993. //            if($date == $compDate){
  7994. //                echo $date;
  7995. //                echo $compDate;
  7996. //                echo "holiday" ;
  7997. //
  7998. //            }
  7999. //            else{
  8000. //                echo "no holiday" ;
  8001. //            }
  8002. //        }
  8003.         $twigData HumanResource::twigDataForWorkHourPolicy($em);
  8004.         return $this->render('ApplicationBundle:pages/human_resource/list:meeting_schedule_list_for_tab.html.twig', array(
  8005.             'page_title' => 'Meeting Schedule List',
  8006.             'date' => $date,
  8007.             'totalWeekends' => $totalWeekends,
  8008.             'totalCompanyWorkingDay' => $totalCompanyWorkingDay,
  8009. //            'attendanceData' => $attendanceData,
  8010. //            'employeeId' => $employeeId,
  8011.             'count' => $count,
  8012.             'totalAbsent' => $totalAbsent,
  8013.             'employeeDataDetail' => $employeeDataDetail,
  8014.             'holiday' => $DateRange,
  8015.             'holidayStartDate' => $holidayStartDate,
  8016.             'holidayEndDate' => $holidayEndDate,
  8017.             'holidayCount' => $dateCount,
  8018.             'totalOffDay' => $totalOffDay,
  8019.             'employeeIds' => $twigData['employeeIds'],
  8020.         ));
  8021.     }
  8022.     public function getEmployeeDataForDisburseAction($id)
  8023.     {
  8024.         $em $this->getDoctrine()->getManager();
  8025.         $employeeDetail $em->getRepository('ApplicationBundle:EmployeeDetails')->find($id);
  8026.         return new JsonResponse(
  8027.             array(
  8028.                 'success' => true,
  8029.                 'firstName' => $employeeDetail->getFirstName(),
  8030.             )
  8031.         );
  8032.     }
  8033.     public function BulkAttendanceAction(Request $request)
  8034.     {
  8035.         $em $this->getDoctrine()->getManager();
  8036.         $companyId $this->getLoggedUserCompanyId($request);
  8037.         if ($request->isMethod('POST')) {
  8038.             $attendance = [];
  8039.             foreach ($request->request->get('date') as $key => $val) {
  8040.                 $loginId $request->getSession()->get(UserConstants::USER_LOGIN_ID);
  8041.                 $bulkAttendance null;
  8042.                 if ($request->request->get('attId')[$key] != 0)
  8043.                     $bulkAttendance $em->getRepository('ApplicationBundle:EmployeeAttendance')->findOneBy(array(
  8044.                         'id' => $request->request->get('attId')[$key],
  8045.                     ));
  8046.                 if (!$bulkAttendance)
  8047.                     $bulkAttendance = new EmployeeAttendance;
  8048.                 $theDate = new \DateTime($request->request->get('date')[$key]);
  8049.                 $bulkAttendance->setEmployeeId($request->request->get('employeeId'));
  8050.                 $bulkAttendance->setDate($theDate);
  8051.                 $bulkAttendance->setEntry(
  8052.                     ($request->request->get('startTimeTs')[$key] == '' ||
  8053.                         $request->request->get('startTimeTs')[$key] == 'NaN' ||
  8054.                         $request->request->get('startTimeTs')[$key] == 0) ? null :
  8055.                         new \DateTime('@' $request->request->get('startTimeTs')[$key])
  8056.                 );
  8057.                 $bulkAttendance->setLastOut(($request->request->get('endTimeTs')[$key] == '' ||
  8058.                     $request->request->get('endTimeTs')[$key] == 'NaN' ||
  8059.                     $request->request->get('endTimeTs')[$key] == 0) ? null :
  8060.                     new \DateTime('@' $request->request->get('endTimeTs')[$key]));
  8061.                 $bulkAttendance->setData(json_encode(
  8062.                     array(
  8063.                         "in" => json_decode($request->request->get('entryDataIn')[$key], true),
  8064.                         "out" => json_decode($request->request->get('entryDataOut')[$key], true)
  8065.                     )
  8066.                 ));
  8067. //                $bulkAttendance->setLastStartTime(new \DateTime($request->request->get('startDate')));
  8068. //                $bulkAttendance->setIsPresent(1);
  8069.                 $bulkAttendance->setLastStartTimeTs($request->request->get('startTimeTs')[$key]);
  8070.                 $bulkAttendance->setLastEndTimeTs($request->request->get('endTimeTs')[$key]);
  8071. //                $bulkAttendance->setTotalWorkHour($request->request->get('totalWorkHour')[$key]);
  8072.                 $em->persist($bulkAttendance);
  8073.                 $em->flush();
  8074.                 $bulkAttendanceLog $em->getRepository('ApplicationBundle:EmployeeAttendanceLog')->findOneBy(array(
  8075.                     'attendance_id' => $bulkAttendance->getId(),
  8076.                 ));
  8077.                 if (!$bulkAttendanceLog)
  8078.                     $bulkAttendanceLog = new EmployeeAttendanceLog;
  8079.                 $bulkAttendanceLog->setAttendanceId($bulkAttendance->getId());
  8080.                 $bulkAttendanceLog->setEmployeeId($request->request->get('employeeId'));
  8081.                 $bulkAttendanceLog->setLastStartTime(
  8082.                     ($request->request->get('startTimeTs')[$key] == '' ||
  8083.                         $request->request->get('startTimeTs')[$key] == 'NaN' ||
  8084.                         $request->request->get('startTimeTs')[$key] == 0) ? null :
  8085.                         new \DateTime('@' $request->request->get('startTimeTs')[$key])
  8086.                 );
  8087.                 $bulkAttendanceLog->setLastEndTime(($request->request->get('endTimeTs')[$key] == '' ||
  8088.                     $request->request->get('endTimeTs')[$key] == 'NaN' ||
  8089.                     $request->request->get('endTimeTs')[$key] == 0) ? null :
  8090.                     new \DateTime('@' $request->request->get('endTimeTs')[$key]));
  8091. //                $bulkAttendance->setLastStartTime(new \DateTime($request->request->get('startDate')));
  8092.                 $bulkAttendanceLog->setIsPresent(1);
  8093.                 $bulkAttendanceLog->setLastStartTimeTs($request->request->get('startTimeTs')[$key]);
  8094.                 $bulkAttendanceLog->setLastEndTimeTs($request->request->get('endTimeTs')[$key]);
  8095.                 $bulkAttendanceLog->setTotalWorkHour($request->request->get('totalWorkHour')[$key]);
  8096. //                $bulkAttendanceLog->setPositionArray(json_encode($request->request->get('locations')[$key]));
  8097.                 $em->persist($bulkAttendanceLog);
  8098.                 $em->flush();
  8099.             }
  8100.         }
  8101.         $startDate $request->query->get('start_date''');
  8102.         $endDate $request->query->get('end_date''');
  8103.         $employeeId $request->query->get('employee_id'0);
  8104.         $existingData = [];
  8105.         $startDateTs 0;
  8106.         $endDateTs 0;
  8107.         $returnData = array(
  8108.             'page_title' => 'Bulk Attendance',
  8109.             'existingData' => $existingData,
  8110.             'startDateTs' => $startDateTs,
  8111.             'endDateTs' => $endDateTs,
  8112.         );
  8113.         if ($request->query->has('returnJson')) {
  8114.             if ($startDate != '' && $endDate != '' && $employeeId != 0) {
  8115.                 $startDateDt = new \DateTime($startDate);
  8116.                 $endDateDt = new \DateTime($endDate);
  8117.                 $startDateTs $startDateDt->format('U');
  8118.                 $endDateTs $endDateDt->format('U');
  8119.                 $attendanceQuery $em->getRepository('ApplicationBundle:EmployeeAttendance')
  8120.                     ->createQueryBuilder('p')
  8121.                     ->where("p.employeeId = " $employeeId)
  8122. //                ->andWhere("p.date => '" . ($startDateDt->format('Y-m-d'))."'")
  8123.                     ->andWhere("p.date <= :last")
  8124.                     ->andWhere("p.date >= :start")
  8125.                     ->setParameter('start'$startDateDt)
  8126.                     ->setParameter('last'$endDateDt);
  8127.                 $attendanceResults $attendanceQuery->getQuery()->getResult();
  8128.                 foreach ($attendanceResults as $att) {
  8129.                     $entryDateTime null;
  8130.                     $outDateTime null;
  8131.                     if ($att->getEntry()) $entryDateTime = new \DateTime($att->getDate()->format('Y-m-d') . ' ' $att->getEntry()->format('H:i:00 +0000'));
  8132.                     if ($att->getLastOut()) $outDateTime = new \DateTime($att->getDate()->format('Y-m-d') . ' ' $att->getLastOut()->format('H:i:00 +0000'));
  8133.                     $attData = array(
  8134.                         'id' => $att->getId(),
  8135.                         'date_str' => $att->getDate()->format('Y-m-d'),
  8136.                         'date_str_full' => $att->getDate()->format('Y-m-d H:i:s'),
  8137.                         'in_time_full' => $entryDateTime $entryDateTime->format(DATE_RFC2822) : '',
  8138.                         'date_ts' => $att->getDate()->format('U'),
  8139.                         'in_time' => $entryDateTime $entryDateTime->format('H:i:s') : '',
  8140.                         'in_time_ts' => $entryDateTime $entryDateTime->format('U') : 0,
  8141.                         'last_out_time' => $outDateTime $outDateTime->format('H:i:s') : '',
  8142.                         'last_out_time_ts' => $outDateTime $outDateTime->format('U') : '',
  8143.                     );
  8144.                     $locations = [];
  8145.                     $locList = [];
  8146.                     $logHere $em->getRepository('ApplicationBundle:EmployeeAttendanceLog')->findOneBy(array(
  8147.                         'attendance_id' => $att->getId(),
  8148.                     ));
  8149.                     if ($logHere)
  8150.                         $locList json_decode($logHere->getPositionArray(), true);
  8151.                     if ($locList == null)
  8152.                         $locList = [];
  8153.                     $entry_data json_decode($att->getData(), true);
  8154.                     if ($entry_data == null$entry_data = [];
  8155.                     $lastLat 0;
  8156.                     $lastLng 0;
  8157.                     foreach ($locList as $lg) {
  8158.                         $dist 0;
  8159.                         if (isset($lg['lat'])) {
  8160.                             if ($lastLat == 0) {
  8161.                                 $lastLat $lg['lat'];
  8162.                                 $lastLng $lg['lng'];
  8163.                             }
  8164.                             $theta $lastLng $lg['lng'];
  8165.                             $dist sin(deg2rad($lastLat)) * sin(deg2rad($lg['lat'])) + cos(deg2rad($lastLat)) * cos(deg2rad($lg['lat'])) * cos(deg2rad($theta));
  8166.                             $dist acos($dist);
  8167.                             $dist rad2deg($dist);
  8168.                             $miles $dist 60 1.1515;
  8169.                             $dist $miles 1609.344;
  8170.                             if (abs($dist) > 1000) {
  8171.                                 $locations[] = array(
  8172.                                     'ts' => $lg['ts'],
  8173.                                     'lat' => $lg['lat'],
  8174.                                     'lng' => $lg['lng'],
  8175.                                 );
  8176.                                 $lastLat $lg['lat'];
  8177.                                 $lastLng $lg['lng'];
  8178.                             }
  8179.                         }
  8180.                     }
  8181.                     $attData['locations'] = $locations;
  8182.                     $attData['entryData'] = $entry_data;
  8183.                     $existingData[$att->getDate()->format('U')] = $attData;
  8184.                 }
  8185.             }
  8186.             $returnData = array(
  8187.                 'page_title' => 'Bulk Attendance',
  8188.                 'existingData' => $existingData,
  8189.                 'startDateTs' => $startDateTs,
  8190.                 'endDateTs' => $endDateTs,
  8191.             );
  8192.             return new JsonResponse($returnData);
  8193.         } else
  8194.             return $this->render('ApplicationBundle:pages/human_resource/attendance:bulk_attendance.html.twig'$returnData);
  8195.     }
  8196.     public function CreateAttendanceAmendmentAction(Request $request$id 0)
  8197.     {
  8198.         $em $this->getDoctrine()->getManager();
  8199.         $companyId $this->getLoggedUserCompanyId($request);
  8200.         $extDocData = [];
  8201.         if ($request->isMethod('POST')) {
  8202.             $em $this->getDoctrine()->getManager();
  8203.             $entity_id array_flip(GeneralConstant::$Entity_list)['AttendanceAmendment']; //change
  8204.             $dochash $request->request->get('docHash'); //change
  8205.             $loginId $request->getSession()->get(UserConstants::USER_LOGIN_ID);
  8206.             $approveRole $request->request->get('approvalRole');
  8207.             $approveHash $request->request->get('approvalHash');
  8208.             if ($dochash == '') {
  8209.                 $numberHash MiscActions::GetNumberHash($em'ATAM'$request->request->get('prefix_hash'$request->request->get('employeeId'0)), $request->request->get('assoc_hash'0), ''1);
  8210.                 $dochash 'ATAM' '/' $request->request->get('prefix_hash'$request->request->get('employeeId'0)) . '/' $request->request->get('assoc_hash'0) . '/' $numberHash;
  8211.             } else
  8212.                 $numberHash $request->request->get('number_hash');
  8213.             if (!DocValidation::isInsertable($em$entity_id$dochash,
  8214.                 $loginId$approveRole$approveHash$id)
  8215.             ) {
  8216.                 if ($request->request->has('returnJson')) {
  8217.                     return new JsonResponse(array(
  8218.                         'success' => false,
  8219.                         'documentHash' => 0,
  8220.                         'documentId' => 0,
  8221.                     ));
  8222.                 } else
  8223.                     $this->addFlash(
  8224.                         'error',
  8225.                         'Sorry Could not insert Data.'
  8226.                     );
  8227.             } else {
  8228.                 $funcname 'AttendanceAmendment';
  8229.                 $doc_id $id;
  8230.                 DeleteDocument::$funcname($em$doc_id0);
  8231.                 $attendanceAmendment = new AttendanceAmendment();
  8232.                 $attendanceAmendment->setDocumentHash($dochash);
  8233.                 $attendanceAmendment->setAttendanceAmendmentDate(new \DateTime($request->request->get('docDate''')));
  8234.                 $attendanceAmendment->setStartDate(new \DateTime($request->request->get('startDate''')));
  8235.                 $attendanceAmendment->setEndDate(new \DateTime($request->request->get('endDate''')));
  8236.                 $attendanceAmendment->setTypeHash('ATAM');
  8237.                 $attendanceAmendment->setPrefixHash($request->request->get('prefix_hash'0));
  8238.                 $attendanceAmendment->setAssocHash($request->request->get('assoc_hash'0));
  8239.                 $attendanceAmendment->setNumberHash($numberHash);
  8240.                 $attendanceAmendment->setCreatedLoginId($request->getSession()->get(UserConstants::USER_LOGIN_ID));
  8241.                 $attendanceAmendment->setApproved(array_flip(GeneralConstant::$approvalStatus)['pending']);
  8242.                 $attendanceAmendment->setAutoCreated($request->request->get('fullApprove'0));
  8243.                 $attendanceAmendment->setEmployeeId($request->request->get('forcedEmployeeId'$request->request->get('employeeId'0)));
  8244. //                $attendanceAmendment->setAutocreated(0);
  8245.                 if ($request->request->has('dataArrayJson')) {
  8246.                     $attendanceAmendment->setData($request->request->get('dataArrayJson''[]'));
  8247.                 } else {
  8248.                     $arr = [
  8249.                     ];
  8250.                     //dump($arr);
  8251.                     foreach ($request->request->get('date', []) as $key => $val) {
  8252.                         if ($request->request->get('isChanged')[$key] == 1) {
  8253.                             $dt = array(
  8254.                                 'enabled' => 1,
  8255.                                 'attId' => $request->request->get('attId')[$key],
  8256.                                 'note' => $request->request->get('note')[$key],
  8257.                                 'startTimeTs' => $request->request->get('startTimeTs')[$key],
  8258.                                 'endTimeTs' => $request->request->get('endTimeTs')[$key],
  8259.                                 'totalWorkHour' => $request->request->get('totalWorkHour')[$key],
  8260.                                 'entryDataIn' => json_decode($request->request->get('entryDataIn')[$key], true),
  8261.                                 'entryDataOut' => json_decode($request->request->get('entryDataOut')[$key], true),
  8262.                             );
  8263.                             $arr[$val] = $dt;
  8264.                         }
  8265.                     }
  8266.                     $attendanceAmendment->setData(json_encode($arr));
  8267.                 }
  8268.                 $em->persist($attendanceAmendment);
  8269.                 $em->flush();
  8270.                 $ID $attendanceAmendment->getAttendanceAmendmentId();
  8271.                 //now add Approval info
  8272.                 $loginId $request->getSession()->get(UserConstants::USER_LOGIN_ID);
  8273.                 $approveRole 1;  //created
  8274.                 $options = array(
  8275.                     'notification_enabled' => $this->container->getParameter('notification_enabled'),
  8276.                     'notification_server' => $this->container->getParameter('notification_server'),
  8277.                     'appId' => $request->getSession()->get(UserConstants::USER_APP_ID),
  8278.                     'url' => $this->generateUrl(
  8279.                         GeneralConstant::$Entity_list_details[array_flip(GeneralConstant::$Entity_list)['AttendanceAmendment']]
  8280.                         ['entity_view_route_path_name']
  8281.                     )
  8282.                 );
  8283.                 System::setApprovalInfo($this->getDoctrine()->getManager(), $options,
  8284.                     array_flip(GeneralConstant::$Entity_list)['AttendanceAmendment'],
  8285.                     $ID,
  8286.                     $request->getSession()->get(UserConstants::USER_LOGIN_ID)    //journal voucher
  8287.                 );
  8288.                 if ($request->request->get('fullApprove'0) == 1) {
  8289.                     DeleteDocument::AttendanceAmendment($em$ID);
  8290.                 } else {
  8291.                     System::createEditSignatureHash($this->getDoctrine()->getManager(), array_flip(GeneralConstant::$Entity_list)['AttendanceAmendment'], $ID,
  8292.                         $loginId,
  8293.                         $approveRole,
  8294.                         $request->request->get('approvalHash'));
  8295.                     $url $this->generateUrl(
  8296.                         'view_attendance_amendment'
  8297.                     );
  8298.                     if ($request->request->has('returnJson')) {
  8299.                         return new JsonResponse(array(
  8300.                             'success' => true,
  8301.                             'documentHash' => $dochash,
  8302.                             'documentId' => $ID,
  8303.                             'viewUrl' => $url "/" $ID,
  8304.                         ));
  8305.                     } else {
  8306.                         $this->addFlash(
  8307.                             'success',
  8308.                             'Attendance Amendment Note Added.'
  8309.                         );
  8310.                         return $this->redirect($url "/" $ID);
  8311.                     }
  8312.                 }
  8313.             }
  8314.         }
  8315.         if ($id == 0) {
  8316.         } else {
  8317.             $extDoc $em->getRepository('ApplicationBundle:AttendanceAmendment')->findOneBy(
  8318.                 array(
  8319.                     'salesOrderId' => $id///material
  8320.                 )
  8321.             );
  8322.             //now if its not editable, redirect to view
  8323.             if ($extDoc) {
  8324.                 if ($extDoc->getEditFlag() != 1) {
  8325.                     $url $this->generateUrl(
  8326.                         'view_attendance_amendment'
  8327.                     );
  8328.                     return $this->redirect($url "/" $id);
  8329.                 } else {
  8330.                     $extDocData $extDoc;
  8331.                 }
  8332.             } else {
  8333.             }
  8334.         }
  8335.         $startDate $request->query->get('start_date''');
  8336.         $endDate $request->query->get('end_date''');
  8337.         $employeeId $request->query->get('employee_id'0);
  8338.         $existingData = [];
  8339.         $startDateTs 0;
  8340.         $endDateTs 0;
  8341.         $returnData = array(
  8342.             'page_title' => 'Attendance Amendment',
  8343.             'existingData' => $existingData,
  8344.             'startDateTs' => $startDateTs,
  8345.             'extDocData' => $extDocData,
  8346.             'endDateTs' => $endDateTs,
  8347.         );
  8348.         if ($request->query->has('returnJson')) {
  8349.             if ($startDate != '' && $endDate != '' && $employeeId != 0) {
  8350.                 $startDateDt = new \DateTime($startDate);
  8351.                 $endDateDt = new \DateTime($endDate);
  8352.                 $startDateTs $startDateDt->format('U');
  8353.                 $endDateTs $endDateDt->format('U');
  8354.                 $attendanceQuery $em->getRepository('ApplicationBundle:EmployeeAttendance')
  8355.                     ->createQueryBuilder('p')
  8356.                     ->where("p.employeeId = " $employeeId)
  8357. //                ->andWhere("p.date => '" . ($startDateDt->format('Y-m-d'))."'")
  8358.                     ->andWhere("p.date <= :last")
  8359.                     ->andWhere("p.date >= :start")
  8360.                     ->setParameter('start'$startDateDt)
  8361.                     ->setParameter('last'$endDateDt);
  8362.                 $attendanceResults $attendanceQuery->getQuery()->getResult();
  8363.                 foreach ($attendanceResults as $att) {
  8364.                     $entryDateTime null;
  8365.                     $outDateTime null;
  8366.                     if ($att->getEntry()) $entryDateTime = new \DateTime($att->getDate()->format('Y-m-d') . ' ' $att->getEntry()->format('H:i:00 +0000'));
  8367.                     if ($att->getLastOut()) $outDateTime = new \DateTime($att->getDate()->format('Y-m-d') . ' ' $att->getLastOut()->format('H:i:00 +0000'));
  8368.                     $attData = array(
  8369.                         'id' => $att->getId(),
  8370.                         'date_str' => $att->getDate()->format('Y-m-d'),
  8371.                         'date_str_full' => $att->getDate()->format('Y-m-d H:i:s'),
  8372.                         'in_time_full' => $entryDateTime $entryDateTime->format(DATE_RFC2822) : '',
  8373.                         'date_ts' => $att->getDate()->format('U'),
  8374.                         'in_time' => $entryDateTime $entryDateTime->format('H:i:s') : '',
  8375.                         'in_time_ts' => $entryDateTime $entryDateTime->format('U') : 0,
  8376.                         'last_out_time' => $outDateTime $outDateTime->format('H:i:s') : '',
  8377.                         'last_out_time_ts' => $outDateTime $outDateTime->format('U') : '',
  8378.                     );
  8379.                     $locations = [];
  8380.                     $locList = [];
  8381.                     $logHere $em->getRepository('ApplicationBundle:EmployeeAttendanceLog')->findOneBy(array(
  8382.                         'attendance_id' => $att->getId(),
  8383.                     ));
  8384.                     if ($logHere)
  8385.                         $locList json_decode($logHere->getPositionArray(), true);
  8386.                     if ($locList == null)
  8387.                         $locList = [];
  8388.                     $entry_data json_decode($att->getData(), true);
  8389.                     if ($entry_data == null$entry_data = [];
  8390.                     $lastLat 0;
  8391.                     $lastLng 0;
  8392.                     foreach ($locList as $lg) {
  8393.                         $dist 0;
  8394.                         if (isset($lg['lat'])) {
  8395.                             if ($lastLat == 0) {
  8396.                                 $lastLat $lg['lat'];
  8397.                                 $lastLng $lg['lng'];
  8398.                             }
  8399.                             $theta $lastLng $lg['lng'];
  8400.                             $dist sin(deg2rad($lastLat)) * sin(deg2rad($lg['lat'])) + cos(deg2rad($lastLat)) * cos(deg2rad($lg['lat'])) * cos(deg2rad($theta));
  8401.                             $dist acos($dist);
  8402.                             $dist rad2deg($dist);
  8403.                             $miles $dist 60 1.1515;
  8404.                             $dist $miles 1609.344;
  8405.                             if (abs($dist) > 1000) {
  8406.                                 $locations[] = array(
  8407.                                     'ts' => $lg['ts'],
  8408.                                     'lat' => $lg['lat'],
  8409.                                     'lng' => $lg['lng'],
  8410.                                 );
  8411.                                 $lastLat $lg['lat'];
  8412.                                 $lastLng $lg['lng'];
  8413.                             }
  8414.                         }
  8415.                     }
  8416.                     $attData['locations'] = $locations;
  8417.                     $attData['entryData'] = $entry_data;
  8418.                     $existingData[$att->getDate()->format('U')] = $attData;
  8419.                 }
  8420.             }
  8421.             $returnData = array(
  8422.                 'page_title' => 'Attendance Amendment',
  8423.                 'existingData' => $existingData,
  8424.                 'startDateTs' => $startDateTs,
  8425.                 'extDocData' => $extDocData,
  8426.                 'endDateTs' => $endDateTs,
  8427.             );
  8428.             return new JsonResponse($returnData);
  8429.         } else
  8430.             return $this->render('ApplicationBundle:pages/human_resource/attendance:create_attendance_amendment.html.twig'$returnData);
  8431.     }
  8432.     public function AttendanceAmendmentListAction(Request $request)
  8433.     {
  8434.         $data = [];
  8435.         return $this->render('ApplicationBundle:pages/human_resource/list:attendance_amendment_list.html.twig',
  8436.             array(
  8437.                 'page_title' => 'Attendance Amendment List',
  8438.                 'data' => $data
  8439.             )
  8440.         );
  8441.     }
  8442.     public function ViewAttendanceAmendmentAction(Request $request$id)
  8443.     {
  8444.         $em $this->getDoctrine()->getManager();
  8445.         $dt HumanResource::GetAttendanceAmendmentDetails($em$id);
  8446.         return $this->render('ApplicationBundle:pages/human_resource/views:view_attendance_amendment.html.twig',
  8447.             array(
  8448.                 'page_title' => 'Attendance Amendment',
  8449.                 'data' => $dt,
  8450.                 'approval_data' => System::checkIfApprovalExists($emarray_flip(GeneralConstant::$Entity_list)['AttendanceAmendment'],
  8451.                     $id$request->getSession()->get(UserConstants::USER_LOGIN_ID)),
  8452.                 'document_log' => System::getDocumentLog($this->getDoctrine()->getManager(),
  8453.                     array_flip(GeneralConstant::$Entity_list)['AttendanceAmendment'],
  8454.                     $id,
  8455.                     $dt['created_by'],
  8456.                     $dt['edited_by'])
  8457.             )
  8458.         );
  8459.     }
  8460.     public function PrintAttendanceAmendmentAction(Request $request$id)
  8461.     {
  8462.         $em $this->getDoctrine()->getManager();
  8463.         $dt HumanResource::GetAttendanceAmendmentDetails($em$id);
  8464.         $company_data Company::getCompanyData($em1);
  8465.         $document_mark = array(
  8466.             'original' => '/images/Original-Stamp-PNG-Picture.png',
  8467.             'copy' => ''
  8468.         );
  8469.         if ($request->query->has('pdf') && $this->get('knp_snappy.pdf')) {
  8470.             $html $this->renderView('@Inventory/pages/print/print_stock_received_note.html.twig',
  8471.                 array(
  8472.                     //full array here
  8473.                     'pdf' => true,
  8474.                     'page_title' => 'Stock Received Note',
  8475.                     'export' => 'pdf,print',
  8476.                     'data' => $dt,
  8477.                     'approval_data' => System::checkIfApprovalExists($emarray_flip(GeneralConstant::$Entity_list)['AttendanceAmendment'],
  8478.                         $id$request->getSession()->get(UserConstants::USER_LOGIN_ID)),
  8479.                     'document_log' => System::getDocumentLog($this->getDoctrine()->getManager(),
  8480.                         array_flip(GeneralConstant::$Entity_list)['AttendanceAmendment'],
  8481.                         $id,
  8482.                         $dt['created_by'],
  8483.                         $dt['edited_by']),
  8484.                     'document_mark_image' => $document_mark['original'],
  8485.                     'company_name' => $company_data->getName(),
  8486.                     'company_data' => $company_data,
  8487.                     'company_address' => $company_data->getAddress(),
  8488.                     'company_image' => $company_data->getImage(),
  8489.                     'invoice_footer' => $company_data->getInvoiceFooter(),
  8490.                     'red' => 0
  8491.                 )
  8492.             );
  8493.             $pdf_response $this->get('knp_snappy.pdf')->getOutputFromHtml($html, array(
  8494. //                'orientation' => 'landscape',
  8495. //                'enable-javascript' => true,
  8496. //                'javascript-delay' => 1000,0
  8497.                 'no-stop-slow-scripts' => false,
  8498.                 'no-background' => false,
  8499.                 'lowquality' => false,
  8500.                 'encoding' => 'utf-8',
  8501. //            'images' => true,
  8502. //            'cookie' => array(),
  8503.                 'dpi' => 300,
  8504.                 'image-dpi' => 300,
  8505. //                'enable-external-links' => true,
  8506. //                'enable-internal-links' => true
  8507.             ));
  8508.             return new Response(
  8509.                 $pdf_response,
  8510.                 200,
  8511.                 array(
  8512.                     'Content-Type' => 'application/pdf',
  8513.                     'Content-Disposition' => 'attachment; filename="stock_received_note_' $id '.pdf"'
  8514.                 )
  8515.             );
  8516.         }
  8517.         return $this->render('ApplicationBundle:pages/human_resource/views:view_attendance_amendment.html.twig',
  8518.             array(
  8519.                 'page_title' => 'Attendance Amendment',
  8520.                 'data' => $dt,
  8521.                 'approval_data' => System::checkIfApprovalExists($emarray_flip(GeneralConstant::$Entity_list)['AttendanceAmendment'],
  8522.                     $id$request->getSession()->get(UserConstants::USER_LOGIN_ID)),
  8523.                 'document_log' => System::getDocumentLog($this->getDoctrine()->getManager(),
  8524.                     array_flip(GeneralConstant::$Entity_list)['AttendanceAmendment'],
  8525.                     $id,
  8526.                     $dt['created_by'],
  8527.                     $dt['edited_by'])
  8528.             )
  8529.         );
  8530.     }
  8531.     public function createRoomAction(Request $request)
  8532.     {
  8533.         $em $this->getDoctrine()->getManager();
  8534.         $companyId $this->getLoggedUserCompanyId($request);
  8535.         if ($request->isMethod('POST')) {
  8536.             $loginId $request->getSession()->get(UserConstants::USER_LOGIN_ID);
  8537.             $room = new Room;
  8538.             $room->setRoomNo($request->request->get('RoomNo'));
  8539.             //$room->setRoomName($request->request->get('RoomName'));
  8540.             $room->setBuilding($request->request->get('buildingName'));
  8541.             $room->setFloor($request->request->get('floor'));
  8542.             $room->setCapacity($request->request->get('capacity'));
  8543.             $room->setCreatedLoginId($request->getSession()->get(UserConstants::USER_LOGIN_ID));
  8544.             $em->persist($room);
  8545.             $em->flush();
  8546.         }
  8547.         return $this->render('ApplicationBundle:pages/human_resource/input_forms:create_room.html.twig', array(
  8548.             'page_title' => 'Add Room',
  8549.         ));
  8550.     }
  8551.     public function ExpenseTypeAction()
  8552.     {
  8553.         $expenseType HumanResourceConstant::$employeeExpenseAllowanceTypes;
  8554.         $expenseTypeArray = [];
  8555.         foreach ($expenseType as $k => $dt) {
  8556.             $dt['id'] = $k;
  8557.             $newSegs = [];
  8558.             foreach ($dt['segregations'] as $l => $s) {
  8559.                 $newOptions = [];
  8560.                 foreach ($s['options'] as $l2 => $s2) {
  8561.                     $s3 = array(
  8562.                         'value' => $l2,
  8563.                         'text' => $s2,
  8564.                     );
  8565.                     $newOptions[] = $s3;
  8566.                 }
  8567.                 $s['options'] = $newOptions;
  8568.                 if (is_string($s['defaultVal'])) $s['defaultVal'] = [$s['defaultVal']];
  8569.                 $newSegs[] = $s;
  8570.             }
  8571.             $dt['segregations'] = $newSegs;
  8572.             $expenseTypeArray[] = $dt;
  8573.         }
  8574.         return new JsonResponse(
  8575.             array(
  8576.                 'success' => true,
  8577.                 'expenseType' => $expenseType,
  8578.                 'expenseTypeArray' => $expenseTypeArray,
  8579.             )
  8580.         );
  8581.     }
  8582.     public function DemoDataTableAction()
  8583.     {
  8584.         return $this->render('ApplicationBundle:pages/human_resource/list:demo_data_table.html.twig', array(
  8585.             'page_title' => 'Add Room',
  8586.         ));
  8587.     }
  8588.     public function workEnrtyAction(Request $request)
  8589.     {
  8590. //        $em = $this->getDoctrine()->getManager();
  8591. //        $companyId = $this->getLoggedUserCompanyId($request);
  8592. //        if ($request->isMethod('POST')) {
  8593. //            $loginId = $request->getSession()->get(UserConstants::USER_LOGIN_ID);
  8594. //            $labour = new Labour();
  8595. //            $labour->setLabourName($request->request->get('labourName'));
  8596. //            $labour->setNidNumber($request->request->get('nidNumber'));
  8597. //            $em->persist($labour);
  8598. //            $em->flush();
  8599. //            $this->addFlash(
  8600. //                'success',
  8601. //                'Labour Added'
  8602. //            );
  8603. //        }
  8604.         return $this->render('ApplicationBundle:pages/human_resource/input_forms:work_entry.html.twig', array(
  8605.             'page_title' => 'Work Entry',
  8606.         ));
  8607.     }
  8608.     public function ViewContractLetterAction(Request $request$id)
  8609.     {
  8610.         $em $this->getDoctrine()->getManager();
  8611.         $employeeDetail $em->getRepository('ApplicationBundle:EmployeeDetails')->find($id);
  8612. //        $employeeData = [];
  8613. //        foreach ($employeeDetails as $employeeDetail) {
  8614. //            $data = array(
  8615. //                'firstName' => $employeeDetail->getNid(),
  8616. //
  8617. //
  8618. //
  8619. //            );
  8620. //
  8621. //
  8622. //            $employeeData[] = $data;
  8623. //        }
  8624.         return $this->render('ApplicationBundle:pages/human_resource/views:viewContractLetter.html.twig', array(
  8625.             'page_title' => 'Contract Letter',
  8626.             'employeeDetail' => $employeeDetail
  8627.         ));
  8628.     }
  8629.     public function getAttendanceReportForEmployeeAction(Request $request)
  8630.     {
  8631.         $em $this->getDoctrine()->getManager();
  8632.         $session $request->getSession();
  8633.         $fromDateRow = (new \DateTime($request->get('start_date''')));
  8634. //        $fromDate = $fromDateRow->format("M d, Y");
  8635.         $toDateRow = (new \DateTime($request->get('end_date'$fromDateRow) . ' 23:59:59'));
  8636. //        $toDate = $toDateRow->format("M d, Y");
  8637. //        $startDate = "2025-02-13";
  8638. //        $endDate = "2025-02-16";
  8639.         $userId $session->get(UserConstants::USER_ID);
  8640.         $attendanceDetails $em->getRepository('ApplicationBundle:EmployeeAttendance')->createQueryBuilder('A')
  8641. //            ->select('A.createdAt','A.data')
  8642.             ->where('A.sysId = :userId')
  8643.             ->andWhere('A.createdAt >=  :startDate')
  8644.             ->andWhere('A.createdAt <=  :endDate')
  8645.             ->setParameter('userId'$userId)
  8646.             ->setParameter('startDate'$fromDateRow)
  8647.             ->setParameter('endDate'$toDateRow)
  8648.             ->getQuery()
  8649.             ->getResult();
  8650.         $attendance = [];
  8651.         $dt = [];
  8652.         foreach ($attendanceDetails as $data) {
  8653.             $in_out_data json_decode($data->getData(), true);
  8654.             $new_in_data = [];
  8655.             $elapsed_data = [];
  8656.             $new_out_data = [];
  8657.             if ($in_out_data == null$in_out_data = [];
  8658.             if (isset($in_out_data['in'])) {
  8659.                 foreach ($in_out_data['in'] as $ind => $g) {
  8660.                     if (!isset($elapsed_data[$ind])) {
  8661.                         $elapsed_data[$ind] = 0;
  8662.                     }
  8663.                     $the_time = new \DateTime($data->getDate()->format('Y-m-d ') . $g ' +0000');
  8664.                     $new_in_data[] = $the_time->format('U');
  8665.                 }
  8666.             }
  8667.             if (isset($in_out_data['out'])) {
  8668.                 foreach ($in_out_data['out'] as $ind => $g) {
  8669.                     if (!isset($elapsed_data[$ind])) {
  8670.                         $elapsed_data[$ind] = 0;
  8671.                     }
  8672.                     $the_time = new \DateTime($data->getDate()->format('Y-m-d ') . $g ' +0000');
  8673.                     $new_out_data[] = $the_time->format('U');
  8674.                     if (isset($new_in_data[$ind])) {
  8675.                         $elapsed_data[$ind] = $new_out_data[$ind] - $new_in_data[$ind];
  8676.                     }
  8677.                 }
  8678.             }
  8679.             $list = array(
  8680.                 'date' => $data->getDate()->format('F d Y'),
  8681.                 'attendanceData' => [
  8682.                     'in' => $new_in_data,
  8683.                     'out' => $new_out_data,
  8684.                     'elapsedSec' => $elapsed_data,
  8685.                 ]
  8686.             );
  8687.             $dt[] = $list;
  8688.         }
  8689.         $count count($attendance);
  8690. //        for ($i=0;$i < $count; $i++){
  8691. //            $dt[] = $attendance[$i]['date'];
  8692. //            $dt[] = ($attendance[$i]['attendanceData']);
  8693. //        }
  8694. ////        $decodeData = json_decode($dt, true);
  8695. //
  8696. //        $work_hours = [];
  8697. //
  8698. //        foreach ($dt as $index => $entry) {
  8699. //            $in_times = $entry['in'];
  8700. //            $out_times = $entry['out'];
  8701. //
  8702. //
  8703. //            $count = min(count($in_times), count($out_times));
  8704. //
  8705. //            for ($i = 0; $i < $count; $i++) {
  8706. //                $time_in = new DateTime($in_times[$i]);
  8707. //                $time_out = new DateTime($out_times[$i]);
  8708. //
  8709. //
  8710. //                $interval = $time_in->diff($time_out);
  8711. //                $total_hours = $interval->format('%h');
  8712. //                $total_minutes = $interval->format('%i');
  8713. //
  8714. //
  8715. //                $work_hours[] = [
  8716. ////                    "set" => $index + 1,
  8717. //                    "in" => $in_times[$i],
  8718. //                    "out" => $out_times[$i],
  8719. //                    "worked" => "$total_hours hours, $total_minutes minutes"
  8720. //                ];
  8721. //            }
  8722. //        }
  8723. //
  8724. ////        foreach ($work_hours as $work) {
  8725. ////           return new  JsonResponse(
  8726. ////               array(
  8727. ////                   'in'=>$work['in'],
  8728. ////                   'out' => $work['out'],
  8729. ////                   'hour' => $work['worked']
  8730. ////               )
  8731. ////           ) ;
  8732. //////            echo "Set {$work['set']} - IN: {$work['in']} - OUT: {$work['out']} => Worked: {$work['worked']}\n";
  8733. ////        }
  8734.         return new JsonResponse($dt);
  8735.     }
  8736.     public function getTotalWorkHourAction(Request $request)
  8737.     {
  8738.         $em $this->getDoctrine()->getManager();
  8739.         $currentDate = new \DateTime(date('y-m-d'));
  8740.         $session $request->getSession();
  8741.         $token $session->get(UserConstants::USER_TOKEN);
  8742.         $employeeId $session->get(UserConstants::USER_EMPLOYEE_ID);
  8743.         $planningItemId $session->get(UserConstants::USER_CURRENT_PLANNING_ITEM_ID);
  8744.         $attendanceData $em->getRepository('ApplicationBundle:EmployeeAttendance');
  8745.         $currentStatus HumanResource::getCurrentStatusFromDb($attendanceData$employeeId$currentDate);
  8746.         $providedToken $request->headers->get('auth-token');
  8747.         if (empty($providedToken) || $providedToken !== $token) {
  8748.             return new JsonResponse([
  8749.                 'status' => 'error',
  8750.                 'message' => 'Token not match or missing',
  8751.             ], 401);
  8752.         }
  8753.         $planningItemDetails $em->getRepository(PlanningItem::class)->createQueryBuilder('p')
  8754.             ->select('p.itemAlias')
  8755.             ->where('p.id = :planningItemId')
  8756.             ->setParameter('planningItemId'$planningItemId)
  8757.             ->getQuery()
  8758.             ->getResult();
  8759.         // Check if "data" key exists and contains "in" times
  8760.         if (empty($currentStatus["data"]["in"])) {
  8761.             return new JsonResponse([
  8762. //                'message' => 'No attendance data available',
  8763.                 'currentStatus' => $currentStatus,
  8764.                 'totalWorkingTime' => '00:00:00'
  8765.             ]);
  8766.         }
  8767.         $totalSeconds 0;
  8768.         for ($i 0$i count($currentStatus["data"]["in"]); $i++) {
  8769.             $inTime $currentStatus["data"]["in"][$i];
  8770.             // Check if "out" time exists for this "in" time
  8771.             if (!isset($currentStatus["data"]["out"][$i])) {
  8772.                 continue; // Skip this entry if there is no out time
  8773.             }
  8774.             $outTime $currentStatus["data"]["out"][$i];
  8775.             // Calculate the difference
  8776.             $totalSeconds += ($outTime $inTime);
  8777.         }
  8778.         // If no valid time pairs were found, return 00:00:00
  8779. //        if ($totalSeconds == 0) {
  8780. //            return new JsonResponse([
  8781. //                'message' => 'No complete in-out records found',
  8782. //                'totalWorkingTime' => '00:00:00'
  8783. //            ]);
  8784. //        }
  8785.         // Convert total seconds to hours, minutes, and seconds
  8786.         $hours floor($totalSeconds 3600);
  8787.         $minutes floor(($totalSeconds 3600) / 60);
  8788.         $seconds $totalSeconds 60;
  8789.         $totalWorkingTime sprintf("%02d:%02d:%02d"$hours$minutes$seconds);
  8790.         return new JsonResponse([
  8791.             'taskName' => isset($planningItemDetails[0]) ? $planningItemDetails[0]['itemAlias'] : '',
  8792.             'currentStatus' => $currentStatus,
  8793.             'totalWorkingTime' => $totalWorkingTime,
  8794.         ]);
  8795.     }
  8796. //    public function getEmployeeDataAction(Request $request)
  8797. //    {
  8798. //        $em = $this->getDoctrine()->getManager();
  8799. //        $session = $request->getSession();
  8800. //        $employeeId = $session->get(UserConstants::USER_EMPLOYEE_ID);
  8801. //
  8802. //
  8803. //        $employeeDetails = $em->getRepository('ApplicationBundle:EmployeeDetails')->createQueryBuilder('E')
  8804. //            ->select('E.firstname', 'E.lastname', 'E.nid', 'E.tin','E.image', 'P.positionName')
  8805. //            ->addSelect('A.current_balance')
  8806. //            ->leftJoin('ApplicationBundle:SysDepartmentPosition', 'P', 'WITH', 'E.desg = P.positionId')
  8807. //            ->leftJoin('ApplicationBundle:Employee', 'EMP', 'WITH', 'EMP.employeeId = E.id')
  8808. //            ->leftJoin('ApplicationBundle:AccAccountsHead', 'A', 'WITH', 'EMP.accountsHeadId = A.accountsHeadId')
  8809. //            ->where('E.id = :employeeId')
  8810. //            ->setParameter('employeeId', $employeeId)
  8811. //            ->getQuery()
  8812. //            ->getResult();
  8813. //
  8814. //        return new JsonResponse($employeeDetails[0]);
  8815. //    }
  8816. //    public function getEmployeeDataAction(Request $request)
  8817. //    {
  8818. //        $em = $this->getDoctrine()->getManager();
  8819. //        $session = $request->getSession();
  8820. //        $employeeId = $session->get(UserConstants::USER_EMPLOYEE_ID);
  8821. //        $image = $session->get(UserConstants::USER_IMAGE);
  8822. //        $absoluteUrl = $this->generateUrl('dashboard', [], UrlGenerator::ABSOLUTE_URL);
  8823. //
  8824. //        $employeeDetails = $em->getRepository('ApplicationBundle:EmployeeDetails')->createQueryBuilder('E')
  8825. //            ->select('E.firstname', 'E.lastname', 'E.nid', 'E.tin', 'E.image', 'P.positionName')
  8826. //            ->addSelect('A.current_balance')
  8827. //            ->leftJoin('ApplicationBundle:SysDepartmentPosition', 'P', 'WITH', 'E.desg = P.positionId')
  8828. //            ->leftJoin('ApplicationBundle:Employee', 'EMP', 'WITH', 'EMP.employeeId = E.id')
  8829. //            ->leftJoin('ApplicationBundle:AccAccountsHead', 'A', 'WITH', 'EMP.accountsHeadId = A.accountsHeadId')
  8830. //            ->where('E.id = :employeeId')
  8831. //            ->setParameter('employeeId', $employeeId)
  8832. //            ->getQuery()
  8833. //            ->getResult();
  8834. //
  8835. //        // If image is null or empty, assign empty string
  8836. //        if (empty($employeeDetails['image'])) {
  8837. //            $employeeDetails['image'] =  $image;
  8838. //        }
  8839. //
  8840. //        return new JsonResponse($employeeDetails);
  8841. //    }
  8842.     public function getEmployeeDataAction(Request $request)
  8843.     {
  8844.         $em $this->getDoctrine()->getManager();
  8845.         $session $request->getSession();
  8846.         $employeeId $session->get(UserConstants::USER_EMPLOYEE_ID);
  8847.         $image $session->get(UserConstants::USER_IMAGE);
  8848.         $absoluteUrl $this->generateUrl('dashboard', [], UrlGenerator::ABSOLUTE_URL);
  8849.         $userImage $session->get(UserConstants::USER_IMAGE);
  8850.         $employeeDetails $em->getRepository('ApplicationBundle:EmployeeDetails')->createQueryBuilder('E')
  8851.             ->select('E.firstname''E.lastname''E.nid''E.tin''E.image''P.positionName')
  8852.             ->addSelect('A.current_balance')
  8853.             ->leftJoin('ApplicationBundle:SysDepartmentPosition''P''WITH''E.desg = P.positionId')
  8854.             ->leftJoin('ApplicationBundle:Employee''EMP''WITH''EMP.employeeId = E.id')
  8855.             ->leftJoin('ApplicationBundle:AccAccountsHead''A''WITH''EMP.accountsHeadId = A.accountsHeadId')
  8856.             ->where('E.id = :employeeId')
  8857.             ->setParameter('employeeId'$employeeId)
  8858.             ->getQuery()
  8859.             ->getOneOrNullResult(\Doctrine\ORM\Query::HYDRATE_ARRAY); // Only one employee expected
  8860.         if (!$employeeDetails) {
  8861.             return new JsonResponse(['error' => 'Employee not found'], 404);
  8862.         }
  8863.         // If image is missing, fallback to session image
  8864.         if (empty($employeeDetails['image'])) {
  8865.             $employeeDetails['image'] = $image;
  8866.         }
  8867.         // If image is still available, prefix it with absolute URL
  8868.         if (!empty($employeeDetails['image'])) {
  8869.             $employeeDetails['image_url'] = $absoluteUrl '' $userImage;
  8870.         } else {
  8871.             $employeeDetails['image_url'] = ''// no image
  8872.         }
  8873.         return new JsonResponse($employeeDetails);
  8874.     }
  8875.     public function updateEmployeeDataForAppAction(Request $request)
  8876.     {
  8877.         $em $this->getDoctrine()->getManager();
  8878.         $session $request->getSession();
  8879.         $employeeId $session->get(UserConstants::USER_EMPLOYEE_ID);
  8880.         $employeeDetails $em->getRepository('ApplicationBundle:EmployeeDetails')->find($employeeId);
  8881.         if ($request->isMethod('POST')) {
  8882.             $firstname $request->request->get('firstname');
  8883.             $lastname $request->request->get('lastname');
  8884.             $nid $request->request->get('nid');
  8885.             $tin $request->request->get('tin');
  8886.             if ($firstname !== null) {
  8887.                 $employeeDetails->setFirstName($firstname);
  8888.             }
  8889.             if ($lastname !== null) {
  8890.                 $employeeDetails->setLastName($lastname);
  8891.             }
  8892.             if ($nid !== null) {
  8893.                 $employeeDetails->setNid($nid);
  8894.             }
  8895.             if ($tin !== null) {
  8896.                 $employeeDetails->setTin($tin);
  8897.             }
  8898.             $em->flush();
  8899.             return new JsonResponse(['success' => true]);
  8900.         }
  8901.         return new JsonResponse(['success' => false'message' => 'Invalid request method']);
  8902.     }
  8903. //    public function updateEmployeeDataForAppAction(Request $request){
  8904. //        $em = $this->getDoctrine()->getManager();
  8905. //        $session = $request->getSession();
  8906. //        $employeeId = $session->get(UserConstants::USER_EMPLOYEE_ID);
  8907. //        $employeeDetails = $em->getRepository('ApplicationBundle:EmployeeDetails')->find($employeeId);
  8908. //
  8909. //        if ($request->isMethod('POST')) {
  8910. //            $employeeDetails->setFirstName(($request->request->get('firstname',$employeeDetails->getFirstName())));
  8911. //            $employeeDetails->setLastName($request->request->get('lastname',$employeeDetails->getLastName()));
  8912. //            $employeeDetails->setNid($request->request->get('nid'),$employeeDetails->getNid());
  8913. //            $employeeDetails->setTin($request->request->get('tin'),$employeeDetails->getTin());
  8914. //
  8915. //            $em->flush(); //
  8916. //
  8917. //            return new JsonResponse(['success' => true]);
  8918. //        }
  8919. //
  8920. //
  8921. //    }
  8922.     public function leaveApplicationListForAppAction(Request $request)
  8923.     {
  8924.         $em $this->getDoctrine()->getManager();
  8925.         $session $request->getSession();
  8926.         $employeeId $session->get(UserConstants::USER_EMPLOYEE_ID);
  8927.         $leaveType HumanResourceConstant::$LeaveType;
  8928.         $approvalStatus GeneralConstant::$approvalAction;
  8929.         $leaveCategory HumanResourceConstant::$leavCategory;
  8930.         // Get page and limit from request (default: page=1, limit=10)
  8931.         $page max((int)$request->query->get('page'1), 1);
  8932.         $limit max((int)$request->query->get('limit'10), 1);
  8933.         $offset = ($page 1) * $limit;
  8934.         // Get total count
  8935.         $total $em->getRepository('ApplicationBundle:EmployeeLeaveApplication')
  8936.             ->createQueryBuilder('L')
  8937.             ->select('COUNT(L.employeeLeaveApplicationId)')
  8938.             ->where('L.employeeId = :employeeId')
  8939.             ->setParameter('employeeId'$employeeId)
  8940.             ->getQuery()
  8941.             ->getSingleScalarResult();
  8942.         // Get paginated results
  8943.         $leaveRecords $em->getRepository('ApplicationBundle:EmployeeLeaveApplication')
  8944.             ->createQueryBuilder('L')
  8945.             ->select(
  8946.                 'L.documentHash',
  8947.                 'L.employeeLeaveApplicationId',
  8948.                 'L.leaveStartDate',
  8949.                 'L.leaveEndDate',
  8950.                 'L.leaveTypeId',
  8951.                 'L.leaveCategory',
  8952.                 'L.approved',
  8953.                 'L.createdAt',
  8954.                 'L.alternateDate',
  8955.                 'L.leaveComment',
  8956.                 'L.createdAt',
  8957.                 'L.approved_by'
  8958.             )
  8959.             ->where('L.employeeId = :employeeId')
  8960.             ->setParameter('employeeId'$employeeId)
  8961.             ->setFirstResult($offset)
  8962.             ->setMaxResults($limit)
  8963.             ->getQuery()
  8964.             ->getResult();
  8965.         // Format the results
  8966.         $formattedData = [];
  8967.         foreach ($leaveRecords as $leave) {
  8968.             $formattedData[] = [
  8969.                 'documentHash' => $leave['documentHash'],
  8970.                 'employeeLeaveApplicationId' => $leave['employeeLeaveApplicationId'],
  8971.                 'leaveStartDate' => $leave['leaveStartDate'] ? $leave['leaveStartDate']->getTimestamp() : 0,
  8972.                 'leaveEndDate' => $leave['leaveEndDate'] ? $leave['leaveEndDate']->getTimestamp() : 0,
  8973.                 'leaveType' => $leaveType[$leave['leaveTypeId']] ?? 'Unknown',
  8974.                 'leaveCategory' => $leaveCategory[$leave['leaveCategory']] ?? 'Unknown',
  8975.                 'approved' => $approvalStatus[$leave['approved']] ?? 'Unknown',
  8976.                 'createdAt' => $leave['createdAt'] ? $leave['createdAt']->getTimestamp() : 0,
  8977.                 'alternateDate' => $leave['alternateDate'] ? $leave['alternateDate']->getTimestamp() : 0,
  8978.                 'note' => $leave['leaveComment'] ? $leave['leaveComment'] : '',
  8979.                 'appliedOn' => $leave['createdAt'] ? $leave['createdAt']->getTimestamp() : 0,
  8980.                 'approvedBy' => $leave['approved_by'] ? $leave['approved_by'] : 'automatically approved',
  8981.             ];
  8982.         }
  8983.         // Final response with pagination meta
  8984.         return new JsonResponse([
  8985.             'CurrentPage' => $page,
  8986.             'limit' => $limit,
  8987.             'total' => (int)$total,
  8988.             'data' => $formattedData,
  8989.         ]);
  8990.     }
  8991.     public function PublicProfilePageAction(Request $request)
  8992.     {
  8993.         return new JsonResponse(['success' => true]);
  8994.     }
  8995.     public function leaveSettingsAction(Request $request)
  8996.     {
  8997.         $em $this->getDoctrine()->getManager();
  8998.         if ($request->isMethod('POST')) {
  8999.             $ids $request->request->get('id', []);
  9000.             $leaveTitles $request->request->get('leaveTitle', []);
  9001.             $carryForwardTypes $request->request->get('carryForwardType', []);
  9002.             $carryForwardQtys $request->request->get('number', []);
  9003.             $totalLeaves $request->request->get('totalLeave', []);
  9004.             $resetFreqTypes $request->request->get('resetFrequencyType', []);
  9005.             $resetFreqQtys $request->request->get('resetFrequencyQty', []);
  9006.             $additionConditions $request->request->get('additionCondition', []);
  9007.             $additionDurations $request->request->get('additionConditionDuration', []);
  9008.             for ($i 0$i count($leaveTitles); $i++) {
  9009.                 if (
  9010.                     isset(
  9011.                         $carryForwardTypes[$i],
  9012.                         $carryForwardQtys[$i],
  9013.                         $totalLeaves[$i],
  9014.                         $resetFreqTypes[$i],
  9015.                         $resetFreqQtys[$i],
  9016.                         $additionConditions[$i],
  9017.                         $additionDurations[$i]
  9018.                     )
  9019.                 ) {
  9020.                     $id $ids[$i] ?? null;
  9021.                     $leaveSetting null;
  9022.                     if ($id) {
  9023.                         $leaveSetting $em->getRepository('ApplicationBundle:LeaveSettings')->find($id);
  9024.                     }
  9025.                     if (!$leaveSetting) {
  9026.                         $leaveSetting = new LeaveSettings();
  9027.                     }
  9028.                     $leaveSetting->setLeaveTitle($leaveTitles[$i]);
  9029.                     $leaveSetting->setCarryForwardType((int)$carryForwardTypes[$i]);
  9030.                     $leaveSetting->setCarryForwardQty((int)$carryForwardQtys[$i]);
  9031.                     $leaveSetting->setTotalLeave((int)$totalLeaves[$i]);
  9032.                     $leaveSetting->setResetFrequencyType((int)$resetFreqTypes[$i]);
  9033.                     $leaveSetting->setResetFrequencyQty((int)$resetFreqQtys[$i]);
  9034.                     $leaveSetting->setAdditionCondition((int)$additionConditions[$i]);
  9035.                     $leaveSetting->setAdditionConditionDuration((int)$additionDurations[$i]);
  9036.                     $em->persist($leaveSetting);
  9037.                 }
  9038.             }
  9039.             $em->flush();
  9040.             $this->addFlash('success''Leave settings saved successfully!');
  9041.             return $this->redirectToRoute('leave_settings_list');
  9042.         }
  9043.         $defaultLeaveType HumanResourceConstant::$defaultLeaveType;
  9044.         $savedLeaveSettings $em->getRepository('ApplicationBundle:LeaveSettings')->findAll();
  9045.         $useDefaultLeave count($savedLeaveSettings) === 0;
  9046.         $leaveSettings array_map(function ($setting) {
  9047.             return [
  9048.                 'id' => $setting->getId(),
  9049.                 'leaveTitle' => $setting->getLeaveTitle(),
  9050.                 'carryForwardType' => $setting->getCarryForwardType(),
  9051.                 'carryForwardQty' => $setting->getCarryForwardQty(),
  9052.                 'totalLeave' => $setting->getTotalLeave(),
  9053.                 'resetFrequencyType' => $setting->getResetFrequencyType(),
  9054.                 'resetFrequencyQty' => $setting->getResetFrequencyQty(),
  9055.                 'additionCondition' => $setting->getAdditionCondition(),
  9056.                 'additionConditionDuration' => $setting->getAdditionConditionDuration(),
  9057.             ];
  9058.         }, $savedLeaveSettings);
  9059.         return $this->render('ApplicationBundle:pages/human_resource/input_forms:leave_settings.html.twig', [
  9060.             'page_title' => 'Leave Settings',
  9061.             'defaultLeaveType' => $defaultLeaveType,
  9062.             'leaveSettings' => $leaveSettings,
  9063.             'useDefaultLeave' => $useDefaultLeave,
  9064.         ]);
  9065.     }
  9066.     public function leavePolicyListAction()
  9067.     {
  9068.         return $this->render("ApplicationBundle:pages/human_resource/list:leaveApplicationSettingsList.html.twig", array(
  9069.             'page_title' => 'Leave PolicyList',
  9070.         ));
  9071.     }
  9072. }