TicketController.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. <?php
  2. namespace App\Http\Controllers\Client;
  3. use Illuminate\Http\Request;
  4. use App\Http\Requests;
  5. use App\Http\Controllers\Controller;
  6. use App\Models\Project;
  7. use App\Models\Group;
  8. use App\Models\Task;
  9. use App\Models\ActivityLog;
  10. use App\Models\Notification;
  11. use App\Models\CompanyModel;
  12. use App\Models\ServiceList;
  13. use App\Models\Ticket;
  14. use App\Models\TicketThread;
  15. use App\Models\AddressBookModel;
  16. use App\User;
  17. use Auth;
  18. use Mail;
  19. class TicketController extends Controller
  20. {
  21. function index()
  22. {
  23. $client_id=\Auth::user()->id;
  24. $query=(new Ticket)->newQuery();
  25. $query->with(['user','created_user','user.company_data']);
  26. //$query->where('status','!=',3);
  27. if(\Auth::user()->utype==3)
  28. {
  29. $query->where('client_id',$client_id);
  30. }
  31. $query->orderBy('id','desc');
  32. $data['tickets']=$query->paginate(5);
  33. $data['title']='Support Ticket';
  34. return view('client.ticket.index',$data);
  35. }
  36. function create()
  37. {
  38. $data['clients']=CompanyModel::where('status',2)->orderBy('name')->get(['id','name']);
  39. $data['services']=ServiceList::orderBy('name','asc')->get(['id','name']);
  40. $data['title']='New Support Ticket';
  41. return view('client.ticket.create',$data);
  42. }
  43. function store(Request $req)
  44. {
  45. $this->validate($req,[
  46. 'title'=>'required',
  47. 'service'=>'required',
  48. ]);
  49. $client=0;
  50. if(\Auth::user()->utype==3)
  51. {
  52. $client=\Auth::user()->id;
  53. }
  54. else
  55. {
  56. $client=$req->get('client');
  57. }
  58. $documentUpload = $req->file('ticket_document');
  59. if ( !empty( $documentUpload )) {
  60. $documentname = $documentUpload->getClientOriginalName();
  61. $path = 'public/ticket_document/';
  62. $documentUpload->move($path,$documentname);
  63. $ticketDocument = $documentname;
  64. } else {
  65. $ticketDocument = '';
  66. }
  67. $ticket=new Ticket();
  68. $ticket->client_id = $client;
  69. $ticket->ticket_id = $this->generate_ticket_id();
  70. $ticket->service_id = $req->get('service');
  71. $ticket->title = $req->get('title');
  72. $ticket->details = $req->get('details');
  73. $ticket->priority = $req->get('prority');
  74. $ticket->ticket_document = $ticketDocument;
  75. $ticket->status = 0;
  76. $ticket->created_by = \Auth::user()->id;
  77. $ticket->save();
  78. $client=AddressBookModel::find($ticket->client_id);
  79. $service=ServiceList::find($ticket->service_id);
  80. $created_user=User::find($ticket->created_by);
  81. //dd($ticket->client_id);
  82. $company_id = $created_user->company;
  83. $company = CompanyModel::find($company_id);
  84. $manager_id = $company->account_manager;
  85. if($manager_id != null){
  86. $manager_details = User::find($manager_id);
  87. $manager_email = $manager_details->email;
  88. }
  89. $data['client']=$client;
  90. $data['created_by']=$created_user;
  91. $data['company']=$company;
  92. $data['service']=$service;
  93. $data['title']='';
  94. $data['ticket']=$ticket;
  95. if($manager_id != null){
  96. Mail::send('emails.ticket_created_email',$data,function($message)use($created_user,$client,$manager_email){
  97. $message->from('m.revinr@gmail.com', 'Revinr CMS');
  98. //$message->to($manager_email)->subject('New ticket created');
  99. if($manager_email)
  100. {
  101. $message->to($manager_email)->subject('New ticket created');
  102. }
  103. if($client)
  104. {
  105. $message->to($client->email1)->subject('New ticket created');
  106. }
  107. if($created_user)
  108. {
  109. $message->to($created_user->email)->subject('New ticket created');
  110. }
  111. $message->bcc('helaldu@gmail.com','Shamim Shams');
  112. });
  113. }else{
  114. Mail::send('emails.ticket_created_email',$data,function($message)use($created_user,$client){
  115. $message->from('m.revinr@gmail.com', 'Revinr CMS');
  116. $message->to('helaldu@gmail.com')->subject('New ticket created');
  117. if($client)
  118. {
  119. $message->to($client->email1)->subject('New ticket created');
  120. }
  121. if($created_user)
  122. {
  123. $message->to($created_user->email)->subject('New ticket created');
  124. }
  125. $message->cc('sabuj@revinr.com', 'New ticket created');
  126. $message->bcc('tarikul@revinr.com','New ticket created');
  127. });
  128. }
  129. return redirect('ticket')->with('msg','Ticket created successfully !!');
  130. }
  131. function client_mail()
  132. {
  133. }
  134. function admin_mail()
  135. {
  136. }
  137. function show($id)
  138. {
  139. $data['ticket']=Ticket::with(['user','created_user','user.company_data'])->find($id);
  140. // echo "<pre>";
  141. // print_r ($data['ticket']);
  142. // echo "</pre>";
  143. // exit;
  144. $data['title']='Ticket Details';
  145. return view('client.ticket.show',$data);
  146. }
  147. function edit($id)
  148. {
  149. $data['title']='Edit Support Ticket';
  150. return view('client.ticket.edit',$data);
  151. }
  152. function update(Request $req)
  153. {
  154. }
  155. function save_comment(Request $req)
  156. {
  157. $comment=new TicketThread();
  158. $comment->ticket_id=$req->get('ticket');
  159. $comment->comment_by=\Auth::user()->id;
  160. $comment->comment=$req->get('comment');
  161. $comment->display=1;
  162. $comment->save();
  163. return "ok";
  164. }
  165. function get_comments($tkt_id)
  166. {
  167. $data['comments']=TicketThread::where('ticket_id',$tkt_id)->get();
  168. return view('client.ticket.comment',$data)->render();
  169. }
  170. function change_status(Request $req)
  171. {
  172. $id=$req->get('ticket_id');
  173. $status=$req->get('status');
  174. $ticket=Ticket::find($id);
  175. $ticket->status=$status;
  176. $ticket->save();
  177. $client=AddressBookModel::find($ticket->client_id);
  178. $service=ServiceList::find($ticket->service_id);
  179. $created_user=User::find($ticket->created_by);
  180. $data['client']=$client;
  181. $data['service']=$service;
  182. $data['title']='';
  183. $data['ticket']=$ticket;
  184. Mail::send('emails.ticket_status_change_email',$data,function($message)use($created_user,$client){
  185. $message->from('m.revinr@gmail.com', 'Revinr CMS');
  186. if($client)
  187. {
  188. $message->to($client->email1)->subject('New ticket created');
  189. }
  190. if($created_user)
  191. {
  192. $message->to($created_user->email)->subject('New ticket created');
  193. }
  194. $message->to('helaldu@gmail.com')->subject('Ticket Status Change');
  195. $message->bcc('shamim@revinr.com','Shamim Shams');
  196. });
  197. return "ok";
  198. }
  199. function generate_ticket_id()
  200. {
  201. $ticket=Ticket::orderBy('id','desc')->first();
  202. if($ticket)
  203. {
  204. $last_ticket_id=$ticket->ticket_id;
  205. if(empty($last_ticket_id))
  206. {
  207. return 'REV-0001';
  208. }
  209. $ticket_arr=explode('-',$last_ticket_id);
  210. $ticket_id=(int)$ticket_arr[1];
  211. $ticket_id=$ticket_id+1;
  212. if($ticket_id<10)
  213. {
  214. return 'REV-000'.$ticket_id;
  215. }
  216. if($ticket_id<100)
  217. {
  218. return 'REV-00'.$ticket_id;
  219. }
  220. if($ticket_id<1000)
  221. {
  222. return 'REV-0'.$ticket_id;
  223. }
  224. if($ticket_id<10000)
  225. {
  226. return 'REV-'.$ticket_id;
  227. }
  228. }
  229. else
  230. {
  231. return 'REV-001';
  232. }
  233. }
  234. }