<% # report = {'name'=> 'Передвижение менеджеров', 'format'=>'html', 'report_params_attributes'=>[{'name'=>'date', 'view_name'=>'Дата', 'param_type'=> 'date', 'required'=> true},{'name'=>'manager', 'view_name'=>'Менеджер', 'param_type'=> 'managers_select', 'required'=> true},{'name'=>'display_route_points', 'view_name'=>'Отображать точки маршрута', 'param_type'=> 'boolean', 'required'=> false},{'name'=>'display_actions', 'view_name'=>'Отображать операции', 'param_type'=> 'boolean', 'required'=> false}]} @errors = [] params = {} params[:q] = {} params[:q][:timestamp_gt] = @params['date'].to_date.beginning_of_day params[:q][:timestamp_lt] = @params['date'].to_date.end_of_day params[:q][:user_manager_id_eq] = @params['manager'] @search = Location.search(params[:q]) @locations = @search.result.order(:timestamp) @polyline_point = [] @polyline = [] @locations.each do |loc| @polyline_point << {:lat => loc.latitude, :lng => loc.longitude} end @polyline << @polyline_point unless @locations.empty? @markers = Gmaps4rails.build_markers(@locations) do |location, marker| if location == @locations.first marker.lat location.latitude marker.lng location.longitude marker.infowindow render(:partial => "/reports/location", :locals => { :object => location}) marker.picture({:url => '/assets/start.png', :width => 24, :height => 24, :anchor => [12, 24]}) marker.title l(location.timestamp.in_time_zone(@user_timezone)) elsif location == @locations.last marker.lat location.latitude marker.lng location.longitude marker.infowindow render(:partial => "/reports/location", :locals => { :object => location}) marker.picture({:url => '/assets/finish.png', :width => 24, :height => 24, :anchor => [12, 24]}) marker.title l(location.timestamp.in_time_zone(@user_timezone)) else marker.lat location.latitude marker.lng location.longitude marker.infowindow render(:partial => "/reports/location", :locals => { :object => location}) marker.picture({:url => '/assets/point.png', :width => 8, :height => 8, :anchor => [4, 4]}) marker.title l(location.timestamp.in_time_zone(@user_timezone)) end end if @params['display_route_points'] route = Route.find_by_date_and_manager_id(params[:q][:timestamp_gt], params[:q][:user_manager_id_eq]) if route @route_point_locations = [] number = 1 route.route_points.each do |route_point| if route_point.shipping_address.latitude and route_point.shipping_address.longitude route_point_location = {} route_point_location[:lat] = route_point.shipping_address.latitude route_point_location[:lng] = route_point.shipping_address.longitude route_point_location[:picture] = {:url => "http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=#{number}|FF0000|000000", :width => 21, :height => 34} route_point_location[:infowindow] = render(:partial => "/shipping_addresses/location", :locals => { :object => route_point.shipping_address}) route_point_location[:title] = route_point.shipping_address.name @route_point_locations << route_point_location end number += 1 end @markers = @markers + @route_point_locations end end if @params['display_actions'] route = Route.find_by_date_and_manager_id(params[:q][:timestamp_gt], params[:q][:user_manager_id_eq]) if route number = 1 route.route_points.each do |route_point| order_locations = [] audit_document_locations = [] refund_locations = [] route_point_photo_locations = [] completed_survey_locations = [] route_point.orders.each do |order| order_location = {} order_location[:lat] = order.latitude order_location[:lng] = order.longitude order_location[:infowindow] = render(:partial => "/orders/location", :formats => [:html], :locals => { :object => order}) order_location[:picture] = {:url => "http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=#{number}|00FF00|000000", :width => 21, :height => 34} order_location[:title] = order.date order_locations << order_location end route_point.audit_documents.each do |audit_document| audit_document_location = {} audit_document_location[:lat] = audit_document.latitude audit_document_location[:lng] = audit_document.longitude audit_document_location[:infowindow] = render(:partial => "/audit_documents/location", :formats => [:html], :locals => { :object => audit_document}) audit_document_location[:picture] = {:url => "http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=#{number}|0000FF|000000", :width => 21, :height => 34} audit_document_location[:title] = audit_document.date audit_document_locations << audit_document_location end route_point.refunds.each do |refund| refund_location = {} refund_location[:lat] = refund.latitude refund_location[:lng] = refund.longitude refund_location[:infowindow] = render(:partial => "/refunds/location", :formats => [:html], :locals => { :object => refund}) refund_location[:picture] = {:url => "http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=#{number}|FFFF00|000000", :width => 21, :height => 34} refund_location[:title] = refund.date refund_locations << refund_location end route_point.route_point_photos.each do |route_point_photo| route_point_photo_location = {} route_point_photo_location[:lat] = route_point_photo.latitude route_point_photo_location[:lng] = route_point_photo.longitude route_point_photo_location[:infowindow] = render(:partial => "/route_point_photos/location", :formats => [:html], :locals => { :object => route_point_photo}) route_point_photo_location[:picture] = {:url => "http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=#{number}|00FFFF|000000", :width => 21, :height => 34} route_point_photo_locations << route_point_photo_location end route_point.completed_surveys.each do |completed_survey| completed_survey_location = {} completed_survey_location[:lat] = completed_survey.latitude completed_survey_location[:lng] = completed_survey.longitude completed_survey_location[:infowindow] = render(:partial => "/completed_surveys/location", :formats => [:html], :locals => { :object => completed_survey}) completed_survey_location[:picture] = {:url => "http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=#{number}|FF00FF|000000", :width => 21, :height => 34} completed_survey_locations << completed_survey_location end number += 1 @markers = @markers + order_locations @markers = @markers + audit_document_locations @markers = @markers + refund_locations @markers = @markers + route_point_photo_locations @markers = @markers + completed_survey_locations end end end else error = t('errors.not_found_location') @errors << error end %> <% content_for :javascripts do %> <%= javascript_include_tag 'locations' %> <%= javascript_include_tag 'markerclusterer.min' %> <% end %>

<%= t(:manager_movements_report)%>

<% unless @errors.empty? %>

<%=t('errors.title')%>

<% end %> <% if @errors.empty? %>
<% end %>
<%= link_to t(:back), :back, class: 'btn btn-default' %>