Ejemplo n.º 1
0
 /**
  * @param $context \Workflow\VTEntity
  */
 public function handleTask(&$context)
 {
     $setterMap = $this->get("setter");
     $newModule = $this->get("new_module");
     if (empty($newModule)) {
         $this->addStat("NO Configuration set");
         return "yes";
     }
     $newObj = VTEntity::create($newModule);
     $this->fieldSetter->apply($newObj, $setterMap, $context, $this);
     if ($newObj->isInventory() && $context->isInventory()) {
         $newObj->importInventory($context->exportInventory());
         $newObj->set('hdnTaxType', $context->get('hdnTaxType'));
     }
     //$newObj->redirectToCreationForm();
     try {
         $newObj->save();
     } catch (WebServiceException $exp) {
         // Somethink is wrong with the values. missing mandatory fields?
     }
     if ($this->_productchooser !== null && $this->get('product') != -1) {
         $newObj = $this->_productchooser->addProducts2Entity($this->get('product'), $context, $newObj);
         try {
             $newObj->save();
         } catch (WebServiceException $exp) {
             // Somethink is wrong with the values. missing mandatory fields?
         }
     }
     if ($context->getModuleName() == "Assets" && $newModule == "HelpDesk") {
         global $adb;
         $sql = "INSERT INTO vtiger_crmentityrel SET crmid = ?, module = ?, relcrmid = ?, relmodule = ?";
         $adb->pquery($sql, array($context->getId(), $context->getModuleName(), $newObj->getId(), $newObj->getModuleName()));
     }
     $context->setEnvironment("new_record_id", $newObj->getId(), $this);
     if ($this->get("redirectAfter") == "1") {
         $this->getWorkflow()->setSuccessRedirection("index.php?module=" . $newModule . "&view=Detail&record=" . $newObj->getId(), 'same');
     }
     if ($this->get("exec_workflow") !== "" && $this->get("exec_workflow") != -1) {
         $newContext = VTEntity::getForId($newObj->getId(), $newObj->getModuleName());
         $newContext->loadEnvironment($context->getEnvironment());
         $objWorkflow = new \Workflow\Main($this->get("exec_workflow"), false, $context->getUser());
         $objWorkflow->setContext($newContext);
         $objWorkflow->start();
     }
     return "yes";
 }
 /**
  * @param $context \Workflow\VTEntity
  */
 public function handleTask(&$context)
 {
     $recordID = trim($this->get("recordid", $context));
     if (!empty($recordID) && $recordID != -1) {
         $contextRecord = \Workflow\VTEntity::getForId($recordID);
     } else {
         $contextRecord = $context;
     }
     $newObj = \Workflow\VTEntity::create($contextRecord->getModuleName());
     $oldData = $contextRecord->getData();
     foreach ($oldData as $key => $value) {
         $newObj->set($key, $value);
     }
     if ($contextRecord->isInventory()) {
         $products = $contextRecord->exportInventory();
         $newObj->importInventory($products);
         $newObj->save();
     }
     /* After this line, copy from Creator */
     $setterMap = $this->get("setter");
     if (is_array($setterMap)) {
         $this->fieldSetter->apply($newObj, $setterMap, $contextRecord, $this);
     }
     $newObj->save();
     $context->setEnvironment("new_record_id", $newObj->getWsId(), $this);
     if ($this->get("redirectAfter") == "1") {
         $this->getWorkflow()->setSuccessRedirection("index.php?module=" . $newObj->getModuleName() . "&view=Detail&record=" . $newObj->getId());
     }
     if ($this->get("exec_workflow") !== "" && $this->get("exec_workflow") != -1) {
         $newContext = \Workflow\VTEntity::getForId($newObj->getId(), $newObj->getModuleName());
         $objWorkflow = new \Workflow\Main($this->get("exec_workflow"), false, $context->getUser());
         $objWorkflow->setContext($newContext);
         $objWorkflow->isSubWorkflow(true);
         $objWorkflow->start();
     }
     return "yes";
 }
 public function handleTask(&$context)
 {
     /** Copied from WfTaskDuplicateRecord */
     /**
      * @var $contextRecord VTInventoryEntity
      */
     $contextRecord = $context;
     $newObj = \Workflow\VTEntity::create($contextRecord->getModuleName());
     $oldData = $contextRecord->getData();
     //var_dump($oldData);
     foreach ($oldData as $key => $value) {
         $newObj->set($key, $value);
     }
     //$newObj->set('hdnDiscountPercent', -1 * $oldData['hdnDiscountPercent']);
     $newObj->set('hdnDiscountAmount', -1 * $oldData['hdnDiscountAmount']);
     /** Copied from WfTaskDuplicateRecord ENDE */
     $products = $contextRecord->exportInventory();
     foreach ($products["listitems"] as $index => $listitem) {
         $listitem["quantity"] *= -1;
         $listitem['discount_amount'] *= -1;
         $products["listitems"][$index] = $listitem;
     }
     $products["shippingCost"] *= -1;
     $newObj->importInventory($products);
     /* After this line, copy from Creator */
     $setterMap = $this->get("setter");
     $this->fieldSetter->apply($newObj, $setterMap, $contextRecord, $this);
     $products = $this->get("product");
     /* INSERT PRODUCT */
     if (is_array($products) && count($products) > 0) {
         $availTaxes = getAllTaxes("available");
         foreach ($products as $index => $value) {
             if (!empty($value["productid_individual"])) {
                 $productid = VTTemplate::parse($value["productid_individual"], $context);
             } else {
                 $productid = $value["productid"];
             }
             if (strpos($productid, "x") !== false) {
                 $parts = explode("x", $productid);
                 $productid = $parts[1];
             }
             $crmProduct = CRMEntity::getInstance("Products");
             $crmProduct->id = $productid;
             $crmProduct->retrieve_entity_info($productid, "Products");
             $context->setEnvironment("product", $crmProduct->column_fields);
             foreach ($value as $key => $template) {
                 $value[$key] = VTTemplate::parse($template, $context);
             }
             $tax = array();
             foreach ($availTaxes as $aTax) {
                 if ($value["tax" . $aTax["taxid"] . "_enable"] == 1) {
                     $tax[$aTax["taxid"]] = VTTemplate::parse($value["tax" . $aTax["taxid"]], $context);
                 }
             }
             $this->addStat("AddProduct " . $value["quantity"] . " x " . $productid . " (" . $value["unitprice"] . ")");
             $newObj->addProduct($productid, $value["description"], $value["comment"], $value["quantity"], $value["unitprice"], $value["discount_mode"] == "percentage" ? $value["discount_value"] : 0, $value["discount_mode"] == "amount" ? $value["discount_value"] : 0, $tax);
         }
         try {
             $newObj->save();
         } catch (WebServiceException $exp) {
             // Somethink is wrong with the values. missing mandatory fields?
         }
     }
     try {
         $newObj->save();
     } catch (WebServiceException $exp) {
         // Somethink is wrong with the values. missing mandatory fields?
     }
     $context->setEnvironment("new_record_id", $newObj->getWsId(), $this);
     if ($this->get("redirectAfter") == "1") {
         $this->getWorkflow()->setSuccessRedirection($newObj->getDetailUrl());
     }
     if ($this->get("exec_workflow") !== "" && $this->get("exec_workflow") != -1) {
         $newContext = \Workflow\VTEntity::getForId($newObj->getId(), $newObj->getModuleName());
         $objWorkflow = new \Workflow\Main($this->get("exec_workflow"), false, $context->getUser());
         $objWorkflow->setContext($newContext);
         $objWorkflow->isSubWorkflow(true);
         $objWorkflow->start();
     }
     return "yes";
 }
