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

(-)a/C4/Budgets.pm (+46 lines)
Lines 588-593 sub DelBudget { Link Here
588
}
588
}
589
589
590
590
591
sub CopyBudget {
592
    my ($budgetperiod, $budget_period_id) = @_;
593
    my $prev_budget_period_id = $budgetperiod->{'copy_previous_budget'};
594
    my $copy_data_budget = $budgetperiod->{'copy_data_budget'};
595
    #Creates a copy of a selected budget
596
    if ($prev_budget_period_id != 0) {
597
    #Get all the funds of that budget
598
    my $dbh = C4::Context->dbh;
599
    my $query = "
600
        SELECT *
601
        FROM   aqbudgets
602
        WHERE  budget_period_id=?";
603
    my $sth = $dbh->prepare($query);
604
    $sth->execute( $prev_budget_period_id );
605
    my $result = $sth->fetchall_arrayref({});
606
    my @budget_is_copy_of;
607
    #Copy all the funds to the new budget
608
    foreach my $budget (@$result){
609
        $budget->{'budget_period_id'} = $budget_period_id;
610
        #Update the parent_id to be the id of the copy of that parent
611
        $budget->{'budget_parent_id'} = $budget_is_copy_of[$budget->{'budget_parent_id'}];
612
        my $new_budget_id = C4::Budgets::AddBudget($budget);
613
614
        #Remember this budget is a copy of which
615
        $budget_is_copy_of[$budget->{'budget_id'}] = $new_budget_id;
616
617
        if ($copy_data_budget) {
618
            #Transfers the orders from the previous fund to the new
619
            my $query = "
620
            UPDATE aqorders SET budget_id = ?
621
                WHERE budget_id=? AND
622
                quantityreceived = 0 AND
623
                datecancellationprinted IS NULL";
624
            my $sth = $dbh->prepare($query);
625
            $sth->execute($new_budget_id, $budget->{'budget_id'} );
626
        }
627
    }
628
    #Disable the previous budget
629
    my $query = "
630
        UPDATE aqbudgetperiods SET budget_period_active = 0
631
        WHERE budget_period_id=?";
632
    my $sth = $dbh->prepare($query);
633
    $sth->execute( $prev_budget_period_id );
634
    }
635
}
636
591
=head2 GetBudget
637
=head2 GetBudget
592
638
593
  &GetBudget($budget_id);
639
  &GetBudget($budget_id);
(-)a/admin/aqbudgetperiods.pl (-4 / +9 lines)
Lines 128-134 if ( $op eq 'add_form' ) { Link Here
128
        $template->param(
128
        $template->param(
129
			%$budgetperiod_hash
129
			%$budgetperiod_hash
130
        );
130
        );
131
    } # IF-MOD
131
    } # IF-MOD    
132
    else{
133
        my $budgets = C4::Budgets::GetBudgetPeriods();
134
        $template->param( budgets => $budgets );
135
    }    
132
    $template->param( DHTMLcalendar_dateformat 	=> C4::Dates->DHTMLcalendar(),);
136
    $template->param( DHTMLcalendar_dateformat 	=> C4::Dates->DHTMLcalendar(),);
133
}
137
}
134
138
Lines 142-147 elsif ( $op eq 'add_validate' ) { Link Here
142
	} 
146
	} 
143
	else {    # ELSE ITS AN ADD
147
	else {    # ELSE ITS AN ADD
144
		my $budget_period_id=AddBudgetPeriod($budget_period_hashref);
148
		my $budget_period_id=AddBudgetPeriod($budget_period_hashref);
149
        C4::Budgets::CopyBudget($budget_period_hashref, $budget_period_id);
145
	}
150
	}
146
	$op='else';
151
	$op='else';
147
}
152
}
Lines 154-163 elsif ( $op eq 'delete_confirm' ) { Link Here
154
    my $total = 0;
159
    my $total = 0;
155
    my $data = GetBudgetPeriod( $budget_period_id);
160
    my $data = GetBudgetPeriod( $budget_period_id);
156
161
157
	FormatData($data);
162
    FormatData($data);
158
	$$data{'budget_period_total'}=$num->format_price(  $data->{'budget_period_total'});
163
    $$data{'budget_period_total'}=$num->format_price(  $data->{'budget_period_total'});
159
    $template->param(
164
    $template->param(
160
		%$data
165
        %$data
161
    );
166
    );
162
}
167
}
163
168
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/aqbudgetperiods.tt (-11 / +26 lines)
Lines 34-41 Link Here
34
            }
34
            }
35
35
36
/*
36
/*
37
			checkBudgetTotal(f) {
37
            checkBudgetTotal(f) {
38
			}
38
            }
39
*/
39
*/
40
40
41
            if (_alertString.length==0) {
41
            if (_alertString.length==0) {
Lines 47-59 Link Here
47
                    alert(alertString2);
47
                    alert(alertString2);
48
            }
48
            }
49
    }
49
    }
50
	$(document).ready(function() {
50
    $(document).ready(function() {
51
		 $("#periodsh").tablesorter({
51
         $("#periodsh").tablesorter({
52
	            widgets : ['zebra'],
52
                widgets : ['zebra'],
53
	            sortList: [[0,0]],
53
                sortList: [[0,0]],
54
	            headers:  {6:{sorter:false}}
54
                headers:  {6:{sorter:false}}
55
	     });
55
         });
56
	});
56
    });
57
</script>
57
</script>
58
58
59
<title>
59
<title>
Lines 144-149 Link Here
144
    <input type="hidden" name="op" value="add_validate" />
144
    <input type="hidden" name="op" value="add_validate" />
145
    <input type="hidden" name="budget_period_id" value="[% budget_period_id %]" />
145
    <input type="hidden" name="budget_period_id" value="[% budget_period_id %]" />
146
    <ol>
146
    <ol>
147
    <!-- st_copier_budget_dans_creation - SYS-TECH -->
148
    [% UNLESS ( budget_period_id ) %]
149
    <li>
150
        <label>Copy from a previous budget</label>
151
        <select name="copy_previous_budget">
152
            <option value="0"></option>
153
            [% FOREACH budget IN budgets %]
154
            <option value="[% budget.budget_period_id %]" onclick="$('#budget_period_total').val('[% budget.budget_period_total %]')">[% budget.budget_period_description %]</option>
155
            [% END %]
156
        </select>
157
        <p>
158
        <input type="checkbox" name="copy_data_budget" /> Transfer the ordered acquisitions
159
        </p>
160
    </li>
161
    [% END %]
162
    <!-- /st_copier_budget_dans_creation - SYS-TECH -->
147
    <li>
163
    <li>
148
    <label class="required" for="budget_period_startdate">Start date</label>
164
    <label class="required" for="budget_period_startdate">Start date</label>
149
    <input type="text" size="10" id="budget_period_startdate" name="budget_period_startdate"   value="[% budget_period_startdate %]"  />
165
    <input type="text" size="10" id="budget_period_startdate" name="budget_period_startdate"   value="[% budget_period_startdate %]"  />
Lines 157-163 Link Here
157
        singleClick    :    false
173
        singleClick    :    false
158
        });
174
        });
159
    </script>
175
    </script>
160
				<div class="hint">[% INCLUDE 'date-format.inc' %]</div>
176
                <div class="hint">[% INCLUDE 'date-format.inc' %]</div>
161
    </li>
177
    </li>
162
    <li>
178
    <li>
163
179
164
- 

Return to bug 6943