View | Details | Raw Unified | Return to bug 13881
Collapse All | Expand All

(-)a/C4/Desks.pm (+183 lines)
Line 0 Link Here
1
# This file is part of Koha.
2
#
3
# Copyright (C) 2011 Progilone
4
# Copyright (C) 2015 BULAC
5
#
6
# Koha is free software; you can redistribute it and/or modify it
7
# under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 3 of the License, or
9
# (at your option) any later version.
10
#
11
# Koha is distributed in the hope that it will be useful, but
12
# WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License
17
# along with Koha; if not, see <http://www.gnu.org/licenses>.
18
19
package C4::Desks;
20
21
use Modern::Perl;
22
23
use C4::Context;
24
use vars qw(@ISA @EXPORT);
25
26
BEGIN {
27
    require Exporter;
28
    @ISA       = qw(Exporter);
29
    @EXPORT = qw(
30
		       &AddDesk
31
		       &ModDesk
32
		       &DelDesk
33
		       &GetDesk
34
		       &GetDesks
35
		  );
36
}
37
38
=head1 NAME
39
40
C4::Desks - Desk management functions
41
42
=head1 DESCRIPTION
43
44
This module contains an API for manipulating issue desks in Koha. It
45
is used by circulation.
46
47
=head1 HISTORICAL NOTE
48
49
Developped by Progilone on a customised Koha 3.2 for BULAC
50
library. The module is ported to Koha 3.19 and up by the BULAC.
51
52
=cut
53
54
=head2 AddDesk
55
56
  AddDesk({
57
    'deskcode'        => $deskcode,
58
    'deskname'        => $deskname,
59
    'deskdescription' => $deskdescription
60
    'branchcode'      => $branchcode });
61
62
  returns 1 on success, undef on error. A return value greater than 1
63
  or just -1 means something went wrong.
64
65
=cut
66
67
sub AddDesk {
68
    my ($args) = @_;
69
    C4::Context->dbh->do
70
	    ('INSERT INTO desks ' .
71
	     '(deskcode, deskname, deskdescription, branchcode) ' .
72
	     'VALUES (?,?,?,?)' ,
73
	     undef,
74
	     $args->{'deskcode'},
75
	     $args->{'deskname'},
76
	     $args->{'deskdescription'},
77
	     $args->{'branchcode'},
78
	    );
79
}
80
81
=head2 DelDesk
82
83
  DelDesk($deskcode)
84
85
  returns 1 on success, undef on error. A return value greater than 1
86
  or just -1 means something went wrong.
87
88
=cut
89
90
sub DelDesk {
91
    my $deskcode = shift;
92
    C4::Context->dbh->do
93
	    ('DELETE FROM desks WHERE deskcode = ?',
94
	     undef,
95
	     $deskcode
96
	    );
97
}
98
99
=head2 GetDesk
100
101
  $desk_href = GetDesk($deskcode);
102
103
  returns undef when no desk matches $deskcode, return a href
104
  containing desk parameters:
105
    {'deskcode' => $deskcode,
106
     'deskname' => $deskname,
107
     'deskdescription' => $deskdescription,
108
     'branchcode' => $branchcode }
109
110
=cut
111
112
sub GetDesk {
113
    my $deskcode = shift;
114
    my $query = '
115
        SELECT *
116
        FROM desks
117
        WHERE deskcode = ?';
118
119
    my $sth = C4::Context->dbh->prepare($query);
120
    $sth->execute($deskcode);
121
    $sth->fetchrow_hashref;
122
}
123
124
=head2 GetDesks
125
126
    $desk_aref = GetDesks([$branch])
127
128
    returns an array ref containing deskcodes. If no desks are
129
    available, the array is empty.
130
131
=cut
132
133
sub GetDesks  {
134
    my $branchcode   = shift || '';
135
    my $retaref = [];
136
    my $query = 'SELECT deskcode FROM desks';
137
    if ($branchcode) {
138
        $query = $query . ' WHERE branchcode = ?';
139
    }
140
    my $sth = C4::Context->dbh->prepare($query);
141
    if ($branchcode) {
142
	$sth->execute($branchcode);
143
    } else {
144
	$sth->execute();
145
    }
146
    while (my $rowaref = $sth->fetchrow_arrayref()) {
147
	push @{ $retaref }, $rowaref->[0];
148
    }
149
    return $retaref;
150
}
151
152
=head2 ModDesks
153
154
    $deskhref = {
155
       'deskcode' => $deskcode,
156
       'deskname' => $deskname,
157
       'deskdescription' => $deskdescription,
158
       'branchcode' => $branchcode
159
    }