Ejemplo n.º 4
0
 /**
  * @param $context \Workflow\VTEntity
  */
 public function handleTask(&$context)
 {
     $setterMap = $this->get("setter");
     $newModule = $this->get("new_module");
     if (empty($newModule)) {
         $this->addStat("NO Configuration set");
         return "yes";
     }
     $uniqueCheck = $this->get('uniquecheck');
     $createNew = true;
     if ($uniqueCheck !== -1 && is_array($uniqueCheck) && !empty($uniqueCheck)) {
         $setterMap = $this->get('setter');
         $fieldValue = $this->fieldSetter->getFieldValueArray($context, $setterMap);
         $condition = array();
         foreach ($uniqueCheck as $checkField) {
             $condition[$checkField] = $fieldValue[$checkField];
         }
         $records = \Workflow\VtUtils::findRecordIDs($newModule, $condition);
         if (count($records) > 0) {
             // duplicate records found
             $this->addStat('duplicate Record found [' . implode(',', $records) . '] -> do not create new');
             $updateexisting = $this->get('updateexisting');
             if ($updateexisting !== -1 && is_array($updateexisting) && !empty($updateexisting)) {
                 foreach ($records as $crmid) {
                     $entity = \Workflow\VTEntity::getForId($crmid);
                     foreach ($updateexisting as $field) {
                         $entity->set($field, $fieldValue[$field]);
                     }
                     $entity->save();
                     break;
                 }
             }
             $context->setEnvironment("new_record_id", $records[0], $this);
             $context->setEnvironment("was_created_new", 'false', $this);
             $createNew = false;
             $newObj = \Workflow\VTEntity::getForId($records[0]);
         }
     }
     if ($createNew === true) {
         $newObj = VTEntity::create($newModule);
         $this->fieldSetter->apply($newObj, $setterMap, $context, $this);
         try {
             $newObj->save();
         } catch (WebServiceException $exp) {
             // Somethink is wrong with the values. missing mandatory fields?
         }
         $context->setEnvironment("new_record_id", $newObj->getId(), $this);
         $context->setEnvironment("was_created_new", 'true', $this);
     }
     if ($context->getModuleName() == "Assets" && $newModule == "HelpDesk") {
         global $adb;
         $sql = "INSERT INTO vtiger_crmentityrel SET crmid = ?, module = ?, relcrmid = ?, relmodule = ?";
         $adb->pquery($sql, array($context->getId(), $context->getModuleName(), $newObj->getId(), $newObj->getModuleName()));
     }
     if ($this->get("redirectAfter") == "1") {
         $this->getWorkflow()->setSuccessRedirection("index.php?module=" . $newModule . "&view=Detail&record=" . $newObj->getId());
     }
     if ($this->get("exec_workflow") !== "" && $this->get("exec_workflow") != -1) {
         $newContext = VTEntity::getForId($newObj->getId(), $newObj->getModuleName());
         $newContext->loadEnvironment($context->getEnvironment());
         $objWorkflow = new \Workflow\Main($this->get("exec_workflow"), false, $context->getUser());
         $objWorkflow->isSubWorkflow(true);
         $objWorkflow->setContext($newContext);
         $objWorkflow->start();
     }
     Workflow2::$enableError = true;
     return "yes";
 }
 public function handleTask(&$context)
 {
     $setterMap = $this->get("setter");
     $globalMap = $this->get("global");
     $products = $this->get("product");
     $shippingCost = 0;
     $newModule = $this->get("new_module");
     if (empty($newModule)) {
         $this->addStat("NO Configuration set");
         return "yes";
     }
     /**
      * @var $newObj \Workflow\VTInventoryEntity
      */
     $newObj = \Workflow\VTEntity::create($newModule);
     try {
         foreach ($setterMap as $setter) {
             if (!empty($setter["field"]) && $setter["field"] == "currency_id") {
                 $setter["value"] = vtws_getWebserviceEntityId("Currency", $setter["value"]);
             }
             if ($setter["mode"] == "function") {
                 $parser = new VTWfExpressionParser($setter["value"], $context, false);
                 # Last Parameter = DEBUG
                 try {
                     $parser->run();
                 } catch (\Workflow\ExpressionException $exp) {
                     Workflow2::error_handler(E_EXPRESSION_ERROR, $exp->getMessage(), "", "");
                 }
                 $newValue = $parser->getReturn();
             } else {
                 $setter["value"] = \Workflow\VTTemplate::parse($setter["value"], $context);
                 $newValue = $setter["value"];
             }
             $this->addStat("`" . $setter["field"] . "` = '" . $newValue . "'");
             if ($setter["field"] == "hdnS_H_Amount") {
                 $shippingCost = $newValue;
             }
             #            var_dump($setter["field"], $newValue);
             $newObj->set($setter["field"], $newValue);
         }
     } catch (Exception $e) {
         var_dump($e);
         // ONLY ERROR
     }
     try {
         $newObj->save();
     } catch (WebServiceException $exp) {
         // Somethink is wrong with the values. missing mandatory fields?
     }
     $context->setEnvironment("new_record_id", $newObj->getWsId(), $this);
     if ($this->get("redirectAfter") == "1") {
         $this->getWorkflow()->setSuccessRedirection($newObj->getDetailUrl());
     }
     $groupTaxes = array();
     $shipTaxes = array();
     foreach ($globalMap as $globalKey => $globalValue) {
         $globalValue = \Workflow\VTTemplate::parse($globalValue, $context);
         if (strpos($globalKey, "_group_percentage") !== false) {
             $groupTaxes[$globalKey] = $globalValue;
         }
         if (strpos($globalKey, "_sh_percent") !== false) {
             $shipTaxes[$globalKey] = $globalValue;
         }
         $this->addStat("`" . $globalKey . "` = '" . $globalValue . "'");
     }
     $newObj->setGroupTaxes($groupTaxes);
     $newObj->setShipTaxes($shipTaxes);
     $newObj->setShippingCost($shippingCost);
     $newObj->save();
     $newObj = $this->_productchooser->addProducts2Entity($this->get('product'), $context, $newObj);
     $newObj->save();
     if ($this->get("exec_workflow") !== "" && $this->get("exec_workflow") != -1) {
         $newContext = \Workflow\VTEntity::getForId($newObj->getId(), $newObj->getModuleName());
         $objWorkflow = new \Workflow\Main($this->get("exec_workflow"), false, $context->getUser());
         $newContext->loadEnvironment($context->getEnvironment());
         $objWorkflow->setContext($newContext);
         $objWorkflow->isSubWorkflow(true);
         $objWorkflow->start();
     }
     Workflow2::$enableError = true;
     return 'yes';
 }