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

(-)a/acqui/invoice.pl (-80 / +57 lines)
Lines 95-180 elsif ( $op && $op eq 'delete' ) { Link Here
95
    }
95
    }
96
}
96
}
97
97
98
my $details     = GetInvoiceDetails($invoiceid);
98
99
my $bookseller  = GetBookSellerFromId( $details->{booksellerid} );
99
my $details = GetInvoiceDetails($invoiceid);
100
my ($bookseller) = GetBookSellerFromId($details->{supplierid});
100
my @orders_loop = ();
101
my @orders_loop = ();
101
my $orders      = $details->{'orders'};
102
my $orders = $details->{'orders'};
102
my $qty_total;
103
my $qty_total;
103
my @books_loop;
104
my @foot_loop;
104
my @book_foot_loop;
105
my %foot;
105
my %foot;
106
my $total_quantity = 0;
106
my $total_quantity = 0;
107
my $total_rrp      = 0;
107
my $total_gste = 0;
108
my $total_est      = 0;
108
my $total_gsti = 0;
109
109
my $total_gstvalue = 0;
110
foreach my $order (@$orders) {
110
foreach my $order (@$orders) {
111
    my $line = get_infos( $order, $bookseller );
111
    my $line = get_infos( $order, $bookseller);
112
112
113
    $foot{$$line{gstgsti}}{gstgsti} = $$line{gstgsti};
114
    $foot{$$line{gstgsti}}{gstvalue} += $$line{gstvalue};
115
    $total_gstvalue += $$line{gstvalue};
116
    $foot{$$line{gstgsti}}{quantity}  += $$line{quantity};
113
    $total_quantity += $$line{quantity};
117
    $total_quantity += $$line{quantity};
114
    $total_rrp      += $order->{quantity} * $order->{rrp};
118
    $foot{$$line{gstgsti}}{totalgste} += $$line{totalgste};
115
    $total_est      += $order->{quantity} * $order->{'ecost'};
119
    $total_gste += $$line{totalgste};
120
    $foot{$$line{gstgsti}}{totalgsti} += $$line{totalgsti};
121
    $total_gsti += $$line{totalgsti};
116
122
117
    my %row = ( %$order, %$line );
123
    my %row = %{ $order, $line };
124
    $row{'orderline'} = $row{'parent_ordernumber'};
118
    push @orders_loop, \%row;
125
    push @orders_loop, \%row;
119
}
126
}
120
127
121
my $gist = $bookseller->{gstrate} // C4::Context->preference("gist") // 0;
128
push @foot_loop, map {$_} values %foot;
122
my $discount =
123
  $bookseller->{'discount'} ? ( $bookseller->{discount} / 100 ) : 0;
