Ejemplo n.º 1
0
 /**
  * @param $context \Workflow\VTEntity
  * @return array
  */
 public function handleTask(&$context)
 {
     $wf_chooser = $this->get("wf_chooser");
     if ($wf_chooser == -1 || $wf_chooser == "1") {
         $workflow_id = $this->get("workflow_id");
     } else {
         if ($wf_chooser == "2") {
             $wf_name = $this->get("wf_name", $context);
             if (empty($wf_name) || $wf_name == -1) {
                 return "yes";
             }
             global $adb;
             $this->addStat("execute Workflow '" . $wf_name . "'");
             $sql = "SELECT id FROM vtiger_wf_settings WHERE module_name = '" . $this->getModuleName() . "' AND title = ? AND `active` = 1";
             $result = $adb->pquery($sql, array($wf_name));
             $workflow_id = $adb->query_result($result, 0, "id");
             $this->addStat("found Workflow ID '" . $workflow_id . "'");
         }
     }
     if (!empty($workflow_id)) {
         $obj = new \Workflow\Main($workflow_id, false, $context->getUser());
         $obj->setExecutionTrigger($this->getWorkflow()->getExecutionTrigger());
         $obj->isSubWorkflow(true);
         $obj->setContext($context);
         $obj->start();
         return 'yes';
     }
     return "yes";
 }
Ejemplo n.º 2
0
 /**
  * @param $key
  * @param $value
  * @param $context \Workflow\VTEntity
  * @return array|void
  */
 public function doAction($configuration, $filepath, $filename, $context, $targetRecordIds = array())
 {
     $adb = \PearDatabase::getInstance();
     require_once 'modules/Documents/Documents.php';
     $focus = new \Documents();
     $focus->parentid = $context->getId();
     $docTitle = $configuration["title"];
     $docDescr = nl2br($configuration["description"]);
     $docTitle = \Workflow\VTTemplate::parse($docTitle, $context);
     $docDescr = \Workflow\VTTemplate::parse($docDescr, $context);
     $focus->column_fields['notes_title'] = $docTitle;
     $focus->column_fields['assigned_user_id'] = $context->get('assigned_user_id');
     $focus->column_fields['filename'] = $filename;
     $focus->column_fields['notecontent'] = $docDescr;
     $focus->column_fields['filetype'] = 'application/pdf';
     $focus->column_fields['filesize'] = filesize($filepath);
     $focus->column_fields['filelocationtype'] = 'I';
     $focus->column_fields['fileversion'] = '';
     $focus->column_fields['filestatus'] = 'on';
     $focus->column_fields['folderid'] = $configuration["folderid"];
     $focus->save('Documents');
     $upload_file_path = decideFilePath();
     $date_var = date("Y-m-d H:i:s");
     $next_id = $adb->getUniqueID("vtiger_crmentity");
     copy($filepath, $upload_file_path . $next_id . "_" . $filename);
     $sql1 = "insert into vtiger_crmentity (crmid,smcreatorid,smownerid,setype,description,createdtime,modifiedtime) values(?, ?, ?, ?, ?, ?, ?)";
     $params1 = array($next_id, $context->get('assigned_user_id'), $context->get('assigned_user_id'), "Documents Attachment", 'Documents Attachment', date("Y-m-d H:i:s"), date("Y-m-d H:i:s"));
     $adb->pquery($sql1, $params1);
     $filetype = "application/octet-stream";
     $sql2 = "insert into vtiger_attachments(attachmentsid, name, description, type, path) values(?, ?, ?, ?, ?)";
     $params2 = array($next_id, $filename, $docDescr, $filetype, $upload_file_path);
     $adb->pquery($sql2, $params2, true);
     $sql3 = 'insert into vtiger_seattachmentsrel values(?,?)';
     $adb->pquery($sql3, array($focus->id, $next_id));
     if ($configuration["relation"] === "1") {
         foreach ($targetRecordIds as $id) {
             $sql = "INSERT INTO vtiger_senotesrel SET crmid = " . $id . ", notesid = " . $focus->id;
             $adb->query($sql);
         }
     } else {
         $sql = "DELETE FROM vtiger_senotesrel WHERE crmid = " . $context->getId() . " AND notesid = " . $focus->id;
         $adb->query($sql);
     }
     $newContext = \Workflow\VTEntity::getForId($focus->id, "Documents");
     if ($configuration['workflowid'] !== "") {
         $objWorkflow = new \Workflow\Main($configuration['workflowid'], false, $context->getUser());
         $objWorkflow->setContext($newContext);
         $objWorkflow->isSubWorkflow(true);
         $objWorkflow->start();
     }
 }
