Guest User

Untitled

a guest
Jun 30th, 2016
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 88.33 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * This is the MongoDB Document model class based on table "user_leaves".
  5. */
  6. class UserLeaves extends EMongoDocument {
  7.  
  8. const STATUS_PENDING = 1;
  9. const STATUS_APPROVED = 2;
  10. const STATUS_REJECTED = 3;
  11. const STATUS_REVOKED = 4;
  12. const ISOVERUTILIZED_YES = 1;
  13. const ISOVERUTILIZED_NO = 0;
  14. const LEAVE_PAID = 0;
  15. const LEAVE_UNPAID = 1;
  16. const HALF_DAY_NO = 0;
  17. const HALF_DAY_YES = 1;
  18. const LEAVE_ACTION_APPROVE = "approve";
  19. const LEAVE_ACTION_REVOKE = "revoke";
  20.  
  21. public $id;
  22. public $leave_id;
  23. public $parent_leave_id;
  24. public $user_id;
  25. public $from_date;
  26. public $to_date;
  27. public $isUnpaid = self::LEAVE_PAID;
  28. public $isUnpaidAll = self::LEAVE_PAID;
  29. public $overutilization_other_leave = self::LEAVE_UNPAID;
  30. public $is_half_day;
  31. public $orginal_leave;
  32. public $status;
  33. public $message;
  34. public $manager_message;
  35. public $tenant_id;
  36. public $created;
  37. public $is_overutilized = self::ISOVERUTILIZED_NO;
  38. public $compoff_used_date = array();
  39. public $userOptionalHoliday = array();
  40.  
  41. // public $optional_holiday_date = array();
  42. // public $optional_status;
  43.  
  44. /**
  45. * Returns the static model of the specified AR class.
  46. * @return UserLeaves the static model class
  47. */
  48. public static function model($className = __CLASS__) {
  49. return parent::model($className);
  50. }
  51.  
  52. /**
  53. * returns the primary key field for this model
  54. */
  55. public function primaryKey() {
  56. return 'id';
  57. }
  58.  
  59. /**
  60. * @return string the associated collection name
  61. */
  62. public function getCollectionName() {
  63. return 'user_leaves';
  64. }
  65.  
  66. /**
  67. * @return array validation rules for model attributes.
  68. */
  69. public function rules() {
  70. // NOTE: you should only define rules for those attributes that
  71. // will receive user inputs.
  72. return array(
  73. array('leave_id, from_date, to_date, message', 'required', 'on' => 'apply'),
  74. array('leave_id, from_date, to_date, message', 'required', 'on' => 'import'),
  75. array('status', 'numerical', 'integerOnly' => true),
  76. array('leave_id, user_id, tenant_id', 'length', 'max' => 20),
  77. array('from_date, to_date', 'compareDates', 'on' => 'unpaid'),
  78. array('from_date, to_date', 'compareDates', 'on' => 'apply'),
  79. //array('from_date, to_date', 'compareDatesMonth', 'on' => 'apply'),
  80. array('from_date, to_date', 'checkyear', 'on' => 'apply'),
  81. array('from_date, to_date', 'compareImportDates', 'on' => 'import'),
  82. array('from_date', 'checkHalfDayDate', 'compare_date' => 'to_date'),
  83. /* Validating various leave policies based on 'leave_id' */
  84. array('leave_id', 'ext.validators.CLeavePoliciesValidator', 'on' => 'apply'),
  85. array('leave_id', 'ext.validators.CLeavePoliciesValidatorUnpaid', 'on' => 'unpaid'),
  86. );
  87. }
  88.  
  89. public function checkHalfDayDate($attribute, $params) {
  90. if (!$this->hasErrors()) {
  91. if ($this->is_half_day == self::HALF_DAY_YES) {
  92. if ($this->$attribute->sec != $this->$params['compare_date']->sec) {
  93. $this->addError($attribute, 'Start date and End date should be same.');
  94. }
  95. }
  96. }
  97. }
  98.  
  99. public function compareDates($attribute, $params)
  100. {
  101. if (!$this->hasErrors())
  102. {
  103. if ($this->to_date == '' || $this->to_date == '0.00000000 0')
  104. {
  105. $this->addError($attribute, 'Plese enter End Date');
  106. }
  107. else if ($this->from_date == '' || $this->from_date == '0.00000000 0')
  108. {
  109. $this->addError($attribute, 'Plese enter Start Date');
  110. }
  111. else if ($this->from_date > $this->to_date)
  112. {
  113. $this->addError($attribute, 'End Date cannot be before Start Date');
  114. }
  115. }
  116. }
  117.  
  118. public function compareImportDates($attribute, $params) {
  119. if (!$this->hasErrors()) {
  120. if ($this->to_date == '') {
  121. $this->addError($attribute, 'Plese enter End Date');
  122. } else if ($this->from_date->sec > $this->to_date->sec) {
  123. $this->addError($attribute, 'End Date cannot be before Start Date');
  124. }
  125. }
  126. }
  127.  
  128. public function compareDatesMonth($attribute, $params) {
  129. if (!$this->hasErrors()) {
  130. if ($this->from_date->sec < strtotime(date('Y-m-d', strtotime('-1 month')))) {
  131. $this->addError($attribute, 'Invalid Start Date (Leave applications before ' . date('Y-m-d', strtotime('-1 month')) . ' are not allowed).');
  132. }
  133. }
  134. }
  135.  
  136. public function checkyear($attribute, $params)
  137. {
  138. if (!$this->hasErrors())
  139. {
  140. $leave = Leaves::model()->findByPk($this->leave_id);
  141.  
  142. if (isset($leave->p4_carry_over_time) && $leave->p4_carry_over_time == 1)
  143. {
  144. // If leave is "Compensatory Off" then allow user for apply leave for next year is user is applying leave for Jan in Dec month. KT 10th Dec 2015
  145. if($leave->name == "Compensatory Off")
  146. {
  147. $currentdate = date("Y") + 1;
  148. }
  149. else
  150. {
  151. $currentdate = date("Y");
  152. }
  153.  
  154. $start_date = date('Y', $this->from_date->sec);
  155. $end_date = date('Y', $this->to_date->sec);
  156.  
  157. if ($currentdate != $end_date)
  158. {
  159. if ($end_date > $start_date)
  160. {
  161. $this->addError($attribute, 'Leave applications cannot have dates from the next annual leave cycle. You can apply for such leaves only after the completion of your current annual leave cycle.');
  162. }
  163. }
  164.  
  165. if ($start_date > $currentdate)
  166. {
  167. $this->addError($attribute, 'Leave applications cannot have dates from the next annual leave cycle. You can apply for such leaves only after the completion of your current annual leave cycle.');
  168. }
  169. }
  170. else
  171. {
  172. $currentdate = date("Y-m");
  173. $start_date = date('Y-m', $this->from_date->sec);
  174. $end_date = date('Y-m', $this->to_date->sec);
  175. $currentdatearr = explode('-', $currentdate);
  176. $end_datearr = explode('-', $end_date);
  177. $start_datearr = explode('-', $start_date);
  178.  
  179. if ($start_datearr[0] > $currentdatearr[0])
  180. {
  181. if ($start_datearr[1] > 3)
  182. {
  183. $this->addError($attribute, 'Leave applications cannot have dates from the next annual leave cycle. You can apply for such leaves only after the completion of your current annual leave cycle1.');
  184. }
  185.  
  186. if ($start_datearr[0] > $currentdatearr[0] + 1)
  187. {
  188. $this->addError($attribute, 'Leave applications cannot have dates from the next annual leave cycle. You can apply for such leaves only after the completion of your current annual leave cycle2.');
  189. }
  190. }
  191.  
  192. if ($start_datearr[0] == $currentdatearr[0] + 1)
  193. {
  194. if ($end_datearr[1] > 3)
  195. {
  196. $this->addError($attribute, 'Leave applications cannot have dates from the next annual leave cycle. You can apply for such leaves only after the completion of your current annual leave cycle3.');
  197. }
  198. }
  199.  
  200. if ($end_datearr[0] > $start_datearr[0])
  201. {
  202. if ($end_datearr[0] > $start_datearr[0] + 1)
  203. {
  204. $this->addError($attribute, 'Leave applications cannot have dates from the next annual leave cycle. You can apply for such leaves only after the completion of your current annual leave cycle.4');
  205. }
  206.  
  207. if ($end_datearr[1] > 3)
  208. {
  209. $this->addError($attribute, 'Leave applications cannot have dates from the next annual leave cycle. You can apply for such leaves only after the completion of your current annual leave cycle5.');
  210. }
  211. }
  212. }
  213. }
  214. }
  215.  
  216. /**
  217. * @return array customized attribute labels (name=>label)
  218. */
  219. public function attributeLabels() {
  220. return array(
  221. 'id' => 'ID',
  222. 'leave_id' => 'Leave Type',
  223. 'user_id' => 'User',
  224. 'tenant_id' => 'Tenant',
  225. 'from_date' => 'Start Date',
  226. 'to_date' => 'End Date',
  227. 'status' => 'Status',
  228. 'message' => 'Message',
  229. 'manager_message' => 'Manager Message',
  230. 'created' => 'Created',
  231. );
  232. }
  233.  
  234. public static function itemAlias($type, $code = NULL) {
  235. $_items = array(
  236. 'leavetype' => array(
  237. self::STATUS_PENDING => 'Pending',
  238. self::STATUS_APPROVED => 'Approved',
  239. self::STATUS_REJECTED => 'Rejected',
  240. self::STATUS_REVOKED => 'Revoked',
  241. ),
  242. 'isUnpaid' => array(
  243. self::LEAVE_PAID => 'No',
  244. self::LEAVE_UNPAID => 'Yes',
  245. ),
  246. );
  247. if (isset($code))
  248. return isset($_items[$type][$code]) ? $_items[$type][$code] : false;
  249. else
  250. return isset($_items[$type]) ? $_items[$type] : false;
  251. }
  252.  
  253. public function beforeSave() {
  254. if ($this->isNewRecord) {
  255. $this->id = uniqid();
  256. $this->tenant_id = ($this->tenant_id == null) ? Yii::app()->user->getTenantId() : $this->tenant_id;
  257. $this->created = new MongoDate(time());
  258. }
  259. return parent::beforeSave();
  260. }
  261.  
  262. public function tenant($tenant_id = null) {
  263. $this->getDbCriteria()->mergeWith(array(
  264. 'conditions' => array(
  265. 'tenant_id' => array('==' => ($tenant_id == null) ? Yii::app()->user->getTenantId() : $tenant_id),
  266. ),
  267. ));
  268. return $this;
  269. }
  270.  
  271. public function leaveUser($user_id = null) {
  272. $this->getDbCriteria()->mergeWith(array(
  273. 'conditions' => array(
  274. 'user_id' => array('==' => ($user_id == null) ? Yii::app()->user->id : $user_id),
  275. ),
  276. ));
  277. return $this;
  278. }
  279.  
  280. public function leave_request($user_id) {
  281. $this->getDbCriteria()->mergeWith(array(
  282. 'conditions' => array(
  283. 'user_id' => array('==' => $user_id),
  284. 'status' => array('==' => self::STATUS_PENDING),
  285. ),
  286. ));
  287. return $this;
  288. }
  289.  
  290. public function user_approved_leave($user_id = null, $leave_id = null , $start = null , $end = null)
  291. {
  292. if ($leave_id != null && $start == null && $end == null && $user_id != null)
  293. {
  294. $this->getDbCriteria()->mergeWith(array(
  295. 'conditions' => array(
  296. 'user_id' => array('==' => $user_id),
  297. 'status' => array('==' => self::STATUS_APPROVED),
  298. 'leave_id' => array('==' => $leave_id),
  299. ),
  300. ));
  301. }
  302. elseif ($start != null && $end != null && $user_id != null)
  303. {
  304. $this->getDbCriteria()->mergeWith(array(
  305. 'conditions' => array(
  306. 'user_id' => array('==' => $user_id),
  307. 'to_date' => array('>=' => $start),
  308. 'from_date' => array('<=' => $end),
  309. 'leave_id' => array('==' => $leave_id),
  310. 'status' => array('==' => self::STATUS_APPROVED),
  311. ),
  312. ));
  313. }
  314. elseif ($leave_id != null && $start != null && $end == null && $user_id != null)
  315. {
  316. $this->getDbCriteria()->mergeWith(array(
  317. 'conditions' => array(
  318. 'user_id' => array('==' => $user_id),
  319. 'from_date' => array('>=' => $start),
  320. 'leave_id' => array('==' => $leave_id),
  321. 'status' => array('==' => self::STATUS_APPROVED),
  322. ),
  323. ));
  324. }elseif ($leave_id != null && $start == null && $end == null && $user_id == null)
  325. {
  326. $this->getDbCriteria()->mergeWith(array(
  327. 'conditions' => array(
  328. 'leave_id' => array('==' => $leave_id),
  329. 'status' => array('==' => self::STATUS_APPROVED),
  330. ),
  331. ));
  332. }
  333. elseif ($leave_id == null && $start == null && $end == null && $user_id == null)
  334. {
  335. $this->getDbCriteria()->mergeWith(array(
  336. 'conditions' => array(
  337. 'status' => array('==' => self::STATUS_APPROVED),
  338. ),
  339. ));
  340. }
  341. else
  342. {
  343. $this->getDbCriteria()->mergeWith(array(
  344. 'conditions' => array(
  345. 'user_id' => array('==' => $user_id),
  346. 'status' => array('==' => self::STATUS_APPROVED),
  347. ),
  348. ));
  349. }
  350. return $this;
  351. }
  352.  
  353. public function related($related) {
  354. $this->getDbCriteria()->mergeWith(array(
  355. 'conditions' => array(
  356. 'user_id' => array('in' => $related),
  357. ),
  358. ));
  359. return $this;
  360. }
  361.  
  362. public function user_leaves($user_id, $leave_id = null) {
  363. if ($leave_id != null) {
  364. $this->getDbCriteria()->mergeWith(array(
  365. 'conditions' => array(
  366. 'user_id' => array('==' => $user_id),
  367. 'leave_id' => array('==' => $leave_id),
  368. ),
  369. ));
  370. } else {
  371. $this->getDbCriteria()->mergeWith(array(
  372. 'conditions' => array(
  373. 'user_id' => array('==' => $user_id),
  374. ),
  375. ));
  376. }
  377. return $this;
  378. }
  379.  
  380. public function approved() {
  381. $this->getDbCriteria()->mergeWith(array(
  382. 'conditions' => array(
  383. 'status' => array('==' => self::STATUS_APPROVED),
  384. ),
  385. 'sort' => array('from_date' => EMongoCriteria::SORT_DESC),
  386. ));
  387. return $this;
  388. }
  389.  
  390. public function pending() {
  391. $this->getDbCriteria()->mergeWith(array(
  392. 'conditions' => array(
  393. 'status' => array('==' => self::STATUS_PENDING),
  394. ),
  395. ));
  396. return $this;
  397. }
  398.  
  399. public function inRange($start, $end) {
  400. $this->getDbCriteria()->mergeWith(array(
  401. 'conditions' => array(
  402. 'to_date' => array('>=' => $start),
  403. 'from_date' => array('<=' => $end),
  404. ),
  405. 'sort' => array('from_date' => EMongoCriteria::SORT_ASC),
  406. ));
  407. return $this;
  408. }
  409.  
  410. public function paid() {
  411. $this->getDbCriteria()->mergeWith(array(
  412. 'conditions' => array(
  413. 'isUnpaid' => array('==' => UserLeaves::LEAVE_PAID),
  414. ),
  415. ));
  416. return $this;
  417. }
  418.  
  419. public function unpaidCalander() {
  420. $today = new MongoDate(strtotime(date('Y-m-d')));
  421. $year = (int) date('Y') - 1;
  422. $duration = new MongoDate(strtotime("$year-12-31"));
  423. $this->getDbCriteria()->mergeWith(array(
  424. 'conditions' => array(
  425. 'isUnpaid' => array('==' => UserLeaves::LEAVE_UNPAID),
  426. 'from_date' => array('<=' => $today),
  427. 'from_date' => array('>' => $duration),
  428. ),
  429. ));
  430. return $this;
  431. }
  432.  
  433.  
  434.  
  435. public function unpaidFinancial()
  436. {
  437. $tenant_profile = TenantProfile::model()->active()->tenant($this->tenant_id)->find();
  438. $currentyear = (int) date('Y');
  439. $currentmonth = (int) date('m');
  440. $financialmonth = 4;
  441.  
  442. if(isset($tenant_profile->financial_cycle) && $tenant_profile->financial_cycle != "")
  443. {
  444. $financialmonth = (int) $tenant_profile->financial_cycle;
  445. if($currentmonth >= $financialmonth)
  446. {
  447. $duration = new MongoDate(strtotime("$currentyear-$financialmonth-1"));
  448. }
  449. if($currentmonth < $financialmonth)
  450. {
  451. $year = (int) date('Y') -1;
  452. $duration = new MongoDate(strtotime("$year-$financialmonth-1"));
  453. }
  454. }
  455. else
  456. {
  457. if($currentmonth >= $financialmonth)
  458. {
  459. $duration = new MongoDate(strtotime("$currentyear-$financialmonth-1"));
  460. }
  461. if($currentmonth < $financialmonth)
  462. {
  463. $year = (int) date('Y') -1;
  464. $duration = new MongoDate(strtotime("$year-$financialmonth-1"));
  465. }
  466. }
  467. $today = new MongoDate(strtotime(date('Y-m-d')));
  468. $this->getDbCriteria()->mergeWith(array(
  469. 'conditions' => array(
  470. 'isUnpaid' => array('==' => UserLeaves::LEAVE_UNPAID),
  471. 'from_date' => array('<=' => $today),
  472. 'from_date' => array('>=' => $duration),
  473. ),
  474. ));
  475.  
  476. return $this;
  477. }
  478.  
  479. public function unpaid() {
  480. $this->getDbCriteria()->mergeWith(array(
  481. 'conditions' => array(
  482. 'isUnpaid' => array('==' => UserLeaves::LEAVE_UNPAID),
  483. ),
  484. ));
  485. return $this;
  486. }
  487.  
  488. public function duration($duration) {
  489. $today = new MongoDate(strtotime(date('Y-m-d')));
  490. $duration = new MongoDate(strtotime(date('Y-m-d', strtotime('-' . $duration . ' Month'))));
  491. $this->getDbCriteria()->mergeWith(array(
  492. 'conditions' => array(
  493. 'from_date' => array('<=' => $today),
  494. 'from_date' => array('>' => $duration),
  495. ),
  496. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  497. ));
  498. return $this;
  499. }
  500.  
  501. public function forMonth($for_month= null, $from = null, $to = null) {
  502. if(isset($from,$to) && $from != null && $to != null)
  503. {
  504. $first_day = strtotime($from);
  505. $last_day = strtotime($to);
  506. }
  507. else
  508. {
  509. $first_day = strtotime($for_month."-01");
  510. $last_day = strtotime($for_month."-".date('t', $first_day));
  511. }
  512. $this->getDbCriteria()->mergeWith(array(
  513. 'conditions' => array(
  514. 'from_date' => array('>=' => new MongoDate($first_day)),
  515. 'to_date' => array('<=' => new MongoDate($last_day)),
  516. ),
  517. 'sort' => array('created' => EMongoCriteria::SORT_DESC),
  518. ));
  519. return $this;
  520. }
  521.  
  522. public function getCountOfMonths($user_id, $leave_id, $for_month = null , $is_paid = 1, $from = null, $to = null, $location = null, $getCount=false, $getCountOfRang = false)
  523. {
  524. if(isset($from,$to) && $from != null && $to != null)
  525. {
  526. $from = strtotime($from);
  527. $to = strtotime($to);
  528. }
  529. else
  530. {
  531. $from = strtotime($for_month."-01");
  532. $to = strtotime($for_month."-".date('t', $from));
  533. }
  534.  
  535. $criteria = new EMongoCriteria();
  536. $criteria->from_date('<=', new MongoDate($to));
  537. $criteria->from_date('>=', new MongoDate($from));
  538.  
  539. if($is_paid == 1)
  540. {
  541. $leaves_approved = UserLeaves::model()->user_approved_leave($user_id, $leave_id)->paid()->findAll($criteria);
  542. }
  543. else
  544. {
  545. $leaves_approved = UserLeaves::model()->user_approved_leave($user_id, $leave_id)->unpaid()->findAll($criteria);
  546. }
  547. $total_working_days_one = array();
  548. foreach ($leaves_approved as $leaves)
  549. {
  550. $applied_leave_data = Leaves::model()->tenant($leaves->tenant_id)->findByPk($leaves->leave_id);
  551.  
  552. if(isset($applied_leave_data->policy_count_intervening_holidays->status) && $applied_leave_data->policy_count_intervening_holidays->status == LeavePolicy_InterveningHolidays::STATUS_ACTIVE)
  553. {
  554. //if(isset($applied_leave_data->policy_count_intervening_holidays->count_intervening_holidays->count_public_holiday) && $applied_leave_data->policy_count_intervening_holidays->count_intervening_holidays->count_public_holiday == 1 && isset($applied_leave_data->policy_count_intervening_holidays->count_intervening_holidays->count_weekly_off) && $applied_leave_data->policy_count_intervening_holidays->count_intervening_holidays->count_weekly_off == 1)
  555. if(isset($applied_leave_data->policy_count_intervening_holidays->count_intervening_holidays['count_public_holiday']) && $applied_leave_data->policy_count_intervening_holidays->count_intervening_holidays['count_public_holiday'] == 1 && isset($applied_leave_data->policy_count_intervening_holidays->count_intervening_holidays['count_weekly_off']) && $applied_leave_data->policy_count_intervening_holidays->count_intervening_holidays['count_weekly_off'] == 1)
  556. {
  557. /***Code correction not counting leaves applied on weekoff/holiday only if Intervening is ON [SG 10 Feb 2016]***/
  558. if($getCount)
  559. {
  560. $total_working_days_one = array_merge($total_working_days_one, RandomHelper::getWorkingDaysAccToLeavesPolicy($leaves->from_date->sec, $leaves->to_date->sec, $user_id, $leaves->tenant_id, $leaves->id, $location, true, $leaves->userOptionalHoliday));
  561. }
  562. else
  563. {
  564. $total_working_days_one = array_merge($total_working_days_one, RandomHelper::getWorkingDaysIncludingWeeklyoff($leaves->from_date->sec, $leaves->to_date->sec, $user_id, $leaves->tenant_id));
  565. }
  566. //$working_days = RandomHelper::getWorkingDaysIncludingWeeklyoff($le->from_date->sec, $le->to_date->sec, $user->mongo()->id, $user->tenant_id);
  567. //$total_days = count($working_days);
  568. }
  569. elseif (isset($applied_leave_data->policy_count_intervening_holidays->count_intervening_holidays['count_public_holiday']) && $applied_leave_data->policy_count_intervening_holidays->count_intervening_holidays['count_public_holiday'] == 1 && ((isset($applied_leave_data->policy_count_intervening_holidays->count_intervening_holidays['count_weekly_off']) && $applied_leave_data->policy_count_intervening_holidays->count_intervening_holidays['count_weekly_off'] == 0) || (!isset($applied_leave_data->policy_count_intervening_holidays->count_intervening_holidays['count_weekly_off'])) ))
  570. {
  571. /***Added below code not counting leaves applied on weekoff/holiday only if Intervening is ON [SG 16 Feb 2016]***/
  572. if($getCount)
  573. {
  574. $total_working_days_one = array_merge($total_working_days_one, RandomHelper::getWorkingDaysAccToLeavesPolicy($leaves->from_date->sec, $leaves->to_date->sec, $user_id, $leaves->tenant_id, $leaves->id, $location, true, $leaves->userOptionalHoliday));
  575. }
  576. else
  577. {
  578. $total_working_days_one = array_merge($total_working_days_one, RandomHelper::getWorkingDays($leaves->from_date->sec, $leaves->to_date->sec, $user_id, $leaves->tenant_id));
  579. }
  580. //$working_days = RandomHelper::getWorkingDays($le->from_date->sec, $le->to_date->sec, $user->mongo()->id, $user->tenant_id);
  581. //$total_days = count($working_days);
  582. }
  583. else
  584. {
  585. /***Added below code not counting leaves applied on weekoff/holiday only if Intervening is ON [SG 16 Feb 2016]***/
  586. if($getCount)
  587. {
  588. $total_working_days_one = array_merge($total_working_days_one, RandomHelper::getWorkingDaysAccToLeavesPolicy($leaves->from_date->sec, $leaves->to_date->sec, $user_id, $leaves->tenant_id, $leaves->id, $location, true, $leaves->userOptionalHoliday));
  589. }
  590. else
  591. {
  592. $total_working_days_one = array_merge($total_working_days_one, RandomHelper::getWorkingDaysIncludingWeeklyoff($leaves->from_date->sec, $leaves->to_date->sec, $user_id, $leaves->tenant_id));
  593. $holidays_year = RandomHelper::getHolidaysWithYear($leaves->from_date->sec, $leaves->to_date->sec, $leaves->tenant_id, array(), $leaves->user($leaves->tenant_id)->personal->office_location);
  594. /**/
  595. $total_working_days_one = RandomHelper::excludeHolidaysNew($total_working_days_one, $holidays_year);
  596. }
  597. //$working_days = RandomHelper::getWorkingDaysIncludingWeeklyoff($le->from_date->sec, $le->to_date->sec, $user->mongo()->id, $user->tenant_id);
  598. //$total_days = count($working_days);
  599. }
  600. }
  601. else
  602. {
  603. $total_working_days_one = array_merge($total_working_days_one, RandomHelper::getWorkingDays($leaves->from_date->sec, $leaves->to_date->sec, $user_id, $leaves->tenant_id));
  604. /**/
  605. // $holidays_year = RandomHelper::getHolidaysWithYear($leaves->from_date->sec, $leaves->to_date->sec, $leaves->tenant_id, array(), $leaves->user($leaves->tenant_id)->personal->office_location);
  606. //Commented above it was fetching only current year holidays now will get holidays as per the applied date[SG 12 Feb 2016]
  607. $holidays_year = RandomHelper::getHolidaysWithYearForHoliday($leaves->from_date->sec, $leaves->to_date->sec, $leaves->tenant_id, $leaves->user($leaves->tenant_id)->personal->office_location, $leaves->user($leaves->tenant_id)->id, $leaves->userOptionalHoliday);
  608. $total_working_days_one = RandomHelper::excludeHolidaysNew($total_working_days_one, $holidays_year);
  609. //$total_days = count(RandomHelper::excludeHolidays($working_days, $holidays));
  610. }
  611. //$total_working_days_one = array_merge($total_working_days_one, RandomHelper::getWorkingDays($leaves->from_date->sec, $leaves->to_date->sec, $user_id, $leaves->tenant_id));
  612. }
  613. $criteria = new EMongoCriteria();
  614. $criteria->to_date('>=', new MongoDate($from));
  615. $criteria->to_date('<=', new MongoDate($to));
  616. // $leaves_approved = UserLeaves::model()->user_approved_leave($user_id, $leave_id)->paid()->findAll($criteria);
  617. if($is_paid == 1)
  618. {
  619. $leaves_approved = UserLeaves::model()->user_approved_leave($user_id, $leave_id)->paid()->findAll($criteria);
  620. }
  621. else
  622. {
  623. $leaves_approved = UserLeaves::model()->user_approved_leave($user_id, $leave_id)->unpaid()->findAll($criteria);
  624. }
  625. /*** Previous leaves Calculation if applied on last month and carrying to next month [SG 11 Feb 2016] ***/
  626. $past_dates = array();
  627. if(isset($leaves_approved) && !empty($leaves_approved))
  628. {
  629. foreach ($leaves_approved as $model)
  630. {
  631. if($model->from_date->sec < $from)
  632. {
  633. $total_new_days = RandomHelper::getDaysWithDate($model->from_date->sec, $model->to_date->sec, true);
  634. $weekoff = UserWeeklyOff::getNonWorkingDays($model->user_id, $model->from_date->sec, $model->to_date->sec, $model->tenant_id);
  635. $past_dates = array_diff($total_new_days, $weekoff);
  636. }
  637. }
  638. }
  639. $total_working_days_two = array();
  640. foreach ($leaves_approved as $leaves)
  641. {
  642. $applied_leave_data = Leaves::model()->tenant($leaves->tenant_id)->findByPk($leaves->leave_id);
  643. if(isset($applied_leave_data->policy_count_intervening_holidays->status) && $applied_leave_data->policy_count_intervening_holidays->status == LeavePolicy_InterveningHolidays::STATUS_ACTIVE)
  644. {
  645. if(isset($applied_leave_data->policy_count_intervening_holidays->count_intervening_holidays['count_public_holiday']) && $applied_leave_data->policy_count_intervening_holidays->count_intervening_holidays['count_public_holiday'] == 1 && isset($applied_leave_data->policy_count_intervening_holidays->count_intervening_holidays['count_weekly_off']) && $applied_leave_data->policy_count_intervening_holidays->count_intervening_holidays['count_weekly_off'] == 1)
  646. {
  647. /***Code correction not counting leaves applied on weekoff/holiday only if Intervening is ON [SG 10 Feb 2016]***/
  648. if($getCount)
  649. {
  650. $total_working_days_two = array_merge($total_working_days_two, RandomHelper::getWorkingDaysAccToLeavesPolicy($leaves->from_date->sec, $leaves->to_date->sec, $user_id, $leaves->tenant_id, $leaves->id, $location, true, $leaves->userOptionalHoliday));
  651. if(!empty($past_dates))
  652. {
  653. /** This is for leave applied from last month to this month only **/
  654. $total_working_days_two = array_merge($total_working_days_two, $past_dates);
  655. }
  656. }
  657. else
  658. {
  659. $total_working_days_two = array_merge($total_working_days_one, RandomHelper::getWorkingDaysIncludingWeeklyoff($leaves->from_date->sec, $leaves->to_date->sec, $user_id, $leaves->tenant_id));
  660. }
  661. // $total_working_days_two = array_merge($total_working_days_two, RandomHelper::getWorkingDaysIncludingWeeklyoff($leaves->from_date->sec, $leaves->to_date->sec, $user_id, $leaves->tenant_id));
  662. }
  663. elseif (isset($applied_leave_data->policy_count_intervening_holidays->count_intervening_holidays['count_public_holiday']) && $applied_leave_data->policy_count_intervening_holidays->count_intervening_holidays['count_public_holiday'] == 1 && ((isset($applied_leave_data->policy_count_intervening_holidays->count_intervening_holidays['count_weekly_off']) && $applied_leave_data->policy_count_intervening_holidays->count_intervening_holidays['count_weekly_off'] == 0) || (!isset($applied_leave_data->policy_count_intervening_holidays->count_intervening_holidays['count_weekly_off'])) ))
  664. {
  665. /***Code correction not counting leaves applied on weekoff/holiday only if Intervening is ON [SG 16 Feb 2016]***/
  666. if($getCount)
  667. {
  668. $total_working_days_two = array_merge($total_working_days_two, RandomHelper::getWorkingDaysAccToLeavesPolicy($leaves->from_date->sec, $leaves->to_date->sec, $user_id, $leaves->tenant_id, $leaves->id, $location, true, $leaves->userOptionalHoliday));
  669. if(!empty($past_dates))
  670. {
  671. /** This is for leave applied from last month to this month only **/
  672. $total_working_days_two = array_merge($total_working_days_two, $past_dates);
  673. }
  674. }
  675. else
  676. {
  677. $total_working_days_two = array_merge($total_working_days_two, RandomHelper::getWorkingDays($leaves->from_date->sec, $leaves->to_date->sec, $user_id, $leaves->tenant_id));
  678. //$working_days = RandomHelper::getWorkingDays($le->from_date->sec, $le->to_date->sec, $user->mongo()->id, $user->tenant_id);
  679. //$total_days = count($working_days);
  680. }
  681. }
  682. else
  683. {
  684. /***Code correction not counting leaves applied on weekoff/holiday only if Intervening is ON [SG 16 Feb 2016]***/
  685. if($getCount)
  686. {
  687. $total_working_days_two = array_merge($total_working_days_two, RandomHelper::getWorkingDaysAccToLeavesPolicy($leaves->from_date->sec, $leaves->to_date->sec, $user_id, $leaves->tenant_id, $leaves->id, $location, true, $leaves->userOptionalHoliday));
  688. if(!empty($past_dates))
  689. {
  690. /** This is for leave applied from last month to this month only **/
  691. $total_working_days_two = array_merge($total_working_days_two, $past_dates);
  692. }
  693. }
  694. else
  695. {
  696. $total_working_days_two = array_merge($total_working_days_two, RandomHelper::getWorkingDaysIncludingWeeklyoff($leaves->from_date->sec, $leaves->to_date->sec, $user_id, $leaves->tenant_id));
  697. $holidays_year = RandomHelper::getHolidaysWithYear($leaves->from_date->sec, $leaves->to_date->sec, $leaves->tenant_id, array(), $leaves->user($leaves->tenant_id)->personal->office_location);
  698. $total_working_days_two = RandomHelper::excludeHolidaysNew($total_working_days_two, $holidays_year);
  699. //$working_days = RandomHelper::getWorkingDaysIncludingWeeklyoff($le->from_date->sec, $le->to_date->sec, $user->mongo()->id, $user->tenant_id);
  700. //$total_days = count($working_days);
  701. }
  702. }
  703. }
  704. else
  705. {
  706. $total_working_days_two = array_merge($total_working_days_two, RandomHelper::getWorkingDays($leaves->from_date->sec, $leaves->to_date->sec, $user_id, $leaves->tenant_id));
  707. // $holidays_year = RandomHelper::getHolidaysWithYear($leaves->from_date->sec, $leaves->to_date->sec, $leaves->tenant_id, array(), $leaves->user($leaves->tenant_id)->personal->office_location);
  708. //Commented above it was fetching only current year holidays now will get holidays as per the applied date[SG 12 Feb 2016]
  709. $holidays_year = RandomHelper::getHolidaysWithYearForHoliday($leaves->from_date->sec, $leaves->to_date->sec, $leaves->tenant_id, $leaves->user($leaves->tenant_id)->personal->office_location, $leaves->user($leaves->tenant_id)->id, $leaves->userOptionalHoliday);
  710. /**/
  711. $total_working_days_two = RandomHelper::excludeHolidaysNew($total_working_days_two, $holidays_year);
  712. //$total_days = count(RandomHelper::excludeHolidays($working_days, $holidays));
  713. }
  714. // $total_working_days_two = array_merge($total_working_days_two, RandomHelper::getWorkingDays($leaves->from_date->sec, $leaves->to_date->sec, $user_id, $leaves->tenant_id));
  715. }
  716.  
  717. if(empty($total_working_days_two))
  718. {
  719. $total_working_days_two = array_merge($total_working_days_two, $total_working_days_one);
  720. }
  721. else
  722. {
  723. foreach ($total_working_days_one as $key_one_new => $value_one_new)
  724. {
  725. if( date("Y-m",strtotime($value_one_new)) == $for_month )
  726. {
  727. $total_working_days_two[] = $value_one_new;
  728. }
  729. if( $getCountOfRang == true ){
  730. $total_working_days_two[] = $value_one_new;
  731. }
  732. }
  733. $total_working_days_two = array_unique($total_working_days_two, SORT_REGULAR);
  734. }
  735. //filter for current month days
  736. $days_list = self::getDateList($from, $to);
  737. $total_working_days_two_new = array();
  738.  
  739. foreach ($total_working_days_two as $total_working_days)
  740. {
  741. if(in_array($total_working_days, $days_list))
  742. {
  743. $total_working_days_two_new[] = $total_working_days;
  744. }
  745. }
  746. return count($total_working_days_two_new);
  747. }
  748.  
  749. public static function getDateList($from, $to) {
  750. $date_list = array();
  751. while($from <= $to) {
  752. $date_list[] = date('Y-m-d', $from);
  753. $from = strtotime('+1 day', $from);
  754. }
  755. return $date_list;
  756. }
  757.  
  758. public function message($tenant_id = null) {
  759. if(isset($tenant_id) && $tenant_id == null)
  760. {
  761. return Messages::model()->tenant()->findByAttributes(array('filter_type' => Notifications::FILTER_LEAVE, 'attachments.items.id' => $this->id, 'thread_id' => '0'));
  762. }
  763. else
  764. {
  765. return Messages::model()->tenant($tenant_id)->findByAttributes(array('filter_type' => Notifications::FILTER_LEAVE, 'attachments.items.id' => $this->id, 'thread_id' => '0'));
  766. }
  767. }
  768.  
  769. public function leaveType() {
  770. return Leaves::model()->tenant()->findByPk($this->leave_id);
  771. }
  772.  
  773. public function user($tenant_id = null) {
  774. return UserMongo::model()->tenant($tenant_id)->findByPk($this->user_id);
  775. }
  776.  
  777. public static function paidUnpaid() {
  778. $data = array(
  779. UserLeaves::LEAVE_PAID => UserLeaves::itemAlias('isUnpaid', UserLeaves::LEAVE_PAID),
  780. UserLeaves::LEAVE_UNPAID => UserLeaves::itemAlias('isUnpaid', UserLeaves::LEAVE_UNPAID)
  781. );
  782. return $data;
  783. }
  784.  
  785. public function interveningHolidays($tenant_id = null, $isHalfDay = false) {
  786. $leave = Leaves::model()->findByPk($this->leave_id);
  787. if( !isset($leave) && empty($leave) ) {
  788. $leave_unpaid = TenantUnpaidLeave::model()->findByAttributes(array('tenant_id' => Yii::app()->user->getTenantId()));
  789. if(isset($leave_unpaid) && !empty($leave_unpaid)) {
  790. if(isset($leave_unpaid->count_weekly_off,$leave_unpaid->count_holiday) && ($leave_unpaid->count_weekly_off == TenantUnpaidLeave::STATUS_ACTIVE || $leave_unpaid->count_holiday == 2)) {
  791. $leave->policy_count_intervening_holidays->status = LeavePolicy_InterveningHolidays::STATUS_ACTIVE;
  792. if($leave_unpaid->count_weekly_off == TenantUnpaidLeave::STATUS_ACTIVE && $leave_unpaid->count_holiday == 2)
  793. {
  794. $leave->policy_count_intervening_holidays->count_intervening_holidays['count_weekly_off'] = LeavePolicy_InterveningHolidays::COUNT_INTERVENING_HOLIDAY;
  795. $leave->policy_count_intervening_holidays->count_intervening_holidays['count_public_holiday'] = LeavePolicy_InterveningHolidays::COUNT_INTERVENING_HOLIDAY;
  796. } elseif($leave_unpaid->count_weekly_off == TenantUnpaidLeave::STATUS_ACTIVE) {
  797. $leave->policy_count_intervening_holidays->count_intervening_holidays['count_weekly_off'] = LeavePolicy_InterveningHolidays::COUNT_INTERVENING_HOLIDAY;
  798. } elseif($leave_unpaid->count_holiday == 2) {
  799. $leave->policy_count_intervening_holidays->count_intervening_holidays['count_public_holiday'] = LeavePolicy_InterveningHolidays::COUNT_INTERVENING_HOLIDAY;
  800. }
  801. } else {
  802. $leave->policy_count_intervening_holidays->status = LeavePolicy_InterveningHolidays::STATUS_INACTIVE;
  803. }
  804. }
  805. }
  806.  
  807. if ($leave != null && $this->user($tenant_id) != null && $this->user($tenant_id)->department != null) {
  808. $all_days = RandomHelper::getDaysWithDate($this->from_date->sec, $this->to_date->sec, true);
  809. $non_working_days_new_check = UserWeeklyOff::getNonWorkingDays($this->user($tenant_id)->id, $this->from_date->sec, $this->to_date->sec, $this->tenant_id);
  810. $holidays_year_new_check = RandomHelper::getHolidaysWithYearForHoliday($this->from_date->sec, $this->to_date->sec, $tenant_id, $this->user($tenant_id)->personal->office_location, $this->user($tenant_id)->id, $this->userOptionalHoliday);
  811. $original_applied_days = $all_days;
  812. $common_days = array_intersect($non_working_days_new_check, $holidays_year_new_check);
  813. $all_days = array_diff($all_days, $common_days);
  814.  
  815. // Count Intervening Holidays in Leave
  816. if ($leave->policy_count_intervening_holidays->status == LeavePolicy_InterveningHolidays::STATUS_ACTIVE) {
  817. if(!empty($all_days) ) {
  818. if ($leave->policy_count_intervening_holidays->count_intervening_holidays != null)
  819. {
  820. // this condition count both are true (PUBLIC HOLIDAY and WEEKLY OFF)
  821. if (isset($leave->policy_count_intervening_holidays->count_intervening_holidays['count_public_holiday']) && isset($leave->policy_count_intervening_holidays->count_intervening_holidays['count_weekly_off']) && $leave->policy_count_intervening_holidays->count_intervening_holidays['count_public_holiday'] == LeavePolicy_InterveningHolidays::COUNT_INTERVENING_HOLIDAY && $leave->policy_count_intervening_holidays->count_intervening_holidays['count_weekly_off'] == LeavePolicy_InterveningHolidays::COUNT_INTERVENING_HOLIDAY)
  822. {
  823. // Added th code to get all working days in applied leave including holidays and weekoff [SG 09 Feb 2016]
  824. $final_days = RandomHelper::getInterveinigCalculatedDays($original_applied_days, $non_working_days_new_check, $holidays_year_new_check, true, true);
  825. if($isHalfDay) {
  826. $non_working_days = $non_working_days_new_check;
  827. $holidays_year = $holidays_year_new_check;
  828. } else {
  829. $non_working_days = null;
  830. $holidays_year = null;
  831. }
  832. $not_included = null;
  833. $working_days = $all_days;
  834. $total_days = count($final_days);
  835. }
  836. elseif (isset($leave->policy_count_intervening_holidays->count_intervening_holidays['count_public_holiday']) && !isset($leave->policy_count_intervening_holidays->count_intervening_holidays['count_weekly_off']) && $leave->policy_count_intervening_holidays->count_intervening_holidays['count_public_holiday'] == LeavePolicy_InterveningHolidays::COUNT_INTERVENING_HOLIDAY)
  837. {
  838. $non_working_days = UserWeeklyOff::getNonWorkingDays($this->user($tenant_id)->id, $this->from_date->sec, $this->to_date->sec, $this->tenant_id);
  839. $holidays_year = null;
  840. $not_included = $non_working_days;
  841. $working_days = array_diff($all_days, $non_working_days);
  842. $total_days = count(RandomHelper::getInterveinigCalculatedDays($original_applied_days,$non_working_days, $holidays_year_new_check, true, false));
  843.  
  844. }
  845. elseif (!isset($leave->policy_count_intervening_holidays->count_intervening_holidays['count_public_holiday']) && isset($leave->policy_count_intervening_holidays->count_intervening_holidays['count_weekly_off']) && $leave->policy_count_intervening_holidays->count_intervening_holidays['count_weekly_off'] == LeavePolicy_InterveningHolidays::COUNT_INTERVENING_HOLIDAY)
  846. {
  847. /* COUNT WEEKLY OFF CHECK */
  848. $non_working_days = UserWeeklyOff::getNonWorkingDays($this->user($tenant_id)->id, $this->from_date->sec, $this->to_date->sec, $this->tenant_id);
  849. $holidays_year = RandomHelper::getHolidaysWithYearForHoliday($this->from_date->sec, $this->to_date->sec, $tenant_id, $this->user($tenant_id)->personal->office_location, $this->user($tenant_id)->id, $this->userOptionalHoliday);
  850. $not_included = $holidays_year;
  851. $working_days = array_diff($all_days, $holidays_year);
  852. $total_days = count(RandomHelper::getInterveinigCalculatedDays($original_applied_days,$non_working_days, $holidays_year, false, true));
  853. }
  854. } else {
  855. $non_working_days = null;
  856. $holidays_year = null;
  857. $not_included = null;
  858. $working_days = $all_days;
  859. $total_days = count($working_days);
  860. }
  861. } else {
  862. $non_working_days = $common_days;
  863. $holidays_year = $common_days;
  864. $not_included = $common_days;
  865. $working_days = $all_days;
  866. $total_days = 0;
  867. }
  868. } else {
  869. $non_working_days = UserWeeklyOff::getNonWorkingDays($this->user($tenant_id)->id, $this->from_date->sec, $this->to_date->sec, $this->tenant_id);
  870. //Changes to count holidays for back date also [SG 12 Feb 2016]
  871.  
  872. $holidays_year = RandomHelper::getHolidaysWithYearForHoliday($this->from_date->sec, $this->to_date->sec, $tenant_id, $this->user($tenant_id)->personal->office_location, $this->user($tenant_id)->id, $this->userOptionalHoliday);
  873. $not_included = array_merge($non_working_days, $holidays_year);
  874. $working_days = array_diff($all_days, $non_working_days);
  875. $holidays = RandomHelper::getHolidays($this->from_date->sec, $this->to_date->sec, $tenant_id);
  876. $total_days = count(RandomHelper::excludeHolidaysNew($working_days, $holidays_year));
  877. }
  878.  
  879. return array($non_working_days, $holidays_year, $not_included, $total_days);
  880. } else {
  881. $all_days = count(RandomHelper::getDaysWithDate($this->from_date->sec, $this->to_date->sec, true));
  882. return array(null, null, null,$all_days);
  883. }
  884. }
  885.  
  886. /**
  887. * function to check if the user is in leave, if yes then return the user leaves object else empty array
  888. * @param string $user_id mongo id
  889. * @param timestamp $date
  890. * @return object
  891. */
  892. public static function inLeave($user_id, $date, $tenant_id = null) {
  893. $return = array();
  894. $date = strtotime(date('Y-m-d', $date)); // done this as cron sends 12+ in case of next day shift
  895. $user_leaves = UserLeaves::model()->tenant($tenant_id)->user_leaves($user_id)->findAll();
  896. if (!empty($user_leaves)) {
  897. foreach ($user_leaves as $leave) {
  898. $from_date = $leave->from_date->sec;
  899. $to_date = $leave->to_date->sec;
  900. if ($leave->status == UserLeaves::STATUS_APPROVED || $leave->status == UserLeaves::STATUS_PENDING) {
  901. //check date in leave range
  902. //CA_Debug::output_array(array('shift_date' => $date, 'from_date' => $from_date, 'to_date' => $to_date));
  903. //CA_Debug::output_array(array('shift_date' => date('d-m-Y H:i:s', $date), 'from_date' => date('d-m-Y H:i:s', $from_date), 'to_date' => date('d-m-Y H:i:s', $to_date)));
  904. $is_inleave = AttendanceHelper::checkInRange($from_date, $to_date, $date);
  905. if ($is_inleave == true) {
  906. //in leave
  907. $return = $leave;
  908. return $return;
  909. }
  910. }
  911. }
  912. }
  913.  
  914. return $return;
  915. }
  916.  
  917. /**
  918. * function to apply leave
  919. * @param string $user_id mongo id
  920. * @param number $tenant_id
  921. * @param string $leave_id
  922. * @param timestamp $from
  923. * @param timestamp $to
  924. * @param string $leave_message
  925. * @param integer $is_unpaid flage value
  926. * @param integer $is_halfday
  927. * @return array an array of leave_id and message_id on scccess else empty array
  928. */
  929. public static function applyLeave($user_id, $tenant_id, $leave_id, $from, $to, $leave_message, $is_unpaid, $is_halfday) {
  930. //get user
  931. $user = UserMongo::model()->tenant($tenant_id)->findByPk($user_id);
  932. // get recipients
  933. $leave_recipients = $user->getLeaveRecipients();
  934.  
  935. //create message
  936. $message = new Messages(Messages::SCENARIO_INSERT, true);
  937. $message->tenant_id = $tenant_id;
  938. $message->thread_id = Messages::THREAD_ROOT;
  939. $message->message_type = Messages::MSG_TYPE_UPDATE;
  940. $message->filter_type = Notifications::FILTER_LEAVE;
  941. $message->sender_type = Messages::SENDER_TYPE_USER;
  942. $message->sender_id = $user->user_id;
  943. $message->privacy = Messages::MESSAGE_PRIVATE;
  944. $message->isDirectMessage = TRUE;
  945. $message->receiver_id = $leave_recipients;
  946. $message->body_plain = $leave_message;
  947. $message->group = Messages::NO_GROUP;
  948. $message->tags = array();
  949.  
  950. //create leave
  951. $apply_leave = new UserLeaves('apply');
  952. $apply_leave->tenant_id = $tenant_id;
  953. $apply_leave->leave_id = $leave_id;
  954. $apply_leave->from_date = new MongoDate($from);
  955. $apply_leave->to_date = new MongoDate($to);
  956. $apply_leave->message = $leave_message;
  957. $apply_leave->isUnpaid = $is_unpaid;
  958. $apply_leave->is_half_day = $is_halfday;
  959. $apply_leave->user_id = $user_id;
  960.  
  961. if ($apply_leave->validate() && $apply_leave->save()) {
  962. //leaves attachments
  963. $leaveItems = array(
  964. 'id' => $apply_leave->id,
  965. 'type' => $apply_leave->leave_id,
  966. 'from_date' => date('Y-m-d', $apply_leave->from_date->sec),
  967. 'to_date' => date('Y-m-d', $apply_leave->to_date->sec),
  968. 'total_days' => RandomHelper::getWorkingDays($apply_leave->from_date->sec, $apply_leave->to_date->sec, $user->id, $user->tenant_id),
  969. 'status' => $apply_leave->status,
  970. 'updated_by' => array(),
  971. );
  972.  
  973. $attachment = array(
  974. 'type' => Notifications::FILTER_LEAVE,
  975. 'items' => $leaveItems,
  976. );
  977.  
  978. $message->attachments = $attachment;
  979.  
  980. if ($message->validate() && $message->save()) {
  981. return array('leave_id' => $apply_leave->id, 'message_id' => $message->id);
  982. }
  983. }
  984.  
  985. //CA_Debug::output_array($apply_leave->getErrors());
  986. return array();
  987. }
  988.  
  989. /**
  990. * function to update user leaves
  991. * @param string $leave_id mongo id
  992. * @param string $message_id
  993. * @param number $tenant_id
  994. * @param integer $status a constant
  995. * @param string $manager_message
  996. * @return boolean
  997. */
  998. public static function autoUpdateLeaves($leave_id, $message_id, $tenant_id = null, $status = UserLeaves::STATUS_APPROVED, $manager_message = null) {
  999. $userLeave = UserLeaves::model()->tenant($tenant_id)->findByPk($leave_id);
  1000.  
  1001. $messages = Messages::model()->tenant($tenant_id)->findByPk($message_id);
  1002.  
  1003. $user_id = $userLeave->user_id;
  1004. $user = UserMongo::model()->tenant($tenant_id)->findByPk($user_id);
  1005. $manager_id = ($user->manager_id == null) ? $user->id : $user->manager_id;
  1006.  
  1007. $user_manager_name = $user->getFullname();
  1008. $user_manager_id = $user->user_id;
  1009. if ($user->manager_id != null) {
  1010. $user_manager = UserMongo::model()->tenant($tenant_id)->findByPk($manager_id);
  1011. if (!empty($user_manager)) {
  1012. $user_manager_name = $user_manager->getFullname();
  1013. $user_manager_id = $user_manager->user_id;
  1014. }
  1015. }
  1016.  
  1017.  
  1018. $userLeave->status = $status;
  1019. $userLeave->manager_message = $manager_message;
  1020. $messages->last_action = Notifications::TYPE_REQUEST;
  1021.  
  1022. if ($userLeave->save()) {
  1023. $messages->attachments['items']['status'] = $userLeave->status;
  1024. $messages->attachments['items']['updated_by'][$user_manager_id] = $user_manager_name;
  1025. if ($userLeave->status != UserLeaves::STATUS_REVOKED) {
  1026. $messages->attachments['items']['updated_by']['manager_message'] = $manager_message;
  1027. }
  1028.  
  1029. if ($messages->save()) {
  1030. return true;
  1031. }
  1032. }
  1033.  
  1034. return false;
  1035. }
  1036.  
  1037. /**
  1038. * update attendance log when approving or revoking leave
  1039. * @param type $date (timestamp)
  1040. * @param type $leav_action(approve,revoke)
  1041. */
  1042. public function updateAttendanceLog($date, $leav_action, $new_leave_id = null, $optional_holiday_used = false) {
  1043. $criteria = new EMongoCriteria();
  1044. $criteria->shift_date('>=', new MongoDate($date));
  1045. $criteria->shift_date('<', new MongoDate(($date + (24 * 3600))));
  1046.  
  1047. $userAttendanceLog = UserAttendanceLog::model()->tenant($this->tenant_id)->user($this->user_id)->find($criteria);
  1048. $userShift = UserShiftPlanner::getUserShift($this->user_id, $date, $this->tenant_id);
  1049. if (!empty($userShift))
  1050. {
  1051. $policy_id = $userShift['policy_id'];
  1052. $attendancePolicy = AttendancePolicy::model()->tenant($this->tenant_id)->findByPk($policy_id);
  1053. }
  1054.  
  1055. if (!empty($userAttendanceLog)) {
  1056.  
  1057. if ($leav_action == self::LEAVE_ACTION_APPROVE) {
  1058. $userAttendanceLog->in_leave->status = (int) InLeave::INLEAVE_YES;
  1059. $userAttendanceLog->in_leave->leave_id = ($new_leave_id != null)? $new_leave_id : $this->id;
  1060. $userAttendanceLog->is_holiday->optional_holiday_used = ($optional_holiday_used == true)? IsHoliday::IS_OPTIONAL_YES : IsHoliday::IS_OPTIONAL_NO;
  1061. } elseif ($leav_action == self::LEAVE_ACTION_REVOKE) {
  1062. $userAttendanceLog->in_leave->status = InLeave::INLEAVE_NO;
  1063. $userAttendanceLog->in_leave->leave_id = null;
  1064. if($attendancePolicy->max_optional_holiday_policy->optional_holiday_status == MaxOptionalHolidayPolicy::ALL_OPTIONAL_HOLIDAY_STATUS)
  1065. {
  1066. $userAttendanceLog->is_holiday->optional_holiday_used = IsHoliday::HOLIDAY_YES;
  1067. }
  1068. }
  1069. $userAttendanceLog->save(false);
  1070. }
  1071. }
  1072. /*annual leaves export */
  1073. public static function getCountOfMonthsExport($user_id, $leave_id, $for_month , $is_paid = 1)
  1074. {
  1075. $from = strtotime($for_month."-01");
  1076. $to = strtotime($for_month."-".date('t', $from));
  1077. $criteria = new EMongoCriteria();
  1078. $criteria->from_date('>=', new MongoDate($from));
  1079. $criteria->from_date('<=', new MongoDate($to));
  1080.  
  1081. if($is_paid == 1)
  1082. {
  1083. $leaves_approved = UserLeaves::model()->user_approved_leave($user_id, $leave_id)->paid()->findAll($criteria);
  1084. }
  1085. else{
  1086. $leaves_approved = UserLeaves::model()->user_approved_leave($user_id, $leave_id)->unpaid()->findAll($criteria);
  1087. }
  1088. $total_working_days_one = array();
  1089.  
  1090. foreach ($leaves_approved as $leaves)
  1091. {
  1092. $applied_leave_data = Leaves::model()->tenant($leaves->tenant_id)->findByPk($leaves->leave_id);
  1093. $holidays = RandomHelper::getHolidays($leaves->from_date->sec, $leaves->to_date->sec, $leaves->tenant_id);
  1094. if(isset($applied_leave_data->policy_count_intervening_holidays->status) && $applied_leave_data->policy_count_intervening_holidays->status == LeavePolicy_InterveningHolidays::STATUS_ACTIVE)
  1095. {
  1096. if(isset($applied_leave_data->policy_count_intervening_holidays->count_intervening_holidays->count_public_holiday) && $applied_leave_data->policy_count_intervening_holidays->count_intervening_holidays->count_public_holiday == 1 && isset($applied_leave_data->policy_count_intervening_holidays->count_intervening_holidays->count_weekly_off) && $applied_leave_data->policy_count_intervening_holidays->count_intervening_holidays->count_weekly_off == 1)
  1097. {
  1098. $total_working_days_one = array_merge($total_working_days_one, RandomHelper::getWorkingDaysIncludingWeeklyoff($leaves->from_date->sec, $leaves->to_date->sec, $user_id, $leaves->tenant_id));
  1099. //$working_days = RandomHelper::getWorkingDaysIncludingWeeklyoff($le->from_date->sec, $le->to_date->sec, $user->mongo()->id, $user->tenant_id);
  1100. //$total_days = count($working_days);
  1101. }
  1102. elseif (isset($applied_leave_data->policy_count_intervening_holidays->count_intervening_holidays->count_public_holiday) && $applied_leave_data->policy_count_intervening_holidays->count_intervening_holidays->count_public_holiday == 1 && isset($applied_leave_data->policy_count_intervening_holidays->count_intervening_holidays->count_weekly_off) && $applied_leave_data->policy_count_intervening_holidays->count_intervening_holidays->count_weekly_off == 0)
  1103. {
  1104. $total_working_days_one = array_merge($total_working_days_one, RandomHelper::getWorkingDays($leaves->from_date->sec, $leaves->to_date->sec, $user_id, $leaves->tenant_id));
  1105. //$working_days = RandomHelper::getWorkingDays($le->from_date->sec, $le->to_date->sec, $user->mongo()->id, $user->tenant_id);
  1106. //$total_days = count($working_days);
  1107. }
  1108. else
  1109. {
  1110. $total_working_days_one = array_merge($total_working_days_one, RandomHelper::getWorkingDaysIncludingWeeklyoff($leaves->from_date->sec, $leaves->to_date->sec, $user_id, $leaves->tenant_id));
  1111. //$working_days = RandomHelper::getWorkingDaysIncludingWeeklyoff($le->from_date->sec, $le->to_date->sec, $user->mongo()->id, $user->tenant_id);
  1112. //$total_days = count($working_days);
  1113. }
  1114.  
  1115. }
  1116. else
  1117. {
  1118. $total_working_days_one = array_merge($total_working_days_one, RandomHelper::getWorkingDays($leaves->from_date->sec, $leaves->to_date->sec, $user_id, $leaves->tenant_id));
  1119. //$total_days = count(RandomHelper::excludeHolidays($working_days, $holidays));
  1120. }
  1121. //$total_working_days_one = array_merge($total_working_days_one, RandomHelper::getWorkingDays($leaves->from_date->sec, $leaves->to_date->sec, $user_id, $leaves->tenant_id));
  1122. }
  1123.  
  1124. $criteria = new EMongoCriteria();
  1125. $criteria->to_date('>=', new MongoDate($from));
  1126. $criteria->to_date('<=', new MongoDate($to));
  1127.  
  1128. // $leaves_approved = UserLeaves::model()->user_approved_leave($user_id, $leave_id)->paid()->findAll($criteria);
  1129. if($is_paid == 1)
  1130. {
  1131. $leaves_approved = UserLeaves::model()->user_approved_leave($user_id, $leave_id)->paid()->findAll($criteria);
  1132. }
  1133. else{
  1134. $leaves_approved = UserLeaves::model()->user_approved_leave($user_id, $leave_id)->unpaid()->findAll($criteria);
  1135. }
  1136. $total_working_days_two = array();
  1137. foreach ($leaves_approved as $leaves)
  1138. {
  1139. $applied_leave_data = Leaves::model()->tenant($leaves->tenant_id)->findByPk($leaves->leave_id);
  1140. $holidays = RandomHelper::getHolidays($leaves->from_date->sec, $leaves->to_date->sec, $leaves->tenant_id);
  1141. $applied_leave_data = Leaves::model()->tenant($leaves->tenant_id)->findByPk($leaves->leave_id);
  1142. $holidays = RandomHelper::getHolidays($leaves->from_date->sec, $leaves->to_date->sec, $leaves->tenant_id);
  1143. if(isset($applied_leave_data->policy_count_intervening_holidays->status) && $applied_leave_data->policy_count_intervening_holidays->status == LeavePolicy_InterveningHolidays::STATUS_ACTIVE)
  1144. {
  1145. if(isset($applied_leave_data->policy_count_intervening_holidays->count_intervening_holidays->count_public_holiday) && $applied_leave_data->policy_count_intervening_holidays->count_intervening_holidays->count_public_holiday == 1 && isset($applied_leave_data->policy_count_intervening_holidays->count_intervening_holidays->count_weekly_off) && $applied_leave_data->policy_count_intervening_holidays->count_intervening_holidays->count_weekly_off == 1)
  1146. {
  1147. $total_working_days_two = array_merge($total_working_days_two, RandomHelper::getWorkingDaysIncludingWeeklyoff($leaves->from_date->sec, $leaves->to_date->sec, $user_id, $leaves->tenant_id));
  1148. //$working_days = RandomHelper::getWorkingDaysIncludingWeeklyoff($le->from_date->sec, $le->to_date->sec, $user->mongo()->id, $user->tenant_id);
  1149. //$total_days = count($working_days);
  1150. }
  1151. elseif (isset($applied_leave_data->policy_count_intervening_holidays->count_intervening_holidays->count_public_holiday) && $applied_leave_data->policy_count_intervening_holidays->count_intervening_holidays->count_public_holiday == 1 && isset($applied_leave_data->policy_count_intervening_holidays->count_intervening_holidays->count_weekly_off) && $applied_leave_data->policy_count_intervening_holidays->count_intervening_holidays->count_weekly_off == 0)
  1152. {
  1153. $total_working_days_two = array_merge($total_working_days_two, RandomHelper::getWorkingDays($leaves->from_date->sec, $leaves->to_date->sec, $user_id, $leaves->tenant_id));
  1154. //$working_days = RandomHelper::getWorkingDays($le->from_date->sec, $le->to_date->sec, $user->mongo()->id, $user->tenant_id);
  1155. //$total_days = count($working_days);
  1156. }
  1157. else
  1158. {
  1159. $total_working_days_two = array_merge($total_working_days_two, RandomHelper::getWorkingDaysIncludingWeeklyoff($leaves->from_date->sec, $leaves->to_date->sec, $user_id, $leaves->tenant_id));
  1160. //$working_days = RandomHelper::getWorkingDaysIncludingWeeklyoff($le->from_date->sec, $le->to_date->sec, $user->mongo()->id, $user->tenant_id);
  1161. //$total_days = count($working_days);
  1162. }
  1163.  
  1164. }
  1165. else
  1166. {
  1167. $total_working_days_two = array_merge($total_working_days_two, RandomHelper::getWorkingDays($leaves->from_date->sec, $leaves->to_date->sec, $user_id, $leaves->tenant_id));
  1168. //$total_days = count(RandomHelper::excludeHolidays($working_days, $holidays));
  1169. }
  1170. // $total_working_days_two = array_merge($total_working_days_two, RandomHelper::getWorkingDays($leaves->from_date->sec, $leaves->to_date->sec, $user_id, $leaves->tenant_id));
  1171.  
  1172. }
  1173. if(empty($total_working_days_two))
  1174. {
  1175. $total_working_days_two = array_merge($total_working_days_two, $total_working_days_one);
  1176. }
  1177. //filter for current month days
  1178. $days_list = self::getDateList($from, $to);
  1179. $total_working_days_two_new = array();
  1180. foreach ($total_working_days_two as $total_working_days) {
  1181. if(in_array($total_working_days, $days_list)){
  1182. $total_working_days_two_new[] = $total_working_days;
  1183. }
  1184. }
  1185. return count($total_working_days_two_new);
  1186.  
  1187. }
  1188. // annual leaves export
  1189. /**Passed additionla parameter to check correct count in case of intervening if leaves applied on holiday/weekoff only [SG 11 Feb 2016]**/
  1190. public function getCountOfMonthsUnpaid($user_id, $for_month = null, $from = null, $to = null, $getCount = false)
  1191. {
  1192. if(isset($for_month) && $for_month != null)
  1193. {
  1194. $from = strtotime($for_month."-01");
  1195. $to = strtotime($for_month."-".date('t', $from));
  1196. }
  1197. else
  1198. {
  1199. $from = strtotime($from);
  1200. $to = strtotime($to);
  1201. }
  1202. $criteria = new EMongoCriteria();
  1203. $criteria->from_date('>=', new MongoDate($from));
  1204. $criteria->from_date('<=', new MongoDate($to));
  1205. $user_mongo_details = UserMongo::model()->tenant()->findByPk($user_id);
  1206. $leaves_approved = UserLeaves::model()->tenant($user_mongo_details->tenant_id)->user_approved_leave($user_id)->unpaid()->findAll($criteria);
  1207.  
  1208. $total_working_days_one = array();
  1209. foreach ($leaves_approved as $leaves)
  1210. {
  1211. //$leave_id_number = (isset($leaves->parent_leave_id) && $leaves->parent_leave_id != "") ? $leaves->parent_leave_id : "unpaid";
  1212. $leave_id_number = "unpaid";
  1213. $get_working_days_array = RandomHelper::getWorkingDaysAccToLeavesPolicy($leaves->from_date->sec, $leaves->to_date->sec, $user_id, $leaves->tenant_id, $leave_id_number,$user_mongo_details->personal->office_location, $getCount, $leaves->userOptionalHoliday);
  1214.  
  1215. // Description : Since the above get_working_days_array return array the below code was not written in wich we need all the leaves applied date.[KP: 16 March 2016]
  1216. if (!is_array($get_working_days_array))
  1217. {
  1218. $get_working_days_new_array[] = $get_working_days_array;
  1219. }
  1220. else
  1221. {
  1222. $get_working_days_new_array = $get_working_days_array;
  1223. }
  1224. $total_working_days_one = array_merge($total_working_days_one, $get_working_days_new_array);
  1225. }
  1226.  
  1227. $criteria = new EMongoCriteria();
  1228. $criteria->to_date('>=', new MongoDate($from));
  1229. $criteria->to_date('<=', new MongoDate($to));
  1230.  
  1231. // $leaves_approved = UserLeaves::model()->user_approved_leave($user_id, $leave_id)->paid()->findAll($criteria);
  1232. $leaves_approved = UserLeaves::model()->tenant()->user_approved_leave($user_id)->unpaid()->findAll($criteria);
  1233. $total_working_days_two = array();
  1234. foreach ($leaves_approved as $leaves)
  1235. {
  1236. //$leave_id_number = (isset($leaves->parent_leave_id) && $leaves->parent_leave_id != "") ? $leaves->parent_leave_id : "unpaid";
  1237. $leave_id_number = "unpaid";
  1238. $get_working_days_new_array = array();
  1239. // Description : The Below Condition has been checked because for Infogix(lalit) from_date was saving blank array.[KP: 17 March 2016]
  1240. $from_date_leaves = isset($leaves->from_date->sec) ? $leaves->from_date->sec : $leaves->to_date->sec;
  1241. $get_working_days_array = RandomHelper::getWorkingDaysAccToLeavesPolicy($from_date_leaves, $leaves->to_date->sec, $user_id,$leaves->tenant_id,$leave_id_number,$user_mongo_details->personal->office_location, $getCount, $leaves->userOptionalHoliday);
  1242. if (!is_array($get_working_days_array))
  1243. {
  1244. $get_working_days_new_array[] = $get_working_days_array;
  1245. }
  1246. else
  1247. {
  1248. $get_working_days_new_array = $get_working_days_array;
  1249. }
  1250. $total_working_days_two = array_merge($total_working_days_two, $get_working_days_new_array);
  1251. }
  1252. if(empty($total_working_days_two))
  1253. {
  1254. $total_working_days_two = array_merge($total_working_days_two, $total_working_days_one);
  1255. }
  1256. else
  1257. {
  1258. $total_working_days_new_one = array();
  1259. if (!is_array($total_working_days_one))
  1260. {
  1261. $total_working_days_new_one[] = $total_working_days_one;
  1262. }
  1263. else
  1264. {
  1265. $total_working_days_new_one = $total_working_days_one;
  1266. }
  1267.  
  1268. foreach ($total_working_days_new_one as $key_one_new => $value_one_new)
  1269. {
  1270. if(date("Y-m",strtotime($value_one_new)) == $for_month)
  1271. {
  1272. $total_working_days_two[] = $value_one_new;
  1273. }
  1274. }
  1275. $total_working_days_two = array_unique($total_working_days_two, SORT_REGULAR);
  1276. }
  1277. //filter for current month days
  1278. $days_list = self::getDateList($from, $to);
  1279. $total_working_days_two_new = array();
  1280. foreach ($total_working_days_two as $total_working_days)
  1281. {
  1282. if(in_array($total_working_days, $days_list))
  1283. {
  1284. $total_working_days_two_new[] = $total_working_days;
  1285. }
  1286. }
  1287. return count($total_working_days_two_new);
  1288. }
  1289.  
  1290. /*
  1291. * Description : Below function will produce list of compoff available for user. [KP : 9 Sept 2015]
  1292. */
  1293. public function checkCompoffAvailable($user_id)
  1294. {
  1295. $user_data = UserMongo::model()->tenant()->findByAttributes(array('id' => $user_id));
  1296. $compoff_available = UserAttendanceLog::getCompoffLeavesavailableattlist($user_data->user_id, 'compofflist');
  1297.  
  1298. /* get leaves applied for compoff */
  1299. $usermongo_data = UserMongo::model()->tenant()->findByAttributes(array('user_id' => $user_data->user_id));
  1300. $leaves_compoff_obj = Leaves::model()->tenant()->findByAttributes(array('name' => 'Compensatory Off'));
  1301. $criteria = new EMongoCriteria();
  1302. $criteria->user_id('==', $usermongo_data->id);
  1303. $criteria->leave_id('==', $leaves_compoff_obj->id);
  1304. $criteria->status('==', UserLeaves::STATUS_APPROVED);
  1305. $user_leaves_for_previous_compoff = UserLeaves::model()->findAll($criteria);
  1306. /* get leaves applied for compoff */
  1307.  
  1308. /* getting the compoff setting for the tenant */
  1309. $tenant_compoff = TenantLeavesCompoff::model()->tenant()->find();
  1310. $lapse_period = $tenant_compoff->Compoff_earned_will_lapse_after_how_many_days;
  1311.  
  1312. /* Below compoof_used array will give list of compoff date used by user. */
  1313. $compoof_used = array();
  1314. $com_cont =0;
  1315. foreach ($user_leaves_for_previous_compoff as $key_compoff_leaves => $value_compoff_leaves)
  1316. {
  1317. if(isset($value_compoff_leaves->compoff_used_date) && !empty($value_compoff_leaves->compoff_used_date) && count($value_compoff_leaves->compoff_used_date) > 0 && is_array($value_compoff_leaves->compoff_used_date))
  1318. {
  1319. $comp_date = array();
  1320. foreach ($value_compoff_leaves->compoff_used_date as $key => $nvalue)
  1321. {
  1322. $comp_date = $nvalue;
  1323. }
  1324. $compoof_used[$com_cont] = $comp_date;
  1325. $com_cont++;
  1326. }
  1327. }
  1328. $compoof_available_list = array();
  1329. $comcnt_avl=0;
  1330. foreach ($compoff_available as $compoff_key => $compoff_value)
  1331. {
  1332. $lapse = (isset($lapse_period) && $lapse_period == 0) ? 'No lapse period' : date('d F Y', strtotime('+'.$lapse_period.'day', strtotime($compoff_value['date']))); // getting lapse period available for compoff.
  1333.  
  1334. /* Checking weather the compoff has been lapsed or not.*/
  1335. $status = "Active";
  1336. if($lapse != 'No lapse period')
  1337. {
  1338. if(strtotime(date('Y-m-d')) > strtotime($lapse))
  1339. {
  1340. $status = "Lapsed";
  1341. }
  1342. }
  1343. if ($status == "Active")
  1344. {
  1345. if(!in_array($compoff_value['date'], $compoof_used)) // Here we are checking for compoff available date is not in compoff used array.
  1346. {
  1347. $compoof_available_list[$comcnt_avl]= $compoff_value;
  1348. }
  1349. $comcnt_avl++;
  1350. }
  1351. }
  1352. $compoof_available_list = array_values($compoof_available_list); /*rearranging the key for compoff available list.*/
  1353. /* Sort the compoff available date in desending order. */
  1354. usort($compoof_available_list, function($a, $b)
  1355. {
  1356. $format = 'Y-m-d';
  1357. $descending = true;
  1358. $zone = new DateTimeZone('UTC');
  1359. $d1 = DateTime::createFromFormat($format, $a['date'], $zone)->getTimestamp();
  1360. $d2 = DateTime::createFromFormat($format, $b['date'], $zone)->getTimestamp();
  1361. return $descending ? ($d1 - $d2) : ($d2 - $d1);
  1362. });
  1363. return $compoof_available_list;
  1364. }
  1365.  
  1366. public function getCountOfMonthsUnScheduled($user_id=null, $leave_id= null, $for_month)
  1367. {
  1368. $from = strtotime($for_month."-01");
  1369. $to = strtotime($for_month."-".date('t', $from));
  1370. $criteria = new EMongoCriteria();
  1371. $criteria->from_date('>=', new MongoDate($from));
  1372. $criteria->from_date('<=', new MongoDate($to));
  1373.  
  1374. $leaves_approved = UserLeaves::model()->user_approved_leave($user_id, $leave_id)->findAll($criteria);
  1375. $total_working_days_one = array();
  1376.  
  1377. foreach ($leaves_approved as $leaves)
  1378. {
  1379. if($leaves->created->sec >= $leaves->from_date->sec)
  1380. {
  1381. $applied_leave_data = Leaves::model()->tenant($leaves->tenant_id)->findByPk($leaves->leave_id);
  1382. $holidays = RandomHelper::getHolidays($leaves->from_date->sec, $leaves->to_date->sec);
  1383. if(isset($applied_leave_data->policy_count_intervening_holidays->status) && $applied_leave_data->policy_count_intervening_holidays->status == LeavePolicy_InterveningHolidays::STATUS_ACTIVE)
  1384. {
  1385. if(isset($applied_leave_data->policy_count_intervening_holidays->count_intervening_holidays->count_public_holiday) && $applied_leave_data->policy_count_intervening_holidays->count_intervening_holidays->count_public_holiday == 1 && isset($applied_leave_data->policy_count_intervening_holidays->count_intervening_holidays->count_weekly_off) && $applied_leave_data->policy_count_intervening_holidays->count_intervening_holidays->count_weekly_off == 1)
  1386. {
  1387. $total_working_days_one = array_merge($total_working_days_one, RandomHelper::getWorkingDaysIncludingWeeklyoff($leaves->from_date->sec, $leaves->to_date->sec, $user_id, $leaves->tenant_id));
  1388. //$working_days = RandomHelper::getWorkingDaysIncludingWeeklyoff($le->from_date->sec, $le->to_date->sec, $user->mongo()->id, $user->tenant_id);
  1389. //$total_days = count($working_days);
  1390. }
  1391. elseif (isset($applied_leave_data->policy_count_intervening_holidays->count_intervening_holidays->count_public_holiday) && $applied_leave_data->policy_count_intervening_holidays->count_intervening_holidays->count_public_holiday == 1 && isset($applied_leave_data->policy_count_intervening_holidays->count_intervening_holidays->count_weekly_off) && $applied_leave_data->policy_count_intervening_holidays->count_intervening_holidays->count_weekly_off == 0)
  1392. {
  1393. $total_working_days_one = array_merge($total_working_days_one, RandomHelper::getWorkingDays($leaves->from_date->sec, $leaves->to_date->sec, $user_id, $leaves->tenant_id));
  1394. //$working_days = RandomHelper::getWorkingDays($le->from_date->sec, $le->to_date->sec, $user->mongo()->id, $user->tenant_id);
  1395. //$total_days = count($working_days);
  1396. }
  1397. else
  1398. {
  1399. $total_working_days_one = array_merge($total_working_days_one, RandomHelper::getWorkingDaysIncludingWeeklyoff($leaves->from_date->sec, $leaves->to_date->sec, $user_id, $leaves->tenant_id));
  1400. //$working_days = RandomHelper::getWorkingDaysIncludingWeeklyoff($le->from_date->sec, $le->to_date->sec, $user->mongo()->id, $user->tenant_id);
  1401. //$total_days = count($working_days);
  1402. }
  1403. }
  1404. else
  1405. {
  1406. $total_working_days_one = array_merge($total_working_days_one, RandomHelper::getWorkingDays($leaves->from_date->sec, $leaves->to_date->sec, $user_id, $leaves->tenant_id));
  1407. $holidays = RandomHelper::getHolidays($leaves->from_date->sec, $leaves->to_date->sec);
  1408. $total_working_days_one = RandomHelper::excludeHolidays($total_working_days_one, $holidays);
  1409. //$total_days = count(RandomHelper::excludeHolidays($working_days, $holidays));
  1410. }
  1411. //$total_working_days_one = array_merge($total_working_days_one, RandomHelper::getWorkingDays($leaves->from_date->sec, $leaves->to_date->sec, $user_id, $leaves->tenant_id));
  1412. }
  1413. }
  1414. $criteria = new EMongoCriteria();
  1415. $criteria->to_date('>=', new MongoDate($from));
  1416. $criteria->to_date('<=', new MongoDate($to));
  1417.  
  1418. // $leaves_approved = UserLeaves::model()->user_approved_leave($user_id, $leave_id)->paid()->findAll($criteria);
  1419.  
  1420. $leaves_approved = UserLeaves::model()->user_approved_leave($user_id, $leave_id)->findAll($criteria);
  1421. $total_working_days_two = array();
  1422. foreach ($leaves_approved as $leaves)
  1423. {
  1424. if($leaves->created->sec >= $leaves->from_date->sec)
  1425. {
  1426. $applied_leave_data = Leaves::model()->tenant($leaves->tenant_id)->findByPk($leaves->leave_id);
  1427. $holidays = RandomHelper::getHolidays($leaves->from_date->sec, $leaves->to_date->sec);
  1428. $applied_leave_data = Leaves::model()->tenant($leaves->tenant_id)->findByPk($leaves->leave_id);
  1429. $holidays = RandomHelper::getHolidays($leaves->from_date->sec, $leaves->to_date->sec);
  1430. if(isset($applied_leave_data->policy_count_intervening_holidays->status) && $applied_leave_data->policy_count_intervening_holidays->status == LeavePolicy_InterveningHolidays::STATUS_ACTIVE)
  1431. {
  1432. if(isset($applied_leave_data->policy_count_intervening_holidays->count_intervening_holidays->count_public_holiday) && $applied_leave_data->policy_count_intervening_holidays->count_intervening_holidays->count_public_holiday == 1 && isset($applied_leave_data->policy_count_intervening_holidays->count_intervening_holidays->count_weekly_off) && $applied_leave_data->policy_count_intervening_holidays->count_intervening_holidays->count_weekly_off == 1)
  1433. {
  1434. $total_working_days_two = array_merge($total_working_days_two, RandomHelper::getWorkingDaysIncludingWeeklyoff($leaves->from_date->sec, $leaves->to_date->sec, $user_id, $leaves->tenant_id));
  1435. //$working_days = RandomHelper::getWorkingDaysIncludingWeeklyoff($le->from_date->sec, $le->to_date->sec, $user->mongo()->id, $user->tenant_id);
  1436. //$total_days = count($working_days);
  1437. }
  1438. elseif (isset($applied_leave_data->policy_count_intervening_holidays->count_intervening_holidays->count_public_holiday) && $applied_leave_data->policy_count_intervening_holidays->count_intervening_holidays->count_public_holiday == 1 && isset($applied_leave_data->policy_count_intervening_holidays->count_intervening_holidays->count_weekly_off) && $applied_leave_data->policy_count_intervening_holidays->count_intervening_holidays->count_weekly_off == 0)
  1439. {
  1440. $total_working_days_two = array_merge($total_working_days_two, RandomHelper::getWorkingDays($leaves->from_date->sec, $leaves->to_date->sec, $user_id, $leaves->tenant_id));
  1441. //$working_days = RandomHelper::getWorkingDays($le->from_date->sec, $le->to_date->sec, $user->mongo()->id, $user->tenant_id);
  1442. //$total_days = count($working_days);
  1443. }
  1444. else
  1445. {
  1446. $total_working_days_two = array_merge($total_working_days_two, RandomHelper::getWorkingDaysIncludingWeeklyoff($leaves->from_date->sec, $leaves->to_date->sec, $user_id, $leaves->tenant_id));
  1447. //$working_days = RandomHelper::getWorkingDaysIncludingWeeklyoff($le->from_date->sec, $le->to_date->sec, $user->mongo()->id, $user->tenant_id);
  1448. //$total_days = count($working_days);
  1449. }
  1450. }
  1451. else
  1452. {
  1453. $total_working_days_two = array_merge($total_working_days_two, RandomHelper::getWorkingDays($leaves->from_date->sec, $leaves->to_date->sec, $user_id, $leaves->tenant_id));
  1454. $holidays = RandomHelper::getHolidays($leaves->from_date->sec, $leaves->to_date->sec);
  1455. $total_working_days_two = RandomHelper::excludeHolidays($total_working_days_two, $holidays);
  1456. //$total_days = count(RandomHelper::excludeHolidays($working_days, $holidays));
  1457. }
  1458. // $total_working_days_two = array_merge($total_working_days_two, RandomHelper::getWorkingDays($leaves->from_date->sec, $leaves->to_date->sec, $user_id, $leaves->tenant_id));
  1459. }
  1460. }
  1461.  
  1462. if(empty($total_working_days_two))
  1463. {
  1464. $total_working_days_two = array_merge($total_working_days_two, $total_working_days_one);
  1465. }
  1466. else
  1467. {
  1468. foreach ($total_working_days_one as $key_one_new => $value_one_new)
  1469. {
  1470. if(date("Y-m",strtotime($value_one_new)) == $for_month)
  1471. {
  1472. $total_working_days_two[] = $value_one_new;
  1473. }
  1474. }
  1475. $total_working_days_two = array_unique($total_working_days_two, SORT_REGULAR);
  1476. }
  1477. //filter for current month days
  1478. $days_list = self::getDateList($from, $to);
  1479. $total_working_days_two_new = array();
  1480. foreach ($total_working_days_two as $total_working_days)
  1481. {
  1482. if(in_array($total_working_days, $days_list))
  1483. {
  1484. $total_working_days_two_new[] = $total_working_days;
  1485. }
  1486. }
  1487. return count($total_working_days_two_new);
  1488. }
  1489.  
  1490. public function getCompleateLeavesDetails()
  1491. {
  1492. $tenant_id = Yii::app()->user->getTenantId();
  1493. $id = Yii::app()->user->id;
  1494. $user = User::model()->tenant()->findByPk($id);
  1495. $leave_settings = TenantLeavesSettings::model()->findByAttributes(array('tenant_id' => $tenant_id));
  1496. if(isset($leave_settings->unpaid_refresh) && $leave_settings->unpaid_refresh == TenantLeavesSettings::FINANCIAL_UNPAID_REFRESH)
  1497. {
  1498. $tenantProfile = TenantProfile::model()->tenant($tenant_id)->find();
  1499. $year_to_pass = (date("m") < 4)? date('Y') - 1 : date('Y');
  1500. $month_list = $tenantProfile->getMonthList('Y-m','M', $year_to_pass);
  1501. }
  1502. else{
  1503. $tenantProfile = TenantProfile::model()->tenant($tenant_id)->find();
  1504. $month_list = $tenantProfile->getMonthListCalendar('Y-m','M');
  1505. }
  1506.  
  1507. $leaveList = Leaves::getLeaveList();
  1508. $leaveListIds = array();
  1509. foreach ($leaveList as $id => $name)
  1510. {
  1511. $leaveListIds[] = Leaves::model()->tenant()->findByPk($id);
  1512. }
  1513.  
  1514. $list = $month_list;
  1515. $leaves_total = array('c1' => 0, 'c2' => 0, 'c3' => 0, 'c4' => 0, 'c5' => 0, 'c6' => 0, 'c7' => 0, 'c8' => 0, 'c9' => 0, 'c10' => 0, 'c11' => 0, 'c12' => 0, );
  1516. $leaves = $leaveListIds;
  1517. if (!empty($leaves))
  1518. {
  1519. foreach ($leaves as $l)
  1520. {
  1521. if (!empty($l))
  1522. {
  1523. $c = 1;
  1524. foreach ($list as $for_month => $month)
  1525. {
  1526. $leaves_approved = UserLeaves::model()->user_approved_leave($user->mongo()->id, $l->id)->forMonth($for_month)->paid()->findAll();
  1527. $total_days = 0;
  1528. foreach ($leaves_approved as $le)
  1529. {
  1530. $wekly_off_days = RandomHelper::getWorkingDays($le->from_date->sec, $le->to_date->sec, $le->user_id, $le->tenant_id);
  1531. if (!empty($wekly_off_days))
  1532. {
  1533. if ($le->is_half_day == UserLeaves::HALF_DAY_YES)
  1534. {
  1535. $total_days += 0.5;
  1536. }
  1537. }
  1538. else
  1539. {
  1540. if ($total_days > 0)
  1541. {
  1542. $total_days -= 0.5;
  1543. }
  1544. }
  1545. }
  1546. $counter = 0;
  1547. $total_data_of_leaves = UserLeaves::getCountOfMonths($user->mongo()->id, $l->id, $for_month, 1);
  1548. if ($total_data_of_leaves > 0)
  1549. {
  1550. $counter = UserLeaves::getCountOfMonths($user->mongo()->id, $l->id, $for_month, 1) - $total_days;
  1551. }
  1552. else
  1553. {
  1554. $counter = $total_data_of_leaves;
  1555. }
  1556. $leaves_total['c' . $c++] += $counter;
  1557. }
  1558. }
  1559. }
  1560. }
  1561.  
  1562. $unpaid_array = array();
  1563. foreach ($list as $for_month => $month)
  1564. {
  1565. $leaves_approved = UserLeaves::model()->user_approved_leave($user->mongo()->id)->forMonth($for_month)->unpaid()->findAll();
  1566. $total_days = 0;
  1567. foreach ($leaves_approved as $le)
  1568. {
  1569. $wekly_off_days = RandomHelper::getWorkingDays($le->from_date->sec, $le->to_date->sec, $le->user_id, $le->tenant_id);
  1570. if (!empty($wekly_off_days))
  1571. {
  1572. if ($le->is_half_day == UserLeaves::HALF_DAY_YES)
  1573. {
  1574. $total_days += 0.5;
  1575. }
  1576. }
  1577. else
  1578. {
  1579. if ($total_days > 0)
  1580. {
  1581. $total_days -= 0.5;
  1582. }
  1583. }
  1584. }
  1585.  
  1586. $counter = 0;
  1587. $counter_new = 0;
  1588. $counter = UserLeaves::getCountOfMonthsUnpaid($user->mongo()->id, $for_month);
  1589. if ($counter > 0)
  1590. {
  1591. $counter = $counter - $total_days;
  1592. }
  1593. else
  1594. {
  1595. $counter = $counter;
  1596. }
  1597. $unpaid_array[] += $counter;
  1598. }
  1599. $leaves_per_month = array();
  1600. $i = 0;
  1601. foreach ($leaves_total as $total) :
  1602. $leaves_per_month[]= ($total + $unpaid_array[$i]);
  1603. $i++;
  1604. endforeach;
  1605.  
  1606.  
  1607. // UNSCHEDULED leave calculations
  1608. $unschedule_array = array();
  1609. foreach ($list as $for_month => $month)
  1610. {
  1611. $leaves_approved = UserLeaves::model()->user_approved_leave($user->mongo()->id)->forMonth($for_month)->findAll();
  1612. $total_days_unsheduled = 0;
  1613. foreach ($leaves_approved as $le)
  1614. {
  1615. if($le->created->sec >= $le->from_date->sec)
  1616. {
  1617. $wekly_off_days = RandomHelper::getWorkingDays($le->from_date->sec, $le->to_date->sec, $le->user_id, $le->tenant_id);
  1618. // echo "<pre>"; print_r($wekly_off_days); "</pre>";
  1619.  
  1620. if (!empty($wekly_off_days))
  1621. {
  1622. if ($le->is_half_day == UserLeaves::HALF_DAY_YES)
  1623. {
  1624. $total_days_unsheduled += 0.5;
  1625. }
  1626. }
  1627.  
  1628. else
  1629. {
  1630. if ($total_days_unsheduled > 0)
  1631. {
  1632. $total_days_unsheduled -= 0.5;
  1633. }
  1634. }
  1635. }
  1636. }
  1637.  
  1638. $counter_unscheduled = 0;
  1639. $total_data_of_leaves = UserLeaves::getCountOfMonthsUnScheduled($user->mongo()->id, null, $for_month, 0);
  1640. if ($total_data_of_leaves > 0)
  1641. {
  1642. $counter_unscheduled = $total_data_of_leaves - $total_days_unsheduled;
  1643. }
  1644. else
  1645. {
  1646. $counter_unscheduled = $total_data_of_leaves;
  1647. }
  1648. $unschedule_array[] = $counter_unscheduled;
  1649. }
  1650. // UNSCHEDULED leave calculations
  1651.  
  1652. $total_leaves_taken = array_sum($leaves_per_month);
  1653. $total_unpaid_leaves = array_sum($unpaid_array);
  1654. $total_unscheduled_leaves = array_sum($unschedule_array);
  1655.  
  1656. $params = array(
  1657. 'total_leaves_taken'=> $total_leaves_taken,
  1658. 'total_unpaid_leaves' => $total_unpaid_leaves,
  1659. 'total_unscheduled_leaves' => $total_unscheduled_leaves,
  1660. );
  1661. return $params;
  1662. }
  1663.  
  1664. public function userAttendanceDetailsAdmin($user_indivual, $from, $to, $tenant_id,$month_for)
  1665. {
  1666. $index = 0;
  1667. $output = array();
  1668. $begin = new DateTime($from);
  1669. $end = new DateTime($to);
  1670. $end = $end->modify('+1 day');
  1671. $interval = new DateInterval('P1D');
  1672. $daterange = new DatePeriod($begin, $interval, $end);
  1673. $from = strtotime($from);
  1674. if($month_for == "curr_month")
  1675. {
  1676. $to = strtotime("+1 day", strtotime($to));
  1677. }
  1678. else
  1679. {
  1680. $to = strtotime($to);
  1681. }
  1682. $criteria = new EMongoCriteria();
  1683. $criteria->shift_date('>=', new MongoDate($from));
  1684. $criteria->shift_date('<=', new MongoDate($to));
  1685. foreach ($user_indivual as $key => $user)
  1686. {
  1687. $user_name = $user['personal']['firstname'] . " " . $user['personal']['lastname'];
  1688. $criteria->user_id = $user->id;
  1689. $userAttendanceLogs = UserAttendanceLog::model()->tenant($tenant_id)->findAll($criteria);
  1690. sort($userAttendanceLogs);
  1691. $present = 0;
  1692. $absent = 0;
  1693. $weeklyoff_count = 0;
  1694. $holiday_count = 0;
  1695. $leave_count = 0;
  1696. $unpaidleave_count = 0;
  1697. $unscheduled_leave_count = 0;
  1698. $output[] = array(
  1699. $user_name,
  1700. );
  1701. $jindex = 0;
  1702. foreach ($daterange as $date)
  1703. {
  1704. $unpaidFlag = false;
  1705. if (isset($userAttendanceLogs[$jindex]))
  1706. {
  1707.  
  1708. if ($date->format("d") == date("d", $userAttendanceLogs[$jindex]->shift_date->sec))
  1709. {
  1710. $date = date("d", $userAttendanceLogs[$jindex]->shift_date->sec);
  1711. if (isset($userAttendanceLogs[$jindex]->attendance_status))
  1712. {
  1713. $status = $userAttendanceLogs[$jindex]->attendance_status;
  1714. if ($status == UserAttendance::ATTENDANCE_STATUS_ABSENT)
  1715. {
  1716. $checkBothClockInClockOut = false;
  1717. $checkOnlyClockIn = false;
  1718. $shift_planner_id = $userAttendanceLogs[$jindex]->shift_planner;
  1719. // Get shift planner
  1720. $useShiftPlanner = UserShiftPlanner::model()->user($user->id)->findByPk($shift_planner_id);
  1721. if (!empty($useShiftPlanner))
  1722. {
  1723. $policy_id = $useShiftPlanner->policy_id;
  1724. }
  1725. else
  1726. {
  1727. $policy_id = "";
  1728. }
  1729.  
  1730. // Get user policy using policy Id.
  1731. $attendancePolicy = AttendancePolicy::getAttendancePolicy($policy_id, $tenant_id);
  1732. if (!empty($attendancePolicy))
  1733. {
  1734. if ($attendancePolicy->markin_policy->status == MarkinPolicy::MARKIN_BOTH)
  1735. {
  1736. $checkBothClockInClockOut = true;
  1737. $checkOnlyClockIn = false;
  1738. }
  1739. else if ($attendancePolicy->markin_policy->status == MarkinPolicy::MARKIN_IN)
  1740. {
  1741. $checkBothClockInClockOut = false;
  1742. $checkOnlyClockIn = true;
  1743. }
  1744. }
  1745.  
  1746. if ($checkBothClockInClockOut)
  1747. {
  1748. if(($userAttendanceLogs[$jindex]->punchin_time != '') && ($userAttendanceLogs[$jindex]->punchout_time != ''))
  1749. {
  1750. $status = UserAttendanceLog::ATTENDANCE_STATUS_PRESENT;
  1751. }
  1752. else
  1753. {
  1754. $status = UserAttendanceLog::ATTENDANCE_STATUS_ABSENT;
  1755. }
  1756. }
  1757. else if ($checkOnlyClockIn)
  1758. {
  1759. if(($userAttendanceLogs[$jindex]->punchin_time != ''))
  1760. {
  1761. $status = UserAttendanceLog::ATTENDANCE_STATUS_PRESENT;
  1762. }
  1763. else
  1764. {
  1765. $status = UserAttendanceLog::ATTENDANCE_STATUS_ABSENT;
  1766. }
  1767. }
  1768. else
  1769. {
  1770. $status = UserAttendanceLog::ATTENDANCE_STATUS_ABSENT;
  1771. }
  1772. }
  1773. elseif ($status == UserAttendance::ATTENDANCE_STATUS_PRESENT)
  1774. {
  1775. $status = UserAttendanceLog::ATTENDANCE_STATUS_PRESENT;
  1776. }
  1777. // ***************************** <END> *****************************
  1778.  
  1779. $weeklyoff = $userAttendanceLogs[$jindex]->is_weekly_off->status;
  1780. $holiday = $userAttendanceLogs[$jindex]->is_holiday->status;
  1781. $leave = $userAttendanceLogs[$jindex]->in_leave->status;
  1782. $leave_revoked = false;
  1783. if (isset($userAttendanceLogs[$jindex]->in_leave->leave_id))
  1784. {
  1785. $unpaidLeave = UserLeaves::model()->tenant($tenant_id)->findByPk($userAttendanceLogs[$jindex]->in_leave->leave_id);
  1786. if ($unpaidLeave->isUnpaid == UserLeaves::LEAVE_UNPAID)
  1787. {
  1788. $unpaidleave_count++;
  1789. $unpaidFlag = true;
  1790. }
  1791. else
  1792. {
  1793. $unpaidFlag = false;
  1794. }
  1795. if ($unpaidLeave->status == UserLeaves::STATUS_REVOKED || $unpaidLeave->status == UserLeaves::STATUS_REJECTED)
  1796. {
  1797. $leave_revoked = true;
  1798. }
  1799. }
  1800. else
  1801. {
  1802. $unpaidFlag = false;
  1803. }
  1804.  
  1805. if (isset($userAttendanceLogs[$jindex]->in_leave))
  1806. {
  1807. $unscheduleLeave = UserLeaves::model()->tenant($tenant_id)->findByPk($userAttendanceLogs[$jindex]->in_leave->leave_id);
  1808. if (isset($unscheduleLeave->status) && $unscheduleLeave->status == UserLeaves::STATUS_APPROVED)
  1809. {
  1810. if($unscheduleLeave->created->sec >= $unscheduleLeave->from_date->sec)
  1811. {
  1812. if(isset($unscheduleLeave->is_half_day) && $unscheduleLeave->is_half_day)
  1813. {
  1814. $unscheduled_leave_count += 0.5;
  1815. }
  1816. else
  1817. {
  1818. $unscheduled_leave_count++;
  1819. }
  1820. }
  1821. }
  1822. }
  1823.  
  1824. if (isset($weeklyoff) && $weeklyoff == "1")
  1825. {
  1826. if ($status == UserAttendanceLog::ATTENDANCE_STATUS_PRESENT || $status == UserAttendanceLog::ATTENDANCE_STATUS_PENDING)
  1827. {
  1828. $show_status = "P";
  1829. }
  1830. else
  1831. {
  1832. $show_status = "W";
  1833. }
  1834. $weeklyoff_count++;
  1835. }
  1836. elseif (isset($holiday) && $holiday == "1")
  1837. {
  1838. $show_status = "H";
  1839. $holiday_count++;
  1840. }
  1841. elseif ((isset($leave)) && ($leave == "1") && ($leave_revoked == false))
  1842. {
  1843. $show_status = "L";
  1844. $leave_count++;
  1845. }
  1846. elseif ($status == UserAttendanceLog::ATTENDANCE_STATUS_PRESENT || $status == UserAttendanceLog::ATTENDANCE_STATUS_PENDING)
  1847. {
  1848. $show_status = "P";
  1849. $present++;
  1850. }
  1851. elseif ($status == UserAttendanceLog::ATTENDANCE_STATUS_ABSENT || $status == UserAttendance::ATTENDANCE_STATUS_ABSENT)
  1852. {
  1853. $show_status = "A";
  1854. $absent++;
  1855. }
  1856. else
  1857. {
  1858. $show_status = "";
  1859. }
  1860. }
  1861. else
  1862. {
  1863. $show_status = "";
  1864. }
  1865. $jindex++;
  1866. }
  1867. else
  1868. {
  1869. $show_status = "-";
  1870. }
  1871. }
  1872. else
  1873. {
  1874. $show_status = "-";
  1875. }
  1876.  
  1877. if ($unpaidFlag)
  1878. {
  1879. $show_status = "U";
  1880. }
  1881. // array_push($output[$index], $show_status);
  1882. }
  1883.  
  1884. array_push($output[$index], $present);
  1885. array_push($output[$index], $absent);
  1886. array_push($output[$index], $weeklyoff_count);
  1887. array_push($output[$index], $leave_count);
  1888. array_push($output[$index], $unpaidleave_count);
  1889. array_push($output[$index], $unscheduled_leave_count);
  1890. $index++;
  1891. }
  1892. return $output;
  1893. }
  1894.  
  1895. public function updateAttendanceLogOptionalHolday($date, $leav_action, $optional_holiday_used = false)
  1896. {
  1897. $criteria = new EMongoCriteria();
  1898. $criteria->shift_date('>=', new MongoDate($date));
  1899. $criteria->shift_date('<', new MongoDate(($date + (24 * 3600))));
  1900. $userAttendanceLog = UserAttendanceLog::model()->tenant($this->tenant_id)->user($this->user_id)->find($criteria);
  1901. if (!empty($userAttendanceLog))
  1902. {
  1903. if ($leav_action == UserLeaves::LEAVE_ACTION_APPROVE)
  1904. {
  1905. $userAttendanceLog->in_leave->status = InLeave::INLEAVE_NO;
  1906. $userAttendanceLog->in_leave->leave_id = null;
  1907. $userAttendanceLog->is_holiday->optional_holiday_used = ($optional_holiday_used == true)? IsHoliday::IS_OPTIONAL_YES : IsHoliday::IS_OPTIONAL_NO;
  1908. }
  1909. $userAttendanceLog->save(false);
  1910. }
  1911. }
  1912. }
Add Comment
Please, Sign In to add comment