@@ -, +, @@ the table under 'Manage cash registers' that the default has been switched to the new register. no longer a default register for this branch. --- Koha/Cash/Register.pm | 69 ++++++++++++++++- Koha/Exceptions/Object.pm | 8 ++ admin/cash_registers.pl | 31 +++++++- .../prog/css/src/staff-global.scss | 6 ++ .../prog/en/modules/admin/cash_registers.tt | 75 +++++++++++++++---- 5 files changed, 170 insertions(+), 19 deletions(-) --- a/Koha/Cash/Register.pm +++ a/Koha/Cash/Register.pm @@ -42,10 +42,75 @@ Return the library linked to this cash register =cut sub library { - my ( $self ) = @_; + my ($self) = @_; my $rs = $self->_result->branch; return unless $rs; - return Koha::Library->_new_from_dbic( $rs ); + return Koha::Library->_new_from_dbic($rs); +} + +=head3 store + +Local store method to prevent direct manipulation of the 'branch_default' field + +=cut + +sub store { + my ($self) = @_; + $self->_result->result_source->schema->txn_do( + sub { + if ( $self->_result->is_column_changed('branch_default') ) { + Koha::Exceptions::Object::ReadOnlyProperty->throw( + property => 'branch_default' ); + } + else { + if ($self->_result->is_column_changed('branch') && $self->branch_default) { + } + $self = $self->SUPER::store; + } + } + ); + return $self; +} + +=head3 make_default + +Set the current cash register as the branch default + +=cut + +sub make_default { + my ($self) = @_; + + $self->_result->result_source->schema->txn_do( + sub { + my $registers = + Koha::Cash::Registers->search( { branch => $self->branch } ); + $registers->update( { branch_default => 0 } ); + $self->set( { branch_default => 1 } ); + $self->SUPER::store; + } + ); + + return $self; +} + +=head3 drop_default + +Drop the current cash register as the branch default + +=cut + +sub drop_default { + my ($self) = @_; + + $self->_result->result_source->schema->txn_do( + sub { + $self->set( { branch_default => 0 } ); + $self->SUPER::store; + } + ); + + return $self; } =head2 Internal methods --- a/Koha/Exceptions/Object.pm +++ a/Koha/Exceptions/Object.pm @@ -41,6 +41,11 @@ use Exception::Class ( isa => 'Koha::Exceptions::Object', description => "Invalid property", }, + 'Koha::Exceptions::Object::ReadOnlyProperty' => { + isa => 'Koha::Exceptions::Object', + description => "Change of readonly property attempted", + fields => [ 'property' ], + }, 'Koha::Exceptions::Object::MethodNotCoveredByTests' => { isa => 'Koha::Exceptions::Object', description => "Method not covered by tests", @@ -64,6 +69,9 @@ sub full_message { elsif ( $self->isa('Koha::Exceptions::Object::BadValue') ) { $msg = sprintf("Invalid value passed, %s=%s expected type is %s", $self->property, $self->value, $self->type ); } + elsif ( $self->isa('Koha::Exceptions::Object::ReadOnlyProperty') ) { + $msg = sprintf("Invalid attempt to change readonly property: %s", $self->property ); + } } return $msg; --- a/admin/cash_registers.pl +++ a/admin/cash_registers.pl @@ -128,9 +128,38 @@ elsif ( $op eq 'unarchive' ) { $op = 'list'; } +elsif ( $op eq 'make_default' ) { + if ($registerid) { + try { + my $cash_register = Koha::Cash::Registers->find($registerid); + $cash_register->make_default; + push @messages, { code => 'success_on_default', type => 'message' }; + } + catch { + push @messages, { code => 'error_on_default', type => 'alert' }; + } + } + $op = 'list'; +} +elsif ( $op eq 'drop_default' ) { + if ($registerid) { + try { + my $cash_register = Koha::Cash::Registers->find($registerid); + $cash_register->drop_default; + push @messages, { code => 'success_on_default', type => 'message' }; + } + catch { + push @messages, { code => 'error_on_default', type => 'alert' }; + } + } + $op = 'list'; +} + + if ( $op eq 'list' ) { my $cash_registers = - Koha::Cash::Registers->search( {}, { prefetch => 'branch' } ); + Koha::Cash::Registers->search( {}, + { prefetch => 'branch', order_by => { -asc => [qw/branch name/] } } ); $template->param( cash_registers => $cash_registers, ); } --- a/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss +++ a/koha-tmpl/intranet-tmpl/prog/css/src/staff-global.scss @@ -840,6 +840,12 @@ tr { } } } + + &.default { + td { + font-weight: bold; + } + } } .table_borrowers { --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/cash_registers.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/cash_registers.tt @@ -1,9 +1,9 @@ [% USE raw %] [% USE Asset %] +[% USE Branches %] [% SET footerjs = 1 %] -[% USE ColumnsSettings %] [% INCLUDE 'doc-head-open.inc' %] -
Id | Name | Description | -Branch | +Library | +Default | Initial float | Actions | [% FOREACH cash_register IN cash_registers %] + [% IF cash_register.branch_default %] +|
---|---|---|---|---|---|---|---|---|
[% cash_register.id %] | + [% END %][% cash_register.name %] | [% cash_register.description %] | [% cash_register.library.branchname %] | +[% IF cash_register.branch_default %]Yes[% ELSE %]No[% END %] | [% cash_register.starting_float %] | [% IF cash_register.archived == '0' %] -Edit Archive | ++ Edit + [% IF cash_register.branch_default %] + Drop default + [% ELSE %] + Make default + [% END %] + Archive + | [% ELSE %]Restore | [% END %] @@ -161,15 +180,39 @@ [% MACRO jsinclude BLOCK %] [% Asset.js("js/admin-menu.js") | $raw %] [% INCLUDE 'datatables.inc' %] - [% END %] --