Guest User

Untitled

a guest
May 23rd, 2018
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.04 KB | None | 0 0
  1. class Ticket < ActiveRecord::Base
  2. BLACK_SIGN = "black"
  3. YELLOW_SIGN ="yellow"
  4. RED_SIGN = "red"
  5. GREEN_SIGN ="green"
  6. NO_PLANNING = "SEM PLANEJAMENTO"
  7. NONE = " - "
  8.  
  9. file_column :image
  10. validates_presence_of :status_id,:analyst_id,:designer_id,:developer_id
  11. validates_format_of :image, :allow_nil => true, :with => %r{.(jpg)$}i, :message => "must be a jpg image."
  12. file_column :attachement
  13.  
  14. def Ticket.calculate_working_days(d1,d2,wdays)
  15.  
  16. if(d1 == d2)
  17. return 1
  18. end
  19.  
  20. diff = d2 - d1 + 1
  21. holidays = 0
  22. ret = (d2-d1).divmod(7)
  23. holidays = ret[0].truncate * wdays.length
  24. d1 = d2 - ret[1]
  25. while(d1 <= d2)
  26. if wdays.include?(d1.wday)
  27. holidays += 1
  28. end
  29. d1 += 1
  30. end
  31. diff - holidays
  32. end
  33.  
  34. #Retorna a próxima data alvo do ticket.
  35. def Ticket.targetDate (ticket)
  36.  
  37. #O ticket está em elaboração?
  38. if ticket.hasBasicPlanning && Status.getStepsForDV().include?(ticket.status_id)
  39. return ticket.targetDateDV
  40. end
  41.  
  42. #O ticket está em elaboração e não foi planajedo?
  43. if !ticket.hasBasicPlanning && Status.getStepsForDV().include?(ticket.status_id)
  44. return Ticket::NO_PLANNING
  45. end
  46.  
  47. # Ticket está em construção?
  48. if ticket.hasDetailedPlanning && Status.getStepsForHomologation().include?(ticket.status_id)
  49. return ticket.targetDateHomologation
  50. end
  51.  
  52. # Ticket está em construção e não foi planejado?
  53. if !ticket.hasDetailedPlanning && Status.getStepsForHomologation().include?(ticket.status_id)
  54. return Ticket::NO_PLANNING
  55. end
  56.  
  57. # Ticket está em Fechamento de Pedido?
  58. if Status::FECHAMENTO_PEDIDO == ticket.status_id
  59. return ticket.statusDate + 12
  60. end
  61.  
  62. # Ticket está pendente com solicitante?
  63. if Status.getUserSteps().include?(ticket.status_id)
  64. return ticket.statusDate + 21
  65. end
  66.  
  67. return Ticket::NONE
  68. end
  69.  
  70. #Retorna string que representa semaforo de atendimento às metas.
  71. def Ticket.targetDateStatus (ticket)
  72.  
  73. #O ticket está em elaboração?
  74. if ticket.hasBasicPlanning && Status.getStepsForDV().include?(ticket.status_id)
  75. date = ticket.targetDateDV
  76. end
  77.  
  78. # Ticket está em construção?
  79. if ticket.hasDetailedPlanning && Status.getStepsForHomologation().include?(ticket.status_id)
  80. date = ticket.targetDateHomologation
  81. end
  82.  
  83. # Ticket está em Fechamento de Pedido
  84. if Status::FECHAMENTO_PEDIDO == ticket.status_id
  85. date = ticket.statusDate + 12
  86. end
  87.  
  88. # Ticket está pendente com solicitante
  89. if Status.getUserSteps().include?(ticket.status_id)
  90. date = ticket.statusDate + 21
  91. end
  92.  
  93. # existe alguma data alvo para comparar?
  94. if date != nil
  95. working_days = calculate_working_days Date.today,date, [0,5];
  96. if ( working_days < 0 )
  97. return Ticket::BLACK_SIGN;
  98. else
  99. if ( working_days == 0 )
  100. return Ticket::RED_SIGN
  101. else
  102. if working_days <= 2
  103. return Ticket::YELLOW_SIGN
  104. else
  105. if working_days > 2
  106. return Ticket::GREEN_SIGN
  107. end
  108. end
  109. end
  110. end
  111. end
  112. end
  113.  
  114.  
  115. end
  116.  
  117. ################################################################################################
  118.  
  119. class TicketsController < ApplicationController
  120. # GET /tickets
  121. # GET /tickets.xml
  122. def index
  123.  
  124. order = "(CASE status_id
  125. WHEN " + Status::AGUARDANDO.to_s + " THEN targetDateDV
  126. WHEN " + Status::ANALISE.to_s + " THEN targetDateDV
  127. WHEN " + Status::APROVACAO_DV_PROJETISTA.to_s + " THEN targetDateDV
  128. WHEN " + Status::APROVACAO_DV_GP.to_s + " THEN targetDateDV
  129. WHEN " + Status::REVISAO_ORTOGRAFICA_DV.to_s + " THEN targetDateDV
  130. WHEN " + Status::ENVIAR_DV_AO_SOLICITANTE.to_s + " THEN targetDateDV
  131. ELSE targetDateHomologation end
  132. )"
  133. condition = "status_id not in (" + Status::CANCELADO.to_s + "," + Status::CONCLUIDO.to_s + ")"
  134.  
  135. if params[:developer_id]
  136. condition += " and developer_id=" + params[:developer_id]
  137. end
  138.  
  139. if params[:analyst_id]
  140. condition += " and analyst_id=" + params[:analyst_id]
  141. end
  142.  
  143. if params[:designer_id]
  144. condition += " and designer_id=" + params[:designer_id]
  145. end
  146.  
  147. if params[:status_id]
  148. condition += " and status_id=" + params[:status_id]
  149. end
  150.  
  151. if params[:user_id]
  152. condition += " and user_id=" + params[:user_id]
  153. end
  154.  
  155. if params[:area_id]
  156. condition += " and area_id=" + params[:area_id]
  157. @area = Area.find(params[:area_id])
  158. @analyst = Analyst.find(@area.analyst_id)
  159. @designer = Designer.find(@area.designer_id)
  160. @developer = Developer.find(@area.developer_id)
  161. else
  162. condition += " and area_id <> 6 "
  163. end
  164.  
  165. @tickets = Ticket.find(:all, :order => order, :conditions => condition)
  166.  
  167. @tickets_analyst = Array.new
  168. @tickets_designer = Array.new
  169. @tickets_developer = Array.new
  170. @tickets_auditor = Array.new
  171. @tickets_scm = Array.new
  172. @tickets_user = Array.new
  173. @tickets_test = Array.new
  174.  
  175. for ticket in @tickets
  176. if(Status.getAnalystSteps().include?(ticket.status_id))
  177. @tickets_analyst << ticket
  178. end
  179.  
  180. if(Status.getTestSteps().include?(ticket.status_id))
  181. @tickets_test << ticket
  182. end
  183.  
  184. if(Status.getDesignerSteps().include?(ticket.status_id))
  185. @tickets_designer << ticket
  186. end
  187.  
  188. if(Status.getAuditorSteps().include?(ticket.status_id))
  189. @tickets_auditor << ticket
  190. end
  191.  
  192. if(Status.getScmSteps().include?(ticket.status_id))
  193. @tickets_scm << ticket
  194. end
  195.  
  196. if(Status.getUserSteps().include?(ticket.status_id))
  197. @tickets_user << ticket
  198. end
  199.  
  200. if(Status.getDeveloperSteps().include?(ticket.status_id))
  201. @tickets_developer << ticket
  202. end
  203. end
  204.  
  205. respond_to do |format|
  206. format.html # index.html.erb
  207. format.xml { render :xml => @tickets }
  208. end
  209. end
  210.  
  211. # GET /tickets/1
  212. # GET /tickets/1.xml
  213. def show
  214. @ticket = Ticket.find(params[:id])
  215. @user = User.find(@ticket.user_id)
  216. @area = Area.find(@user.area_id)
  217.  
  218. respond_to do |format|
  219. format.html # show.html.erb
  220. format.xml { render :xml => @ticket }
  221. end
  222. end
  223.  
  224. # GET /tickets/new
  225. # GET /tickets/new.xml
  226. def new
  227. @ticket = Ticket.new
  228. respond_to do |format|
  229. format.html # new.html.erb
  230. format.xml { render :xml => @ticket }
  231. end
  232. end
  233.  
  234. # GET /tickets/1/edit
  235. def edit
  236. @ticket = Ticket.find(params[:id])
  237. @area = Area.find(@ticket.area_id)
  238. @histories = History.find(:all, :order => 'date desc', :conditions => {:ticket_id => @ticket.id})
  239. end
  240.  
  241. # GET /tickets/edit_by_external_id/1
  242. def edit_by_external_id
  243. @ticket = Ticket.find(:first, :conditions => {:external_id => params[:id]})
  244. @user = User.find(@ticket.user_id)
  245. @area = Area.find(@ticket.area_id)
  246. @histories = History.find(:all, :order => 'date desc', :conditions => {:ticket_id => @ticket.id})
  247. end
  248.  
  249. # POST /tickets
  250. # POST /tickets.xml
  251. def create
  252. @ticket = Ticket.new(params[:ticket])
  253.  
  254. #Recupera o solicitante do ticket
  255. @user = User.find(@ticket.user_id)
  256.  
  257. #Recupera a área do solicitante
  258. @area = Area.find(@user.area_id)
  259. @ticket.area_id = @area.id
  260.  
  261. #Status inicial é Aguardando
  262. @ticket.status_id = Status::AGUARDANDO
  263.  
  264. #Data de abertura é igual hoje
  265. @ticket.openDate = Time.today
  266.  
  267. #Data do status é igual hoje
  268. @ticket.statusDate = Time.today
  269.  
  270. #Setar no ticket os recursos default da área
  271. @ticket.analyst_id = @area.analyst_id
  272. @ticket.designer_id = @area.designer_id
  273. @ticket.developer_id = @area.developer_id
  274.  
  275. respond_to do |format|
  276. if @ticket.save
  277.  
  278. #Existe identificacao externa?
  279. if @ticket.external_id == ""
  280. @ticket.update_attributes(:external_id=>"S" + @ticket.id.to_s)
  281. end
  282.  
  283. #Registrando histórico para a mudanca
  284. History::registerHistory(@ticket)
  285.  
  286. #Notificar equipe sobre mudança de status
  287. Emailer.deliver_ticket_status_notification(@ticket)
  288.  
  289. flash[:notice] = 'Ticket was successfully created.'
  290. format.html { redirect_to(@ticket) }
  291. format.xml { render :xml => @ticket, :status => :created, :location => @ticket }
  292. else
  293. format.html { render :action => "new" }
  294. format.xml { render :xml => @ticket.errors, :status => :unprocessable_entity }
  295. end
  296. end
  297. end
  298.  
  299. # PUT /tickets/1
  300. # PUT /tickets/1.xml
  301. def update
  302. @ticket = Ticket.find(params[:id])
  303.  
  304. #Recupera o status antigo do ticket
  305. old_status = @ticket.status_id
  306.  
  307. #Atualiza a data de atualizacao do ticket
  308. @ticket.statusDate = Time.today
  309.  
  310. @user = User.find(@ticket.user_id)
  311. @area = Area.find(@ticket.area_id)
  312.  
  313. respond_to do |format|
  314. if @ticket.update_attributes(params[:ticket])
  315.  
  316. #Registrando histórico para a mudanca
  317. History::registerHistory(@ticket)
  318.  
  319. #Status do ticket foi alterado?
  320. if( old_status != @ticket.status_id )
  321. #Notificar equipe sobre mudança de status
  322. Emailer.deliver_ticket_status_notification(@ticket)
  323. end
  324.  
  325. #Status antigo é "Auditoria Desenho" e o ticket está em Implementação, mas o branch nao foi criado.
  326. status_atual = Status.find(@ticket.status_id)
  327. aprovacao_desenho = Status.find(Status::AUDITORIA_DESENHO)
  328. if( @ticket.projects != "" && @ticket.branch == "" && status_atual.position > aprovacao_desenho.position)
  329. Emailer.deliver_create_branch_notification(@ticket)
  330. end
  331.  
  332. #Status antigo é "aprovar DV" e o ticket está em construção?
  333. if(old_status == Status::APROVACAO_DV && Status.getStepsForHomologation().include?(@ticket.status_id))
  334. Emailer.deliver_ticket_status_billing_notification(@ticket)
  335. end
  336.  
  337. flash[:notice] = 'Ticket was successfully updated.'
  338. format.html { redirect_to(@ticket) }
  339. format.xml { head :ok }
  340. else
  341. format.html { render :action => "edit" }
  342. format.xml { render :xml => @ticket.errors, :status => :unprocessable_entity }
  343. end
  344. end
  345. end
  346.  
  347. # DELETE /tickets/1
  348. # DELETE /tickets/1.xml
  349. def destroy
  350. @ticket = Ticket.find(params[:id])
  351. @ticket.destroy
  352.  
  353. respond_to do |format|
  354. format.html { redirect_to(tickets_url) }
  355. format.xml { head :ok }
  356. end
  357. end
  358.  
  359. def send_status_change_notification(ticket)
  360.  
  361. end
  362.  
  363. end
  364.  
  365. ###########################################################################################
  366.  
  367. class History < ActiveRecord::Base
  368.  
  369. file_column :attachement
  370.  
  371. def History.registerHistory(ticket)
  372. history = History.new()
  373. history.date = Time.now()
  374. history.ticket_id = ticket.id
  375. history.status_id = ticket.status_id
  376. history.attachement = ticket.attachement
  377. history.analyst_id = ticket.analyst_id
  378. history.developer_id = ticket.developer_id
  379. history.designer_id = ticket.designer_id
  380. history.targetDateHomologation = ticket.targetDateHomologation
  381. history.targetDateDV = ticket.targetDateDV
  382. history.notes = ticket.notes
  383. history.priority_id = ticket.priority_id
  384. history.save
  385. end
  386.  
  387. end
  388.  
  389. #############################################################################################
  390.  
  391. <h1>Editing ticket <%=@ticket.external_id%></h1>
  392.  
  393. <%= link_to 'Voltar Para Fila', (tickets_path + "?area_id=" + @area.id.to_s) %> |
  394. <%= link_to 'Voltar Para Todos', (tickets_path) %>
  395.  
  396. <%= error_messages_for :ticket %>
  397.  
  398. <% form_for(@ticket, :html => {:multipart => true}) do |f| %>
  399.  
  400. <table class="edit">
  401. <tr>
  402. <th colspan=6>Informacoes</th>
  403. </tr>
  404. <tr class="odd">
  405. <td>Notes</td>
  406. <td width="100%" colspan=5><%= f.text_field :notes, :value=>"", :maxlength => "180"%></td>
  407. </tr>
  408. <tr class="even">
  409. <td>Nome</td>
  410. <td width="100%" colspan=5><%= f.text_field :name, :maxlength => "180"%></td>
  411. </tr>
  412. <tr class="odd">
  413. <td>Status</td>
  414. <td><%= select("ticket", "status_id", Status.find(:all, :order=>:position).collect{|c| [c.name, c.id] }) %></td>
  415. <td>Prioridade</td>
  416. <td colspan=3><%= select("ticket", "priority_id", Priority.find(:all).collect{|c| [c.name, c.id] }) %></td>
  417. </tr>
  418. <tr class="even">
  419. <td>Analista</td>
  420. <td><%= select("ticket", "analyst_id", Analyst.find(:all, :order => 'name').collect{|c| [c.name, c.id] }) %></td>
  421. <td>Projetista</td>
  422. <td><%= select("ticket", "designer_id", Designer.find(:all, :order => 'name').collect{|c| [c.name, c.id] }) %></td>
  423. <td>Desenvolvedor</td>
  424. <td><%= select("ticket", "developer_id", Developer.find(:all, :order => 'name').collect{|c| [c.name, c.id] }) %></td>
  425. </tr>
  426. <tr class="odd">
  427. <td>Branch</td>
  428. <td><%= f.text_field :branch %></td>
  429. <td>Projetos</td>
  430. <td><%= f.text_field :projects %></td>
  431. <td>Script Banco?</td>
  432. <td><%= f.check_box :hasDataBaseScripts %></td>
  433. </tr>
  434. <tr class="even">
  435. <td>Qualidade</td>
  436. <td><%= select("ticket", "feedbackQuality_id", Feedback.find(:all).collect{|c| [c.value, c.id] }) %></td>
  437. <td>Prazo</td>
  438. <td><%= select("ticket", "feedbackPeriod_id", Feedback.find(:all).collect{|c| [c.value, c.id] }) %></td>
  439. <td>Documentacao</td>
  440. <td><%= select("ticket", "feedbackDocumentation_id", Feedback.find(:all).collect{|c| [c.value, c.id] }) %></td>
  441. </tr>
  442. <tr class="odd">
  443. <td>Auditoria</td>
  444. <td colspan=5><%= file_column_field "ticket", "image" %></td>
  445. </tr>
  446. <tr class="even">
  447. <td>Tipo</td>
  448. <td><%= select("ticket", "ticket_type_id", TicketType.find(:all, :order => 'name').collect{|c| [c.name, c.id] }) %></td>
  449. <td>Fila</td>
  450. <td><%= select("ticket", "area_id", Area.find(:all, :order => 'name').collect{|c| [c.name, c.id] }) %></td>
  451. <td>Usuario</td>
  452. <td><%= select("ticket", "user_id", User.find(:all, :order => 'name').collect{|c| [c.name, c.id] }) %></td>
  453. </tr>
  454. <tr class="odd">
  455. <td>Liberacao DV</td>
  456. <td colspan=5><%= f.date_select :targetDateDV %> Planejado? <%=f.check_box :hasBasicPlanning %></td>
  457. </tr>
  458. <tr class="even">
  459. <td>Homologacao</td>
  460. <td colspan="5"><%= f.date_select :targetDateHomologation %> Planejado? <%= f.check_box :hasDetailedPlanning %></td>
  461. </tr>
  462. <tr class="odd">
  463. <td>Anexo</td>
  464. <td colspan="4"><%= file_column_field "abadfa", "file" %></td>
  465. <td><%= f.submit "Update" %></td>
  466. </tr>
  467. </table>
  468. <p>
  469.  
  470. </p>
  471. <% end %>
  472.  
  473. <h1>Historico do ticket <%=@ticket.external_id%></h1>
  474. <table class="desenvolvedor">
  475. <tr>
  476. <th class="data" >Data</th>
  477. <th class="status" >Status</th>
  478. <th class="prioridade" >Prioridade</th>
  479. <th class="attachement" >Anexo</th>
  480. <th class="analista" >Analista</th>
  481. <th class="projetista" >Projetista</th>
  482. <th class="desenvolvedor" >Desenvolvedor</th>
  483. <th class="data" >Liberacao DV</th>
  484. <th class="data" >Liberacao Homologacao</th>
  485. <th class="imagem" >Observacao</th>
  486. </tr>
  487. <% for history in @histories %>
  488. <tr class="<%= cycle ('odd', 'even') %>">
  489. <td><%=h history.date %></td>
  490. <td><%=h Status.find(history.status_id).name %></td>
  491. <td><%=h Priority.find(history.priority_id).name %></td>
  492. <td>
  493. <% if history.attachement != nil %>
  494. <% @history = history %>
  495. <%= link_to history.attachement, url_for_file_column("history","attachement"), :target=>"_blank" %>
  496. <% end%>
  497. </td>
  498. <td><%=h Analyst.find(history.analyst_id).name %></td>
  499. <td><%=h Designer.find(history.designer_id).name %></td>
  500. <td><%=h Developer.find(history.developer_id).name %></td>
  501. <td><%=h history.targetDateDV %></td>
  502. <td><%=h history.targetDateHomologation %></td>
  503. <td><%=h history.notes %></td>
  504. </tr>
  505. <% end %>
  506.  
  507.  
  508. </br></br>
Add Comment
Please, Sign In to add comment