Bug 25946: borrowerRelationship can be empty
[koha-ffzg.git] / pos / registers.pl
index fafaf64..44c8136 100755 (executable)
@@ -34,6 +34,7 @@ my ( $template, $loggedinuser, $cookie, $user_flags ) = get_template_and_user(
         query           => $input,
         type            => 'intranet',
         authnotrequired => 0,
+        flagsrequired   => { cash_management => [ 'cashup', 'anonymous_refund' ] },
     }
 );
 my $logged_in_user = Koha::Patrons->find($loggedinuser) or die "Not logged in";
@@ -55,24 +56,30 @@ else {
 
 my $op = $input->param('op') // '';
 if ( $op eq 'cashup' ) {
-    my $registerid = $input->param('registerid');
-    if ( $registerid ) {
-        my $register = Koha::Cash::Registers->find( { id => $registerid } );
-        $register->add_cashup(
-            {
-                user_id => $logged_in_user->id,
-                amount  => $register->outstanding_accountlines->total
-            }
-        );
-    } else {
-        for my $register ( $registers->as_list ) {
+    if ( $logged_in_user->has_permission( { cash_management => 'cashup' } ) ) {
+        my $registerid = $input->param('registerid');
+        if ($registerid) {
+            my $register = Koha::Cash::Registers->find( { id => $registerid } );
             $register->add_cashup(
                 {
-                    user_id => $logged_in_user->id,
-                    amount  => $register->outstanding_accountlines->total
+                    manager_id => $logged_in_user->id,
+                    amount     => $register->outstanding_accountlines->total
                 }
             );
         }
+        else {
+            for my $register ( $registers->as_list ) {
+                $register->add_cashup(
+                    {
+                        manager_id => $logged_in_user->id,
+                        amount     => $register->outstanding_accountlines->total
+                    }
+                );
+            }
+        }
+    }
+    else {
+        $template->param( error_cashup_permission => 1 );
     }
 }