Ejemplo n.º 1
0
 public static function CreateCalcTaskEx($name, $id_company, $id_deal, $id_smart, $qw = 0, $qp = 0, $source, $email, $smart, $method, $doc, $primech = '', $bitrix_user = '', $urgency = '', $produc = '', $taskname = '', $tasktype = 0, $status = 'Ждет!', $phone_sms = '', $arFiles = array(), $title_company = '')
 {
     //$title_company = '';
     //error_log("id_company is $id_company\n",3,'kkk.log');
     //+++ can be deleted imho
     // get company
     /*
     $ibc = new CAllCrmCompany ();
     $arFilter = array (
     		'ID' => $id_company 
     );
     $res_comp = $ibc->GetList ( array (), $arFilter );
     if ($comp_info = $res_comp->Fetch ()) {
     	$title_company = $comp_info ['TITLE'];
     }
     */
     //---
     //error_log("title_company is $title_company\n",3,'kkk.log');
     // save
     $ib = new CIBlockElement();
     $arFlds = array('NAME' => $name, 'IBLOCK_ID' => 65, 'ACTIVE' => 'Y');
     //error_log("start\n",3,'konvita.log');
     $prod_id = $ib->Add($arFlds);
     // крайний срок задачи
     $mins = CArkaConstant::GetValueByName('win_start') + CArkaConstant::GetValueByName('win_pos') * $qp + CArkaConstant::GetValueByName('Reserv_Time');
     $maxTime = CArkaMisc::CurrentTimePlusMinutes($mins);
     $maxTime = ConvertTimeStamp($maxTime, "FULL");
     //error_log("maxTime is $maxTime\n",3,'konvita.log');
     // define time to process
     if ($tasktype == 0) {
         // просчет окон
         $timeStart = CArkaConstant::GetValueByName('win_start');
         $timeProcess = CArkaConstant::GetValueByName('win_pos') * $qp;
     } elseif ($tasktype == 1) {
         // технический вопрос
         $timeStart = CArkaConstant::GetValueByName('tech_start');
         $timeProcess = CArkaConstant::GetValueByName('tech_solve');
     } elseif ($tasktype == 2) {
         // обратный звонок
         $timeStart = CArkaConstant::GetValueByName('callback_start');
         $timeProcess = CArkaConstant::GetValueByName('callback_solve');
     }
     // $wtime перекрывает все расчитанное
     if ($wtime > 0) {
         $timeStart = $wtime;
         $timeProcess = 0;
     }
     // prepare text
     $arPrimech = array("VALUE" => array("TEXT" => $primech, "TYPE" => "text"));
     // phone sms
     if ($phone_sms == '') {
         $phone_sms = CArkaCrm::GetPhoneSmsForCompany($id_company);
     }
     // bitrix_user
     if ($bitrix_user == 0) {
         $bitrix_user = CArkaCrm::GetBitrixUserForCompany($id_company);
     }
     // method
     // если метод не указан, берем из компании
     if ($method == '') {
         $method = CArkaCrm::GetMethodForCompany($id_company);
     }
     // urgency
     // не оставлять срочность пустой
     // если не указана, пишем стандартная
     if ($urgency == '') {
         $urgency = 'Стандартная';
         //error_log("urgency is $urgency\n",3,'kkk2.log');
     }
     // определить имя компании
     //$title_company = CArkaCrm::GetTitleForCompany($id_company);
     //$title_company = 'debug';
     if ($title_company == '') {
         $title_company = CArkaCrm::GetTitleForCompany($id_company);
     }
     //error_log("id_company is $id_company\n",3,'kkk2.log');
     //error_log("title is $title_company\n",3,'kkk2.log');
     // ex fields
     if ($prod_id) {
         $ib->SetPropertyValueCode($prod_id, "QW", $qw);
         $ib->SetPropertyValueCode($prod_id, "QP", $qp);
         $ib->SetPropertyValueCode($prod_id, "CompanyName", $title_company);
         $ib->SetPropertyValueCode($prod_id, "CompanyID", $id_company);
         $ib->SetPropertyValueCode($prod_id, "Source", $source);
         $ib->SetPropertyValueCode($prod_id, "NormaStart", $timeStart);
         $ib->SetPropertyValueCode($prod_id, "NormaProcess", $timeProcess);
         $ib->SetPropertyValueCode($prod_id, "Due_Date_Task", $maxTime);
         // ex props
         $ib->SetPropertyValueCode($prod_id, "email", $email);
         $ib->SetPropertyValueCode($prod_id, "smart", $smart);
         $ib->SetPropertyValueCode($prod_id, "method", $method);
         $ib->SetPropertyValueCode($prod_id, "doc", $doc);
         // $ib->SetPropertyValueCode($prod_id,"primech",$primech);
         //$ib->SetPropertyValueCode ( $prod_id, "bitrix_user", $arBitrixUser );
         $ib->SetPropertyValueCode($prod_id, "bitrix_user", $bitrix_user);
         $ib->SetPropertyValueCode($prod_id, "urgency", $urgency);
         $ib->SetPropertyValueCode($prod_id, "produc", $produc);
         $ib->SetPropertyValueCode($prod_id, "TaskName", $taskname);
         $ib->SetPropertyValueCode($prod_id, "STATUS_TASK", $status);
         $ib->SetPropertyValueCode($prod_id, "PHONE_SMS", $phone_sms);
         // text saving
         // $ib->SetPropertyValuesEx($prod_id,65,$ar);
         $ib->SetPropertyValueCode($prod_id, "primech", $arPrimech);
         // attached files (for mail)
         $ib->SetPropertyValueCode($prod_id, "FormFiles", $arFiles);
     }
     return $prod_id;
 }