@@ -34,7 +34,11 @@ public function setImported(bool $bool): void
3434 */
3535 public function logCheckout ($ note , $ target , $ action_date = null , $ originalValues = [])
3636 {
37+
3738 $ log = new Actionlog ;
39+
40+ $ fields_array = [];
41+
3842 $ log = $ this ->determineLogItemType ($ log );
3943 if (auth ()->user ()) {
4044 $ log ->created_by = auth ()->id ();
@@ -55,6 +59,7 @@ public function logCheckout($note, $target, $action_date = null, $originalValues
5559 $ log ->target_type = get_class ($ target );
5660 $ log ->target_id = $ target ->id ;
5761
62+
5863 // Figure out what the target is
5964 if ($ log ->target_type == Location::class) {
6065 $ log ->location_id = $ target ->id ;
@@ -64,6 +69,21 @@ public function logCheckout($note, $target, $action_date = null, $originalValues
6469 $ log ->location_id = $ target ->location_id ;
6570 }
6671
72+ if (static ::class == Asset::class) {
73+ if ($ asset = Asset::find ($ log ->item_id )) {
74+
75+ // add the custom fields that were changed
76+ if ($ asset ->model ->fieldset ) {
77+ $ fields_array = [];
78+ foreach ($ asset ->model ->fieldset ->fields as $ field ) {
79+ if ($ field ->display_checkout == 1 ) {
80+ $ fields_array [$ field ->db_column ] = $ asset ->{$ field ->db_column };
81+ }
82+ }
83+ }
84+ }
85+ }
86+
6787 $ log ->note = $ note ;
6888 $ log ->action_date = $ action_date ;
6989
@@ -72,7 +92,10 @@ public function logCheckout($note, $target, $action_date = null, $originalValues
7292 }
7393
7494 $ changed = [];
75- $ originalValues = array_intersect_key ($ originalValues , array_flip (['action_date ' ,'name ' ,'status_id ' ,'location_id ' ,'expected_checkin ' ]));
95+ $ array_to_flip = array_keys ($ fields_array );
96+ $ array_to_flip = array_merge ($ array_to_flip , ['action_date ' ,'name ' ,'status_id ' ,'location_id ' ,'expected_checkin ' ]);
97+ $ originalValues = array_intersect_key ($ originalValues , array_flip ($ array_to_flip ));
98+
7699
77100 foreach ($ originalValues as $ key => $ value ) {
78101 if ($ key == 'action_date ' && $ value != $ action_date ) {
@@ -119,6 +142,8 @@ public function logCheckin($target, $note, $action_date = null, $originalValues
119142 {
120143 $ log = new Actionlog ;
121144
145+ $ fields_array = [];
146+
122147 if ($ target != null ){
123148 $ log ->target_type = get_class ($ target );
124149 $ log ->target_id = $ target ->id ;
@@ -135,6 +160,16 @@ public function logCheckin($target, $note, $action_date = null, $originalValues
135160 if (static ::class == Asset::class) {
136161 if ($ asset = Asset::find ($ log ->item_id )) {
137162 $ asset ->increment ('checkin_counter ' , 1 );
163+
164+ // add the custom fields that were changed
165+ if ($ asset ->model ->fieldset ) {
166+ $ fields_array = [];
167+ foreach ($ asset ->model ->fieldset ->fields as $ field ) {
168+ if ($ field ->display_checkin == 1 ) {
169+ $ fields_array [$ field ->db_column ] = $ asset ->{$ field ->db_column };
170+ }
171+ }
172+ }
138173 }
139174 }
140175 }
@@ -152,9 +187,14 @@ public function logCheckin($target, $note, $action_date = null, $originalValues
152187 }
153188
154189 $ changed = [];
155- $ originalValues = array_intersect_key ($ originalValues , array_flip (['action_date ' ,'name ' ,'status_id ' ,'location_id ' ,'rtd_location_id ' ,'expected_checkin ' ]));
190+
191+ $ array_to_flip = array_keys ($ fields_array );
192+ $ array_to_flip = array_merge ($ array_to_flip , ['action_date ' ,'name ' ,'status_id ' ,'location_id ' ,'expected_checkin ' ]);
193+
194+ $ originalValues = array_intersect_key ($ originalValues , array_flip ($ array_to_flip ));
156195
157196 foreach ($ originalValues as $ key => $ value ) {
197+
158198 if ($ key == 'action_date ' && $ value != $ action_date ) {
159199 $ changed [$ key ]['old ' ] = $ value ;
160200 $ changed [$ key ]['new ' ] = is_string ($ action_date ) ? $ action_date : $ action_date ->format ('Y-m-d H:i:s ' );
0 commit comments