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