Пример #1
0
 /**
  * Get the product object by part number  using ROQL
  * @param int $partNumber Product part number used in RightNow
  * @return object|null Product queried by it's ID
  */
 function getProductByPartNumber($partNumber)
 {
     if ($partNumber === null) {
         return null;
     }
     $queryString = "SELECT S.ServiceProduct.ID, S.PartNumber, S.Name, S.Descriptions.LabelText FROM SalesProduct S WHERE S.PartNumber='{$partNumber}'";
     $roqlResultSet = RNCPHP\ROQL::query($queryString)->next();
     if ($product = $roqlResultSet->next()) {
         return $product;
     }
 }
Пример #2
0
 public function updateWorkOrder()
 {
     require_once OFSC_ROOT . 'toalogservice.php';
     $log = ToaLogService::GetLog();
     try {
         //Input validation is required to prevent malicious data being processed and unexpected data being returned.
         //Sanitizing the WorkOrderId in order to avoid SQL injection attack.
         $wkOrderId = $this->sanitizeWorkOrderId();
         $result = null;
         if ($wkOrderId != null) {
             //Caution: All data that is part of WHERE clause must be sanitized to avoid SQL injection attack.
             $result = RNCPHP\ROQL::queryObject("SELECT TOA.Work_Order FROM TOA.Work_Order where TOA.Work_Order.ID = " . $wkOrderId)->next();
         } else {
             if ($log != null) {
                 $log->debug("Invalid WorkOrder Id: " . $this->getWorkOrderId());
             }
         }
         if ($result != null && ($workOrder = $result->next()) != null) {
             $workOrder->Contact_Phone = $this->getContactPhone();
             $workOrder->Contact_Email = $this->getContactEmail();
             $workOrder->Contact_Mobile_Phone = $this->getContactMobilePhone();
             $workOrder->WO_Time_Slot = $this->getWorkOrderTimeSlot();
             $workOrder->WO_Status = $this->getWorkOrderStatus();
             $workOrder->End_Time = $this->getEndTime();
             $workOrder->Start_End_Time = $this->getStartEndTime();
             $workOrder->ETA = $this->getEta();
             $workOrder->Delivery_Window_Start = $this->getDeliveryWindowStart();
             $workOrder->Delivery_Window_End = $this->getDeliveryWindowEnd();
             $workOrder->Resource = $this->getResource();
             $workOrder->Travel_Time = $this->getTravelTime();
             $workOrder->Field_Service_Note = $this->getFieldServiceNote();
             $workOrder->Duration = $this->getDuration();
             $updateFailed = false;
             if ($this->getWorkOrderDate() != null) {
                 try {
                     $workOrderDate = new DateTime($this->getWorkOrderDate());
                     $workOrder->WO_Date = $workOrderDate->getTimestamp();
                 } catch (Exception $e) {
                     $updateFailed = true;
                     $this->setResponseStatus('failed');
                     $this->setResponseDescription('Unable to update WorkOrder');
                     if ($log != null) {
                         $log->debug("Invalid WorkOrder Date : " . $this->getWorkOrderDate());
                     }
                 }
             } else {
                 $updateFailed = true;
                 $this->setResponseStatus('failed');
                 $this->setResponseDescription('Unable to update WorkOrder');
                 if ($log != null) {
                     $log->debug("WorkOrder Date is empty or null.");
                 }
             }
             if ($this->getExternalId() != null) {
                 $workOrder->External_ID = $this->getExternalId();
             } else {
                 $updateFailed = true;
                 $this->setResponseStatus('failed');
                 $this->setResponseDescription('Unable to update WorkOrder');
                 if ($log != null) {
                     $log->debug("External Id is null or empty.");
                 }
             }
             if (!$updateFailed) {
                 $workOrder->save();
                 $this->setResponseStatus('sent');
                 $this->setResponseDescription('WorkOrder updated');
             }
         } else {
             $this->setResponseStatus('failed');
             $this->setResponseDescription('Unable to update WorkOrder');
             if ($log != null) {
                 $log->debug("Unable to update WorkOrder Id: " . $this->getWorkOrderId());
             }
         }
     } catch (RNCPHP\ConnectAPIError $err) {
         $this->setResponseStatus('failed');
         $this->setResponseDescription('Unable to update WorkOrder');
         if ($log != null) {
             $log->debug("Unable to update WorkOrder Id: " . $this->getWorkOrderId() . "  Error: " . $err->getMessage());
         }
     }
 }
Пример #3
0
 public function create($productID, array $formData, $serialNumber)
 {
     if (!Framework::isValidID($productID)) {
         return $this->getResponseObject(null, null, Config::getMessage(INVALID_ID_SALES_PRODUCT_COLON_LBL));
     }
     //$resultSet = Connect\ROQL::queryObject(sprintf("SELECT SalesProduct FROM SalesProduct WHERE ID = %d And Disabled != 1 And Attributes.IsServiceProduct = 1 And Attributes.HasSerialNumber != 1 And AdminVisibleInterfaces.ID = curInterface()", $productID))->next();
     $resultSet = Connect\ROQL::queryObject(sprintf("SELECT SalesProduct FROM SalesProduct WHERE ID = %d And Disabled != 1 And Attributes.IsServiceProduct = 1 And AdminVisibleInterfaces.ID = curInterface()", $productID))->next();
     if (!($salesProduct = $resultSet->next())) {
         return $this->getResponseObject(null, null, Config::getMessage(INVALID_ID_SALES_PRODUCT_COLON_LBL));
     }
     $asset = $this->getBlank()->result;
     if ($contact = $this->getContact()) {
         $asset->Contact = $contact->ID;
     } else {
         return $this->getResponseObject(null, null, Config::getMessage(CONTACT_IS_NOT_LOGGED_IN_MSG));
     }
     if ($asset->Contact->Organization) {
         $asset->Organization = $asset->Contact->Organization->ID;
     }
     $errors = $warnings = array();
     foreach ($formData as $name => $field) {
         if (!\RightNow\Utils\Text::beginsWith($name, 'Asset')) {
             continue;
         }
         $fieldName = explode('.', $name);
         try {
             //Get the metadata about the field we're trying to set. In order to do that we have to
             //populate some of the sub-objects on the record. We don't want to touch the existing
             //record at all, so instead we'll just pass in a dummy instance.
             list(, $fieldMetaData) = ConnectUtil::getObjectField($fieldName, $this->getBlank()->result);
         } catch (\Exception $e) {
             $warnings[] = $e->getMessage();
             continue;
         }
         if (\RightNow\Utils\Validation::validate($field, $name, $fieldMetaData, $errors)) {
             $field->value = ConnectUtil::castValue($field->value, $fieldMetaData);
             if ($setFieldError = $this->setFieldValue($asset, $name, $field->value)) {
                 $errors[] = $setFieldError;
             }
         }
     }
     if ($productID !== null && ($setFieldError = $this->setFieldValue($asset, "Asset.Product", $productID))) {
         $errors[] = $setFieldError;
     }
     if ($serialNumber !== null && ($setFieldError = $this->setFieldValue($asset, "Asset.SerialNumber", $serialNumber))) {
         $errors[] = $setFieldError;
     }
     if ($errors) {
         return $this->getResponseObject(null, null, $errors);
     }
     try {
         $asset = parent::createObject($asset, SRC2_EU_ASSET);
     } catch (\Exception $e) {
         $asset = $e->getMessage();
     }
     if (!is_object($asset)) {
         return $this->getResponseObject(null, null, $asset);
     }
     return $this->getResponseObject($asset, 'is_object', null, $warnings);
 }