public static function addRepairPartsFromPost($post = null) { try { if (is_null($post)) { throw new Exception\ArgumentNullException('$arPost'); } } catch (Exception\ArgumentNullException $e) { die($e->showException()); } //msDebug($post); $arAdd = array(); if (!isset($post['my_car']) || intval($post['my_car']) <= 0) { $arAdd['MY_CAR_ID'] = MyCar::getDefaultCarID(); } else { $arAdd['MY_CAR_ID'] = intval($post['my_car']); } if (!isset($post['date']) || !CoreLib\DateHelper::checkDate($post['date'])) { static::$arError['DATE'] = 'Неверный формат даты'; return false; } else { if (!($arAdd['DATE'] = CoreLib\DateHelper::validateDate($post['date']))) { static::$arError['DATE'] = 'Неверный формат даты'; return false; } } if (!isset($post['name'])) { static::$arError['NAME'] = 'Не указано имя'; return false; } else { $arAdd['NAME'] = htmlspecialchars(trim($post['name'])); } if (!isset($post['storage']) || intval($post['storage']) <= 0) { static::$arError['STORAGE_ID'] = 'Не указано место хранения'; return false; } else { $arAdd['STORAGE_ID'] = intval($post['storage']); } if (isset($post['catalog_number']) && strlen($post['catalog_number']) > 0) { $arAdd['CATALOG_NUMBER'] = htmlspecialchars(trim($post['catalog_number'])); } if (!isset($post['number']) || floatval($post['number']) <= 0) { $arAdd['NUMBER'] = 1; } else { $arAdd['NUMBER'] = CoreLib\Tools::validateFloatVal($post['number']); } if (!isset($post['cost']) || floatval($post['cost']) <= 0) { $arAdd['COST'] = 0; } else { $arAdd['COST'] = CoreLib\Tools::validateFloatVal($post['cost']); } if (!isset($post['reason']) || intval($post['reason']) <= 0) { static::$arError['REASON_REPLACEMENT_ID'] = 'Не указана причина замены'; return false; } else { $arAdd['REASON_REPLACEMENT_ID'] = intval($post['reason']); } $reasonCode = ReasonReplacement::getCodeById($arAdd['REASON_REPLACEMENT_ID']); switch ($reasonCode) { case 'ts': $arAdd['TS_ID'] = intval($post['reason_ts']) > 0 ? intval($post['reason_ts']) : 0; break; case 'breakdown': $arAdd['REPAIR_ID'] = intval($post['reason_breakdown']) > 0 ? intval($post['reason_breakdown']) : 0; break; case 'tuning': $arAdd['REPAIR_ID'] = intval($post['reason_tuning']) > 0 ? intval($post['reason_tuning']) : 0; break; case 'upgrade': $arAdd['REPAIR_ID'] = intval($post['reason_upgrade']) > 0 ? intval($post['reason_upgrade']) : 0; break; case 'tire': break; case 'accident': $arAdd['ACCIDENT_ID'] = intval($post['reason_dtp']) > 0 ? intval($post['reason_dtp']) : 0; break; default: static::$arError['REASON_REPLACEMENT_DETAIL'] = 'Не указана дополнительная информация по причине замены'; return false; } if (!isset($post['who_paid']) || intval($post['who_paid']) <= 0) { static::$arError['WHO_PAID_ID'] = 'Не указано кто платил'; return false; } else { $arAdd['WHO_PAID_ID'] = intval($post['who_paid']); } if (!isset($post['odo']) || floatval($post['odo']) <= 0) { $arAdd['ODO'] = 0; } else { $arAdd['ODO'] = CoreLib\Tools::validateFloatVal($post['odo']); } if (isset($post['ts_point']) && intval($post['ts_point']) > 0) { $arAdd['POINTS_ID'] = intval($post['ts_point']); } else { if (isset($post['newpoint_address']) || isset($post['newpoint_lat']) && isset($post['newpoint_lon'])) { $arPoint = array(); if (isset($post['newpoint_name']) && strlen($post['newpoint_name']) > 0) { $arPoint['NAME'] = $post['newpoint_name']; } else { $arPoint['NAME'] = '[auto] Сервис'; } if (isset($post['newpoint_address']) && strlen($post['newpoint_address']) > 5) { $arPoint['ADDRESS'] = $post['newpoint_address']; } if (isset($post['newpoint_lat']) && strlen($post['newpoint_lat']) > 2 && (isset($post['newpoint_lon']) && strlen($post['newpoint_lon']) > 2)) { $arPoint['LON'] = $post['newpoint_lon']; $arPoint['LAT'] = $post['newpoint_lat']; } $arPoint['TYPE'] = Points::getPointTypeIdByCode('service'); if (!($arAdd['POINTS_ID'] = Points::createNewPoint($arPoint))) { unset($arAdd['POINTS_ID']); static::$arError['POINTS_ADD'] = 'Ошибка добавления путевой точки'; return false; } } else { static::$arError['POINTS_ID'] = 'Не указана путевая точка'; return false; } } if (isset($post['comment']) && strlen($post['comment']) > 0) { $arAdd['DESCRIPTION'] = trim(htmlspecialchars($post['comment'])); } return static::addRepairParts($arAdd); }
public static function convertCurrency($value = null, $fromCur = null, $toCur = null, $date = null) { try { if (is_null($value)) { throw new Exception\ArgumentNullException('$value'); } if (is_null($fromCur)) { throw new Exception\ArgumentNullException('$fromCur'); } if (is_null($toCur)) { throw new Exception\ArgumentNullException('$toCur'); } } catch (Exception\ArgumentNullException $e) { $e->showException(); return false; } if (floatval($value) == 0) { return 0; } $fromCur = strtoupper($fromCur); $toCur = strtoupper($toCur); if (is_null($date) || !DateHelper::checkDate($date)) { $date = date("d.m.Y"); } $res = Tables\CurrencyTable::getList(array("select" => "RATING", "filter" => array("CODE" => $fromCur))); if ($res) { $rating = $res[0]["RATING"]; } else { $rating = 1; } $newValue = $value * (self::getCurrencyRate($toCur, $fromCur, $date) / $rating); return floatval(round($newValue, 4)); }
public static function updateTsFromPost($tsID = null, $post = null) { try { if (is_null($tsID)) { throw new Exception\ArgumentNullException('tsID'); } if (is_null($post)) { throw new Exception\ArgumentNullException('_POST'); } } catch (Exception\ArgumentNullException $e) { $e->showException(); return false; } //msDebug($post); $arUpdate = array(); if (isset($post['my_car']) || intval($post['my_car']) <= 0) { $arUpdate['MY_CAR_ID'] = intval($post['my_car']); } if (isset($post['ts_num'])) { $arUpdate['TS_NUM'] = intval($post['ts_num']); } if (isset($post['date']) && CoreLib\DateHelper::checkDate($post['date'])) { $arUpdate['DATE'] = CoreLib\DateHelper::validateDate($post['date']); } if (isset($post['executor']) && intval($post['executor']) <= 0) { $arUpdate['EXECUTORS_ID'] = intval($post['executor']); } if (isset($post['cost'])) { $post['cost'] = str_replace(" ", "", $post['cost']); $post['cost'] = str_replace(",", ".", $post['cost']); $post['cost'] = floatval($post['cost']); $arUpdate['COST'] = $post['cost']; } if (isset($post['odo'])) { $post['odo'] = str_replace(" ", "", $post['odo']); $post['odo'] = str_replace(",", ".", $post['odo']); $post['odo'] = floatval($post['odo']); $arUpdate['ODO'] = $post['odo']; } if (isset($post['ts_point']) && intval($post['ts_point']) > 0) { $arUpdate['POINTS_ID'] = intval($post['ts_point']); } else { if (isset($post['newpoint_address']) || isset($post['newpoint_lat']) && isset($post['newpoint_lon'])) { $arPoint = array(); if (isset($post['newpoint_name']) && strlen($post['newpoint_name']) > 3) { $arPoint['NAME'] = $post['newpoint_name']; } else { $arPoint['NAME'] = '[auto] Сервис'; } if (isset($post['newpoint_address']) && strlen($post['newpoint_address']) > 5) { $arPoint['ADDRESS'] = $post['newpoint_address']; } if (isset($post['newpoint_lat']) && strlen($post['newpoint_lat']) > 2 && (isset($post['newpoint_lon']) && strlen($post['newpoint_lon']) > 2)) { $arPoint['LON'] = $post['newpoint_lon']; $arPoint['LAT'] = $post['newpoint_lat']; } $arPoint['TYPE'] = Points::getPointTypeIdByCode('service'); $arUpdate['POINTS_ID'] = Points::createNewPoint($arPoint); } } if (isset($post['comment']) && strlen($post['comment']) > 0) { $arUpdate['DESCRIPTION'] = trim(htmlspecialchars($post['comment'])); } if ($res = static::updateTs($tsID, $arUpdate)) { return true; } else { return false; } }