Ejemplo n.º 3
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";
 }
Ejemplo n.º 5
0
 /**
  * @param $context \Workflow\VTEntity|\Workflow\VTInventoryEntity
  */
 public function handleTask(&$context)
 {
     $referenceId = $context->getId();
     Workflow2::$enableError = true;
     $parentRecordModel = Inventory_Record_Model::getInstanceById($referenceId);
     $currencyInfo = $parentRecordModel->getCurrencyInfo();
     $taxes = $parentRecordModel->getProductTaxes();
     $shippingTaxes = $parentRecordModel->getShippingTaxes();
     $relatedProducts = $parentRecordModel->getProducts();
     $recordModel = Vtiger_Record_Model::getCleanInstance('Invoice');
     $recordModel->setRecordFieldValues($parentRecordModel);
     $recordModel->save();
     $newId = $recordModel->getId();
     $contextRecord = $context;
     /**
      * @var $newObj \Workflow\VTEntity|\Workflow\VTInventoryEntity
      */
     $newObj = \Workflow\VTEntity::getForId($newId);
     $newObj->set('hdnTaxType', $parentRecordModel->get('hdnTaxType'));
     $newObj->importProductsFromRecord($relatedProducts, true);
     $setterMap = $this->get("setter");
     $this->fieldSetter->apply($newObj, $setterMap, $contextRecord, $this);
     $newObj->save();
     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 = 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;
 }
 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.º 7
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";
 }
 /**
  * @param $context \Workflow\VTEntity
  * @return string
  */
 public function handleTask(&$context)
 {
     global $adb;
     if ($this->get("search_module") == -1) {
         return "no";
     }
     $found_rows = $this->get("found_rows");
     if (empty($found_rows) || $found_rows == -1) {
         $found_rows = 1;
     }
     $recordsource = $this->get('recordsource');
     if (empty($recordsource) || $recordsource == -1) {
         $recordsource = 'condition';
     }
     $parts = explode("#~#", $this->get("search_module"));
     $functionName = $parts[0];
     $related_module = VtUtils::getModuleName($parts[1]);
     $recordids = array();
     if ($recordsource == 'condition') {
         require_once 'modules/Workflow2/VTConditionMySql.php';
         $logger = new \Workflow\ConditionLogger();
         $objMySQL = new \Workflow\ConditionMysql($related_module, $context);
         $objMySQL->setLogger($logger);
         $main_module = CRMEntity::getInstance($related_module);
         #$sqlTables = $main_module->generateReportsQuery($related_module);
         $sqlCondition = $objMySQL->parse($this->get("condition"));
         $sqlTables = $objMySQL->generateTables();
         if (strlen($sqlCondition) > 3) {
             $sqlCondition .= " AND vtiger_crmentity.deleted = 0";
         } else {
             $sqlCondition .= " vtiger_crmentity.deleted = 0";
         }
         $logs = $logger->getLogs();
         $this->setStat($logs);
         $idColumn = $main_module->table_name . "." . $main_module->table_index;
         $sqlQuery = "SELECT {$idColumn} as `idCol` " . $sqlTables . " WHERE " . (strlen($sqlCondition) > 3 ? $sqlCondition : "");
         $sortField = $this->get("sort_field");
         $sqlQuery .= ' GROUP BY crmid ';
         if (!empty($sortField) && $sortField != -1) {
             $sortDirection = $this->get("sortDirection");
             $sortField = VtUtils::getColumnName($sortField);
             $sqlQuery .= " ORDER BY " . $sortField . " " . $sortDirection;
         }
         $numRows = $this->get("found_rows");
         if (!empty($numRows) && $numRows != -1) {
             $sqlQuery .= " LIMIT " . $found_rows;
         }
         $this->addStat("MySQL Query: " . $sqlQuery);
         $result = $adb->query($sqlQuery, true);
         $this->addStat("num Rows: " . $adb->num_rows($result));
         while ($row = $adb->fetchByAssoc($result)) {
             $recordids[] = $row["idcol"];
         }
     }
     if ($recordsource == 'customview') {
         $queryGenerator = new \QueryGenerator($related_module, \Users::getActiveAdminUser());
         $queryGenerator->initForCustomViewById($this->get('customviewsource'));
         $query = $queryGenerator->getQuery();
         $parts = preg_split('/FROM/i', $query);
         $sqlQuery = 'SELECT vtiger_crmentity.crmid as id_col FROM ' . $parts[1];
         $result = $adb->query($sqlQuery, true);
         $this->addStat("num Rows: " . $adb->num_rows($result));
         while ($row = $adb->fetchByAssoc($result)) {
             $recordids[] = $row["id_col"];
         }
     }
     $filterbyproduct = $this->get('filterbyproduct');
     if ($filterbyproduct === 'yes') {
         $products = $this->get('products');
         if (!empty($products)) {
             $sql = 'SELECT id FROM vtiger_inventoryproductrel WHERE id IN (' . generateQuestionMarks($recordids) . ') AND productid = ? GROUP BY id';
             $recordids[] = $products;
             $result = $adb->pquery($sql, $recordids);
             $recordids = array();
             while ($row = $adb->fetchByAssoc($result)) {
                 $recordids[] = $row['id'];
             }
         }
     }
     $workflow_id = $this->get("workflow_id");
     if (!empty($workflow_id)) {
         foreach ($recordids as $recordId) {
             $tmpContext = \Workflow\VTEntity::getForId($recordId, $related_module);
             $tmpContext->clearEnvironment();
             $tmpContext->loadEnvironment($context->getEnvironment());
             $obj = new \Workflow\Main($workflow_id, false, $context->getUser());
             $obj->setExecutionTrigger($this->getWorkflow()->getExecutionTrigger());
             $obj->setContext($tmpContext);
             $obj->isSubWorkflow(true);
             $obj->start();
             if ($obj->getSuccessRedirection() != false) {
                 $this->getWorkflow()->setSuccessRedirection($obj->getSuccessRedirection());
                 $this->getWorkflow()->setSuccessRedirectionTarget($obj->getSuccessRedirectionTarget());
             }
             $env = $this->get("env");
             if ($env !== -1 && !empty($env["result_environments"])) {
                 $oldEnv = $context->getEnvironment($env["result_environments"]);
                 $oldEnv[] = $tmpContext->getEnvironment();
                 $context->setEnvironment("result_environments", $oldEnv, $this);
             }
         }
     }
     return "yes";
 }
