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); }
/** * Функция обрабатывает данные о маршруте из формы, для сохранении в БЛ * * @param null $post * * @return bool|int */ public static function addNewRouteFromPost($post = null) { try { if (is_null($post)) { throw new Exception\ArgumentNullException("_POST"); } } catch (Exception\ArgumentNullException $e) { $e->showException(); return false; } $arData = array(); if (isset($post['my_car'])) { $arData['MY_CAR_ID'] = intval($post['my_car']); } else { $arData['MY_CAR_ID'] = MyCar::getDefaultCarID(); } if (isset($post['date'])) { $arData['DATE'] = $post['date']; } else { $arData['DATE'] = date('d.m.Y'); } if (isset($post['odo'])) { $arData['ODO'] = $post['odo']; } if (isset($post['start_point']) && intval($post['start_point']) > 0) { $arData['START_POINTS_ID'] = $post['start_point']; } else { $arPoint = array(); if (isset($post['start_name']) && strlen($post['start_name']) > 3) { $arPoint['NAME'] = $post['start_name']; } if (isset($post['start_address']) && strlen($post['start_address']) > 5) { $arPoint['ADDRESS'] = $post['start_address']; } if (isset($post['start_lat']) && strlen($post['start_lat']) > 2 && (isset($post['start_lon']) && strlen($post['start_lon']) > 2)) { $arPoint['LON'] = $post['start_lon']; $arPoint['LAT'] = $post['start_lat']; } $arPoint['TYPE'] = Points::getPointTypeIdByCode('waypoint'); $arData['START_POINTS_ID'] = Points::createNewPoint($arPoint); } if (isset($post['end_start']) && intval($post['end_start']) == 1) { $arData['END_START'] = true; } else { $arData['END_START'] = false; if (isset($post['end_point']) && intval($post['end_point']) > 0) { $arData['END_POINTS_ID'] = $post['end_point']; $arData['end_point_num'] = true; } else { $arPoint = array(); if (isset($post['end_name']) && strlen($post['end_name']) > 3) { $arPoint['NAME'] = $post['end_name']; } if (isset($post['end_address']) && strlen($post['end_address']) > 5) { $arPoint['ADDRESS'] = $post['end_address']; } if (isset($post['end_lat']) && strlen($post['end_lat']) > 2 && (isset($post['end_lon']) && strlen($post['end_lon']) > 2)) { $arPoint['LON'] = $post['end_lon']; $arPoint['LAT'] = $post['end_lat']; } $arPoint['TYPE'] = Points::getPointTypeIdByCode('waypoint'); $arData['END_POINTS_ID'] = Points::createNewPoint($arPoint); } } return static::addNewRoute($arData); }
<?php include_once __DIR__ . "/../include/header.php"; MSergeev\Core\Lib\Buffer::setTitle("Запчасти - Добавление информации о приобретенных зап.частях"); use MSergeev\Packages\Icar\Lib; use MSergeev\Core\Lib as CoreLib; if (isset($_REQUEST['car'])) { $carID = intval($_REQUEST["car"]); } else { $carID = Lib\MyCar::getDefaultCarID(); } $pService = Lib\Points::getPointTypeIdByCode("service"); $pStore = Lib\Points::getPointTypeIdByCode("shop"); $pCarwash = Lib\Points::getPointTypeIdByCode("wash"); $bError = false; if (isset($_POST["action"])) { if ($res = Lib\RepairParts::addRepairPartsFromPost($_POST)) { ?> <span style="color: green;">Данные успешно добавлены</span><?php $bError = false; } else { ?> <span style="color: red;">Ошибка добавления данных:<?php echo Lib\RepairParts::showErrorList(); ?> </span><?php $bError = true; //msDebug($res); } } ?>
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; } }
public static function updateFuelFromPost($post = null) { try { if (is_null($post)) { throw new Exception\ArgumentNullException('post'); } if (!isset($post['id'])) { throw new Exception\ArgumentNullException('post[id]'); } elseif (intval($post['id']) <= 0) { throw new Exception\ArgumentOutOfRangeException('post[id]', 1); } } catch (Exception\ArgumentNullException $e) { die($e->showException()); } catch (Exception\ArgumentOutOfRangeException $e2) { die($e2->showException()); } $arFuel = static::getFuelList(null, intval($post['id'])); $arFuel = $arFuel[0]; $arUpdate = array(); if (isset($post['my_car']) && intval($post['my_car']) != intval($arFuel['MY_CAR_ID'])) { $arUpdate['MY_CAR_ID'] = intval($post['my_car']); } if (isset($post['date']) && $post['date'] != $arFuel['DATE']) { $arUpdate['DATE'] = $post['date']; } if (isset($post['odo'])) { if (floatval($post['odo']) == 0) { $odo = MyCar::getBuyCarOdo($arUpdate['MY_CAR_ID']); } else { $odo = floatval($post['odo']); } if ($odo != $arFuel['ODO']) { $arUpdate['ODO'] = $odo; } } if (isset($post['fuel_mark']) && intval($post['fuel_mark']) != intval($arFuel['FUELMARK_ID'])) { $arUpdate['FUELMARK_ID'] = intval($post['fuel_mark']); } if (isset($post['liters']) && floatval($post['liters']) != floatval($arFuel['LITER'])) { $arUpdate['LITER'] = floatval($post['liters']); } if (isset($post['cost_liter']) && floatval($post['cost_liter']) != floatval($arFuel['LITER_COST'])) { $arUpdate['LITER_COST'] = floatval($post['cost_liter']); } $sum = floatval($arFuel['LITER'] * $arFuel['LITER_COST']); if ($sum != $arFuel['SUM']) { $arUpdate['SUM'] = $sum; } if (isset($post['full_tank']) && intval($post['full_tank']) == 1) { $full = true; } else { $full = false; } if ($full !== $arFuel['FULL']) { $arUpdate['FULL'] = $full; } /* $expence = static::recalculateExpence($arFuel); if ($expence != $arFuel['EXPENCE']) { $arUpdate['EXPENCE'] = $expence; }*/ if (isset($post['comment']) && $post['comment'] != $arFuel['INFO']) { $arUpdate['DESCRIPTION'] = trim($post['comment']); } if (isset($post['fuel_point']) && intval($post['fuel_point']) > 0 && intval($post['fuel_point']) != intval($arFuel['POINTS_ID'])) { $arUpdate['POINTS_ID'] = intval($post['fuel_point']); } elseif ($post['fuel_point'] == 'NULL') { $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('fuel'); $arUpdate['POINTS_ID'] = Points::createNewPoint($arPoint); } if (!empty($arUpdate)) { $query = new Query('update'); $query->setUpdateParams($arUpdate, $post['id'], Tables\FuelTable::getTableName(), Tables\FuelTable::getMapArray()); $res = $query->exec(); if ($res->getResult()) { static::recalculateExpence($arFuel); return true; } else { return false; } } else { return true; } }