@@ -35,6 +35,7 @@ class TicketsController extends Controller
3535 protected $ member ;
3636 protected $ a_search_fields_numeric = ['creator_id ' , 'user_id ' , 'status_id ' , 'priority_id ' , 'category_id ' , 'agent_id ' ];
3737 protected $ a_search_fields_text = ['subject ' , 'html ' , 'intervention_html ' ];
38+ protected $ a_search_fields_date = ['start_date ' , 'limit_date ' , 'created_at ' , 'completed_at ' , 'updated_at ' ];
3839
3940 public function __construct (Ticket $ tickets , \PanicHDMember $ member )
4041 {
@@ -78,12 +79,19 @@ public function data($ticketList = 'active')
7879 }elseif ($ field == 'list ' ){
7980 $ collection ->inList ($ value );
8081
81- }elseif (in_array ($ field , ['start_date ' , 'limit_date ' ])){
82- if ($ search_fields [$ field . '_type ' ] == 'exact_day ' ){
83- $ collection ->whereDate ($ field , Carbon::createFromFormat (trans ('panichd::lang.datetime-format ' ), $ value )->toDateTimeString ());
82+ }elseif (in_array ($ field , $ this ->a_search_fields_date )){
83+ if (in_array ($ search_fields [$ field . '_type ' ], ['exact_year ' , 'exact_month ' ])){
84+ $ collection ->whereYear ('panichd_tickets. ' . $ field , Carbon::createFromFormat (trans ('panichd::lang.datetime-format ' ), $ value )->format ('Y ' ));
85+
86+ if ($ search_fields [$ field . '_type ' ] == 'exact_month ' ){
87+ $ collection ->whereMonth ('panichd_tickets. ' . $ field , Carbon::createFromFormat (trans ('panichd::lang.datetime-format ' ), $ value )->format ('m ' ));
88+ }
89+
90+ }elseif ($ search_fields [$ field . '_type ' ] == 'exact_day ' ){
91+ $ collection ->whereDate ('panichd_tickets. ' . $ field , Carbon::createFromFormat (trans ('panichd::lang.datetime-format ' ), $ value )->toDateString ());
8492
8593 }else {
86- $ collection ->where ($ field , ($ search_fields [$ field . '_type ' ] == 'from ' ? '>= ' : '< ' ), Carbon::createFromFormat (trans ('panichd::lang.datetime-format ' ), $ value )->toDateTimeString ());
94+ $ collection ->where (' panichd_tickets. ' . $ field , ($ search_fields [$ field . '_type ' ] == 'from ' ? '>= ' : '< ' ), Carbon::createFromFormat (trans ('panichd::lang.datetime-format ' ), $ value )->toDateTimeString ());
8795 }
8896
8997 }elseif (in_array ($ field , $ this ->a_search_fields_text )){
@@ -804,19 +812,17 @@ public function register_search_fields(Request $request)
804812 session ()->forget ('search_fields ' );
805813
806814 // Check all fields
807- $ a_fields = array_merge ($ this ->a_search_fields_numeric , $ this ->a_search_fields_text , ['department_id ' , 'list ' , ' start_date ' , ' limit_date ' , 'comments ' , 'attachment_name ' , 'any_text_field ' ]);
815+ $ a_fields = array_merge ($ this ->a_search_fields_numeric , $ this ->a_search_fields_text , $ this -> a_search_fields_date , ['department_id ' , 'list ' , 'comments ' , 'attachment_name ' , 'any_text_field ' ]);
808816 foreach ($ a_fields as $ field ){
809817 if ($ request ->filled ($ field )){
810818 $ search_fields [$ field ] = $ request ->{$ field };
811819 }
812820 }
813821
814- // Register Start date and Limit date types (from radio buttons)
815- if ($ request ->filled ('start_date ' ) or $ request ->filled ('start_date ' )){
816- foreach (['start_date ' , 'limit_date ' ] as $ field ){
817- if ($ request ->filled ($ field )){
818- $ search_fields [$ field . '_type ' ] = $ request ->{$ field . '_type ' };
819- }
822+ // Register date field related types (specified with radio buttons)
823+ foreach ($ this ->a_search_fields_date as $ field ){
824+ if ($ request ->filled ($ field )){
825+ $ search_fields [$ field . '_type ' ] = $ request ->{$ field . '_type ' };
820826 }
821827 }
822828
0 commit comments