Example #1
0
 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);
 }
Example #2
0
			<td><?php 
echo InputType('text', 'number', $bError ? $_POST['number'] : '', '', false, '', 'class="number"');
?>
</td>
		</tr>
		<tr>
			<td class="title">Стоимость</td>
			<td><?php 
echo InputType('text', 'cost', $bError ? $_POST['cost'] : '', '', false, '', 'class="cost"');
?>
</td>
		</tr>
		<tr>
			<td class="title">Причина замены</td>
			<td><?php 
echo Lib\ReasonReplacement::showSelectReasonReplacementList("reason", '', $bError ? intval($_POST['reason']) : 1);
?>
</td>
		</tr>
		<tr>
			<td class="title">Дополнительная причина замены</td>
			<td class="reason_add">
				<?php 
echo Lib\Ts::showSelectTsList($carID, "reason_ts", 'Не выбрано', $bError && isset($_POST['reason_ts']) ? intval($_POST['reason_ts']) : 'null', 'id="reason_ts" class="tslistselect"');
?>
				<?php 
echo Lib\Repair::showSelectRepairList($carID, "reason_breakdown", 'Не выбрано', $bError && isset($_POST['reason_breakdown']) ? intval($_POST['reason_breakdown']) : 'null', 'id="reason_breakdown" class="repairlistselect" style="display: none;"');
?>
				<?php 
echo Lib\Accident::showSelectAccidentList($carID, "reason_dtp", 'Не выбрано', $bError && isset($_POST['reason_dtp']) ? intval($_POST['reason_dtp']) : 'null', 'id="reason_dtp" class="accidentlistselect" style="display: none;"');
?>