diff --git a/workflow/engine/classes/model/AppDelegation.php b/workflow/engine/classes/model/AppDelegation.php
index bec999201..45d064f14 100755
--- a/workflow/engine/classes/model/AppDelegation.php
+++ b/workflow/engine/classes/model/AppDelegation.php
@@ -1,635 +1,882 @@
-.
- *
- * For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
- * Coral Gables, FL, 33134, USA, or email info@colosa.com.
- *
- */
-
-//require_once 'classes/model/om/BaseAppDelegation.php';
-//require_once ("classes/model/HolidayPeer.php");
-//require_once ("classes/model/TaskPeer.php");
-//require_once ("classes/model/Task.php");
-//G::LoadClass( "dates" );
-
-/**
- * Skeleton subclass for representing a row from the 'APP_DELEGATION' table.
- *
- *
- *
- * You should add additional methods to this class to meet the
- * application requirements. This class will only be generated as
- * long as it does not already exist in the output directory.
- *
- * @package workflow.engine.classes.model
- */
-class AppDelegation extends BaseAppDelegation
-{
-
- /**
- * create an application delegation
- *
- * @param $sProUid process Uid
- * @param $sAppUid Application Uid
- * @param $sTasUid Task Uid
- * @param $sUsrUid User Uid
- * @param $iPriority delegation priority
- * @param $isSubprocess is a subprocess inside a process?
- * @return delegation index of the application delegation.
- */
- public function createAppDelegation ($sProUid, $sAppUid, $sTasUid, $sUsrUid, $sAppThread, $iPriority = 3, $isSubprocess = false, $sPrevious = -1, $sNextTasParam = null)
- {
- if (! isset( $sProUid ) || strlen( $sProUid ) == 0) {
- throw (new Exception( 'Column "PRO_UID" cannot be null.' ));
- }
-
- if (! isset( $sAppUid ) || strlen( $sAppUid ) == 0) {
- throw (new Exception( 'Column "APP_UID" cannot be null.' ));
- }
-
- if (! isset( $sTasUid ) || strlen( $sTasUid ) == 0) {
- throw (new Exception( 'Column "TAS_UID" cannot be null.' ));
- }
-
- if (! isset( $sUsrUid ) /*|| strlen($sUsrUid ) == 0*/ ) {
- throw (new Exception( 'Column "USR_UID" cannot be null.' ));
- }
-
- if (! isset( $sAppThread ) || strlen( $sAppThread ) == 0) {
- throw (new Exception( 'Column "APP_THREAD" cannot be null.' ));
- }
-
- //Get max DEL_INDEX
- $criteria = new Criteria("workflow");
- $criteria->add(AppDelegationPeer::APP_UID, $sAppUid);
- $criteria->add(AppDelegationPeer::DEL_LAST_INDEX, 1);
-
- $criteriaIndex = clone $criteria;
-
- $rs = AppDelegationPeer::doSelectRS($criteriaIndex);
- $rs->setFetchmode(ResultSet::FETCHMODE_ASSOC);
-
- $delIndex = 1;
- $delPreviusUsrUid = '';
- if ($rs->next()) {
- $row = $rs->getRow();
-
- $delIndex = (isset($row["DEL_INDEX"]))? $row["DEL_INDEX"] + 1 : 1;
- $delPreviusUsrUid = $row["USR_UID"];
- } else {
- $criteriaDelIndex = new Criteria("workflow");
-
- $criteriaDelIndex->addSelectColumn(AppDelegationPeer::DEL_INDEX);
- $criteriaDelIndex->addSelectColumn(AppDelegationPeer::DEL_DELEGATE_DATE);
- $criteriaDelIndex->add(AppDelegationPeer::APP_UID, $sAppUid);
- $criteriaDelIndex->addDescendingOrderByColumn(AppDelegationPeer::DEL_DELEGATE_DATE);
-
- $rsCriteriaDelIndex = AppDelegationPeer::doSelectRS($criteriaDelIndex);
- $rsCriteriaDelIndex->setFetchmode(ResultSet::FETCHMODE_ASSOC);
-
- if ($rsCriteriaDelIndex->next()) {
- $row = $rsCriteriaDelIndex->getRow();
-
- $delIndex = (isset($row["DEL_INDEX"]))? $row["DEL_INDEX"] + 1 : 1;
- }
- }
-
- //Update set
- $criteriaUpdate = new Criteria('workflow');
- $criteriaUpdate->add(AppDelegationPeer::DEL_LAST_INDEX, 0);
- BasePeer::doUpdate($criteria, $criteriaUpdate, Propel::getConnection('workflow'));
-
- $this->setAppUid( $sAppUid );
- $this->setProUid( $sProUid );
- $this->setTasUid( $sTasUid );
- $this->setDelIndex( $delIndex );
- $this->setDelLastIndex(1);
- $this->setDelPrevious( $sPrevious == - 1 ? 0 : $sPrevious );
- $this->setUsrUid( $sUsrUid );
- $this->setDelType( 'NORMAL' );
- $this->setDelPriority( ($iPriority != '' ? $iPriority : '3') );
- $this->setDelThread( $sAppThread );
- $this->setDelThreadStatus( 'OPEN' );
- $this->setDelDelegateDate( 'now' );
-
- //The function return an array now. By JHL
- $delTaskDueDate = $this->calculateDueDate( $sNextTasParam );
-
- //$this->setDelTaskDueDate( $delTaskDueDate['DUE_DATE'] ); // Due date formatted
- $this->setDelTaskDueDate( $delTaskDueDate );
-
- if ((defined( "DEBUG_CALENDAR_LOG" )) && (DEBUG_CALENDAR_LOG)) {
- //$this->setDelData( $delTaskDueDate['DUE_DATE_LOG'] ); // Log of actions made by Calendar Engine
- $this->setDelData( $delTaskDueDate );
- } else {
- $this->setDelData( '' );
- }
-
- // this condition assures that an internal delegation like a subprocess dont have an initial date setted
- if ($delIndex == 1 && ! $isSubprocess) {
- //the first delegation, init date this should be now for draft applications, in other cases, should be null.
- $this->setDelInitDate( 'now' );
- }
-
- if ($this->validate()) {
- try {
- $res = $this->save();
+.
+ *
+ * For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
+ * Coral Gables, FL, 33134, USA, or email info@colosa.com.
+ *
+ */
+
+//require_once 'classes/model/om/BaseAppDelegation.php';
+//require_once ("classes/model/HolidayPeer.php");
+//require_once ("classes/model/TaskPeer.php");
+//require_once ("classes/model/Task.php");
+//G::LoadClass( "dates" );
+
+/**
+ * Skeleton subclass for representing a row from the 'APP_DELEGATION' table.
+ *
+ *
+ *
+ * You should add additional methods to this class to meet the
+ * application requirements. This class will only be generated as
+ * long as it does not already exist in the output directory.
+ *
+ * @package workflow.engine.classes.model
+ */
+class AppDelegation extends BaseAppDelegation
+{
+
+ /**
+ * create an application delegation
+ *
+ * @param $sProUid process Uid
+ * @param $sAppUid Application Uid
+ * @param $sTasUid Task Uid
+ * @param $sUsrUid User Uid
+ * @param $iPriority delegation priority
+ * @param $isSubprocess is a subprocess inside a process?
+ * @return delegation index of the application delegation.
+ */
+ public function createAppDelegation ($sProUid, $sAppUid, $sTasUid, $sUsrUid, $sAppThread, $iPriority = 3, $isSubprocess = false, $sPrevious = -1, $sNextTasParam = null)
+ {
+ if (! isset( $sProUid ) || strlen( $sProUid ) == 0) {
+ throw (new Exception( 'Column "PRO_UID" cannot be null.' ));
+ }
+
+ if (! isset( $sAppUid ) || strlen( $sAppUid ) == 0) {
+ throw (new Exception( 'Column "APP_UID" cannot be null.' ));
+ }
+
+ if (! isset( $sTasUid ) || strlen( $sTasUid ) == 0) {
+ throw (new Exception( 'Column "TAS_UID" cannot be null.' ));
+ }
+
+ if (! isset( $sUsrUid ) /*|| strlen($sUsrUid ) == 0*/ ) {
+ throw (new Exception( 'Column "USR_UID" cannot be null.' ));
+ }
+
+ if (! isset( $sAppThread ) || strlen( $sAppThread ) == 0) {
+ throw (new Exception( 'Column "APP_THREAD" cannot be null.' ));
+ }
+
+ //Get max DEL_INDEX
+ $criteria = new Criteria("workflow");
+ $criteria->add(AppDelegationPeer::APP_UID, $sAppUid);
+ $criteria->add(AppDelegationPeer::DEL_LAST_INDEX, 1);
+
+ $criteriaIndex = clone $criteria;
+
+ $rs = AppDelegationPeer::doSelectRS($criteriaIndex);
+ $rs->setFetchmode(ResultSet::FETCHMODE_ASSOC);
+
+ $delIndex = 1;
+ $delPreviusUsrUid = '';
+ if ($rs->next()) {
+ $row = $rs->getRow();
+
+ $delIndex = (isset($row["DEL_INDEX"]))? $row["DEL_INDEX"] + 1 : 1;
+ $delPreviusUsrUid = $row["USR_UID"];
+ } else {
+ $criteriaDelIndex = new Criteria("workflow");
+
+ $criteriaDelIndex->addSelectColumn(AppDelegationPeer::DEL_INDEX);
+ $criteriaDelIndex->addSelectColumn(AppDelegationPeer::DEL_DELEGATE_DATE);
+ $criteriaDelIndex->add(AppDelegationPeer::APP_UID, $sAppUid);
+ $criteriaDelIndex->addDescendingOrderByColumn(AppDelegationPeer::DEL_DELEGATE_DATE);
+
+ $rsCriteriaDelIndex = AppDelegationPeer::doSelectRS($criteriaDelIndex);
+ $rsCriteriaDelIndex->setFetchmode(ResultSet::FETCHMODE_ASSOC);
+
+ if ($rsCriteriaDelIndex->next()) {
+ $row = $rsCriteriaDelIndex->getRow();
+
+ $delIndex = (isset($row["DEL_INDEX"]))? $row["DEL_INDEX"] + 1 : 1;
+ }
+ }
+
+ //Update set
+ $criteriaUpdate = new Criteria('workflow');
+ $criteriaUpdate->add(AppDelegationPeer::DEL_LAST_INDEX, 0);
+ BasePeer::doUpdate($criteria, $criteriaUpdate, Propel::getConnection('workflow'));
+
+ $this->setAppUid( $sAppUid );
+ $this->setProUid( $sProUid );
+ $this->setTasUid( $sTasUid );
+ $this->setDelIndex( $delIndex );
+ $this->setDelLastIndex(1);
+ $this->setDelPrevious( $sPrevious == - 1 ? 0 : $sPrevious );
+ $this->setUsrUid( $sUsrUid );
+ $this->setDelType( 'NORMAL' );
+ $this->setDelPriority( ($iPriority != '' ? $iPriority : '3') );
+ $this->setDelThread( $sAppThread );
+ $this->setDelThreadStatus( 'OPEN' );
+ $this->setDelDelegateDate( 'now' );
+
+ //The function return an array now. By JHL
+ $delTaskDueDate = $this->calculateDueDate( $sNextTasParam );
+
+ //$this->setDelTaskDueDate( $delTaskDueDate['DUE_DATE'] ); // Due date formatted
+ $this->setDelTaskDueDate( $delTaskDueDate );
+
+ if ((defined( "DEBUG_CALENDAR_LOG" )) && (DEBUG_CALENDAR_LOG)) {
+ //$this->setDelData( $delTaskDueDate['DUE_DATE_LOG'] ); // Log of actions made by Calendar Engine
+ $this->setDelData( $delTaskDueDate );
+ } else {
+ $this->setDelData( '' );
+ }
+
+ // this condition assures that an internal delegation like a subprocess dont have an initial date setted
+ if ($delIndex == 1 && ! $isSubprocess) {
+ //the first delegation, init date this should be now for draft applications, in other cases, should be null.
+ $this->setDelInitDate( 'now' );
+ }
+
+ if ($this->validate()) {
+ try {
+ $res = $this->save();
$inbox = new ListInbox();
- $inbox->newRow($this->toArray(BasePeer::TYPE_FIELDNAME), $delPreviusUsrUid);
- } catch (PropelException $e) {
- throw ($e);
- }
- } else {
- // Something went wrong. We can now get the validationFailures and handle them.
- $msg = '';
- $validationFailuresArray = $this->getValidationFailures();
- foreach ($validationFailuresArray as $objValidationFailure) {
- $msg .= $objValidationFailure->getMessage() . "
";
- }
- throw (new Exception( 'Failed Data validation. ' . $msg ));
- }
-
- $delIndex = $this->getDelIndex();
-
- // Hook for the trigger PM_CREATE_NEW_DELEGATION
- if (defined( 'PM_CREATE_NEW_DELEGATION' )) {
- $data = new stdclass();
- $data->TAS_UID = $sTasUid;
- $data->APP_UID = $sAppUid;
- $data->DEL_INDEX = $delIndex;
- $data->USR_UID = $sUsrUid;
- $oPluginRegistry = &PMPluginRegistry::getSingleton();
- $oPluginRegistry->executeTriggers( PM_CREATE_NEW_DELEGATION, $data );
- }
-
- return $delIndex;
- }
-
- /**
- * Load the Application Delegation row specified in [app_id] column value.
- *
- * @param string $AppUid the uid of the application
- * @return array $Fields the fields
- */
-
- public function Load ($AppUid, $sDelIndex)
- {
- $con = Propel::getConnection( AppDelegationPeer::DATABASE_NAME );
- try {
- $oAppDel = AppDelegationPeer::retrieveByPk( $AppUid, $sDelIndex );
- if (is_object( $oAppDel ) && get_class( $oAppDel ) == 'AppDelegation') {
- $aFields = $oAppDel->toArray( BasePeer::TYPE_FIELDNAME );
- $this->fromArray( $aFields, BasePeer::TYPE_FIELDNAME );
- return $aFields;
- } else {
- throw (new Exception( "The row '$AppUid, $sDelIndex' in table AppDelegation doesn't exist!" ));
- }
- } catch (Exception $oError) {
- throw ($oError);
- }
- }
-
- /* Load the Application Delegation row specified in [app_id] column value.
- *
- * @param string $AppUid the uid of the application
- * @return array $Fields the fields
- */
-
- public function LoadParallel ($AppUid)
- {
- $aCases = array();
-
- $c = new Criteria( 'workflow' );
- $c->addSelectColumn( AppDelegationPeer::APP_UID );
- $c->addSelectColumn( AppDelegationPeer::DEL_INDEX );
- $c->addSelectColumn( AppDelegationPeer::PRO_UID );
- $c->addSelectColumn( AppDelegationPeer::TAS_UID );
- $c->addSelectColumn( AppDelegationPeer::USR_UID );
-
- $c->add( AppDelegationPeer::DEL_THREAD_STATUS, 'OPEN' );
- $c->add( AppDelegationPeer::APP_UID, $AppUid );
- $c->addDescendingOrderByColumn( AppDelegationPeer::DEL_INDEX );
- $rs = AppDelegationPeer::doSelectRS( $c );
- $row= $rs->setFetchmode( ResultSet::FETCHMODE_ASSOC );
-
- $rs->next();
- $row = $rs->getRow();
-
- while (is_array($row)) {
- $case = array();
- $case['TAS_UID'] = $row['TAS_UID'];
- $case['USR_UID'] = $row['USR_UID'];
- $aCases[] = $case;
- $rs->next();
- $row = $rs->getRow();
- }
-
- return $aCases;
- }
-
- /**
- * Update the application row
- *
- * @param array $aData
- * @return variant
- *
- */
-
- public function update ($aData)
- {
- $con = Propel::getConnection( AppDelegationPeer::DATABASE_NAME );
- try {
- $con->begin();
- $oApp = AppDelegationPeer::retrieveByPK( $aData['APP_UID'], $aData['DEL_INDEX'] );
- if (is_object( $oApp ) && get_class( $oApp ) == 'AppDelegation') {
- $oApp->fromArray( $aData, BasePeer::TYPE_FIELDNAME );
- if ($oApp->validate()) {
- $res = $oApp->save();
- $con->commit();
- return $res;
- } else {
- $msg = '';
- foreach ($this->getValidationFailures() as $objValidationFailure) {
- $msg .= $objValidationFailure->getMessage() . "
";
- }
-
- throw (new PropelException( 'The row cannot be created!', new PropelException( $msg ) ));
- }
- } else {
- $con->rollback();
- throw (new Exception( "This AppDelegation row doesn't exist!" ));
- }
- } catch (Exception $oError) {
- throw ($oError);
- }
- }
-
- public function remove ($sApplicationUID, $iDelegationIndex)
- {
- $oConnection = Propel::getConnection( StepTriggerPeer::DATABASE_NAME );
- try {
- $oConnection->begin();
- $oApp = AppDelegationPeer::retrieveByPK( $sApplicationUID, $iDelegationIndex );
- if (is_object( $oApp ) && get_class( $oApp ) == 'AppDelegation') {
- $result = $oApp->delete();
- }
- $oConnection->commit();
- return $result;
- } catch (Exception $e) {
- $oConnection->rollback();
- throw ($e);
- }
- }
-
- // TasTypeDay = 1 => working days
- // TasTypeDay = 2 => calendar days
- public function calculateDueDate ($sNextTasParam)
- {
- //Get Task properties
- $task = TaskPeer::retrieveByPK( $this->getTasUid() );
-
- $aData['TAS_UID'] = $this->getTasUid();
- //Added to allow User defined Timing Control at Run time from Derivation screen
- if (isset( $sNextTasParam['NEXT_TASK']['TAS_TRANSFER_HIDDEN_FLY'] ) && $sNextTasParam['NEXT_TASK']['TAS_TRANSFER_HIDDEN_FLY'] == 'true') {
- $aData['TAS_DURATION'] = $sNextTasParam['NEXT_TASK']['TAS_DURATION'];
- $aData['TAS_TIMEUNIT'] = $sNextTasParam['NEXT_TASK']['TAS_TIMEUNIT'];
- $aData['TAS_TYPE_DAY'] = $sNextTasParam['NEXT_TASK']['TAS_TYPE_DAY'];
-
- if (isset( $sNextTasParam['NEXT_TASK']['TAS_CALENDAR'] ) && $sNextTasParam['NEXT_TASK']['TAS_CALENDAR'] != '') {
- $aCalendarUID = $sNextTasParam['NEXT_TASK']['TAS_CALENDAR'];
- } else {
- $aCalendarUID = '';
- }
-
- //Updating the task Table , so that user will see updated values in the assign screen in consequent cases
- $oTask = new Task();
- $oTask->update( $aData );
- } else {
- if (is_null( $task )) {
- return 0;
- }
- $aData['TAS_DURATION'] = $task->getTasDuration();
- $aData['TAS_TIMEUNIT'] = $task->getTasTimeUnit();
- $aData['TAS_TYPE_DAY'] = $task->getTasTypeDay();
- $aCalendarUID = '';
- }
-
- //use the dates class to calculate dates
- $calendar = new calendar();
-
- if ($calendar->pmCalendarUid == '') {
- $calendar->getCalendar(null, $task->getProUid(), $aData['TAS_UID']);
- $calData = $calendar->getCalendarData();
- }
-
- /*$iDueDate = $calendar->calculateDate( $this->getDelDelegateDate(), $aData['TAS_DURATION'], $aData['TAS_TIMEUNIT'] //hours or days, ( we only accept this two types or maybe weeks
- );*/
- $iDueDate = $calendar->dashCalculateDate($this->getDelDelegateDate(), $aData['TAS_DURATION'], $aData['TAS_TIMEUNIT'], $calData);
- return $iDueDate;
- }
-
- public function getDiffDate ($date1, $date2)
- {
- return ($date1 - $date2) / (24 * 60 * 60); //days
- return ($date1 - $date2) / 3600;
- }
-
- public function calculateDuration ($cron = 0)
- {
- try {
- if ($cron == 1) {
- $arrayCron = unserialize( trim( @file_get_contents( PATH_DATA . "cron" ) ) );
- $arrayCron["processcTimeStart"] = time();
- @file_put_contents( PATH_DATA . "cron", serialize( $arrayCron ) );
- }
-
- //patch rows with initdate = null and finish_date
- $c = new Criteria();
- $c->clearSelectColumns();
- $c->addSelectColumn( AppDelegationPeer::APP_UID );
- $c->addSelectColumn( AppDelegationPeer::DEL_INDEX );
- $c->addSelectColumn( AppDelegationPeer::DEL_DELEGATE_DATE );
- $c->addSelectColumn( AppDelegationPeer::DEL_FINISH_DATE );
- $c->add( AppDelegationPeer::DEL_INIT_DATE, null, Criteria::ISNULL );
- $c->add( AppDelegationPeer::DEL_FINISH_DATE, null, Criteria::ISNOTNULL );
- //$c->add(AppDelegationPeer::DEL_INDEX, 1);
-
-
- $rs = AppDelegationPeer::doSelectRS( $c );
- $rs->setFetchmode( ResultSet::FETCHMODE_ASSOC );
- $rs->next();
- $row = $rs->getRow();
-
- while (is_array( $row )) {
- $oAppDel = AppDelegationPeer::retrieveByPk( $row['APP_UID'], $row['DEL_INDEX'] );
- if (isset( $row['DEL_FINISH_DATE'] )) {
- $oAppDel->setDelInitDate( $row['DEL_FINISH_DATE'] );
- } else {
- $oAppDel->setDelInitDate( $row['DEL_INIT_DATE'] );
- }
- $oAppDel->save();
-
- $rs->next();
- $row = $rs->getRow();
- }
- //walk in all rows with DEL_STARTED = 0 or DEL_FINISHED = 0
-
-
- $c = new Criteria( 'workflow' );
- $c->clearSelectColumns();
- $c->addSelectColumn( AppDelegationPeer::APP_UID );
- $c->addSelectColumn( AppDelegationPeer::DEL_INDEX );
- $c->addSelectColumn( AppDelegationPeer::USR_UID);
- $c->addSelectColumn( AppDelegationPeer::PRO_UID);
- $c->addSelectColumn( AppDelegationPeer::TAS_UID);
- $c->addSelectColumn( AppDelegationPeer::DEL_DELEGATE_DATE );
- $c->addSelectColumn( AppDelegationPeer::DEL_INIT_DATE );
- $c->addSelectColumn( AppDelegationPeer::DEL_TASK_DUE_DATE );
- $c->addSelectColumn( AppDelegationPeer::DEL_FINISH_DATE );
- $c->addSelectColumn( AppDelegationPeer::DEL_DURATION );
- $c->addSelectColumn( AppDelegationPeer::DEL_QUEUE_DURATION );
- $c->addSelectColumn( AppDelegationPeer::DEL_DELAY_DURATION );
- $c->addSelectColumn( AppDelegationPeer::DEL_STARTED );
- $c->addSelectColumn( AppDelegationPeer::DEL_FINISHED );
- $c->addSelectColumn( AppDelegationPeer::DEL_DELAYED );
- $c->addSelectColumn( TaskPeer::TAS_DURATION );
- $c->addSelectColumn( TaskPeer::TAS_TIMEUNIT );
- $c->addSelectColumn( TaskPeer::TAS_TYPE_DAY );
-
- $c->addJoin( AppDelegationPeer::TAS_UID, TaskPeer::TAS_UID, Criteria::LEFT_JOIN );
- //$c->add(AppDelegationPeer::DEL_INIT_DATE, NULL, Criteria::ISNULL);
- //$c->add(AppDelegationPeer::APP_UID, '7694483844a37bfeb0931b1063501289');
- //$c->add(AppDelegationPeer::DEL_STARTED, 0);
-
-
- $cton1 = $c->getNewCriterion( AppDelegationPeer::DEL_STARTED, 0 );
- $cton2 = $c->getNewCriterion( AppDelegationPeer::DEL_FINISHED, 0 );
- $cton1->addOR( $cton2 );
- $c->add( $cton1 );
-
- $rs = AppDelegationPeer::doSelectRS( $c );
- $rs->setFetchmode( ResultSet::FETCHMODE_ASSOC );
- $rs->next();
- $row = $rs->getRow();
- $i = 0;
- //print "
";
- //print "| iDelegateDate | iInitDate | iDueDate | iFinishDate | isStarted | isFinished | isDelayed | queueDuration | delDuration | delayDuration |
";
-
- $calendar = new calendar();
-
- $now = strtotime( 'now' );
- while (is_array( $row )) {
- $fTaskDuration = $row['TAS_DURATION'];
- $fTaskDurationUnit = $row['TAS_TIMEUNIT'];
- $iDelegateDate = strtotime( $row['DEL_DELEGATE_DATE'] );
- $iInitDate = strtotime( $row['DEL_INIT_DATE'] );
- $iDueDate = strtotime( $row['DEL_TASK_DUE_DATE'] );
- $iFinishDate = strtotime( $row['DEL_FINISH_DATE'] );
- $isStarted = intval( $row['DEL_STARTED'] );
- $isFinished = intval( $row['DEL_FINISHED'] );
- $isDelayed = intval( $row['DEL_DELAYED'] );
- $queueDuration = $this->getDiffDate( $iInitDate, $iDelegateDate );
- $delDuration = 0;
- $delayDuration = 0;
- $overduePercentage = 0.0;
- //get the object,
- $oAppDel = AppDelegationPeer::retrieveByPk( $row['APP_UID'], $row['DEL_INDEX'] );
-
- //getting the calendar
- $calendar->getCalendar($row['USR_UID'], $row['PRO_UID'], $row['TAS_UID']);
- $calData = $calendar->getCalendarData();
-
- //Recalculating DueDate with the user calendar if it exist. It allways will take the derivation date like initial date.
+ $inbox->newRow($this->toArray(BasePeer::TYPE_FIELDNAME), $delPreviusUsrUid);
+ } catch (PropelException $e) {
+ throw ($e);
+ }
+ } else {
+ // Something went wrong. We can now get the validationFailures and handle them.
+ $msg = '';
+ $validationFailuresArray = $this->getValidationFailures();
+ foreach ($validationFailuresArray as $objValidationFailure) {
+ $msg .= $objValidationFailure->getMessage() . "
";
+ }
+ throw (new Exception( 'Failed Data validation. ' . $msg ));
+ }
+
+ $delIndex = $this->getDelIndex();
+
+ // Hook for the trigger PM_CREATE_NEW_DELEGATION
+ if (defined( 'PM_CREATE_NEW_DELEGATION' )) {
+ $data = new stdclass();
+ $data->TAS_UID = $sTasUid;
+ $data->APP_UID = $sAppUid;
+ $data->DEL_INDEX = $delIndex;
+ $data->USR_UID = $sUsrUid;
+ $oPluginRegistry = &PMPluginRegistry::getSingleton();
+ $oPluginRegistry->executeTriggers(PM_CREATE_NEW_DELEGATION, $data);
+
+ /*----------------------------------********---------------------------------*/
+ // this section evaluates the actions by email trigger execution please
+ // modify this section carefully, the if evaluation checks if the license has been
+ // activated in order to send the mail according to the configuration table
+ if (PMLicensedFeatures
+ ::getSingleton()
+ ->verifyfeature('zLhSk5TeEQrNFI2RXFEVktyUGpnczV1WEJNWVp6cjYxbTU3R29mVXVZNWhZQT0=')) {
+ G::LoadClass('actionsByEmail');
+ $actionsByEmail = new actionsByEmailClass();
+ $actionsByEmail->sendActionsByEmail($data);
+ }
+ /*----------------------------------********---------------------------------*/
+ }
+
+ return $delIndex;
+ }
+
+ /**
+ * Load the Application Delegation row specified in [app_id] column value.
+ *
+ * @param string $AppUid the uid of the application
+ * @return array $Fields the fields
+ */
+
+ public function Load ($AppUid, $sDelIndex)
+ {
+ $con = Propel::getConnection( AppDelegationPeer::DATABASE_NAME );
+ try {
+ $oAppDel = AppDelegationPeer::retrieveByPk( $AppUid, $sDelIndex );
+ if (is_object( $oAppDel ) && get_class( $oAppDel ) == 'AppDelegation') {
+ $aFields = $oAppDel->toArray( BasePeer::TYPE_FIELDNAME );
+ $this->fromArray( $aFields, BasePeer::TYPE_FIELDNAME );
+ return $aFields;
+ } else {
+ throw (new Exception( "The row '$AppUid, $sDelIndex' in table AppDelegation doesn't exist!" ));
+ }
+ } catch (Exception $oError) {
+ throw ($oError);
+ }
+ }
+
+ /* Load the Application Delegation row specified in [app_id] column value.
+ *
+ * @param string $AppUid the uid of the application
+ * @return array $Fields the fields
+ */
+
+ public function LoadParallel ($AppUid)
+ {
+ $aCases = array();
+
+ $c = new Criteria( 'workflow' );
+ $c->addSelectColumn( AppDelegationPeer::APP_UID );
+ $c->addSelectColumn( AppDelegationPeer::DEL_INDEX );
+ $c->addSelectColumn( AppDelegationPeer::PRO_UID );
+ $c->addSelectColumn( AppDelegationPeer::TAS_UID );
+ $c->addSelectColumn( AppDelegationPeer::USR_UID );
+ $c->addSelectColumn( AppDelegationPeer::DEL_DELEGATE_DATE );
+ $c->addSelectColumn( AppDelegationPeer::DEL_INIT_DATE );
+ $c->addSelectColumn( AppDelegationPeer::DEL_TASK_DUE_DATE );
+ $c->addSelectColumn( AppDelegationPeer::DEL_FINISH_DATE );
+
+ $c->add( AppDelegationPeer::DEL_THREAD_STATUS, 'OPEN' );
+ $c->add( AppDelegationPeer::APP_UID, $AppUid );
+ $c->addDescendingOrderByColumn( AppDelegationPeer::DEL_INDEX );
+ $rs = AppDelegationPeer::doSelectRS( $c );
+ $row= $rs->setFetchmode( ResultSet::FETCHMODE_ASSOC );
+
+ $rs->next();
+ $row = $rs->getRow();
+
+ while (is_array($row)) {
+ $case = array();
+ $case['TAS_UID'] = $row['TAS_UID'];
+ $case['USR_UID'] = $row['USR_UID'];
+ $case['DEL_INDEX'] = $row['DEL_INDEX'];
+ $case['TAS_UID'] = $row['TAS_UID'];
+ $case['DEL_DELEGATE_DATE'] = $row['DEL_DELEGATE_DATE'];
+ $case['DEL_INIT_DATE'] = $row['DEL_INIT_DATE'];
+ $case['DEL_TASK_DUE_DATE'] = $row['DEL_TASK_DUE_DATE'];
+ $case['DEL_FINISH_DATE'] = $row['DEL_FINISH_DATE'];
+ $aCases[] = $case;
+ $rs->next();
+ $row = $rs->getRow();
+ }
+
+ return $aCases;
+ }
+
+ /**
+ * Update the application row
+ *
+ * @param array $aData
+ * @return variant
+ *
+ */
+
+ public function update ($aData)
+ {
+ $con = Propel::getConnection( AppDelegationPeer::DATABASE_NAME );
+ try {
+ $con->begin();
+ $oApp = AppDelegationPeer::retrieveByPK( $aData['APP_UID'], $aData['DEL_INDEX'] );
+ if (is_object( $oApp ) && get_class( $oApp ) == 'AppDelegation') {
+ $oApp->fromArray( $aData, BasePeer::TYPE_FIELDNAME );
+ if ($oApp->validate()) {
+ $res = $oApp->save();
+ $con->commit();
+ return $res;
+ } else {
+ $msg = '';
+ foreach ($this->getValidationFailures() as $objValidationFailure) {
+ $msg .= $objValidationFailure->getMessage() . "
";
+ }
+
+ throw (new PropelException( 'The row cannot be created!', new PropelException( $msg ) ));
+ }
+ } else {
+ $con->rollback();
+ throw (new Exception( "This AppDelegation row doesn't exist!" ));
+ }
+ } catch (Exception $oError) {
+ throw ($oError);
+ }
+ }
+
+ public function remove ($sApplicationUID, $iDelegationIndex)
+ {
+ $oConnection = Propel::getConnection( StepTriggerPeer::DATABASE_NAME );
+ try {
+ $oConnection->begin();
+ $oApp = AppDelegationPeer::retrieveByPK( $sApplicationUID, $iDelegationIndex );
+ if (is_object( $oApp ) && get_class( $oApp ) == 'AppDelegation') {
+ $result = $oApp->delete();
+ }
+ $oConnection->commit();
+ return $result;
+ } catch (Exception $e) {
+ $oConnection->rollback();
+ throw ($e);
+ }
+ }
+
+ // TasTypeDay = 1 => working days
+ // TasTypeDay = 2 => calendar days
+ public function calculateDueDate ($sNextTasParam)
+ {
+ //Get Task properties
+ $task = TaskPeer::retrieveByPK( $this->getTasUid() );
+
+ $aData['TAS_UID'] = $this->getTasUid();
+ //Added to allow User defined Timing Control at Run time from Derivation screen
+ if (isset( $sNextTasParam['NEXT_TASK']['TAS_TRANSFER_HIDDEN_FLY'] ) && $sNextTasParam['NEXT_TASK']['TAS_TRANSFER_HIDDEN_FLY'] == 'true') {
+ $aData['TAS_DURATION'] = $sNextTasParam['NEXT_TASK']['TAS_DURATION'];
+ $aData['TAS_TIMEUNIT'] = $sNextTasParam['NEXT_TASK']['TAS_TIMEUNIT'];
+ $aData['TAS_TYPE_DAY'] = $sNextTasParam['NEXT_TASK']['TAS_TYPE_DAY'];
+
+ if (isset( $sNextTasParam['NEXT_TASK']['TAS_CALENDAR'] ) && $sNextTasParam['NEXT_TASK']['TAS_CALENDAR'] != '') {
+ $aCalendarUID = $sNextTasParam['NEXT_TASK']['TAS_CALENDAR'];
+ } else {
+ $aCalendarUID = '';
+ }
+
+ //Updating the task Table , so that user will see updated values in the assign screen in consequent cases
+ $oTask = new Task();
+ $oTask->update( $aData );
+ } else {
+ if (is_null( $task )) {
+ return 0;
+ }
+ $aData['TAS_DURATION'] = $task->getTasDuration();
+ $aData['TAS_TIMEUNIT'] = $task->getTasTimeUnit();
+ $aData['TAS_TYPE_DAY'] = $task->getTasTypeDay();
+ $aCalendarUID = '';
+ }
+
+ //use the dates class to calculate dates
+ $calendar = new calendar();
+
+ if ($calendar->pmCalendarUid == '') {
+ $calendar->getCalendar(null, $task->getProUid(), $aData['TAS_UID']);
+ $calData = $calendar->getCalendarData();
+ }
+
+ /*$iDueDate = $calendar->calculateDate( $this->getDelDelegateDate(), $aData['TAS_DURATION'], $aData['TAS_TIMEUNIT'] //hours or days, ( we only accept this two types or maybe weeks
+ );*/
+ $iDueDate = $calendar->dashCalculateDate($this->getDelDelegateDate(), $aData['TAS_DURATION'], $aData['TAS_TIMEUNIT'], $calData);
+
+ return $iDueDate;
+ }
+
+ public function getDiffDate ($date1, $date2)
+ {
+ return ($date1 - $date2) / (24 * 60 * 60); //days
+ return ($date1 - $date2) / 3600;
+ }
+
+ public function calculateDuration ($cron = 0)
+ {
+ try {
+ if ($cron == 1) {
+ $arrayCron = unserialize( trim( @file_get_contents( PATH_DATA . "cron" ) ) );
+ $arrayCron["processcTimeStart"] = time();
+ @file_put_contents( PATH_DATA . "cron", serialize( $arrayCron ) );
+ }
+
+ //patch rows with initdate = null and finish_date
+ $c = new Criteria();
+ $c->clearSelectColumns();
+ $c->addSelectColumn( AppDelegationPeer::APP_UID );
+ $c->addSelectColumn( AppDelegationPeer::DEL_INDEX );
+ $c->addSelectColumn( AppDelegationPeer::DEL_DELEGATE_DATE );
+ $c->addSelectColumn( AppDelegationPeer::DEL_FINISH_DATE );
+ $c->add( AppDelegationPeer::DEL_INIT_DATE, null, Criteria::ISNULL );
+ $c->add( AppDelegationPeer::DEL_FINISH_DATE, null, Criteria::ISNOTNULL );
+ //$c->add(AppDelegationPeer::DEL_INDEX, 1);
+
+
+ $rs = AppDelegationPeer::doSelectRS( $c );
+ $rs->setFetchmode( ResultSet::FETCHMODE_ASSOC );
+ $rs->next();
+ $row = $rs->getRow();
+
+ while (is_array( $row )) {
+ $oAppDel = AppDelegationPeer::retrieveByPk( $row['APP_UID'], $row['DEL_INDEX'] );
+ if (isset( $row['DEL_FINISH_DATE'] )) {
+ $oAppDel->setDelInitDate( $row['DEL_FINISH_DATE'] );
+ } else {
+ $oAppDel->setDelInitDate( $row['DEL_INIT_DATE'] );
+ }
+ $oAppDel->save();
+
+ $rs->next();
+ $row = $rs->getRow();
+ }
+ //walk in all rows with DEL_STARTED = 0 or DEL_FINISHED = 0
+
+
+ $c = new Criteria( 'workflow' );
+ $c->clearSelectColumns();
+ $c->addSelectColumn( AppDelegationPeer::APP_UID );
+ $c->addSelectColumn( AppDelegationPeer::DEL_INDEX );
+ $c->addSelectColumn( AppDelegationPeer::USR_UID);
+ $c->addSelectColumn( AppDelegationPeer::PRO_UID);
+ $c->addSelectColumn( AppDelegationPeer::TAS_UID);
+ $c->addSelectColumn( AppDelegationPeer::DEL_DELEGATE_DATE );
+ $c->addSelectColumn( AppDelegationPeer::DEL_INIT_DATE );
+ $c->addSelectColumn( AppDelegationPeer::DEL_TASK_DUE_DATE );
+ $c->addSelectColumn( AppDelegationPeer::DEL_FINISH_DATE );
+ $c->addSelectColumn( AppDelegationPeer::DEL_DURATION );
+ $c->addSelectColumn( AppDelegationPeer::DEL_QUEUE_DURATION );
+ $c->addSelectColumn( AppDelegationPeer::DEL_DELAY_DURATION );
+ $c->addSelectColumn( AppDelegationPeer::DEL_STARTED );
+ $c->addSelectColumn( AppDelegationPeer::DEL_FINISHED );
+ $c->addSelectColumn( AppDelegationPeer::DEL_DELAYED );
+ $c->addSelectColumn( TaskPeer::TAS_DURATION );
+ $c->addSelectColumn( TaskPeer::TAS_TIMEUNIT );
+ $c->addSelectColumn( TaskPeer::TAS_TYPE_DAY );
+
+ $c->addJoin( AppDelegationPeer::TAS_UID, TaskPeer::TAS_UID, Criteria::LEFT_JOIN );
+ //$c->add(AppDelegationPeer::DEL_INIT_DATE, NULL, Criteria::ISNULL);
+ //$c->add(AppDelegationPeer::APP_UID, '7694483844a37bfeb0931b1063501289');
+ //$c->add(AppDelegationPeer::DEL_STARTED, 0);
+
+
+ $cton1 = $c->getNewCriterion( AppDelegationPeer::DEL_STARTED, 0 );
+ $cton2 = $c->getNewCriterion( AppDelegationPeer::DEL_FINISHED, 0 );
+ $cton1->addOR( $cton2 );
+ $c->add( $cton1 );
+
+ $rs = AppDelegationPeer::doSelectRS( $c );
+ $rs->setFetchmode( ResultSet::FETCHMODE_ASSOC );
+ $rs->next();
+ $row = $rs->getRow();
+ $i = 0;
+ //print "";
+ //print "| iDelegateDate | iInitDate | iDueDate | iFinishDate | isStarted | isFinished | isDelayed | queueDuration | delDuration | delayDuration |
";
+
+ $calendar = new calendar();
+
+ $now = strtotime( 'now' );
+ while (is_array( $row )) {
+ $fTaskDuration = $row['TAS_DURATION'];
+ $fTaskDurationUnit = $row['TAS_TIMEUNIT'];
+ $iDelegateDate = strtotime( $row['DEL_DELEGATE_DATE'] );
+ $iInitDate = strtotime( $row['DEL_INIT_DATE'] );
+ $iDueDate = strtotime( $row['DEL_TASK_DUE_DATE'] );
+ $iFinishDate = strtotime( $row['DEL_FINISH_DATE'] );
+ $isStarted = intval( $row['DEL_STARTED'] );
+ $isFinished = intval( $row['DEL_FINISHED'] );
+ $isDelayed = intval( $row['DEL_DELAYED'] );
+ $queueDuration = $this->getDiffDate( $iInitDate, $iDelegateDate );
+ $delDuration = 0;
+ $delayDuration = 0;
+ $overduePercentage = 0.0;
+ //get the object,
+ $oAppDel = AppDelegationPeer::retrieveByPk( $row['APP_UID'], $row['DEL_INDEX'] );
+
+ //getting the calendar
+ $calendar->getCalendar($row['USR_UID'], $row['PRO_UID'], $row['TAS_UID']);
+ $calData = $calendar->getCalendarData();
+
+ //Recalculating DueDate with the user calendar if it exist. It allways will take the derivation date like initial date.
$iDueDate = $calendar->dashCalculateDate($row['DEL_DELEGATE_DATE'], $fTaskDuration, $fTaskDurationUnit, $calData);
-
- //if the task is not started
- if ($isStarted == 0) {
- if ($row['DEL_INIT_DATE'] != null && $row['DEL_INIT_DATE'] != '') {
- $oAppDel->setDelStarted( 1 );
- $queueDuration = $this->getDiffDate( $iInitDate, $iDelegateDate );
- $oAppDel->setDelQueueDuration( $queueDuration );
- } else {
- //the task was not started
- $queueDuration = $this->getDiffDate( $now, $iDelegateDate );
- $oAppDel->setDelQueueDuration( $queueDuration );
-
- //we are putting negative number if the task is not delayed, and positive number for the time the task is delayed
+
+ //if the task is not started
+ if ($isStarted == 0) {
+ if ($row['DEL_INIT_DATE'] != null && $row['DEL_INIT_DATE'] != '') {
+ $oAppDel->setDelStarted( 1 );
+ $queueDuration = $this->getDiffDate( $iInitDate, $iDelegateDate );
+ $oAppDel->setDelQueueDuration( $queueDuration );
+ } else {
+ //the task was not started
+ $queueDuration = $this->getDiffDate( $now, $iDelegateDate );
+ $oAppDel->setDelQueueDuration( $queueDuration );
+
+ //we are putting negative number if the task is not delayed, and positive number for the time the task is delayed
//$delayDuration = $this->getDiffDate( $now, $iDueDate );
$delayDuration = $calendar->dashCalculateDurationWithCalendar( $iDueDate, date("Y-m-d H:i:s"), $calData );
- $delayDuration = $delayDuration / (24 * 60 * 60); //Days
- $oAppDel->setDelDelayDuration( $delayDuration );
-
- if ($fTaskDuration != 0) {
- $overduePercentage = $delayDuration / $fTaskDuration;
- $oAppDel->setAppOverduePercentage( $overduePercentage );
- if ($iDueDate < $now) {
- $oAppDel->setDelDelayed( 1 );
- }
- }
- }
- }
-
- //if the task was not finished
- if ($isFinished == 0) {
- if ($row['DEL_FINISH_DATE'] != null && $row['DEL_FINISH_DATE'] != '') {
- $oAppDel->setAppOverduePercentage( $overduePercentage );
- $oAppDel->setDelFinished( 1 );
-
- //$delDuration = $this->getDiffDate( $iFinishDate, $iInitDate );
- $delDuration = $calendar->dashCalculateDurationWithCalendar($row['DEL_INIT_DATE'], $row['DEL_FINISH_DATE'], $calData );
- $delDuration = $delDuration / (24 * 60 * 60); //Saving the delDuration in days. The calculateDurationSLA func returns segs.
-
- $oAppDel->setDelDuration( $delDuration );
- //calculate due date if correspond
- $dueDate = strtotime($iDueDate);
- $finishDate = strtotime($iFinishDate);
- if ($dueDate < $finishDate) {
- $oAppDel->setDelDelayed( 1 );
- //$delayDuration = $this->getDiffDate( $iFinishDate, $iDueDate );
+ $delayDuration = $delayDuration / (24 * 60 * 60); //Days
+ $oAppDel->setDelDelayDuration( $delayDuration );
+ if ($fTaskDuration != 0) {
+ $overduePercentage = $delayDuration / $fTaskDuration;
+ $oAppDel->setAppOverduePercentage( $overduePercentage );
+ if ($iDueDate < $now) {
+ $oAppDel->setDelDelayed( 1 );
+ }
+ }
+ }
+ }
+
+ //if the task was not finished
+ if ($isFinished == 0) {
+ if ($row['DEL_FINISH_DATE'] != null && $row['DEL_FINISH_DATE'] != '') {
+ $oAppDel->setAppOverduePercentage( $overduePercentage );
+ $oAppDel->setDelFinished( 1 );
+
+ //$delDuration = $this->getDiffDate( $iFinishDate, $iInitDate );
+ $delDuration = $this->calculateDurationWithCalendar($row['DEL_INIT_DATE'], $row['DEL_FINISH_DATE'], $calData );//by jen
+ $delDuration = $delDuration / (24 * 60 * 60); //Saving the delDuration in days. The calculateDurationSLA func returns mins.
+
+ $oAppDel->setDelDuration( $delDuration );
+ //calculate due date if correspond
+ if ($iDueDate < $iFinishDate) {
+ $oAppDel->setDelDelayed( 1 );
+ //$delayDuration = $this->getDiffDate( $iFinishDate, $iDueDate );
$delayDuration = $calendar->dashCalculateDurationWithCalendar( $iDueDate, $row['DEL_FINISH_DATE'], $calData );
- $delayDuration = $delayDuration / (24 * 60 * 60); //Days
- } else {
- $oAppDel->setDelDelayed( 0 );
- $delayDuration = 0;
- }
- $oAppDel->setDelDelayDuration( $delayDuration );
- } else {
- //the task was not completed
- if ($row['DEL_INIT_DATE'] != null && $row['DEL_INIT_DATE'] != '') {
- //$delDuration = $this->getDiffDate( $now, $iInitDate );
- $delDuration = $calendar->dashCalculateDurationWithCalendar($row['DEL_INIT_DATE'], date("Y-m-d H:i:s"), $calData );
+ $delayDuration = $delayDuration / (24 * 60 * 60); //Days
+ } else {
+ $oAppDel->setDelDelayed( 0 );
+ $delayDuration = 0;
+ }
+ $oAppDel->setDelDelayDuration( $delayDuration );
+ } else {
+ //the task was not completed
+ if ($row['DEL_INIT_DATE'] != null && $row['DEL_INIT_DATE'] != '') {
+ //$delDuration = $this->getDiffDate( $now, $iInitDate );
+ $delDuration = $this->calculateDurationWithCalendar($row['DEL_INIT_DATE'], date("Y-m-d H:i:s"), $calData );//by jen
$delDuration = $delDuration / (24 * 60 * 60); //Saving the delDuration in days. The calculateDurationSLA func returns mins.
- } else {
+ } else {
//$delDuration = $this->getDiffDate( $now, $iDelegateDate );
- $delDuration = $calendar->dashCalculateDurationWithCalendar($row['DEL_DELEGATE_DATE'], date("Y-m-d H:i:s"), $calData );
- $delDuration = $delDuration / (24 * 60 * 60); //Saving the delDuration in days. The calculateDurationSLA func returns mins.
- }
- $oAppDel->setDelDuration( $delDuration );
-
- //we are putting negative number if the task is not delayed, and positive number for the time the task is delayed
- //$delayDuration = $this->getDiffDate( $now, $iDueDate );
+ $delDuration = $this->calculateDurationWithCalendar($row['DEL_DELEGATE_DATE'], date("Y-m-d H:i:s"), $calData ); //byJen
+ $delDuration = $delDuration / (24 * 60 * 60); //Saving the delDuration in days. The calculateDurationSLA func returns mins.
+ }
+ $oAppDel->setDelDuration( $delDuration );
+
+ //we are putting negative number if the task is not delayed, and positive number for the time the task is delayed
+ //$delayDuration = $this->getDiffDate( $now, $iDueDate );
$delayDuration = $calendar->dashCalculateDurationWithCalendar( $iDueDate, date("Y-m-d H:i:s"), $calData );
- $delayDuration = $delayDuration / (24 * 60 * 60); //Days
- $oAppDel->setDelDelayDuration( $delayDuration );
- if ($fTaskDuration != 0) {
- $overduePercentage = $delayDuration / $fTaskDuration;
- $oAppDel->setAppOverduePercentage( $overduePercentage );
- if ($iDueDate < $now) {
- $oAppDel->setDelDelayed( 1 );
- }
- }
- }
-
- }
- //and finally save the record
- $RES = $oAppDel->save();
- $rs->next();
- $row = $rs->getRow();
- }
-
- if ($cron == 1) {
- $arrayCron = unserialize( trim( @file_get_contents( PATH_DATA . "cron" ) ) );
- $arrayCron["processcTimeStart"] = time();
- @file_put_contents( PATH_DATA . "cron", serialize( $arrayCron ) );
- }
- } catch (Exception $oError) {
- error_log( $oError->getMessage() );
- }
- }
-
- public function getLastDeleration ($APP_UID)
+ $delayDuration = $delayDuration / (24 * 60 * 60); //Days
+ $oAppDel->setDelDelayDuration( $delayDuration );
+ if ($fTaskDuration != 0) {
+ $overduePercentage = $delayDuration / $fTaskDuration;
+ $oAppDel->setAppOverduePercentage( $overduePercentage );
+ if ($iDueDate < $now) {
+ $oAppDel->setDelDelayed( 1 );
+ }
+ }
+ }
+
+ }
+ //and finally save the record
+ $RES = $oAppDel->save();
+ $rs->next();
+ $row = $rs->getRow();
+ }
+
+ if ($cron == 1) {
+ $arrayCron = unserialize( trim( @file_get_contents( PATH_DATA . "cron" ) ) );
+ $arrayCron["processcTimeStart"] = time();
+ @file_put_contents( PATH_DATA . "cron", serialize( $arrayCron ) );
+ }
+ } catch (Exception $oError) {
+ error_log( $oError->getMessage() );
+ }
+ }
+
+ //Calculate the duration betwen two dates with a calendar
+ public function calculateDurationWithCalendar ($iniDate, $finDate = null, $calendarData = array())
{
- $c = new Criteria( 'workflow' );
- $c->addSelectColumn( AppDelegationPeer::APP_UID );
- $c->addSelectColumn( AppDelegationPeer::DEL_INDEX );
- $c->addSelectColumn( AppDelegationPeer::DEL_DELEGATE_DATE );
- $c->addSelectColumn( AppDelegationPeer::DEL_INIT_DATE );
- $c->addSelectColumn( AppDelegationPeer::DEL_TASK_DUE_DATE );
- $c->addSelectColumn( AppDelegationPeer::DEL_FINISH_DATE );
- $c->addSelectColumn( AppDelegationPeer::DEL_DURATION );
- $c->addSelectColumn( AppDelegationPeer::DEL_QUEUE_DURATION );
- $c->addSelectColumn( AppDelegationPeer::DEL_DELAY_DURATION );
- $c->addSelectColumn( AppDelegationPeer::DEL_STARTED );
- $c->addSelectColumn( AppDelegationPeer::DEL_FINISHED );
- $c->addSelectColumn( AppDelegationPeer::DEL_DELAYED );
- $c->addSelectColumn( AppDelegationPeer::USR_UID );
-
- $c->add( AppDelegationPeer::APP_UID, $APP_UID );
- $c->addDescendingOrderByColumn( AppDelegationPeer::DEL_INDEX );
- $rs = AppDelegationPeer::doSelectRS( $c );
- $rs->setFetchmode( ResultSet::FETCHMODE_ASSOC );
- $rs->next();
- return $rs->getRow();
- }
-
- public function getCurrentIndex ($appUid)
- {
- $oCriteria = new Criteria();
- $oCriteria->addSelectColumn( AppDelegationPeer::DEL_INDEX );
- $oCriteria->add( AppDelegationPeer::APP_UID, $appUid );
- $oCriteria->addDescendingOrderByColumn( AppDelegationPeer::DEL_INDEX );
- $oRuleSet = AppDelegationPeer::doSelectRS( $oCriteria );
- $oRuleSet->setFetchmode( ResultSet::FETCHMODE_ASSOC );
- $oRuleSet->next();
- $data = $oRuleSet->getRow();
- return (int)$data['DEL_INDEX'];
- }
-
- public function getCurrentTask ($appUid)
- {
- $oCriteria = new Criteria();
- $oCriteria->addSelectColumn( AppDelegationPeer::TAS_UID );
- $oCriteria->add( AppDelegationPeer::APP_UID, $appUid );
- $oCriteria->addDescendingOrderByColumn( AppDelegationPeer::DEL_INDEX );
- $oRuleSet = AppDelegationPeer::doSelectRS( $oCriteria );
- $oRuleSet->setFetchmode( ResultSet::FETCHMODE_ASSOC );
- $oRuleSet->next();
- $data = $oRuleSet->getRow();
- return $data['TAS_UID'];
+ if ((is_null($finDate)) || ($finDate == '')) {
+ $finDate = date('Y-m-d H:i:s');
+ }
+
+ $secondDuration = 0.00;
+
+ if ( (strtotime($iniDate)) < (strtotime($finDate)) ) {
+ $timeIniDate = strtotime($iniDate);
+ $timeFinDate = strtotime($finDate);
+
+ } elseif ( (strtotime($finDate)) < (strtotime($iniDate)) ) {
+ $timeIniDate = strtotime($finDate);
+ $timeFinDate = strtotime($iniDate);
+ $auxDate = $iniDate;
+ $iniDate = $finDate;
+ $finDate = $auxDate;
+ } else {
+ return $secondDuration;
+ }
+
+ $finDate = $this->getIniDate($finDate, $calendarData);
+ $newDate = $iniDate;
+ while ($timeIniDate < $timeFinDate) {
+ //$dataLog = array();
+ $newDate = $this->getIniDate($newDate, $calendarData);
+
+ //$dataLog[] = $hoursDuration;
+ //$dataLog[] = $newDate;
+
+ $rangeWorkHour = $this->getRangeWorkHours($newDate, $calendarData['BUSINESS_DAY']);
+ $onlyDate = (date('Y-m-d',strtotime($newDate))) . ' ' . $rangeWorkHour['END'];
+
+ //$dataLog[] = date('l',strtotime($newDate));
+ //$dataLog[] = $rangeWorkHour['START'] . ' / ' . $rangeWorkHour['END'];
+ //$dataLog[] = $rangeWorkHour['TOTAL'];
+
+ if ( (strtotime($finDate)) < (strtotime($onlyDate)) ) {
+ $secondRes = ( ((float)strtotime($finDate)) - ((float)strtotime($newDate)) );
+ $timeIniDate = strtotime($finDate);
+ $secondDuration += (float)$secondRes;
+ } else {
+ $secondRes = ( ((float)strtotime($onlyDate)) - ((float)strtotime($newDate)) );
+ $newDate = $onlyDate;
+ $timeIniDate = strtotime($onlyDate);
+ $secondDuration += (float)$secondRes;
+ }
+ //$dataLog[] = $newDate;
+ //$log[] = $dataLog;
+ }
+ return $secondDuration;
}
- /**
- * Verify if the current case is already routed.
- *
- * @param string $AppUid the uid of the application
- * @return array $Fields the fields
- */
-
- public function alreadyRouted ($appUid, $sDelIndex)
+ public function getIniDate ($iniDate, $calendarData = array())
{
- $c = new Criteria("workflow");
- $c->clearSelectColumns();
- $c->addSelectColumn(AppDelegationPeer::APP_UID);
- $c->add(AppDelegationPeer::APP_UID, $appUid);
- $c->add(AppDelegationPeer::DEL_INDEX, $sDelIndex);
- $c->add(AppDelegationPeer::DEL_FINISH_DATE, null, Criteria::ISNOTNULL);
- $result = AppDelegationPeer::doSelectRS($c);
- $result->setFetchmode(ResultSet::FETCHMODE_ASSOC);
- if($result->next()) {
- return true;
- } else {
- return false;
- }
+ $flagIniDate = true;
+
+ while ($flagIniDate) {
+ // 1 if it's a work day
+ $weekDay = date('w',strtotime($iniDate));
+ if ( !(in_array($weekDay, $calendarData['CALENDAR_WORK_DAYS_A'])) ) {
+ $iniDate = date('Y-m-d'.' 00:00:00' , strtotime('+1 day', strtotime($iniDate)));
+ continue;
+ }
+
+ // 2 if it's a holiday
+ $iniDateHolidayDay = $this->is_holiday($iniDate, $calendarData['HOLIDAY']);
+ if ($iniDateHolidayDay) {
+ $iniDate = date('Y-m-d'.' 00:00:00' , strtotime('+1 day', strtotime($iniDate)));
+ continue;
+ }
+
+ // 3 if it's work time
+ $workHours = $this->nextWorkHours($iniDate, $weekDay, $calendarData['BUSINESS_DAY']);
+ if ( !($workHours['STATUS']) ) {
+ $iniDate = date('Y-m-d'.' 00:00:00' , strtotime('+1 day', strtotime($iniDate)));
+ continue;
+ } else {
+ $iniDate = $workHours['DATE'];
+ }
+
+ $flagIniDate = false;
+ }
+
+ return $iniDate;
}
-
-}
-
+
+ public function nextWorkHours ($date, $weekDay, $workHours = array())
+ {
+ $auxIniDate = explode(' ', $date);
+ $timeDate = $auxIniDate['1'];
+ $timeDate = (float)str_replace(':', '', ((strlen($timeDate) == 8) ? $timeDate : $timeDate.':00') );
+ $nextWorkHours = array();
+
+ $workHoursDay = array();
+ $tempWorkHoursDay = array();
+
+ foreach ($workHours as $value) {
+ if ($value['CALENDAR_BUSINESS_DAY'] == $weekDay) {
+ $rangeWorkHour = array();
+ $timeStart = $value['CALENDAR_BUSINESS_START'];
+ $timeEnd = $value['CALENDAR_BUSINESS_END'];
+ $rangeWorkHour['START'] = ((strlen($timeStart) == 8) ? $timeStart : $timeStart.':00');
+ $rangeWorkHour['END'] = ((strlen($timeEnd) == 8) ? $timeEnd : $timeEnd.':00');
+
+ $workHoursDay[] = $rangeWorkHour;
+ }
+
+ if ($value['CALENDAR_BUSINESS_DAY'] == '7') {
+ $rangeWorkHour = array();
+ $timeStart = $value['CALENDAR_BUSINESS_START'];
+ $timeEnd = $value['CALENDAR_BUSINESS_END'];
+ $rangeWorkHour['START'] = ((strlen($timeStart) == 8) ? $timeStart : $timeStart.':00');
+ $rangeWorkHour['END'] = ((strlen($timeEnd) == 8) ? $timeEnd : $timeEnd.':00');
+
+ $tempWorkHoursDay[] = $rangeWorkHour;
+ }
+ }
+
+ if ( !(count($workHoursDay)) ) {
+ $workHoursDay = $tempWorkHoursDay;
+ }
+
+ $countHours = count($workHoursDay);
+ if ($countHours) {
+ for ($i = 1; $i < $countHours; $i++) {
+ for ($j = 0; $j < $countHours-$i; $j++) {
+ $dataft = (float)str_replace(':', '', $workHoursDay[$j]['START']);
+ $datasc = (float)str_replace(':', '', $workHoursDay[$j+1]['END']);
+ if ($dataft > $datasc) {
+ $aux = $workHoursDay[$j+1];
+ $workHoursDay[$j+1] = $workHoursDay[$j];
+ $workHoursDay[$j] = $aux;
+ }
+ }
+ }
+
+ foreach ($workHoursDay as $value) {
+ $iniTime = (float)str_replace(':', '', ((strlen($value['START']) == 8) ? $value['START'] : $value['START'].':00'));
+ $finTime = (float)str_replace(':', '', ((strlen($value['END']) == 8) ? $value['END'] : $value['END'].':00'));
+
+ if ( $timeDate <= $iniTime ) {
+ $nextWorkHours['STATUS'] = true;
+ $nextWorkHours['DATE'] = $auxIniDate['0'] . ' ' . ((strlen($value['START']) == 8) ? $value['START'] : $value['START'].':00');
+ return $nextWorkHours;
+ } elseif ( ($iniTime <= $timeDate) && ($timeDate < $finTime) ) {
+ $nextWorkHours['STATUS'] = true;
+ $nextWorkHours['DATE'] = $date;
+ return $nextWorkHours;
+ }
+ }
+ }
+
+ $nextWorkHours['STATUS'] = false;
+ return $nextWorkHours;
+ }
+
+ public function is_holiday ($date, $holidays = array())
+ {
+ $auxIniDate = explode(' ', $date);
+ $iniDate = $auxIniDate['0'];
+ $iniDate = strtotime($iniDate);
+
+ foreach ($holidays as $value) {
+ $holidayStartDate = strtotime(date('Y-m-d',strtotime($value['CALENDAR_HOLIDAY_START'])));
+ $holidayEndDate = strtotime(date('Y-m-d',strtotime($value['CALENDAR_HOLIDAY_END'])));
+
+ if ( ($holidayStartDate <= $iniDate) && ($iniDate <= $holidayEndDate) ) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public function getRangeWorkHours ($date, $workHours)
+ {
+ $auxIniDate = explode(' ', $date);
+ $timeDate = $auxIniDate['1'];
+ $timeDate = (float)str_replace(':', '', ((strlen($timeDate) == 8) ? $timeDate : $timeDate.':00') );
+ $weekDay = date('w',strtotime($date));
+
+ $workHoursDay = array();
+ $tempWorkHoursDay = array();
+
+ foreach ($workHours as $value) {
+ if ($value['CALENDAR_BUSINESS_DAY'] == $weekDay) {
+ $rangeWorkHour = array();
+ $timeStart = $value['CALENDAR_BUSINESS_START'];
+ $timeEnd = $value['CALENDAR_BUSINESS_END'];
+ $rangeWorkHour['START'] = ((strlen($timeStart) == 8) ? $timeStart : $timeStart.':00');
+ $rangeWorkHour['END'] = ((strlen($timeEnd) == 8) ? $timeEnd : $timeEnd.':00');
+
+ $workHoursDay[] = $rangeWorkHour;
+ }
+
+ if ($value['CALENDAR_BUSINESS_DAY'] == '7') {
+ $rangeWorkHour = array();
+ $timeStart = $value['CALENDAR_BUSINESS_START'];
+ $timeEnd = $value['CALENDAR_BUSINESS_END'];
+ $rangeWorkHour['START'] = ((strlen($timeStart) == 8) ? $timeStart : $timeStart.':00');
+ $rangeWorkHour['END'] = ((strlen($timeEnd) == 8) ? $timeEnd : $timeEnd.':00');
+
+ $tempWorkHoursDay[] = $rangeWorkHour;
+ }
+ }
+
+ if ( !(count($workHoursDay)) ) {
+ $workHoursDay = $tempWorkHoursDay;
+ }
+
+ foreach ($workHoursDay as $value) {
+ $iniTime = (float)str_replace(':', '', $value['START']);
+ $finTime = (float)str_replace(':', '', $value['END']);
+
+ if ( ($iniTime <= $timeDate) && ($timeDate <= $finTime) ) {
+ //pr($finTime .' menos '.$iniTime .' = '.($finTime-$iniTime));
+ $value['TOTAL'] = (($finTime-$iniTime)/10000);
+ return $value;
+ }
+ }
+ return false;
+ }
+
+
+ public function getLastDeleration ($APP_UID)
+ {
+ $c = new Criteria( 'workflow' );
+ $c->addSelectColumn( AppDelegationPeer::APP_UID );
+ $c->addSelectColumn( AppDelegationPeer::DEL_INDEX );
+ $c->addSelectColumn( AppDelegationPeer::DEL_DELEGATE_DATE );
+ $c->addSelectColumn( AppDelegationPeer::DEL_INIT_DATE );
+ $c->addSelectColumn( AppDelegationPeer::DEL_TASK_DUE_DATE );
+ $c->addSelectColumn( AppDelegationPeer::DEL_FINISH_DATE );
+ $c->addSelectColumn( AppDelegationPeer::DEL_DURATION );
+ $c->addSelectColumn( AppDelegationPeer::DEL_QUEUE_DURATION );
+ $c->addSelectColumn( AppDelegationPeer::DEL_DELAY_DURATION );
+ $c->addSelectColumn( AppDelegationPeer::DEL_STARTED );
+ $c->addSelectColumn( AppDelegationPeer::DEL_FINISHED );
+ $c->addSelectColumn( AppDelegationPeer::DEL_DELAYED );
+ $c->addSelectColumn( AppDelegationPeer::USR_UID );
+
+ $c->add( AppDelegationPeer::APP_UID, $APP_UID );
+ $c->addDescendingOrderByColumn( AppDelegationPeer::DEL_INDEX );
+ $rs = AppDelegationPeer::doSelectRS( $c );
+ $rs->setFetchmode( ResultSet::FETCHMODE_ASSOC );
+ $rs->next();
+ return $rs->getRow();
+ }
+
+ public function getCurrentIndex ($appUid)
+ {
+ $oCriteria = new Criteria();
+ $oCriteria->addSelectColumn( AppDelegationPeer::DEL_INDEX );
+ $oCriteria->add( AppDelegationPeer::APP_UID, $appUid );
+ $oCriteria->addDescendingOrderByColumn( AppDelegationPeer::DEL_INDEX );
+ $oRuleSet = AppDelegationPeer::doSelectRS( $oCriteria );
+ $oRuleSet->setFetchmode( ResultSet::FETCHMODE_ASSOC );
+ $oRuleSet->next();
+ $data = $oRuleSet->getRow();
+ return (int)$data['DEL_INDEX'];
+ }
+
+ public function getCurrentTask ($appUid)
+ {
+ $oCriteria = new Criteria();
+ $oCriteria->addSelectColumn( AppDelegationPeer::TAS_UID );
+ $oCriteria->add( AppDelegationPeer::APP_UID, $appUid );
+ $oCriteria->addDescendingOrderByColumn( AppDelegationPeer::DEL_INDEX );
+ $oRuleSet = AppDelegationPeer::doSelectRS( $oCriteria );
+ $oRuleSet->setFetchmode( ResultSet::FETCHMODE_ASSOC );
+ $oRuleSet->next();
+ $data = $oRuleSet->getRow();
+ return $data['TAS_UID'];
+ }
+
+ /**
+ * Verify if the current case is already routed.
+ *
+ * @param string $AppUid the uid of the application
+ * @return array $Fields the fields
+ */
+
+ public function alreadyRouted ($appUid, $sDelIndex)
+ {
+ $c = new Criteria("workflow");
+ $c->clearSelectColumns();
+ $c->addSelectColumn(AppDelegationPeer::APP_UID);
+ $c->add(AppDelegationPeer::APP_UID, $appUid);
+ $c->add(AppDelegationPeer::DEL_INDEX, $sDelIndex);
+ $c->add(AppDelegationPeer::DEL_FINISH_DATE, null, Criteria::ISNOTNULL);
+ $result = AppDelegationPeer::doSelectRS($c);
+ $result->setFetchmode(ResultSet::FETCHMODE_ASSOC);
+ if($result->next()) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+}
+