124
my $total_est_gste;
125
my $total_est_gsti;
126
my $total_rrp_gsti;    # RRP Total, GST included
127
my $total_rrp_gste;    # RRP Total, GST excluded
128
my $gist_est;
129
my $gist_rrp;
130
if ($gist) {
131
132
    # if we have GST
133
    if ( $bookseller->{'listincgst'} ) {
134
135
        # if prices already includes GST
136
137
        # we know $total_rrp_gsti
138
        $total_rrp_gsti = $total_rrp;
139
140
        # and can reverse compute other values
141
        $total_rrp_gste = $total_rrp_gsti / ( $gist + 1 );
142
143
        $gist_rrp       = $total_rrp_gsti - $total_rrp_gste;
144
        $total_est_gste = $total_rrp_gste - ( $total_rrp_gste * $discount );
145
        $total_est_gsti = $total_est;
146
    }
147
    else {
148
        # if prices does not include GST
149
150
        # then we use the common way to compute other values
151
        $total_rrp_gste = $total_rrp;
152
        $gist_rrp       = $total_rrp_gste * $gist;
153
        $total_rrp_gsti = $total_rrp_gste + $gist_rrp;
154
        $total_est_gste = $total_est;
155
        $total_est_gsti = $total_rrp_gsti - ( $total_rrp_gsti * $discount );
156
    }
157
    $gist_est = $gist_rrp - ( $gist_rrp * $discount );
158
}
159
else {
160
    $total_rrp_gste = $total_rrp_gsti = $total_rrp;
161
    $total_est_gste = $total_est_gsti = $total_est;
162
    $gist_rrp       = $gist_est       = 0;
163
}
164
my $total_gsti_shipment = $total_est_gsti + $details->{shipmentcost};
165
129
166
my $format = "%.2f";
130
my $format = "%.2f";
167
$template->param(
168
    total_rrp_gste      => sprintf( $format, $total_rrp_gste ),
169
    total_rrp_gsti      => sprintf( $format, $total_rrp_gsti ),
170
    total_est_gste      => sprintf( $format, $total_est_gste ),
171
    total_est_gsti      => sprintf( $format, $total_est_gsti ),
172
    gist_rrp            => sprintf( $format, $gist_rrp ),
173
    gist_est            => sprintf( $format, $gist_est ),
174
    total_gsti_shipment => sprintf( $format, $total_gsti_shipment ),
175
    gist                => sprintf( $format, $gist * 100 ),
176
);
177
178
my $budgets = GetBudgets();
131
my $budgets = GetBudgets();
179
my @budgets_loop;
132
my @budgets_loop;
180
my $shipmentcost_budgetid = $details->{shipmentcost_budgetid};
133
my $shipmentcost_budgetid = $details->{shipmentcost_budgetid};
Lines 193-226 $template->param( Link Here
193
    invoiceid        => $details->{'invoiceid'},
146
    invoiceid        => $details->{'invoiceid'},
194
    invoicenumber    => $details->{'invoicenumber'},
147
    invoicenumber    => $details->{'invoicenumber'},
195
    suppliername     => $details->{'suppliername'},
148
    suppliername     => $details->{'suppliername'},
196
    booksellerid       => $details->{'booksellerid'},
149
    supplierid       => $details->{'supplierid'},
197
    datereceived     => $details->{'datereceived'},
150
    datereceived     => $details->{'datereceived'},
198
    shipmentdate     => $details->{'shipmentdate'},
151
    billingdate      => C4::Dates->new($details->{'billingdate'}, "iso")->output(),
199
    billingdate      => $details->{'billingdate'},
152
    invoiceclosedate => $details->{'invoiceclosedate'},
200
    invoiceclosedate => $details->{'closedate'},
153
    shipmentcost     => $details->{'shipmentcost'},
201
    shipmentcost     => sprintf( $format, $details->{'shipmentcost'} || 0 ),
202
    orders_loop      => \@orders_loop,
154
    orders_loop      => \@orders_loop,
155
    foot_loop        => \@foot_loop,
203
    total_quantity   => $total_quantity,
156
    total_quantity   => $total_quantity,
157
    total_gste       => sprintf( $format, $total_gste ),
158
    total_gsti       => sprintf( $format, $total_gsti ),
159
    total_gstvalue   => sprintf( $format, $total_gstvalue ),
160
    total_gste_shipment => sprintf( $format, $total_gste + $details->{shipmentcost}),
161
    total_gsti_shipment => sprintf( $format, $total_gsti + $details->{shipmentcost}),
204
    invoiceincgst    => $bookseller->{invoiceincgst},
162
    invoiceincgst    => $bookseller->{invoiceincgst},
205
    currency         => $bookseller->{listprice},
163
    currency         => GetCurrency()->{currency},
206
    budgets_loop             => \@budgets_loop,
164
    budgets_loop     => \@budgets_loop,
207
);
165
);
208
166
167
# FIXME
168
# Fonction dupplicated from basket.pl
169
# Code must to be exported. Where ??
209
sub get_infos {
170
sub get_infos {
210
    my $order      = shift;
171
    my $order = shift;
211
    my $bookseller = shift;
172
    my $bookseller = shift;
212
    my $qty        = $order->{'quantity'} || 0;
173
    my $qty = $order->{'quantity'} || 0;
213
    if ( !defined $order->{quantityreceived} ) {
174
    if ( !defined $order->{quantityreceived} ) {
214
        $order->{quantityreceived} = 0;
175
        $order->{quantityreceived} = 0;
215
    }
176
    }
216
    my $budget = GetBudget( $order->{'budget_id'} );
177
    my $budget = GetBudget( $order->{'budget_id'} );
217
178
218
    my %line = %{$order};
179
    my %line = %{ $order };
219
    $line{order_received} = ( $qty == $order->{'quantityreceived'} );
180
    $line{order_received} = ( $qty == $order->{'quantityreceived'} );
220
    $line{budget_name}    = $budget->{budget_name};
181
    $line{budget_name}    = $budget->{budget_name};
221
    $line{total}          = $qty * $order->{ecost};
182
    if ( $bookseller->{'listincgst'} ) {
183
        $line{gstgsti} = sprintf( "%.2f", $line{gstrate} * 100 );
184
        $line{gstgste} = sprintf( "%.2f", $line{gstgsti} / ( 1 + ( $line{gstgsti} / 100 ) ) );
185
        $line{actualcostgsti} = sprintf( "%.2f", $line{unitprice} );
186
        $line{actualcostgste} = sprintf( "%.2f", $line{unitprice} / ( 1 + ( $line{gstgsti} / 100 ) ) );
187
        $line{gstvalue} = sprintf( "%.2f", ( $line{actualcostgsti} - $line{actualcostgste} ) * $line{quantity});
188
        $line{totalgste} = sprintf( "%.2f", $order->{quantity} * $line{actualcostgste} );
189
        $line{totalgsti} = sprintf( "%.2f", $order->{quantity} * $line{actualcostgsti} );
190
    } else {
191
        $line{gstgsti} = sprintf( "%.2f", $line{gstrate} * 100 );
192
        $line{gstgste} = sprintf( "%.2f", $line{gstrate} * 100 );
193
        $line{actualcostgsti} = sprintf( "%.2f", $line{unitprice} * ( 1 + ( $line{gstrate} ) ) );
194
        $line{actualcostgste} = sprintf( "%.2f", $line{unitprice} );
195
        $line{gstvalue} = sprintf( "%.2f", ( $line{actualcostgsti} - $line{actualcostgste} ) * $line{quantity});
196
        $line{totalgste} = sprintf( "%.2f", $order->{quantity} * $line{actualcostgste} );
197
        $line{totalgsti} = sprintf( "%.2f", $order->{quantity} * $line{actualcostgsti} );
198
    }
222
199
223
    if ( $line{uncertainprice} ) {
200
    if ( $line{uncertainprice} ) {
201
        $template->param( uncertainprices => 1 );
224
        $line{rrp} .= ' (Uncertain)';
202
        $line{rrp} .= ' (Uncertain)';
225
    }
203
    }
226
    if ( $line{'title'} ) {
204
    if ( $line{'title'} ) {
Lines 228-235 sub get_infos { Link Here
228
        my $seriestitle = $order->{'seriestitle'};
206
        my $seriestitle = $order->{'seriestitle'};
229
        $line{'title'} .= " / $seriestitle" if $seriestitle;
207
        $line{'title'} .= " / $seriestitle" if $seriestitle;
230
        $line{'title'} .= " / $volume"      if $volume;
208
        $line{'title'} .= " / $volume"      if $volume;
231
    }
209
    } else {
232
    else {
233
        $line{'title'} = "Deleted bibliographic notice, can't find title.";
210
        $line{'title'} = "Deleted bibliographic notice, can't find title.";
234
    }
211
    }
235
212
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoice.tt (-35 / +64 lines)
Lines 10-15 Link Here
10
<script type="text/javascript" src="[% themelang %]/js/datatables.js"></script>
10
<script type="text/javascript" src="[% themelang %]/js/datatables.js"></script>
11
<script type="text/javascript">
11
<script type="text/javascript">
12
//<![CDATA[
12
//<![CDATA[
13
    function updateColumnsVisibility(visible) {
14
        if ( visible ) {
15
            $("table .gste, .gsti").show();
16
        } else {
17
            [% IF ( invoiceincgst ) %]
18
                $("table .gste").hide();
19
            [% ELSE %]
20
                $("table .gsti").hide();
21
            [% END %]
22
        }
23
    }
24
13
    $(document).ready(function() {
25
    $(document).ready(function() {
14
        $("#orderst").dataTable($.extend(true, {}, dataTablesDefaults, {
26
        $("#orderst").dataTable($.extend(true, {}, dataTablesDefaults, {
15
            bInfo: false,
27
            bInfo: false,
Lines 17-22 Link Here
17
            bFilter: false,
29
            bFilter: false,
18
            sDom: "t"
30
            sDom: "t"
19
        }));
31
        }));
32
33
        $("#show_all_details").click(function(){
34
            updateColumnsVisibility($(this+":checked").val());
35
        });
36
37
        $("#show_all_details").attr('checked', false);
38
        updateColumnsVisibility(false);
20
    });
39
    });
21
//]]>
40
//]]>
22
</script>
41
</script>
Lines 94-109 Link Here
94
      </p>
113
      </p>
95
      <h2>Invoice details</h2>
114
      <h2>Invoice details</h2>
96
      [% IF orders_loop.size %]
115
      [% IF orders_loop.size %]
116
          <label for="show_all_details">
117
            <input type="checkbox" style="vertical-align: middle;" id="show_all_details" />
118
            Show all details
119
          </label>
97
          <table id="orderst">
120
          <table id="orderst">
98
            <thead>
121
            <thead>
99
              <tr>
122
              <tr>
100
                <th>Summary</th>
123
                <th>Summary</th>
101
                <th>Publisher</th>
124
                <th>Publisher</th>
102
                <th>Library</th>
125
                <th>Library</th>
103
                <th>RRP</th>
126
                <th class="gste">Actual cost tax exc.</th>
104
                <th>Est.</th>
127
                <th class="gsti">Actual cost tax inc.</th>
105
                <th>Qty.</th>
128
                <th>Qty.</th>
106
                <th>Total</th>
129
                <th class="gste">Total tax exc. ([% currency %])</th>
130
                <th class="gsti">Total tax inc. ([% currency %])</th>
131
                <th>GST %</th>
132
                <th>GST</th>
107
                <th>Fund</th>
133
                <th>Fund</th>
108
              </tr>
134
              </tr>
109
            </thead>
135
            </thead>
Lines 125-171 Link Here
125
                    [% END %]
151
                    [% END %]
126
                  </td>
152
                  </td>
127
                  <td><p>[% order.branchcode %]</p></td>
153
                  <td><p>[% order.branchcode %]</p></td>
128
                  <td>[% order.rrp %]</td>
154
                  <td class="number gste">[% order.actualcostgste %]</td>
129
                  <td>[% order.ecost %]</td>
155
                  <td class="number gsti">[% order.actualcostgsti %]</td>
130
                  <td class="number">[% order.quantity %]</td>
156
                  <td class="number">[% order.quantity %]</td>
131
                  <td>[% order.total %]</td>
157
                  <td class="number gste">[% order.totalgste %]</td>
158
                  <td class="number gsti">[% order.totalgsti %]</td>
159
                  <td class="number">[% order.gstgsti %]</td>
160
                  <td class="number">[% order.gstvalue %]</td>
132
                  <td>[% order.budget_name %]</td>
161
                  <td>[% order.budget_name %]</td>
133
                </tr>
162
                </tr>
134
              [% END %]
163
              [% END %]
135
            </tbody>
164
            </tbody>
136
            <tfoot>
165
            <tfoot>
166
              [% FOR tf IN foot_loop %]
137
                <tr>
167
                <tr>
138
                    <th colspan="3">Total tax exc.</th>
168
                    <th colspan='3'>Total (GST [% tf.gstgsti %] %)</th>
139
                    <th>[% total_rrp_gste %]</th>
169
                    <th class="gste"/><th class="gsti"/>
140
                    <th>&nbsp;</th>
170
                    <th>[% tf.quantity %]</th>
141
                    <th>[% total_quantity %]</th>
171
                    <th class="gste">[% tf.totalgste %]</th>
142
                    <th>[% total_est_gste %]</th>
172
                    <th class="gsti">[% tf.totalgsti %]</th>
143
                    <th>&nbsp;</th>
144
                </tr>
145
                <tr>
146
                    <th colspan='3'>Tax ([% gist %]%)</th>
147
                    <th>[% gist_rrp %]</th>
148
                    <th>&nbsp;</th>
149
                    <th>&nbsp;</th>
150
                    <th>[% gist_est %]</th>
151
                    <th>&nbsp;</th>
152
                </tr>
153
                <tr>
154
                    <th colspan='3'>Total tax inc. ([% currency %])</th>
155
                    <th>[% total_rrp_gsti %]</th>
156
                    <th>&nbsp;</th>
157
                    <th>[% total_quantity %]</th>
158
                    <th>[% total_est_gsti %]</th>
159
                    <th>&nbsp;</th>
160
                </tr>
161
                <tr>
162
                    <th colspan="3">Total + shipment cost ([% currency %])</th>
163
                    <th>&nbsp;</th>
173
                    <th>&nbsp;</th>
164
                    <th>&nbsp;</th>
174
                    <th>[% tf.gstvalue %]</th>
165
                    <th>[% total_quantity %]</th>
166
                    <th>[% total_gsti_shipment %]</th>
167
                    <th>&nbsp;</th>
175
                    <th>&nbsp;</th>
168
                </tr>
176
                </tr>
177
              [% END %]
178
              <tr>
179
                <th colspan='3'>Total ([% currency %])</th>
180
                <th class="gste"/><th class="gsti"/>
181
                <th>[% total_quantity %]</th>
182
                <th class="gste">[% total_gste %]</th>
183
                <th class="gsti">[% total_gsti %]</th>
184
                <th>&nbsp;</th>
185
                <th>[% total_gstvalue %]</th>
186
                <th>&nbsp;</th>
187
              </tr>
188
              <tr>
189
                <th colspan="3">Total + Shipment cost ([% currency %])</th>
190
                <th class="gste"></th>
191
                <th class="gsti"></th>
192
                <th>[% total_quantity %]</th>
193
                <th class="gste">[% total_gste_shipment %]</th>
194
                <th class="gsti">[% total_gsti_shipment %]</th>
195
                <th>&nbsp;</th>
196
                <th>[% total_gstvalue %]</th>
197
                <th>&nbsp;</th>
198
              </tr>
169
            </tfoot>
199
            </tfoot>
170
          </table>
200
          </table>
171
        [% ELSE %]
201
        [% ELSE %]
172
- 

Return to bug 10613