| Lines 157-256
          sub add_credit {
      
      
        Link Here | 
        
          | 157 |     }; | 157 |     }; | 
        
          | 158 | } | 158 | } | 
        
          | 159 |  | 159 |  | 
            
              | 160 |  |  |  | 
            
              | 161 | =head3 _to_api | 
            
              | 162 |  | 
            
              | 163 | Helper function that maps unblessed Koha::Account::Line objects | 
            
              | 164 | into REST API attribute names. | 
            
              | 165 |  | 
            
              | 166 | =cut | 
            
              | 167 |  | 
            
              | 168 | sub _to_api { | 
            
              | 169 |     my $account_line = shift; | 
            
              | 170 |  | 
            
              | 171 |     # Rename attributes | 
            
              | 172 |     foreach my $column ( keys %{ $Koha::REST::V1::Patrons::Account::to_api_mapping } ) { | 
            
              | 173 |         my $mapped_column = $Koha::REST::V1::Patrons::Account::to_api_mapping->{$column}; | 
            
              | 174 |         if (    exists $account_line->{ $column } | 
            
              | 175 |              && defined $mapped_column ) | 
            
              | 176 |         { | 
            
              | 177 |             # key != undef | 
            
              | 178 |             $account_line->{ $mapped_column } = delete $account_line->{ $column }; | 
            
              | 179 |         } | 
            
              | 180 |         elsif (    exists $account_line->{ $column } | 
            
              | 181 |                 && !defined $mapped_column ) | 
            
              | 182 |         { | 
            
              | 183 |             # key == undef | 
            
              | 184 |             delete $account_line->{ $column }; | 
            
              | 185 |         } | 
            
              | 186 |     } | 
            
              | 187 |  | 
            
              | 188 |     return $account_line; | 
            
              | 189 | } | 
            
              | 190 |  | 
            
              | 191 | =head3 _to_model | 
            
              | 192 |  | 
            
              | 193 | Helper function that maps REST API objects into Koha::Account::Line | 
            
              | 194 | attribute names. | 
            
              | 195 |  | 
            
              | 196 | =cut | 
            
              | 197 |  | 
            
              | 198 | sub _to_model { | 
            
              | 199 |     my $account_line = shift; | 
            
              | 200 |  | 
            
              | 201 |     foreach my $attribute ( keys %{ $Koha::REST::V1::Patrons::Account::to_model_mapping } ) { | 
            
              | 202 |         my $mapped_attribute = $Koha::REST::V1::Patrons::Account::to_model_mapping->{$attribute}; | 
            
              | 203 |         if (    exists $account_line->{ $attribute } | 
            
              | 204 |              && defined $mapped_attribute ) | 
            
              | 205 |         { | 
            
              | 206 |             # key => !undef | 
            
              | 207 |             $account_line->{ $mapped_attribute } = delete $account_line->{ $attribute }; | 
            
              | 208 |         } | 
            
              | 209 |         elsif (    exists $account_line->{ $attribute } | 
            
              | 210 |                 && !defined $mapped_attribute ) | 
            
              | 211 |         { | 
            
              | 212 |             # key => undef / to be deleted | 
            
              | 213 |             delete $account_line->{ $attribute }; | 
            
              | 214 |         } | 
            
              | 215 |     } | 
            
              | 216 |  | 
            
              | 217 |     return $account_line; | 
            
              | 218 | } | 
            
              | 219 |  | 
            
              | 220 | =head2 Global variables | 
            
              | 221 |  | 
            
              | 222 | =head3 $to_api_mapping | 
            
              | 223 |  | 
            
              | 224 | =cut | 
            
              | 225 |  | 
            
              | 226 | our $to_api_mapping = { | 
            
              | 227 |     accountlines_id   => 'account_line_id', | 
            
              | 228 |     credit_type_code  => 'credit_type', | 
            
              | 229 |     debit_type_code   => 'debit_type', | 
            
              | 230 |     amountoutstanding => 'amount_outstanding', | 
            
              | 231 |     borrowernumber    => 'patron_id', | 
            
              | 232 |     branchcode        => 'library_id', | 
            
              | 233 |     issue_id          => 'checkout_id', | 
            
              | 234 |     itemnumber        => 'item_id', | 
            
              | 235 |     manager_id        => 'user_id', | 
            
              | 236 |     note              => 'internal_note', | 
            
              | 237 | }; | 
            
              | 238 |  | 
            
              | 239 | =head3 $to_model_mapping | 
            
              | 240 |  | 
            
              | 241 | =cut | 
            
              | 242 |  | 
            
              | 243 | our $to_model_mapping = { | 
            
              | 244 |     account_line_id    => 'accountlines_id', | 
            
              | 245 |     credit_type        => 'credit_type_code', | 
            
              | 246 |     debit_type         => 'debit_type_code', | 
            
              | 247 |     amount_outstanding => 'amountoutstanding', | 
            
              | 248 |     checkout_id        => 'issue_id', | 
            
              | 249 |     internal_note      => 'note', | 
            
              | 250 |     item_id            => 'itemnumber', | 
            
              | 251 |     library_id         => 'branchcode', | 
            
              | 252 |     patron_id          => 'borrowernumber', | 
            
              | 253 |     user_id            => 'manager_id' | 
            
              | 254 | }; | 
            
              | 255 |  | 
        
          | 256 | 1; | 160 | 1; |