&ModBudget
&DelBudget
&GetBudgetSpent
+ &GetBudgetOrdered
&GetPeriodsCount
&GetBudgetPeriod
my ($budget_id) = @_;
my $dbh = C4::Context->dbh;
my $sth = $dbh->prepare(qq|
- SELECT SUM(ecost * quantity ) AS sum FROM aqorders
+ SELECT SUM(ecost * quantity) AS sum FROM aqorders
WHERE budget_id = ? AND
- datecancellationprinted IS NULL
+ quantityreceived > 0 AND
+ datecancellationprinted IS NULL
+ |);
+
+ $sth->execute($budget_id);
+ my $sum = $sth->fetchrow_array;
+ return $sum;
+}
+
+# -------------------------------------------------------------------
+sub GetBudgetOrdered {
+ my ($budget_id) = @_;
+ my $dbh = C4::Context->dbh;
+ my $sth = $dbh->prepare(qq|
+ SELECT SUM(ecost * quantity) AS sum FROM aqorders
+ WHERE budget_id = ? AND
+ quantityreceived = 0 AND
+ datecancellationprinted IS NULL
|);
$sth->execute($budget_id);
my $classlist = '';
my $total = 0;
my $totspent = 0;
+my $totordered = 0;
my $totcomtd = 0;
my $totavail = 0;
my @loop_budget = ();
my $member = GetMember( $result->{'budget_owner_id'} );
my $member_full = $member->{'firstname'} . ' ' . $member->{'surname'} if $member;
- $result->{'budget_owner'} = $member_full;
- if ($result->{'budget_spent'}){
- $result->{'budget_avail'} = $result->{'budget_amount'} - $result->{'budget_spent'};
- }
- else {
- $result->{'budget_avail'} = $result->{'budget_amount'};
- }
- $result->{'budget_spent'} = GetBudgetSpent( $result->{'budget_id'} );
+ $result->{'budget_owner'} = $member_full;
+ $result->{'budget_ordered'} = GetBudgetOrdered( $result->{'budget_id'} );
+ $result->{'budget_avail'} = $result->{'budget_amount'} - $result->{'budget_spent'} - $result->{'budget_ordered'};
+ $result->{'budget_spent'} = GetBudgetSpent( $result->{'budget_id'} );
- $total += $result->{'budget_amount'};
- $totspent += $result->{'budget_spent'} if $result->{'budget_spent'};
- $totavail += $result->{'budget_avail'};
+ $total += $result->{'budget_amount'};
+ $totspent += $result->{'budget_spent'};
+ $totordered += $result->{'budget_ordered'};
+ $totavail += $result->{'budget_avail'};
- $result->{'budget_amount'} = $num->format_price( $result->{'budget_amount'} );
- $result->{'budget_spent'} = $num->format_price( $result->{'budget_spent'} );
- $result->{'budget_avail'} = $num->format_price( $result->{'budget_avail'} );
+ $result->{'budget_amount'} = $num->format_price( $result->{'budget_amount'} );
+ $result->{'budget_spent'} = $num->format_price( $result->{'budget_spent'} );
+ $result->{'budget_ordered'} = $num->format_price( $result->{'budget_ordered'} );
+ $result->{'budget_avail'} = $num->format_price( $result->{'budget_avail'} );
# my $spent_percent = ( $result->{'budget_spent'} / $result->{'budget_amount'} ) * 100;
# $result->{'budget_spent_percent'} = sprintf( "%00d", $spent_percent );
branchname => $branchname,
budget => $period->{budget_name},
total => $num->format_price( $total ),
- totspent => $num->format_price($totspent ),
+ totspent => $num->format_price( $totspent ),
+ totordered => $num->format_price( $totordered ),
totcomtd => $num->format_price( $totcomtd ),
totavail => $num->format_price( $totavail ),
suggestion => $suggestion,
<th>Owner</th>
<th>Branch</th>
<th>Amount</th>
+ <th>Ordered</th>
<th>Spent</th>
<th>Avail</th>
</tr>
<th> </th>
<th> </th>
<th align="right" ><!-- TMPL_VAR name="total" --></th>
+ <th align="right" ><!-- TMPL_VAR name="totordered" --></th>
<th align="right" ><!-- TMPL_VAR name="totspent" --></th>
<th align="right" ><!-- TMPL_VAR name="totavail" --></th>
</tr>
<td align="center"><!-- TMPL_VAR name="budget_owner" --></td>
<td align="center"><!-- TMPL_VAR name="budget_branchname" --></td>
<td align="right" ><!-- TMPL_VAR name="budget_amount" --></td>
+ <td align="right" ><!-- TMPL_VAR name="budget_ordered" --></td>
<td align="right" ><!-- TMPL_VAR name="budget_spent" --></td>
<td align="right" ><!-- TMPL_VAR name="budget_avail" --></td>
</tr>