Ejemplo n.º 9
0
 /**
  * @param $context VTEntity
  */
 public function handleTask(&$context)
 {
     if (!getTabid('PDFMaker') || !vtlib_isModuleActive('PDFMaker')) {
         return 'yes';
     }
     global $adb, $current_user, $log, $root_directory;
     // PDFMaker greift auf Datenbank zurück. Daher zuerst speichern!
     $context->save();
     $userId = $context->get('assigned_user_id');
     if ($userId === null) {
         $userId = vtws_getWebserviceEntityId('Users', 1);
     }
     $moduleName = $context->getModuleName();
     $id = $context->getId();
     list($id2, $assigned_user_id) = explode("x", $userId);
     $parentid = $id;
     require_once 'modules/Documents/Documents.php';
     $focus = new \Documents();
     $focus->parentid = $parentid;
     $modFocus = $context->getInternalObject();
     $templateid = $this->template;
     $this->folder = 1;
     $foldername = $adb->getOne("SELECT foldername FROM vtiger_attachmentsfolder WHERE folderid='" . $this->folder . "'", 0, "foldername");
     $fieldname = $adb->getOne("SELECT fieldname FROM vtiger_field WHERE uitype=4 AND tabid=" . getTabId($moduleName), 0, "fieldname");
     /* new PDFMaker Routine */
     $PDFMaker = new PDFMaker_PDFMaker_Model();
     if (isset($modFocus->column_fields[$fieldname]) && $modFocus->column_fields[$fieldname] != "") {
         $file_name = $PDFMaker->generate_cool_uri($modFocus->column_fields[$fieldname]) . ".pdf";
     } else {
         $file_name = generate_cool_uri($foldername . "_" . $templateid . $focus->parentid . date("ymdHi")) . ".pdf";
     }
     $this->addStat("Attach Document '" . $file_name . "'");
     $docTitle = $this->get("documenttitle", $context);
     $docDescr = $this->get("documentdescr", $context);
     $focus->column_fields['notes_title'] = $docTitle;
     $focus->column_fields['assigned_user_id'] = $assigned_user_id;
     $focus->column_fields['filename'] = $file_name;
     $focus->column_fields['notecontent'] = $docDescr;
     $focus->column_fields['filetype'] = 'application/pdf';
     $focus->column_fields['filesize'] = '';
     $focus->column_fields['filelocationtype'] = 'I';
     $focus->column_fields['fileversion'] = '';
     $focus->column_fields['filestatus'] = 'on';
     $focus->column_fields['folderid'] = $this->get("folderid");
     $focus->save('Documents');
     $language = $current_user->language;
     $request = $_REQUEST;
     $_REQUEST['search'] = true;
     $_REQUEST['submode'] = true;
     if ($current_user->is_admin != "on") {
         $useUser = Users::getActiveAdminUser();
     } else {
         $useUser = $current_user;
     }
     $oldCurrentUser = $current_user;
     $current_user = $useUser;
     $dummyRequest = new Vtiger_Request(array());
     $PDFMaker->createPDFAndSaveFile($dummyRequest, $this->get("template"), $focus, $modFocus, $file_name, $this->getModuleName(), $language);
     $current_user = $oldCurrentUser;
     $_REQUEST = $request;
     /* new PDFMaker Routine */
     $overwriteFilename = $this->get("filename", $context);
     if ($overwriteFilename != -1 && !empty($overwriteFilename)) {
         global $root_directory;
         $sql = "SELECT attachmentsid FROM vtiger_seattachmentsrel WHERE crmid = " . $focus->id . " ORDER BY attachmentsid DESC LIMIT 1";
         $result = $adb->query($sql);
         if ($adb->num_rows($result) > 0) {
             $attachmentsid = $adb->query_result($result, 0, "attachmentsid");
             $attRst = $adb->query("SELECT * FROM vtiger_attachments WHERE attachmentsid = " . $attachmentsid);
             $attachment = $adb->fetchByAssoc($attRst);
             $oldFilename = $root_directory . "/" . $attachment["path"] . $attachmentsid . "_" . $attachment["name"];
             $newFilename = $root_directory . "/" . $attachment["path"] . $attachmentsid . "_" . $overwriteFilename;
             @rename($oldFilename, $newFilename);
             $adb->pquery("UPDATE vtiger_attachments SET name = ? WHERE attachmentsid = " . $attachmentsid, array($overwriteFilename));
             $adb->pquery("UPDATE vtiger_notes SET filename = ? WHERE notesid = " . $focus->id, array($overwriteFilename));
         }
         $file_name = $foldername . "_" . $overwriteFilename;
     }
     $_REQUEST = $request;
     if ($this->get("createrel") === "1") {
         $sql = "INSERT INTO vtiger_senotesrel SET crmid = " . $context->getId() . ", notesid = " . $focus->id;
         $adb->query($sql);
     } else {
         $sql = "DELETE FROM vtiger_senotesrel WHERE crmid = " . $context->getId() . " AND notesid = " . $focus->id;
         $adb->query($sql);
     }
     $newContext = \Workflow\VTEntity::getForId($focus->id, "Documents");
     if ($this->get("workflow") !== "") {
         $objWorkflow = new \Workflow\Main($this->get("workflow"), false, $context->getUser());
         $objWorkflow->setContext($newContext);
         $objWorkflow->isSubWorkflow(true);
         $objWorkflow->start();
     }
     $context->setEnvironment("new_record_id", $newContext->getWsId(), $this);
     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';
 }