|
Lines 1-8
Link Here
|
| 1 |
use strict; |
1 |
use Modern::Perl; |
| 2 |
use warnings; |
2 |
use Test::More tests => 23; |
| 3 |
use Test::More tests=>20; |
|
|
| 4 |
|
3 |
|
| 5 |
BEGIN {use_ok('C4::Budgets') } |
4 |
BEGIN {use_ok('C4::Budgets') } |
|
|
5 |
use C4::Biblio; |
| 6 |
use C4::Bookseller; |
| 7 |
use C4::Acquisition; |
| 6 |
use C4::Dates; |
8 |
use C4::Dates; |
| 7 |
use C4::Context; |
9 |
use C4::Context; |
| 8 |
|
10 |
|
|
Lines 128-130
ok($budgets->[0]->{budget_name} lt $budgets->[1]->{budget_name}, 'default sort o
Link Here
|
| 128 |
ok($del_status=DelBudget($budget_id), |
130 |
ok($del_status=DelBudget($budget_id), |
| 129 |
"DelBudget returned $del_status"); |
131 |
"DelBudget returned $del_status"); |
| 130 |
|
132 |
|
| 131 |
- |
133 |
|
|
|
134 |
# GetBudgetHierarchySpent and GetBudgetHierarchyOrdered |
| 135 |
my $budget_period_total = 10_000; |
| 136 |
my $budget_1_total = 1_000; |
| 137 |
my $budget_11_total = 100; |
| 138 |
my $budget_111_total = 50; |
| 139 |
my $budget_12_total = 100; |
| 140 |
my $budget_2_total = 2_000; |
| 141 |
|
| 142 |
my $budget_period_id = AddBudgetPeriod( |
| 143 |
{ |
| 144 |
budget_period_startdate => '2013-01-01', |
| 145 |
budget_period_enddate => '2014-12-31', |
| 146 |
budget_description => 'Budget Period', |
| 147 |
budget_period_active => 1, |
| 148 |
budget_period_total => $budget_period_total, |
| 149 |
} |
| 150 |
); |
| 151 |
my $budget_id1 = AddBudget( |
| 152 |
{ |
| 153 |
budget_code => 'budget_1', |
| 154 |
budget_name => 'budget_1', |
| 155 |
budget_active => 1, |
| 156 |
budget_period_id => $budget_period_id, |
| 157 |
budget_parent_id => undef, |
| 158 |
budget_amount => $budget_1_total, |
| 159 |
} |
| 160 |
); |
| 161 |
my $budget_id2 = AddBudget( |
| 162 |
{ |
| 163 |
budget_code => 'budget_2', |
| 164 |
budget_name => 'budget_2', |
| 165 |
budget_active => 1, |
| 166 |
budget_period_id => $budget_period_id, |
| 167 |
budget_parent_id => undef, |
| 168 |
budget_amount => $budget_2_total, |
| 169 |
} |
| 170 |
); |
| 171 |
my $budget_id11 = AddBudget( |
| 172 |
{ |
| 173 |
budget_code => 'budget_11', |
| 174 |
budget_name => 'budget_11', |
| 175 |
budget_active => 1, |
| 176 |
budget_period_id => $budget_period_id, |
| 177 |
budget_parent_id => $budget_id1, |
| 178 |
budget_amount => $budget_11_total, |
| 179 |
} |
| 180 |
); |
| 181 |
my $budget_id12 = AddBudget( |
| 182 |
{ |
| 183 |
budget_code => 'budget_12', |
| 184 |
budget_name => 'budget_12', |
| 185 |
budget_active => 1, |
| 186 |
budget_period_id => $budget_period_id, |
| 187 |
budget_parent_id => $budget_id1, |
| 188 |
budget_amount => $budget_12_total, |
| 189 |
} |
| 190 |
); |
| 191 |
my $budget_id111 = AddBudget( |
| 192 |
{ |
| 193 |
budget_code => 'budget_111', |
| 194 |
budget_name => 'budget_111', |
| 195 |
budget_active => 1, |
| 196 |
budget_period_id => $budget_period_id, |
| 197 |
budget_parent_id => $budget_id11, |
| 198 |
owner_id => 1, |
| 199 |
budget_amount => $budget_111_total, |
| 200 |
} |
| 201 |
); |
| 202 |
my $budget_id21 = AddBudget( |
| 203 |
{ |
| 204 |
budget_code => 'budget_21', |
| 205 |
budget_name => 'budget_21', |
| 206 |
budget_active => 1, |
| 207 |
budget_period_id => $budget_period_id, |
| 208 |
budget_parent_id => $budget_id2, |
| 209 |
} |
| 210 |
); |
| 211 |
|
| 212 |
my $booksellerid = C4::Bookseller::AddBookseller( |
| 213 |
{ |
| 214 |
name => "my vendor", |
| 215 |
address1 => "bookseller's address", |
| 216 |
phone => "0123456", |
| 217 |
active => 1, |
| 218 |
deliverytime => 5, |
| 219 |
} |
| 220 |
); |
| 221 |
|
| 222 |
my $basketno = C4::Acquisition::NewBasket( $booksellerid, 1 ); |
| 223 |
my ( $biblionumber, $biblioitemnumber ) = |
| 224 |
C4::Biblio::AddBiblio( MARC::Record->new, '' ); |
| 225 |
|
| 226 |
my @order_infos = ( |
| 227 |
{ |
| 228 |
budget_id => $budget_id1, |
| 229 |
pending_quantity => 1, |
| 230 |
spent_quantity => 0, |
| 231 |
}, |
| 232 |
{ |
| 233 |
budget_id => $budget_id2, |
| 234 |
pending_quantity => 2, |
| 235 |
spent_quantity => 1, |
| 236 |
}, |
| 237 |
{ |
| 238 |
budget_id => $budget_id11, |
| 239 |
pending_quantity => 3, |
| 240 |
spent_quantity => 4, |
| 241 |
}, |
| 242 |
{ |
| 243 |
budget_id => $budget_id12, |
| 244 |
pending_quantity => 4, |
| 245 |
spent_quantity => 3, |
| 246 |
}, |
| 247 |
{ |
| 248 |
budget_id => $budget_id111, |
| 249 |
pending_quantity => 2, |
| 250 |
spent_quantity => 1, |
| 251 |
}, |
| 252 |
|
| 253 |
# No order for budget_21 |
| 254 |
|
| 255 |
); |
| 256 |
|
| 257 |
my $number_of_orders_to_move = 0; |
| 258 |
my %budgets; |
| 259 |
my $invoiceid = AddInvoice(invoicenumber => 'invoice_test_clone', booksellerid => $booksellerid, unknown => "unknown"); |
| 260 |
my $item_price = 10; |
| 261 |
my $item_quantity = 2; |
| 262 |
for my $infos (@order_infos) { |
| 263 |
for ( 1 .. $infos->{pending_quantity} ) { |
| 264 |
my ( undef, $ordernumber ) = C4::Acquisition::NewOrder( |
| 265 |
{ |
| 266 |
basketno => $basketno, |
| 267 |
biblionumber => $biblionumber, |
| 268 |
budget_id => $infos->{budget_id}, |
| 269 |
order_internalnote => "internal note", |
| 270 |
order_vendornote => "vendor note", |
| 271 |
quantity => 2, |
| 272 |
cost => $item_price, |
| 273 |
rrp => $item_price, |
| 274 |
listprice => $item_price, |
| 275 |
ecost => $item_price, |
| 276 |
rrp => $item_price, |
| 277 |
discount => 0, |
| 278 |
uncertainprice => 0, |
| 279 |
gstrate => 0, |
| 280 |
} |
| 281 |
); |
| 282 |
push @{ $budgets{$infos->{budget_id}} }, $ordernumber; |
| 283 |
$number_of_orders_to_move++; |
| 284 |
} |
| 285 |
for ( 1 .. $infos->{spent_quantity} ) { |
| 286 |
my ( undef, $ordernumber ) = C4::Acquisition::NewOrder( |
| 287 |
{ |
| 288 |
basketno => $basketno, |
| 289 |
biblionumber => $biblionumber, |
| 290 |
budget_id => $infos->{budget_id}, |
| 291 |
order_internalnote => "internal note", |
| 292 |
order_vendornote => "vendor note", |
| 293 |
quantity => $item_quantity, |
| 294 |
cost => $item_price, |
| 295 |
rrp => $item_price, |
| 296 |
listprice => $item_price, |
| 297 |
ecost => $item_price, |
| 298 |
rrp => $item_price, |
| 299 |
discount => 0, |
| 300 |
uncertainprice => 0, |
| 301 |
gstrate => 0, |
| 302 |
} |
| 303 |
); |
| 304 |
ModReceiveOrder({ |
| 305 |
biblionumber => $biblionumber, |
| 306 |
ordernumber => $ordernumber, |
| 307 |
budget_id => $infos->{budget_id}, |
| 308 |
quantityreceived => $item_quantity, |
| 309 |
cost => $item_price, |
| 310 |
ecost => $item_price, |
| 311 |
invoiceid => $invoiceid, |
| 312 |
rrp => $item_price, |
| 313 |
received_items => [], |
| 314 |
} ); |
| 315 |
} |
| 316 |
} |
| 317 |
is( GetBudgetHierarchySpent( $budget_id1 ), 160, "total spent for budget1 is 160" ); |
| 318 |
is( GetBudgetHierarchySpent( $budget_id11 ), 100, "total spent for budget1 is 100" ); |
| 319 |
is( GetBudgetHierarchySpent( $budget_id111 ), 20, "total spent for budget1 is 20" ); |