public function handleTask(&$context) { /* INSERT PRODUCT */ $context = $this->_productchooser->addProducts2Entity($this->get('product'), $context, $context); $context->save(); return 'yes'; }
/** * @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"; }
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'; }