variance_of_time_in_project.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * 按项目统计的的工期偏差。
  4. * Variance of time in project.
  5. *
  6. * 范围:project
  7. * 对象:project
  8. * 目的:time
  9. * 度量名称:按项目统计的的工期偏差
  10. * 单位:天
  11. * 描述:按项目统计的工期偏差表示实际工期与计划工期之间的差异。工期偏差的正值表示项目进度延迟,负值表示项目进度提前。工期偏差可以帮助团队及时识别项目进度的偏差,并采取相应的调整措施来重新规划资源和工作计划,以确保项目能够按时完成。
  12. * 定义:复用:;按项目统计的实际工期;按项目统计的计划工期;公式:;按项目统计的工期偏差=按项目统计的实际工期-按项目统计的计划工期;
  13. *
  14. * @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.zentao.net)
  15. * @author qixinzhi <qixinzhi@easycorp.ltd>
  16. * @package
  17. * @uses func
  18. * @license ZPL(https://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
  19. * @Link https://www.zentao.net
  20. */
  21. class variance_of_time_in_project extends baseCalc
  22. {
  23. public $dataset = 'getAllProjects';
  24. public $fieldList = array('t1.id', 't1.begin', 't1.end', 't1.realBegan', 't1.realEnd', 't1.status');
  25. public $result = array();
  26. public function calculate($row)
  27. {
  28. $project = $row->id;
  29. $begin = $row->begin;
  30. $end = $row->end;
  31. $realBegan = $row->realBegan;
  32. $realEnd = $row->realEnd;
  33. $status = $row->status;
  34. if($status != 'doing' and $status != 'closed') return false;
  35. $plan = (strtotime($end) - strtotime($begin)) / 86400;
  36. if($status == 'doing')
  37. {
  38. if(!$this->isDate($realBegan)) return false;
  39. $realEnd = date('Y-m-d');
  40. }
  41. if($status == 'closed' && (!$this->isDate($realBegan) || !$this->isDate($realEnd))) return false;
  42. $actual = (strtotime($realEnd) - strtotime($realBegan)) / 86400;
  43. $this->result[$project] = $actual - $plan;
  44. }
  45. public function getResult($options = array())
  46. {
  47. $records = $this->getRecords(array('project', 'value'));
  48. return $this->filterByOptions($records, $options);
  49. }
  50. }