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

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

Return to bug 10613