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

(-)a/admin/aqbudgetperiods.pl (+73 lines)
Lines 37-42 script to administer the budget periods table Link Here
37
	- we show the record having primkey=$primkey and ask for deletion validation form
37
	- we show the record having primkey=$primkey and ask for deletion validation form
38
 if $op=delete_confirmed
38
 if $op=delete_confirmed
39
	- we delete the record having primkey=$primkey
39
	- we delete the record having primkey=$primkey
40
 if $op=duplicate_form
41
  - displays the duplication of budget period form (allowing specification of dates)
42
 if $op=duplicate_budget
43
  - we perform the duplication of the budget period specified as budget_period_id
40
44
41
=cut
45
=cut
42
46
Lines 54-59 use C4::Output; Link Here
54
use C4::Acquisition;
58
use C4::Acquisition;
55
use C4::Budgets;
59
use C4::Budgets;
56
use C4::Debug;
60
use C4::Debug;
61
use C4::SQLHelper;
57
62
58
my $dbh = C4::Context->dbh;
63
my $dbh = C4::Context->dbh;
59
64
Lines 169-174 elsif ( $op eq 'delete_confirmed' ) { Link Here
169
	$op='else';
174
	$op='else';
170
}
175
}
171
176
177
# display the form for duplicating
178
elsif ( $op eq 'duplicate_form'){
179
    $template->param(
180
        DHTMLcalendar_dateformat 	=> C4::Dates->DHTMLcalendar(),
181
        'duplicate_form' => '1',
182
        'budget_period_id' => $budget_period_id,
183
    );
184
}
185
186
# handle the actual duplication
187
elsif ( $op eq 'duplicate_budget' ){
188
    die "please specify a budget period id\n" if( !defined $budget_period_id || $budget_period_id eq '' );
189
    my $startdate = $input->param('budget_period_startdate');
190
    my $enddate = $input->param('budget_period_enddate');
191
192
    my $data = GetBudgetPeriod( $budget_period_id);
193
194
    $data->{'budget_period_startdate'} = $startdate;
195
    $data->{'budget_period_enddate'} = $enddate;
196
    delete $data->{'budget_period_id'};
197
    my $new_budget_period_id = C4::SQLHelper::InsertInTable('aqbudgetperiods', $data);
198
199
    my $tree = GetBudgetHierarchy( $budget_period_id ); 
200
201
    # hash mapping old ids to new
202
    my %old_new;
203
    # hash mapping old parent ids to list of new children ids
204
    # only store a child here if the parents old id isnt in the old_new map
205
    # when the parent is found, this map will be used, and then the entry removed and their id placed in old_new
206
    my %parent_children;
207
208
    for my $entry( @$tree ){
209
        die "serious errors, parent period $budget_period_id doesnt match child ", $entry->{'budget_period_id'}, "\n" if( $entry->{'budget_period_id'} != $budget_period_id );
210
        my $orphan = 0; # set to 1 if we need to make an entry in parent_children
211
        my $old_id = delete $entry->{'budget_id'};
212
        my $parent_id = delete $entry->{'budget_parent_id'};
213
        $entry->{'budget_period_id'} = $new_budget_period_id;
214
215
        if( !defined $parent_id ){
216
        } elsif( defined $parent_id && $parent_id eq '' ){
217
        } elsif( defined $old_new{$parent_id} ){
218
            # set parent id now
219
            $entry->{'budget_parent_id'} = $old_new{$parent_id};
220
        } else {
221
            # make an entry in parent_children
222
            $parent_children{$parent_id} = [] unless defined $parent_children{$parent_id};
223
            $orphan = 1;
224
        }
225
226
        # write it to db
227
        my $new_id = C4::SQLHelper::InsertInTable('aqbudgets', $entry);
228
        $old_new{$old_id} = $new_id;
229
        push @{$parent_children{$parent_id}}, $new_id if $orphan;
230
231
        # deal with any children
232
        if( defined $parent_children{$old_id} ){
233
            # tell my children my new id
234
            for my $child ( @{$parent_children{$old_id}} ){
235
                C4::SQLHelper::UpdateInTable('aqcudgets', [ 'budget_id' => $child, 'budget_parent_id' => $new_id ]);
236
            }
237
            delete $parent_children{$old_id};
238
        }
239
    }
240
241
    # display the list of budgets
242
    $op = 'else';
243
}
244
172
# DEFAULT - DISPLAY AQPERIODS TABLE
245
# DEFAULT - DISPLAY AQPERIODS TABLE
173
# -------------------------------------------------------------------
246
# -------------------------------------------------------------------
174
# display the list of budget periods
247
# display the list of budget periods
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/budgets-admin-toolbar.inc (-1 / +1 lines)
Lines 33-39 Link Here
33
        [% IF ( budget_period_id ) %]
33
        [% IF ( budget_period_id ) %]
