Bug 18309: Add UNIMARC field 214 and its subfields
[koha.git] / Koha / Cash / Register.pm
blobb3fe0f5413fd9f7cfa5cf70865e72b5dacb063fc
1 package Koha::Cash::Register;
3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 3 of the License, or (at your option) any later
8 # version.
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License along
15 # with Koha; if not, write to the Free Software Foundation, Inc.,
16 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 use Modern::Perl;
20 use Carp;
22 use Koha::Database;
24 use base qw(Koha::Object);
26 =encoding utf8
28 =head1 NAME
30 Koha::Cash::Register - Koha cashregister Object class
32 =head1 API
34 =head2 Class methods
36 =cut
38 =head3 library
40 Return the library linked to this cash register
42 =cut
44 sub library {
45 my ($self) = @_;
46 my $rs = $self->_result->branch;
47 return unless $rs;
48 return Koha::Library->_new_from_dbic($rs);
51 =head3 store
53 Local store method to prevent direct manipulation of the 'branch_default' field
55 =cut
57 sub store {
58 my ($self) = @_;
59 $self->_result->result_source->schema->txn_do(
60 sub {
61 if ( $self->_result->is_column_changed('branch_default') ) {
62 Koha::Exceptions::Object::ReadOnlyProperty->throw(
63 property => 'branch_default' );
65 else {
66 if ($self->_result->is_column_changed('branch') && $self->branch_default) {
68 $self = $self->SUPER::store;
72 return $self;
75 =head3 make_default
77 Set the current cash register as the branch default
79 =cut
81 sub make_default {
82 my ($self) = @_;
84 $self->_result->result_source->schema->txn_do(
85 sub {
86 my $registers =
87 Koha::Cash::Registers->search( { branch => $self->branch } );
88 $registers->update( { branch_default => 0 } );
89 $self->set( { branch_default => 1 } );
90 $self->SUPER::store;
94 return $self;
97 =head3 drop_default
99 Drop the current cash register as the branch default
101 =cut
103 sub drop_default {
104 my ($self) = @_;
106 $self->_result->result_source->schema->txn_do(
107 sub {
108 $self->set( { branch_default => 0 } );
109 $self->SUPER::store;
113 return $self;
116 =head2 Internal methods
118 =cut
120 =head3 _type
122 =cut
124 sub _type {
125 return 'CashRegister';
130 =head1 AUTHORS
132 Martin Renvoize <martin.renvoize@ptfs-europe.com>
134 =cut