Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Ticket < ActiveRecord::Base
- BLACK_SIGN = "black"
- YELLOW_SIGN ="yellow"
- RED_SIGN = "red"
- GREEN_SIGN ="green"
- NO_PLANNING = "SEM PLANEJAMENTO"
- NONE = " - "
- file_column :image
- validates_presence_of :status_id,:analyst_id,:designer_id,:developer_id
- validates_format_of :image, :allow_nil => true, :with => %r{.(jpg)$}i, :message => "must be a jpg image."
- file_column :attachement
- def Ticket.calculate_working_days(d1,d2,wdays)
- if(d1 == d2)
- return 1
- end
- diff = d2 - d1 + 1
- holidays = 0
- ret = (d2-d1).divmod(7)
- holidays = ret[0].truncate * wdays.length
- d1 = d2 - ret[1]
- while(d1 <= d2)
- if wdays.include?(d1.wday)
- holidays += 1
- end
- d1 += 1
- end
- diff - holidays
- end
- #Retorna a próxima data alvo do ticket.
- def Ticket.targetDate (ticket)
- #O ticket está em elaboração?
- if ticket.hasBasicPlanning && Status.getStepsForDV().include?(ticket.status_id)
- return ticket.targetDateDV
- end
- #O ticket está em elaboração e não foi planajedo?
- if !ticket.hasBasicPlanning && Status.getStepsForDV().include?(ticket.status_id)
- return Ticket::NO_PLANNING
- end
- # Ticket está em construção?
- if ticket.hasDetailedPlanning && Status.getStepsForHomologation().include?(ticket.status_id)
- return ticket.targetDateHomologation
- end
- # Ticket está em construção e não foi planejado?
- if !ticket.hasDetailedPlanning && Status.getStepsForHomologation().include?(ticket.status_id)
- return Ticket::NO_PLANNING
- end
- # Ticket está em Fechamento de Pedido?
- if Status::FECHAMENTO_PEDIDO == ticket.status_id
- return ticket.statusDate + 12
- end
- # Ticket está pendente com solicitante?
- if Status.getUserSteps().include?(ticket.status_id)
- return ticket.statusDate + 21
- end
- return Ticket::NONE
- end
- #Retorna string que representa semaforo de atendimento às metas.
- def Ticket.targetDateStatus (ticket)
- #O ticket está em elaboração?
- if ticket.hasBasicPlanning && Status.getStepsForDV().include?(ticket.status_id)
- date = ticket.targetDateDV
- end
- # Ticket está em construção?
- if ticket.hasDetailedPlanning && Status.getStepsForHomologation().include?(ticket.status_id)
- date = ticket.targetDateHomologation
- end
- # Ticket está em Fechamento de Pedido
- if Status::FECHAMENTO_PEDIDO == ticket.status_id
- date = ticket.statusDate + 12
- end
- # Ticket está pendente com solicitante
- if Status.getUserSteps().include?(ticket.status_id)
- date = ticket.statusDate + 21
- end
- # existe alguma data alvo para comparar?
- if date != nil
- working_days = calculate_working_days Date.today,date, [0,5];
- if ( working_days < 0 )
- return Ticket::BLACK_SIGN;
- else
- if ( working_days == 0 )
- return Ticket::RED_SIGN
- else
- if working_days <= 2
- return Ticket::YELLOW_SIGN
- else
- if working_days > 2
- return Ticket::GREEN_SIGN
- end
- end
- end
- end
- end
- end
- end
- ################################################################################################
- class TicketsController < ApplicationController
- # GET /tickets
- # GET /tickets.xml
- def index
- order = "(CASE status_id
- WHEN " + Status::AGUARDANDO.to_s + " THEN targetDateDV
- WHEN " + Status::ANALISE.to_s + " THEN targetDateDV
- WHEN " + Status::APROVACAO_DV_PROJETISTA.to_s + " THEN targetDateDV
- WHEN " + Status::APROVACAO_DV_GP.to_s + " THEN targetDateDV
- WHEN " + Status::REVISAO_ORTOGRAFICA_DV.to_s + " THEN targetDateDV
- WHEN " + Status::ENVIAR_DV_AO_SOLICITANTE.to_s + " THEN targetDateDV
- ELSE targetDateHomologation end
- )"
- condition = "status_id not in (" + Status::CANCELADO.to_s + "," + Status::CONCLUIDO.to_s + ")"
- if params[:developer_id]
- condition += " and developer_id=" + params[:developer_id]
- end
- if params[:analyst_id]
- condition += " and analyst_id=" + params[:analyst_id]
- end
- if params[:designer_id]
- condition += " and designer_id=" + params[:designer_id]
- end
- if params[:status_id]
- condition += " and status_id=" + params[:status_id]
- end
- if params[:user_id]
- condition += " and user_id=" + params[:user_id]
- end
- if params[:area_id]
- condition += " and area_id=" + params[:area_id]
- @area = Area.find(params[:area_id])
- @analyst = Analyst.find(@area.analyst_id)
- @designer = Designer.find(@area.designer_id)
- @developer = Developer.find(@area.developer_id)
- else
- condition += " and area_id <> 6 "
- end
- @tickets = Ticket.find(:all, :order => order, :conditions => condition)
- @tickets_analyst = Array.new
- @tickets_designer = Array.new
- @tickets_developer = Array.new
- @tickets_auditor = Array.new
- @tickets_scm = Array.new
- @tickets_user = Array.new
- @tickets_test = Array.new
- for ticket in @tickets
- if(Status.getAnalystSteps().include?(ticket.status_id))
- @tickets_analyst << ticket
- end
- if(Status.getTestSteps().include?(ticket.status_id))
- @tickets_test << ticket
- end
- if(Status.getDesignerSteps().include?(ticket.status_id))
- @tickets_designer << ticket
- end
- if(Status.getAuditorSteps().include?(ticket.status_id))
- @tickets_auditor << ticket
- end
- if(Status.getScmSteps().include?(ticket.status_id))
- @tickets_scm << ticket
- end
- if(Status.getUserSteps().include?(ticket.status_id))
- @tickets_user << ticket
- end
- if(Status.getDeveloperSteps().include?(ticket.status_id))
- @tickets_developer << ticket
- end
- end
- respond_to do |format|
- format.html # index.html.erb
- format.xml { render :xml => @tickets }
- end
- end
- # GET /tickets/1
- # GET /tickets/1.xml
- def show
- @ticket = Ticket.find(params[:id])
- @user = User.find(@ticket.user_id)
- @area = Area.find(@user.area_id)
- respond_to do |format|
- format.html # show.html.erb
- format.xml { render :xml => @ticket }
- end
- end
- # GET /tickets/new
- # GET /tickets/new.xml
- def new
- @ticket = Ticket.new
- respond_to do |format|
- format.html # new.html.erb
- format.xml { render :xml => @ticket }
- end
- end
- # GET /tickets/1/edit
- def edit
- @ticket = Ticket.find(params[:id])
- @area = Area.find(@ticket.area_id)
- @histories = History.find(:all, :order => 'date desc', :conditions => {:ticket_id => @ticket.id})
- end
- # GET /tickets/edit_by_external_id/1
- def edit_by_external_id
- @ticket = Ticket.find(:first, :conditions => {:external_id => params[:id]})
- @user = User.find(@ticket.user_id)
- @area = Area.find(@ticket.area_id)
- @histories = History.find(:all, :order => 'date desc', :conditions => {:ticket_id => @ticket.id})
- end
- # POST /tickets
- # POST /tickets.xml
- def create
- @ticket = Ticket.new(params[:ticket])
- #Recupera o solicitante do ticket
- @user = User.find(@ticket.user_id)
- #Recupera a área do solicitante
- @area = Area.find(@user.area_id)
- @ticket.area_id = @area.id
- #Status inicial é Aguardando
- @ticket.status_id = Status::AGUARDANDO
- #Data de abertura é igual hoje
- @ticket.openDate = Time.today
- #Data do status é igual hoje
- @ticket.statusDate = Time.today
- #Setar no ticket os recursos default da área
- @ticket.analyst_id = @area.analyst_id
- @ticket.designer_id = @area.designer_id
- @ticket.developer_id = @area.developer_id
- respond_to do |format|
- if @ticket.save
- #Existe identificacao externa?
- if @ticket.external_id == ""
- @ticket.update_attributes(:external_id=>"S" + @ticket.id.to_s)
- end
- #Registrando histórico para a mudanca
- History::registerHistory(@ticket)
- #Notificar equipe sobre mudança de status
- Emailer.deliver_ticket_status_notification(@ticket)
- flash[:notice] = 'Ticket was successfully created.'
- format.html { redirect_to(@ticket) }
- format.xml { render :xml => @ticket, :status => :created, :location => @ticket }
- else
- format.html { render :action => "new" }
- format.xml { render :xml => @ticket.errors, :status => :unprocessable_entity }
- end
- end
- end
- # PUT /tickets/1
- # PUT /tickets/1.xml
- def update
- @ticket = Ticket.find(params[:id])
- #Recupera o status antigo do ticket
- old_status = @ticket.status_id
- #Atualiza a data de atualizacao do ticket
- @ticket.statusDate = Time.today
- @user = User.find(@ticket.user_id)
- @area = Area.find(@ticket.area_id)
- respond_to do |format|
- if @ticket.update_attributes(params[:ticket])
- #Registrando histórico para a mudanca
- History::registerHistory(@ticket)
- #Status do ticket foi alterado?
- if( old_status != @ticket.status_id )
- #Notificar equipe sobre mudança de status
- Emailer.deliver_ticket_status_notification(@ticket)
- end
- #Status antigo é "Auditoria Desenho" e o ticket está em Implementação, mas o branch nao foi criado.
- status_atual = Status.find(@ticket.status_id)
- aprovacao_desenho = Status.find(Status::AUDITORIA_DESENHO)
- if( @ticket.projects != "" && @ticket.branch == "" && status_atual.position > aprovacao_desenho.position)
- Emailer.deliver_create_branch_notification(@ticket)
- end
- #Status antigo é "aprovar DV" e o ticket está em construção?
- if(old_status == Status::APROVACAO_DV && Status.getStepsForHomologation().include?(@ticket.status_id))
- Emailer.deliver_ticket_status_billing_notification(@ticket)
- end
- flash[:notice] = 'Ticket was successfully updated.'
- format.html { redirect_to(@ticket) }
- format.xml { head :ok }
- else
- format.html { render :action => "edit" }
- format.xml { render :xml => @ticket.errors, :status => :unprocessable_entity }
- end
- end
- end
- # DELETE /tickets/1
- # DELETE /tickets/1.xml
- def destroy
- @ticket = Ticket.find(params[:id])
- @ticket.destroy
- respond_to do |format|
- format.html { redirect_to(tickets_url) }
- format.xml { head :ok }
- end
- end
- def send_status_change_notification(ticket)
- end
- end
- ###########################################################################################
- class History < ActiveRecord::Base
- file_column :attachement
- def History.registerHistory(ticket)
- history = History.new()
- history.date = Time.now()
- history.ticket_id = ticket.id
- history.status_id = ticket.status_id
- history.attachement = ticket.attachement
- history.analyst_id = ticket.analyst_id
- history.developer_id = ticket.developer_id
- history.designer_id = ticket.designer_id
- history.targetDateHomologation = ticket.targetDateHomologation
- history.targetDateDV = ticket.targetDateDV
- history.notes = ticket.notes
- history.priority_id = ticket.priority_id
- history.save
- end
- end
- #############################################################################################
- <h1>Editing ticket <%=@ticket.external_id%></h1>
- <%= link_to 'Voltar Para Fila', (tickets_path + "?area_id=" + @area.id.to_s) %> |
- <%= link_to 'Voltar Para Todos', (tickets_path) %>
- <%= error_messages_for :ticket %>
- <% form_for(@ticket, :html => {:multipart => true}) do |f| %>
- <table class="edit">
- <tr>
- <th colspan=6>Informacoes</th>
- </tr>
- <tr class="odd">
- <td>Notes</td>
- <td width="100%" colspan=5><%= f.text_field :notes, :value=>"", :maxlength => "180"%></td>
- </tr>
- <tr class="even">
- <td>Nome</td>
- <td width="100%" colspan=5><%= f.text_field :name, :maxlength => "180"%></td>
- </tr>
- <tr class="odd">
- <td>Status</td>
- <td><%= select("ticket", "status_id", Status.find(:all, :order=>:position).collect{|c| [c.name, c.id] }) %></td>
- <td>Prioridade</td>
- <td colspan=3><%= select("ticket", "priority_id", Priority.find(:all).collect{|c| [c.name, c.id] }) %></td>
- </tr>
- <tr class="even">
- <td>Analista</td>
- <td><%= select("ticket", "analyst_id", Analyst.find(:all, :order => 'name').collect{|c| [c.name, c.id] }) %></td>
- <td>Projetista</td>
- <td><%= select("ticket", "designer_id", Designer.find(:all, :order => 'name').collect{|c| [c.name, c.id] }) %></td>
- <td>Desenvolvedor</td>
- <td><%= select("ticket", "developer_id", Developer.find(:all, :order => 'name').collect{|c| [c.name, c.id] }) %></td>
- </tr>
- <tr class="odd">
- <td>Branch</td>
- <td><%= f.text_field :branch %></td>
- <td>Projetos</td>
- <td><%= f.text_field :projects %></td>
- <td>Script Banco?</td>
- <td><%= f.check_box :hasDataBaseScripts %></td>
- </tr>
- <tr class="even">
- <td>Qualidade</td>
- <td><%= select("ticket", "feedbackQuality_id", Feedback.find(:all).collect{|c| [c.value, c.id] }) %></td>
- <td>Prazo</td>
- <td><%= select("ticket", "feedbackPeriod_id", Feedback.find(:all).collect{|c| [c.value, c.id] }) %></td>
- <td>Documentacao</td>
- <td><%= select("ticket", "feedbackDocumentation_id", Feedback.find(:all).collect{|c| [c.value, c.id] }) %></td>
- </tr>
- <tr class="odd">
- <td>Auditoria</td>
- <td colspan=5><%= file_column_field "ticket", "image" %></td>
- </tr>
- <tr class="even">
- <td>Tipo</td>
- <td><%= select("ticket", "ticket_type_id", TicketType.find(:all, :order => 'name').collect{|c| [c.name, c.id] }) %></td>
- <td>Fila</td>
- <td><%= select("ticket", "area_id", Area.find(:all, :order => 'name').collect{|c| [c.name, c.id] }) %></td>
- <td>Usuario</td>
- <td><%= select("ticket", "user_id", User.find(:all, :order => 'name').collect{|c| [c.name, c.id] }) %></td>
- </tr>
- <tr class="odd">
- <td>Liberacao DV</td>
- <td colspan=5><%= f.date_select :targetDateDV %> Planejado? <%=f.check_box :hasBasicPlanning %></td>
- </tr>
- <tr class="even">
- <td>Homologacao</td>
- <td colspan="5"><%= f.date_select :targetDateHomologation %> Planejado? <%= f.check_box :hasDetailedPlanning %></td>
- </tr>
- <tr class="odd">
- <td>Anexo</td>
- <td colspan="4"><%= file_column_field "abadfa", "file" %></td>
- <td><%= f.submit "Update" %></td>
- </tr>
- </table>
- <p>
- </p>
- <% end %>
- <h1>Historico do ticket <%=@ticket.external_id%></h1>
- <table class="desenvolvedor">
- <tr>
- <th class="data" >Data</th>
- <th class="status" >Status</th>
- <th class="prioridade" >Prioridade</th>
- <th class="attachement" >Anexo</th>
- <th class="analista" >Analista</th>
- <th class="projetista" >Projetista</th>
- <th class="desenvolvedor" >Desenvolvedor</th>
- <th class="data" >Liberacao DV</th>
- <th class="data" >Liberacao Homologacao</th>
- <th class="imagem" >Observacao</th>
- </tr>
- <% for history in @histories %>
- <tr class="<%= cycle ('odd', 'even') %>">
- <td><%=h history.date %></td>
- <td><%=h Status.find(history.status_id).name %></td>
- <td><%=h Priority.find(history.priority_id).name %></td>
- <td>
- <% if history.attachement != nil %>
- <% @history = history %>
- <%= link_to history.attachement, url_for_file_column("history","attachement"), :target=>"_blank" %>
- <% end%>
- </td>
- <td><%=h Analyst.find(history.analyst_id).name %></td>
- <td><%=h Designer.find(history.designer_id).name %></td>
- <td><%=h Developer.find(history.developer_id).name %></td>
- <td><%=h history.targetDateDV %></td>
- <td><%=h history.targetDateHomologation %></td>
- <td><%=h history.notes %></td>
- </tr>
- <% end %>
- </br></br>
Add Comment
Please, Sign In to add comment