34
                var periods_menu = [
34
                var periods_menu = [
35
                        { text: _("Edit budget") + " '[% budget_period_description %]'", url: "/cgi-bin/koha/admin/aqbudgetperiods.pl?op=add_form&budget_period_id=[% budget_period_id %]" },
35
                        { text: _("Edit budget") + " '[% budget_period_description %]'", url: "/cgi-bin/koha/admin/aqbudgetperiods.pl?op=add_form&budget_period_id=[% budget_period_id %]" },
36
                        <!-- { text: _("Duplicate budget") + " '[% budget_period_description %]'" } -->
36
                        { text: _("Duplicate budget") + " '[% budget_period_description %]'", url: "/cgi-bin/koha/admin/aqbudgetperiods.pl?op=duplicate_form&budget_period_id=[% budget_period_id %]" },
37
                ]
37
                ]
38
        [% END %]
38
        [% END %]
39
39
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgetperiods.tt (-1 / +75 lines)
Lines 8-13 Link Here
8
// #################################################################################
8
// #################################################################################
9
// Javascript
9
// Javascript
10
// #################################################################################
10
// #################################################################################
11
    function CheckDuplicateForm(f){
12
            var ok=1;
13
            var _alertString="";
14
            var alertString="";
15
            if(!(isNotNull(f.budget_period_startdate,1))){
16
              _alertString += "\n- " + _("Start date missing");
17
            }
18
            if (!(isNotNull(f.budget_period_enddate,1))){
19
              _alertString += "\n- " + _("End date missing");
20
            }
21
            if( f.budget_period_startdate > f.budget_period_enddate ) {
22
              _alertString += "\n- " + _("Start date must be before end date");
23
            }
24
25
            if(_alertString.length==0){
26
              f.submit();
27
            } else {
28
              alertString += _("Form not submitted because of the following problem(s)");
29
              alertString += "\n-----------------------------------------\n";
30
              alertString += _alertString;
31
              alert(alertString);
32
            }
33
    }
11
    function Check(f) {
34
    function Check(f) {
12
            var ok=1;
35
            var ok=1;
13
            var _alertString="";
36
            var _alertString="";
Lines 128-133 Link Here
128
151
129
[% INCLUDE 'budgets-admin-toolbar.inc' %]
152
[% INCLUDE 'budgets-admin-toolbar.inc' %]
130
153
154
[% IF ( duplicate_form ) %]
155
<form action="/cgi-bin/koha/admin/aqbudgetperiods.pl" name="f" method="post">
156
    <fieldset class="rows">
157
    <input type="hidden" name="op" value="duplicate_budget" />
158
    <input type="hidden" name="budget_period_id" value="[% budget_period_id %]" />
159
160
    <ol>
161
162
    <li>
163
    <label class="required" for="budget_period_startdate">Start date</label>
164
    <input type="text" size="10" id="budget_period_startdate" name="budget_period_startdate"   value="[% budget_period_startdate %]"  />
165
    <img src="/intranet-tmpl/prog/en/lib/calendar/cal.gif" border="0" id="openCalendarFrom" style="cursor: pointer;" alt="Show start date calendar" />
166
    <script type="text/javascript">
167
        Calendar.setup({
168
        inputField     :    "budget_period_startdate",
169
        ifFormat         :    "[% DHTMLcalendar_dateformat %]",
170
        button         :    "openCalendarFrom",
171
        align          :    "Tl",
172
        singleClick    :    false
173
        });
174
    </script>
175
				<div class="hint">[% INCLUDE 'date-format.inc' %]</div>
176
    </li>
177
    <li>
178
179
    <label class="required" for="budget_period_enddate">End date</label>
180
    <input type="text" size="10" id="budget_period_enddate" name="budget_period_enddate" value="[% budget_period_enddate %]" />
181
    <img src="/intranet-tmpl/prog/en/lib/calendar/cal.gif" border="0" id="openCalendarTo" style="cursor: pointer;" alt="Show end date calendar" />
182
183
    <script type="text/javascript">
184
        Calendar.setup({
185
        inputField     :    "budget_period_enddate",
186
        ifFormat         :    "[% DHTMLcalendar_dateformat %]",
187
        button         :    "openCalendarTo",
188
        align          :    "Tl"
189
        });
190
    </script>
191
				<div class="hint">[% INCLUDE 'date-format.inc' %]</div>
192
    </li>
193
194
    </ol>
195
    </fieldset>
196
197
    <fieldset class="action">
198
        <input type="button" value="Save Changes"  onclick="CheckDuplicateForm(this.form)"    />
199
    </fieldset>
200
201
</form>
202
203
[% END %]
204
131
[% IF ( add_form ) %]
205
[% IF ( add_form ) %]
132
    <!--  add or modify a budget period   -->
206
    <!--  add or modify a budget period   -->
133
207
Lines 297-302 Link Here
297
    <div class="pages">[% pagination_bar %]</div>
371
    <div class="pages">[% pagination_bar %]</div>
298
[% END %]
372
[% END %]
299
373
374
300
</div>
375
</div>
301
</div>
376
</div>
302
<div class="yui-b">
377
<div class="yui-b">
303
- 

Return to bug 6943