Beispiel #1
0
 public function setDplStatus($gps_arr = array())
 {
     $route_data_arr = $this->getRouteData();
     $locations_arr = $this->getLocations();
     $sql_upd = array();
     $new_dpl_arr = array();
     foreach ($route_data_arr as $key => $route_data) {
         $new_dpl = array();
         $gps_data = $gps_arr[$route_data['obj_id']];
         /* Если нет GPS данных по машине пропускаем */
         if ($gps_data['name'] == "") {
             continue;
         }
         $new_dpl['obj_id'] = $route_data['obj_id'];
         $new_dpl['auto_name'] = $gps_data['name'];
         $new_dpl['dt'] = $gps_data['dt'];
         $new_dpl['gps_work'] = sizeof($gps_data) >= 1;
         $new_dpl['old_status'] = $route_data['containers_status'];
         $new_dpl['dir_name'] = $route_data['dir_name'];
         $new_dpl['updated'] = false;
         list($xpos1, $ypos1, $radius1) = pg_fetch_row(pg_query($this->conn, "select xpos, ypos, radius from tgo where id='{$route_data['tgo']}'"));
         list($xpos2, $ypos2, $radius2) = pg_fetch_row(pg_query($this->conn, "select xpos, ypos, radius from location_address where id='{$route_data['loading_location']}'"));
         if ($route_data['discharge_location'] != "") {
             $discharge_location_arr = explode(',', $route_data['discharge_location']);
             list($xpos3, $ypos3, $radius3) = pg_fetch_row(pg_query($this->conn, "select xpos, ypos, radius from location_address where id='{$discharge_location_arr[0]}'"));
         }
         // check location in our base
         foreach ($locations_arr as $lkey => $location) {
             if ($location['lat1'] > $gps_data['lat'] and $location['lon1'] > $gps_data['lon'] and $location['lat2'] < $gps_data['lat'] and $location['lon2'] < $gps_data['lon']) {
                 $new_dpl['location'] = $location['name'];
                 $new_dpl['location_id'] = $location['id'];
                 $new_dpl['update'] = true;
                 break;
             }
         }
         // check location in goole ;)
         if ($new_dpl['location'] == "") {
             $geocode = GpsData::getGeocode($gps_data['lon'], $gps_data['lat']);
             $new_dpl['location'] = $geocode->results[0]->formatted_address;
             $new_dpl['update'] = false;
         }
         if ($route_data['dir'] == 0) {
             // import
             if ($xpos1 + $radius1 > $gps_data['lat'] and $ypos1 + $radius1 > $gps_data['lon'] and $xpos1 - $radius1 < $gps_data['lat'] and $ypos1 - $radius1 < $gps_data['lon'] and $route_data['electronic_declaration'] != 't' and !in_array($route_data['containers_status_id'], array(29, 27, 6, 23))) {
                 $new_dpl['status'] = 16;
                 $new_dpl['color'] = "green";
                 $new_dpl['name'] = "Ждёт таможенную очистку";
             } else {
                 if ($xpos2 + $radius2 > $gps_data['lat'] and $ypos2 + $radius2 > $gps_data['lon'] and $xpos2 - $radius2 < $gps_data['lat'] and $ypos2 - $radius2 < $gps_data['lon'] and $route_data['containers_status_id'] == 49) {
                     $new_dpl['status'] = 18;
                     $new_dpl['color'] = "green";
                     $new_dpl['name'] = "Стоит в порту";
                 } else {
                     if ($discharge_location != "" and $xpos3 + $radius3 > $gps_data['lat'] and $ypos3 + $radius3 > $gps_data['lon'] and $xpos3 - $radius3 < $gps_data['lat'] and $ypos3 - $radius3 < $gps_data['lon'] and !in_array($route_data['containers_status_id'], array(27, 6))) {
                         if (sizeof($discharge_location_arr) == 1) {
                             $new_dpl['status'] = 23;
                             $new_dpl['color'] = "green";
                             $new_dpl['name'] = "Ждет выгрузку";
                         }
                     } else {
                         if ($route_data['containers_status_id'] == 18 and !($xpos2 + $radius2 > $gps_data['lat'] and $ypos2 + $radius2 > $gps_data['lon'] and $xpos2 - $radius2 < $gps_data['lat'] and $ypos2 - $radius2 < $gps_data['lon'])) {
                             // 18 - 'Стоит в порту' --> 50 - '"Выезд из порта"'
                             $new_dpl['status'] = 50;
                             $new_dpl['color'] = "green";
                             $new_dpl['name'] = "Выезд из порта";
                         } else {
                             if ($route_data['containers_status_id'] == 50) {
                                 // 50 - 'Выезд из порта' --> 28 - 'Следует на таможенную очистку' если electronic_declaration --> 'Следует на выгрузку'
                                 if ($route_data['electronic_declaration'] == 't') {
                                     $new_dpl['status'] = 29;
                                     $new_dpl['color'] = "green";
                                     $new_dpl['name'] = "Следует на выгрузку (электронка)";
                                 } else {
                                     $new_dpl['status'] = 28;
                                     $new_dpl['color'] = "green";
                                     $new_dpl['name'] = "Следует на таможенную очистку";
                                 }
                             } else {
                                 if ($route_data['containers_status_id'] == 16) {
                                     // 16 - Ждёт таможенную очистку --> 29 - 'Следует на выгрузку'
                                     if ($route_data['tgo'] != $discharge_location_arr[0]) {
                                         $new_dpl['status'] = 29;
                                         $new_dpl['color'] = "green";
                                         $new_dpl['name'] = "Следует на выгрузку";
                                     } else {
                                         $new_dpl['status'] = "";
                                         $new_dpl['color'] = "green";
                                         $new_dpl['name'] = "Одинаковые ТО и место выгрузки";
                                         $new_dpl['update'] = false;
                                         // не обновлять статус
                                     }
                                 } else {
                                     if ($route_data['containers_status_id'] == 23) {
                                         // 23 - Ждет выгрузку --> 27 - 'Выгружен'
                                         $new_dpl['status'] = 27;
                                         $new_dpl['color'] = "green";
                                         $new_dpl['name'] = "Выгружен";
                                     } else {
                                         if ($route_data['containers_status_id'] == 27) {
                                             // 27 - 'Выгружен' --> 6 - 'Следует порожняком'
                                             /*if ( sizeof($discharge_location_arr) == 1 )
                                             		{*/
                                             $new_dpl['status'] = 6;
                                             $new_dpl['color'] = "green";
                                             $new_dpl['name'] = "Следует порожняком";
                                             /*} elseif ( sizeof($discharge_location_arr) > 1 ) {
                                             			print "<td bgColor='green'>Следует на выгрузку</td>";
                                             			$new_status = 29;
                                             		}*/
                                         } else {
                                             if ($route_data['containers_status_id'] == 6 and ($new_dpl['location_id'] == 69 or $new_dpl['location_id'] == 70) and $new_dpl['location_id'] == $route_data['location_id']) {
                                                 // 6 - 'Следует порожняком' (Если в порту)--> 13 - 'Закрыт'
                                                 $new_dpl['status'] = 30;
                                                 $new_dpl['color'] = "green";
                                                 $new_dpl['name'] = "Сдает порожняк";
                                             } else {
                                                 if ($route_data['containers_status_id'] == 6) {
                                                     // 6 - 'Следует порожняком' --> 13 - не обновлять
                                                     $new_dpl['status'] = "";
                                                     $new_dpl['color'] = "green";
                                                     $new_dpl['name'] = "Следует порожняком (не обновлено)";
                                                     $new_dpl['update'] = false;
                                                     // не обновлять статус
                                                 } else {
                                                     if ($route_data['containers_status_id'] == 30) {
                                                         // 30 - 'Сдает порожняк'
                                                         $new_dpl['status'] = 13;
                                                         $new_dpl['color'] = "green";
                                                         $new_dpl['name'] = "Закрыт";
                                                     } else {
                                                         if ($route_data['containers_status_id'] == "") {
                                                             // 1 - 'Новый'
                                                             $new_dpl['status'] = "";
                                                             $new_dpl['color'] = "green";
                                                             $new_dpl['name'] = "Новый";
                                                             $new_dpl['update'] = false;
                                                             // не обновлять статус
                                                         } else {
                                                             if ($route_data['containers_status_id'] == 11) {
                                                                 // 11 - 'Выгружается у клиента'
                                                                 $new_dpl['status'] = "";
                                                                 $new_dpl['color'] = "green";
                                                                 $new_dpl['name'] = "Выгружается у клиента";
                                                                 $new_dpl['update'] = false;
                                                                 // не обновлять статус
                                                             } else {
                                                                 if ($route_data['containers_status_id'] == 47 or $route_data['containers_status_id'] == 48 or $route_data['containers_status_id'] == 49) {
                                                                     $new_dpl['status'] = "";
                                                                     $new_dpl['color'] = "green";
                                                                     $new_dpl['name'] = "-----";
                                                                     $new_dpl['update'] = false;
                                                                     // не обновлять статус
                                                                 } else {
                                                                     $new_dpl['status'] = $route_data['containers_status_id'];
                                                                     $new_dpl['color'] = "red";
                                                                     $new_dpl['name'] = $route_data['containers_status'];
                                                                 }
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         } else {
             if ($route_data['dir'] == 1) {
                 // export
                 if ($xpos1 + $radius1 > $gps_data['lat'] and $ypos1 + $radius1 > $gps_data['lon'] and $xpos1 - $radius1 < $gps_data['lat'] and $ypos1 - $radius1 < $gps_data['lon']) {
                     $new_dpl['status'] = 19;
                     $new_dpl['color'] = "green";
                     $new_dpl['name'] = "Ждет затаможку";
                 } else {
                     if ($xpos2 + $radius2 > $gps_data['lat'] and $ypos2 + $radius2 > $gps_data['lon'] and $xpos2 - $radius2 < $gps_data['lat'] and $ypos2 - $radius2 < $gps_data['lon']) {
                         $new_dpl['status'] = 25;
                         $new_dpl['color'] = "green";
                         $new_dpl['name'] = "Ждет погрузку экспортом";
                     } else {
                         if ($xpos3 + $radius3 > $gps_data['lat'] and $ypos3 + $radius3 > $gps_data['lon'] and $xpos3 - $radius3 < $gps_data['lat'] and $ypos3 - $radius3 < $gps_data['lon']) {
                             $new_dpl['status'] = 24;
                             $new_dpl['color'] = "green";
                             $new_dpl['name'] = "Сдаёт экспорт";
                         } else {
                             if ($route_data['containers_status_id'] == 25) {
                                 // 25 - 'Ждет погрузку экспортом' --> 32 - 'Следует на затаможку'
                                 $new_dpl['status'] = 32;
                                 $new_dpl['color'] = "green";
                                 $new_dpl['name'] = "Следует на затаможку";
                             } else {
                                 if ($route_data['containers_status_id'] == 19) {
                                     // 19 - Ждет затаможку --> 33 - 'Затаможен, следует в порт'
                                     $new_dpl['status'] = 33;
                                     $new_dpl['color'] = "green";
                                     $new_dpl['name'] = "Затаможен, следует в порт";
                                 } else {
                                     if ($route_data['containers_status_id'] == 24) {
                                         // 24 - Сдаёт экспорт --> 13 - 'Закрыт'
                                         $new_dpl['status'] = 13;
                                         $new_dpl['color'] = "green";
                                         $new_dpl['name'] = "Закрыт";
                                     } else {
                                         $new_dpl['status'] = $route_data['containers_status_id'];
                                         $new_dpl['color'] = "red";
                                         $new_dpl['name'] = $route_data['containers_status'];
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         if ($new_dpl['update'] && $new_dpl['status'] != 10 && date("d.m.Y H:i:s", strtotime($gps_data['dt'])) > $route_data['poll_date'] && ($new_dpl['location_id'] != $route_data['location_id'] || $new_dpl['status'] != $route_data['containers_status_id'])) {
             $sql_upd[] = "INSERT INTO GARAGE.CONTAINERS_POLL(OPERATOR, CONTAINERS_ID, CONTAINERS_STATUS_ID, LOCATION_ID, POLL_DATE) VALUES('931', {$route_data['poll_id']}, {$new_dpl['status']}, {$new_dpl['location_id']}, '" . date("d.m.Y H:i:s", strtotime($gps_data['dt'])) . "');";
             $new_dpl['updated'] = true;
         } else {
         }
         $new_dpl_arr[] = $new_dpl;
         //GpsData::sendMail("*****@*****.**", "Update status", "\r\n");
     }
     return $new_dpl_arr;
 }