/**
  * Save Process Permission
  *
  * @var array $data. Data for Process Permission
  * @var string $op_uid. Uid for Process Permission
  *
  * @access public
  * @author Brayan Pereyra (Cochalo) <*****@*****.**>
  * @copyright Colosa - Bolivia
  *
  * @return void
  */
 public function saveProcessPermission($data, $op_uid = '')
 {
     try {
         $data = array_change_key_case($data, CASE_UPPER);
         $this->validateProUid($data['PRO_UID']);
         if ($op_uid != '') {
             $op_uid = $this->validateOpUid($op_uid);
         }
         if ($data['OP_USER_RELATION'] == "1") {
             $this->validateUsrUid($data['USR_UID']);
         } else {
             $this->validateGrpUid($data['USR_UID']);
         }
         if (isset($data['TAS_UID']) && $data['TAS_UID'] != '') {
             $this->validateTasUid($data['TAS_UID']);
         } else {
             $data['TAS_UID'] = '';
         }
         if (isset($data['OP_TASK_SOURCE']) && $data['OP_TASK_SOURCE'] != '') {
             $this->validateTasUid($data['OP_TASK_SOURCE']);
         } else {
             $data['OP_TASK_SOURCE'] = '';
         }
         $sObjectUID = '';
         switch ($data['OP_OBJ_TYPE']) {
             case 'ANY':
                 //case 'ANY_DYNAFORM':CASES_NOTES
                 //case 'ANY_INPUT':
                 //case 'ANY_OUTPUT':
                 $sObjectUID = '';
                 break;
             case 'DYNAFORM':
                 $data['DYNAFORMS'] = $data['DYNAFORMS'] == 0 ? '' : $data['DYNAFORMS'];
                 if ($data['DYNAFORMS'] != '') {
                     $this->validateDynUid($data['DYNAFORMS']);
                 }
                 $sObjectUID = $data['DYNAFORMS'];
                 break;
             case 'INPUT':
                 $data['INPUTS'] = $data['INPUTS'] == 0 ? '' : $data['INPUTS'];
                 if ($data['INPUTS'] != '') {
                     $this->validateInpUid($data['INPUTS']);
                 }
                 $sObjectUID = $data['INPUTS'];
                 break;
             case 'OUTPUT':
                 $data['OUTPUTS'] = $data['OUTPUTS'] == 0 ? '' : $data['OUTPUTS'];
                 if ($data['OUTPUTS'] != '') {
                     $this->validateOutUid($data['OUTPUTS']);
                 }
                 $sObjectUID = $data['OUTPUTS'];
                 break;
         }
         $oOP = new \ObjectPermission();
         $permissionUid = $op_uid != '' ? $op_uid : G::generateUniqueID();
         $data['OP_UID'] = $permissionUid;
         $data['OP_OBJ_UID'] = $sObjectUID;
         if ($op_uid == '') {
             $oOP->fromArray($data, \BasePeer::TYPE_FIELDNAME);
             $oOP->save();
             $daraRes = $oOP->load($permissionUid);
             $daraRes = array_change_key_case($daraRes, CASE_LOWER);
             return $daraRes;
         } else {
             $data['TAS_UID'] = $data['TAS_UID'] != '' ? $data['TAS_UID'] : '0';
             $data['OP_TASK_SOURCE'] = $data['OP_TASK_SOURCE'] != '' ? $data['OP_TASK_SOURCE'] : '0';
             $data['OP_PARTICIPATE'] = $data['OP_PARTICIPATE'] != '' ? $data['OP_PARTICIPATE'] : 0;
             $data['OP_OBJ_TYPE'] = $data['OP_OBJ_TYPE'] != '' ? $data['OP_OBJ_TYPE'] : '0';
             $data['OP_OBJ_UID'] = $data['OP_OBJ_UID'] != '' ? $data['OP_OBJ_UID'] : '0';
             $data['OP_ACTION'] = $data['OP_ACTION'] != '' ? $data['OP_ACTION'] : '0';
             $data['OP_CASE_STATUS'] = $data['OP_CASE_STATUS'] != '' ? $data['OP_CASE_STATUS'] : '0';
             $oOP->update($data);
         }
     } catch (Exception $e) {
         throw $e;
     }
 }