Esempio n. 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);
 }
Esempio n. 2
0
 private static function getValues($tariffID, $date = null, $type = 'hourly')
 {
     if (is_null($date)) {
         $arDate = explode('.', date('d.m.Y'));
     } else {
         if ($date = DateHelper::validateDate($date)) {
             $arDate = explode('.', $date);
         } else {
             $arDate = explode('.', date('d.m.Y'));
         }
     }
     $query = new Query('select');
     $sqlHelper = new SqlHelper();
     $valuesHourlyTableName = ValuesHourlyTable::getTableName();
     $sql = "SELECT " . $sqlHelper->getSumFunction("VALUE") . " , " . $sqlHelper->getSumFunction("COST");
     if ($type == 'hourly') {
         $sql .= " , " . $sqlHelper->wrapQuotes("HOUR");
     }
     if ($type == 'hourly' || $type == 'daily') {
         $sql .= " , " . $sqlHelper->wrapQuotes("DAY");
     }
     if ($type == 'hourly' || $type == 'daily' || $type == 'monthly') {
         $sql .= " , " . $sqlHelper->wrapQuotes("MONTH");
     }
     $sql .= " , " . $sqlHelper->wrapQuotes("YEAR");
     $sql .= " FROM " . $sqlHelper->wrapQuotes($valuesHourlyTableName) . " WHERE " . $sqlHelper->wrapQuotes($valuesHourlyTableName) . "." . $sqlHelper->wrapQuotes("TARIFF_ID") . " =" . intval($tariffID);
     if ($type == 'hourly') {
         $sql .= " AND " . $sqlHelper->wrapQuotes($valuesHourlyTableName) . "." . $sqlHelper->wrapQuotes("DAY") . " =" . intval($arDate[0]);
     }
     if ($type == 'hourly' || $type == 'daily') {
         $sql .= " AND " . $sqlHelper->wrapQuotes($valuesHourlyTableName) . "." . $sqlHelper->wrapQuotes("MONTH") . " =" . intval($arDate[1]);
     }
     if ($type == 'hourly' || $type == 'daily' || $type == 'monthly') {
         $sql .= " AND " . $sqlHelper->wrapQuotes($valuesHourlyTableName) . "." . $sqlHelper->wrapQuotes("YEAR") . " =" . intval($arDate[2]);
     }
     if ($type == 'hourly') {
         $sql .= " GROUP BY " . $sqlHelper->wrapQuotes("HOUR") . " ";
     } elseif ($type == 'daily') {
         $sql .= " GROUP BY " . $sqlHelper->wrapQuotes("DAY") . " ";
     } elseif ($type == 'monthly') {
         $sql .= " GROUP BY " . $sqlHelper->wrapQuotes("MONTH") . " ";
     } elseif ($type == 'yearly') {
         $sql .= " GROUP BY " . $sqlHelper->wrapQuotes("YEAR") . " ";
     }
     $query->setQueryBuildParts($sql);
     $res = $query->exec();
     if ($res->getResult()) {
         $arResult = array();
         $i = 0;
         while ($ar_res = $res->fetch()) {
             $arResult[$i] = array('SUM_VALUE' => round($ar_res['SUM_VALUE'], 2), 'SUM_COST' => round($ar_res['SUM_COST'], 2), 'YEAR' => intval($ar_res['YEAR']));
             if (isset($ar_res['HOUR'])) {
                 $arResult[$i]['HOUR'] = intval($ar_res['HOUR']);
             }
             if (isset($ar_res['DAY'])) {
                 $arResult[$i]['DAY'] = intval($ar_res['DAY']);
             }
             if (isset($ar_res['MONTH'])) {
                 $arResult[$i]['MONTH'] = intval($ar_res['MONTH']);
             }
             $i++;
         }
         return $arResult;
     } else {
         return false;
     }
 }
Esempio n. 3
0
 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;
     }
 }