160
    ModDesks($deskhref)
161
162
    Modify desk with $deskcode with values contained in various
163
    $deskhref fields. Returns 1 on success, 0 if no desk were
164
    modified, undef, -1 or an int greater than 1 if something went
165
    terribly wrong.
166
167
=cut
168
169
sub ModDesk {
170
    my ($args) = @_;
171
    C4::Context->dbh->do('UPDATE desks SET deskname = ? , ' .
172
			 'deskdescription = ? , ' .
173
			 'branchcode = ? ' .
174
			 'WHERE deskcode = ?' ,
175
			 undef,
176
			 $args->{'deskname'},
177
			 $args->{'deskdescription'},
178
			 $args->{'branchcode'},
179
			 $args->{'deskcode'}
180
			);
181
}
182
183
1;
(-)a/admin/desks.pl (+121 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
#
3
# Copyright (C) 2011 Progilone
4
# Copyright (C) 2015 BULAC
5
#
6
# This file is part of Koha.
7
#
8
# Koha is free software; you can redistribute it and/or modify it under the
9
# terms of the GNU General Public License as published by the Free Software
10
# Foundation; either version 2 of the License, or (at your option) any later
11
# version.
12
#
13
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License along with
18
# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
19
# Suite 330, Boston, MA  02111-1307 USA
20
21
use Modern::Perl;
22
use CGI;
23
use C4::Output;
24
use C4::Auth;
25
use C4::Context;
26
use C4::Koha;
27
use C4::Branch;
28
use C4::Desks;
29
30
my $script_name = "/cgi-bin/koha/admin/desks.pl";
31
32
my $input           = new CGI;
33
my $deskcode        = $input->param('deskcode');
34
my $branchcode      = $input->param('branchcode');
35
my $deskname        = $input->param('deskname');
36
my $deskdescription = $input->param('deskdescription');
37
my $op              = $input->param('op') || '';
38
39
my @deskloop;
40
my @branchloop = GetBranchesLoop();
41
42
43
my ( $template, $borrowernumber, $cookie ) =
44
  get_template_and_user(
45
			{
46
			 template_name   => "admin/desks.tt",
47
			 query           => $input,
48
			 type            => "intranet",
49
			 authnotrequired => 0,
50
			 flagsrequired   => {
51
					     parameters => 'parameters_remaining_permissions'
52
					    },
53
			 debug           => 1,
54
			}
55
		       );
56
57
$template->param(branchloop => \@branchloop);
58
59
$template->param(script_name => $script_name);
60
if ($op) {
61
    $template->param($op  => 1);
62
} else {
63
    $template->param(else => 1);
64
}
65
$template->param(deskcode => $deskcode);
66
67
my $desk;
68
69
if ( $op eq 'add_form' || $op eq 'delete_confirm') {
70
    $desk = GetDesk($deskcode);
71
}
72
elsif ( $op eq 'add_validate' ) {
73
    $desk = {
74
	     'deskcode' => $deskcode,
75
	     'deskname'  => $deskname,
76
	     'deskdescription' => $deskdescription,
77
	     'branchcode' => $branchcode,
78
	    };
79
    if ( GetDesk($deskcode) ) {
80
	$template->param(error => 'ALREADY_EXISTS');
81
	print $input->redirect('desks.pl');
82
	exit;
83
    }
84
    if (AddDesk($desk) != 1) {
85
	$template->param(error => 'CANT_ADD');
86
    }
87
    print $input->redirect('desks.pl');
88
    exit;
89
}
90
elsif ( $op eq 'modify_validate' ) {
91
    $desk = {
92
	     'deskcode' => $deskcode,
93
	     'deskname'  => $deskname,
94
	     'deskdescription' => $deskdescription,
95
	     'branchcode' => $branchcode,
96
	    };
97
    if (ModDesk($desk) != 1) {
98
	$template->param(error => 'CANT_MODIFY');
99
    }
100
    print $input->redirect('desks.pl');
101
    exit;
102
}
103
elsif ( $op eq 'delete_confirmed' ) {
104
    if ( DelDesk($deskcode) != 1) {
105
	    $template->param(error => 'CANT_DELETE');
106
    }
107
    print $input->redirect('desks.pl');
108
    exit;
109
}
110
else {
111
    my $userenv = C4::Context->userenv;
112
    my $desksaref = GetDesks();
113
    foreach my $d (@$desksaref) {
114
	push @deskloop, GetDesk($d);
115
    }
116
     $template->param(deskloop  => \@deskloop);
117
}
118
119
$template->param(desk => $desk);
120
121
output_html_with_http_headers $input, $cookie, $template->output;
(-)a/installer/data/mysql/atomicupdate/bug_13881-add_desk_management.sql (+12 lines)
Line 0 Link Here
1
DROP TABLE IF EXISTS desks;
2
CREATE TABLE desks (
3
  deskcode varchar(10) NOT NULL,         -- desk id
4
  branchcode varchar(10) NOT NULL,       -- branch id the desk is attached to
5
  deskname varchar(80) NOT NULL,         -- name used for OPAC or intranet printing
6
  deskdescription varchar(300) NOT NULL, -- longer description of the desk
7
  PRIMARY KEY (deskcode),
8
  UNIQUE KEY deskcode (deskcode),
9
  KEY fk_desks_branchcode (branchcode),
10
  KEY fk_desks_name_branchcode (branchcode,deskname),
11
  CONSTRAINT fk_desks_branchcode FOREIGN KEY (branchcode) REFERENCES branches (branchcode) ON DELETE CASCADE ON UPDATE CASCADE
12
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
(-)a/installer/data/mysql/kohastructure.sql (-1 / +17 lines)
Lines 455-461 CREATE TABLE `branchtransfers` ( -- information for items that are in transit be Link Here
455
  CONSTRAINT `branchtransfers_ibfk_3` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON DELETE CASCADE ON UPDATE CASCADE
455
  CONSTRAINT `branchtransfers_ibfk_3` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON DELETE CASCADE ON UPDATE CASCADE
456
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
456
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
457
457
458
459
--
458
--
460
-- Table structure for table `browser`
459
-- Table structure for table `browser`
461
--
460
--
Lines 960-965 CREATE TABLE `deleteditems` ( Link Here
960
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
959
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
961
960
962
--
961
--
962
-- Table structure for table `desks`
963
--
964
965
DROP TABLE IF EXISTS `desks`;
966
CREATE TABLE `desks` (
967
  `deskcode` varchar(10) NOT NULL,         -- desk id
968
  `branchcode` varchar(10) NOT NULL,       -- branch id the desk is attached to
969
  `deskname` varchar(80) NOT NULL,         -- name used for OPAC or intranet printing
970
  `deskdescription` varchar(300) NOT NULL, -- longer description of the desk
971
  PRIMARY KEY (`deskcode`),
972
  UNIQUE KEY `deskcode` (`deskcode`),
973
  KEY `fk_desks_branchcode` (`branchcode`),
974
  KEY `fk_desks_name_branchcode` (`branchcode`,`deskname`),
975
  CONSTRAINT `fk_desks_branchcode` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE
976
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
977
978
--
963
-- Table structure for table `ethnicity`
979
-- Table structure for table `ethnicity`
964
--
980
--
965
981
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt (+2 lines)
Lines 32-37 Link Here
32
<dl>
32
<dl>
33
        <dt><a href="/cgi-bin/koha/admin/branches.pl">Libraries and groups</a></dt>
33
        <dt><a href="/cgi-bin/koha/admin/branches.pl">Libraries and groups</a></dt>
34
        <dd>Define libraries and groups.</dd>
34
        <dd>Define libraries and groups.</dd>
35
	<dt><a href="/cgi-bin/koha/admin/desks.pl">Desks</a></dt>
36
	<dd>Define Desks.</dd>
35
        <dt><a href="/cgi-bin/koha/admin/itemtypes.pl">Item types</a></dt>
37
        <dt><a href="/cgi-bin/koha/admin/itemtypes.pl">Item types</a></dt>
36
        <dd>Define item types used for circulation rules.</dd>
38
        <dd>Define item types used for circulation rules.</dd>
37
        <dt><a href="/cgi-bin/koha/admin/authorised_values.pl">Authorized values</a></dt>
39
        <dt><a href="/cgi-bin/koha/admin/authorised_values.pl">Authorized values</a></dt>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/desks.tt (+220 lines)
Line 0 Link Here
1
[% USE AuthorisedValues %]
2
[% INCLUDE 'doc-head-open.inc' %]
3
<title>Koha &rsaquo; Administration &rsaquo; Desks [% IF ( add_form ) %]&rsaquo;
4
  [% IF ( deskcode ) %]
5
Modify desk '[% deskcode %]'
6
  [% ELSE %]
7
Add desk
8
  [% END %]
9
[% END %]
10
[% IF ( delete_confirm ) %]&rsaquo;
11
  Delete desk '[% deskcode %]'?
12
[% END %]
13
[% IF ( delete_confirmed ) %]&rsaquo;
14
Desk deleted
15
[% END %]
16
</title>
17
[% INCLUDE 'doc-head-close.inc' %]
18
<link rel="stylesheet" type="text/css" href="[% themelang %]/css/datatables.css" />
19
[% INCLUDE 'datatables.inc' %]
20
<script type="text/javascript">
21
//<![CDATA[
22
  $(document).ready(function() {
23
    $('#icons').tabs();
24
    $("#table_desks").dataTable($.extend(true, {}, dataTablesDefaults, {
25
      "aoColumnDefs":
26
         [{ "aTargets": [ -1 ], "bSortable": false, "bSearchable": false },],
27
         "aaSorting": [[ 2, "asc" ]],
28
         "iDisplayLength": 10,
29
         "sPaginationType": "four_button"
30
      }));
31
      $( "#deskcodeentry" ).validate({
32
        rules: {
33
          deskcode: { required: true },
34
          description: { required: true },
35
          rentalcharge: { number: true }
36
        }
37
    });
38
  });
39
//]]>
40
</script>
41
<style type="text/css">
42
  fieldset.rows div.toptabs li { clear:none;margin-right:.5em;padding-bottom:0;width:auto; }
43
  fieldset.rows div.toptabs .ui-tabs-nav li.ui-tabs-active {background-color : #F4F8F9; }
44
  fieldset.rows .ui-tabs-panel { margin-right : 10px; margin-left : 10px;margin-bottom:10px;}
45
  fieldset.rows .ui-tabs-nav { margin-left : 10px; }
46
</style>
47
</head>
48
<body id="admin_desks" class="admin">
49
[% INCLUDE 'header.inc' %]
50
[% INCLUDE 'cat-search.inc' %]
51
52
<div id="breadcrumbs">
53
<a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a> &rsaquo;
54
[% IF ( add_form ) %]
55
  [% IF ( desk.deskcode ) %]
56
<a href="/cgi-bin/koha/admin/desks.pl">Desks</a> &rsaquo; Modify desk '[% desk.deskcode %]'
57
  [% ELSE %]
58
<a href="/cgi-bin/koha/admin/desks.pl">Desks</a> &rsaquo; Add desk
59
  [% END %]
60
[% END %]
61
[% IF ( delete_confirm ) %]
62
<a href="/cgi-bin/koha/admin/desks.pl">Desks</a> &rsaquo; Delete desk '[% deskcode %]'?
63
[% END %]
64
[% IF ( else ) %]
65
Desks administration
66
[% END %]</div>
67
68
<div id="doc3" class="yui-t2">
69
  <div id="bd">
70
    <div id="yui-main">
71
      <div class="yui-b">
72
      [% IF ( error ) %]$
73
        <div class="dialog alert">
74
          [% IF ( CANT_ADD ) %]
75
          <h3>Adding Desk [% deskcode %] failed</h3>
76
          [% END %]
77
          [% IF ( ALREADY_EXISTS ) %]
78
          <h3>Adding Desk [% deskcode %] failed, it already exists</h3>
79
          [% END %]
80
          [% IF ( CANT_MODIFY ) %]
81
          <h3>Modifying Desk [% deskcode %] failed</h3>
82
          [% IF ( CANT_DELETE ) %]
83
          <h3>Deleting Desk [% deskcode %] failed</h3>
84
          [% END %]
85
      [% END %]
86
</div>
87
[% END %]
88
[% IF ( else ) %]
89
        <div id="toolbar" class="btn-toolbar">
90
          <a class="btn btn-small" id="newdesk" href="/cgi-bin/koha/admin/desks.pl?op=add_form"><i class="icon-plus"></i> New Desk</a>
91
        </div>
92
[% END %]
93
94
95
[% IF ( add_form ) %]
96
  [% IF ( deskcode ) %]
97
      <h3>Modify desk</h3>
98
  [% ELSE %]
99
      <h3>Add desk</h3>
100
  [% END %]
101
      <form action="[% script_name %]" name="Aform" method="post" id="deskcodeentry">
102
        <input type="hidden" name="op" value=
103
	[% IF ( deskcode ) %]
104
	  "modify_validate"
105
	[% ELSE %]
106
          "add_validate"
107
	[% END %]
108
           />
109
        <input type="hidden" name="checked" value="0" />
110
        <fieldset class="rows">
111
        <ol>
112
  [% IF ( desk.deskcode ) %]
113
          <li>
114
            <span class="label">Desk code: </span>
115
	    <input type="hidden" name="deskcode" value="[% desk.deskcode %]" />
116
            [% desk.deskcode %]
117
          </li>
118
  [% ELSE %]
119
          <li>
120
            <label for="deskcode" class="required">Desk code: </label>
121
	    <input type="text" id="deskcode" name="deskcode" size="10" maxlength="10" onblur="toUC(this)" required="required" />
122
	    <span class="required">Required</span>
123
          </li>
124
  [% END %]
125
          <li>
126
            <label for="deskdescription" class="required">Name: </label>
127
	    <input type="text" id="deskname" name="deskname" size="48" value="[% desk.deskname |html %]" required="required" />
128
	    <span class="required">Required</span>
129
	  </li>
130
          <li>
131
            <label for="deskdescription" class="required">Description: </label>
132
            <input type="text" id="deskdescription" name="deskdescription" size="48" value="[% desk.deskdescription |html %]" required="required" />
133
	    <span class="required">Required</span></li>
134
          <li>
135
	    <label for="branchcode" class="required">Branch: </label>
136
            <select id="branchcode" name="branchcode" required="required">
137
              <option value=""></option>
138
              [% FOREACH branchloo IN branchloop %]
139
                [% IF desk.branchcode == branchloo.value %]
140
                <option value="[% branchloo.value %]" selected="selected">[% branchloo.branchname %]</option>
141
                [% ELSE %]
142
                <option value="[% branchloo.value %]">[% branchloo.branchname %]</option>
143
loop            [% END %]
144
              [% END %]
145
            </select>
146
          </li>
147
        </ol>
148
        </fieldset>
149
        <fieldset class="action">
150
          <input type="submit" value="Save changes" />
151
          <a href="/cgi-bin/koha/admin/desks.pl" class="cancel">Cancel</a>
152
        </fieldset>
153
      </form>
154
      <br class="clear" />
155
[% END %]
156
157
158
[% IF ( delete_confirm ) %]
159
      <div class="dialog alert">
160
        <h3>Delete Desk '[% desk.deskcode %]'?</h3>
161
	<form action="[% script_name %]" method="post">
162
	  <input type='hidden' name='op' value='delete_confirmed'/>
163
          <table>
164
            <tr>
165
              <th scope="row">Desk</th>
166
              <td><input type='hidden' name='deskcode' value='[% desk.deskcode %]'/>[% desk.deskcode %]</td>
167
            </tr>
168
	    <tr><th scope="row">Name</th><td>[% desk.deskname %]</td></tr>
169
	    <tr><th scope="row">Description</th><td>[% desk.deskdescription %]</td></tr>
170
	    <tr><th scope="row">Branch</th><td>[% desk.branchcode %]</td></tr>
171
          </table>
172
	  <input type="submit" class="approve" value="Delete this Desk" />
173
	</form>
174
	<form action="[% script_name %]" method="post">
175
	  <input type="submit" class="deny" value="Do Not Delete" />
176
	</form>
177
      </div>
178
[% END %]
179
180
181
[% IF ( else ) %]
182
      <h2>Desks administration</h2>
183
  [% IF ( deskloop ) %]
184
      <table id="table_desks">
185
        <thead>
186
          <th>Desk code</th>
187
          <th>Name</th>
188
          <th>Description</th>
189
          <th>Branchcode</th>
190
          <th>Action</th>
191
        </thead>
192
    [% FOREACH deskloo IN deskloop %]
193
        <tr>
194
          <td>
195
            <a href="[% deskloo.script_name %]?op=add_form&amp;deskcode=[% loo.deskcode |html %]">
196
            [% deskloo.deskcode %]
197
            </a>
198
          </td>
199
          <td>[% deskloo.deskname %]</td>
200
          <td>[% deskloo.deskdescription %]</td>
201
          <td>[% deskloo.branchcode %]</td>
202
          <td>
203
            <a href="[% deskloo.script_name %]?op=add_form&amp;deskcode=[% deskloo.deskcode |html %]">Edit</a>
204
            <a href="[% deskloo.script_name %]?op=delete_confirm&amp;deskcode=[% deskloo.deskcode |html %]">Delete</a>
205
          </td>
206
        </tr>
207
    [% END %]
208
      </table>
209
  [% ELSE %]
210
      <div class="dialog message">There are no desk defined</div>
211
  [% END %]
212
      <div class="pages">[% pagination_bar %]</div>
213
[% END %]
214
    </div>
215
  </div>
216
  <div class="yui-b">
217
[% INCLUDE 'admin-menu.inc' %]
218
  </div>
219
</div>
220
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/t/db_dependent/Desks.t (-1 / +70 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
#
3
# Copyright (C) 2015 BULAC
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Test::More tests => 17;
21
22
BEGIN {
23
    use_ok('C4::Branch');
24
    use_ok('C4::Desks');
25
}
26
27
my $deskcode = 'MON BUREAU';
28
my $deskname = 'mon bureau';
29
my $deskdescription = "Le beau bureau ici.";
30
my $branchcode = shift [keys GetBranches];
31
32
my $hrdesk = {
33
	      'deskcode'        => $deskcode,
34
	      'deskname'        => $deskname,
35
	      'deskdescription' => $deskdescription,
36
	      'branchcode'      => $branchcode
37
	     };
38
39
ok(AddDesk($hrdesk) == 1, 'AddDesk creates desk.');
40
ok(! defined AddDesk($hrdesk)
41
   , 'AddDesk returns undef when desk already exists');
42
43
my $desk = GetDesk($deskcode);
44
ok (ref($desk) eq 'HASH', 'GetDesk returns hashref.');
45
ok($desk->{'deskcode'} eq $deskcode, 'GetDesk returns desk code');
46
ok($desk->{'deskname'} eq $deskname, 'GetDesk returns desk name');
47
ok($desk->{'deskdescription'} eq $deskdescription, 'GetDesk returns desk description');
48
ok($desk->{'branchcode'} eq $branchcode, 'GetDesk returns branchcode');
49
ok(! defined GetDesk('this desk surely not exists'),
50
   "GetDesk returns undef when desk doesn't exist");
51
52
my $modifieddesk = {
53
		    'deskcode'        => $deskcode,
54
		    'deskname'        => 'mon joli bureau',
55
		    'deskdescription' => "Celui dans l'entrée",
56
		    'branchcode'      => $branchcode
57
		   };
58
ok(ModDesk($modifieddesk) == 1, 'ModDesk modifies Desk');
59
$modifieddesk->{'deskcode'} = 'this desk surely not exists';
60
ok(ModDesk($modifieddesk) == 0, 'ModDesk returns 0 when deskcode is wrong');
61
62
my $desks = GetDesks();
63
ok(ref($desks) eq 'ARRAY', 'GetDesks returns an array');
64
ok(grep($deskcode, @$desks), 'GetDesks returns desk codes');
65
my $emptydesksset = GetDesks("this branch sureley doesn't exist");
66
ok(! @$emptydesksset , 'GetDesks returns [] when no desks are found');
67
68
ok(DelDesk($deskcode) == 1, 'DelDesk returns 1 when successfuly deleting desk');
69
ok(DelDesk('this desk surely not exists'),
70
   "DelDesk returns 0 when no desk were deleted");

Return to bug 13881