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

(-)a/acqui/basketgroup.pl (-52 / +65 lines)
Lines 53-58 use C4::Output; Link Here
53
use CGI;
53
use CGI;
54
54
55
use C4::Bookseller qw/GetBookSellerFromId/;
55
use C4::Bookseller qw/GetBookSellerFromId/;
56
use C4::Budgets qw/ConvertCurrency/;
56
use C4::Acquisition qw/CloseBasketgroup ReOpenBasketgroup GetOrders GetBasketsByBasketgroup GetBasketsByBookseller ModBasketgroup NewBasketgroup DelBasketgroup GetBasketgroups ModBasket GetBasketgroup GetBasket GetBasketGroupAsCSV/;
57
use C4::Acquisition qw/CloseBasketgroup ReOpenBasketgroup GetOrders GetBasketsByBasketgroup GetBasketsByBookseller ModBasketgroup NewBasketgroup DelBasketgroup GetBasketgroups ModBasket GetBasketgroup GetBasket GetBasketGroupAsCSV/;
57
use C4::Bookseller qw/GetBookSellerFromId/;
58
use C4::Bookseller qw/GetBookSellerFromId/;
58
use C4::Branch qw/GetBranches/;
59
use C4::Branch qw/GetBranches/;
Lines 210-272 sub printbasketgrouppdf{ Link Here
210
        my @ba_orders;
211
        my @ba_orders;
211
        my @ords = &GetOrders($basket->{basketno});
212
        my @ords = &GetOrders($basket->{basketno});
212
        for my $ord (@ords) {
213
        for my $ord (@ords) {
213
            # ba_order is filled with : 
214
215
            next unless ( $ord->{biblionumber} or $ord->{quantity}> 0 );
216
            eval {
217
                require C4::Biblio;
218
                import C4::Biblio;
219
            };
220
            if ($@){
221
                croak $@;
222
            }
223
            eval {
224
                require C4::Koha;
225
                import C4::Koha;
226
            };
227
            if ($@){
228
                croak $@;
229
            }
230
231
            $ord->{rrp} = ConvertCurrency( $ord->{'currency'}, $ord->{rrp} );
232
            if ( $bookseller->{'listincgst'} ) {
233
                $ord->{rrpgsti} = sprintf( "%.2f", $ord->{rrp} );
234
                $ord->{gstgsti} = sprintf( "%.2f", $ord->{gstrate} * 100 );
235
                $ord->{rrpgste} = sprintf( "%.2f", $ord->{rrp} / ( 1 + ( $ord->{gstgsti} / 100 ) ) );
236
                $ord->{gstgste} = sprintf( "%.2f", $ord->{gstgsti} / ( 1 + ( $ord->{gstgsti} / 100 ) ) );
237
                $ord->{ecostgsti} = sprintf( "%.2f", $ord->{ecost} );
238
                $ord->{ecostgste} = sprintf( "%.2f", $ord->{ecost} / ( 1 + ( $ord->{gstgsti} / 100 ) ) );
239
                $ord->{gstvalue} = sprintf( "%.2f", ( $ord->{ecostgsti} - $ord->{ecostgste} ) * $ord->{quantity});
240
                $ord->{totalgste} = sprintf( "%.2f", $ord->{quantity} * $ord->{ecostgste} );
241
                $ord->{totalgsti} = sprintf( "%.2f", $ord->{quantity} * $ord->{ecostgsti} );
242
            } else {
243
                $ord->{rrpgsti} = sprintf( "%.2f", $ord->{rrp} * ( 1 + ( $ord->{gstrate} ) ) );
244
                $ord->{rrpgste} = sprintf( "%.2f", $ord->{rrp} );
245
                $ord->{gstgsti} = sprintf( "%.2f", $ord->{gstrate} * 100 );
246
                $ord->{gstgste} = sprintf( "%.2f", $ord->{gstrate} * 100 );
247
                $ord->{ecostgsti} = sprintf( "%.2f", $ord->{ecost} * ( 1 + ( $ord->{gstrate} ) ) );
248
                $ord->{ecostgste} = sprintf( "%.2f", $ord->{ecost} );
249
                $ord->{gstvalue} = sprintf( "%.2f", ( $ord->{ecostgsti} - $ord->{ecostgste} ) * $ord->{quantity});
250
                $ord->{totalgste} = sprintf( "%.2f", $ord->{quantity} * $ord->{ecostgste} );
251
                $ord->{totalgsti} = sprintf( "%.2f", $ord->{quantity} * $ord->{ecostgsti} );
252
            }
253
            my $bib = GetBiblioData($ord->{biblionumber});
254
            my $itemtypes = GetItemTypes();
255
256
            #FIXME DELETE ME
214
            # 0      1        2        3         4            5         6       7      8        9
257
            # 0      1        2        3         4            5         6       7      8        9
215
            #isbn, itemtype, author, title, publishercode, quantity, listprice ecost discount gstrate
258
            #isbn, itemtype, author, title, publishercode, quantity, listprice ecost discount gstrate
216
            my @ba_order;
259
217
            if ( $ord->{biblionumber} && $ord->{quantity}> 0 ) {
260
            # Editor Number
218
                eval {
261
            my $en;
219
		    require C4::Biblio;
262
            my $marcrecord=eval{MARC::Record::new_from_xml( $ord->{marcxml},'UTF-8' )};
220
		    import C4::Biblio;
263
            if ($marcrecord){
221
		};
264
                if ( C4::Context->preference("marcflavour") eq 'UNIMARC' ) {
222
		if ($@){
265
                    $en = $marcrecord->subfield( '345', "b" );
223
		    croak $@;
266
                } elsif ( C4::Context->preference("marcflavour") eq 'MARC21' ) {
224
		}
267
                    $en = $marcrecord->subfield( '037', "a" );
225
                eval {
226
		    require C4::Koha;
227
		    import C4::Koha;
228
		};
229
		if ($@){
230
		    croak $@;
231
		}
232
                my $bib = GetBiblioData($ord->{biblionumber});
233
                my $itemtypes = GetItemTypes();
234
                if($ord->{isbn}){
235
                    push(@ba_order, $ord->{isbn});
236
                } else {
237
                    push(@ba_order, undef);
238
                }
239
                if ($ord->{itemtype} and $bib->{itemtype}){
240
                    push(@ba_order, $itemtypes->{$bib->{itemtype}}->{description});
241
                } else {
242
                    push(@ba_order, undef);
243
                }
244
#             } else {
245
#                 push(@ba_order, undef, undef);
246
                for my $key (qw/author title publishercode quantity listprice ecost/) {
247
                    push(@ba_order, $ord->{$key});                                                  #Order lines
248
                }
249
                push(@ba_order, $bookseller->{discount});
250
                push(@ba_order, $bookseller->{gstrate}*100 // C4::Context->preference("gist") // 0);
251
                push(@ba_orders, \@ba_order);
252
                # Editor Number
253
                my $en;
254
                my $marcrecord=eval{MARC::Record::new_from_xml( $ord->{marcxml},'UTF-8' )};
255
                if ($marcrecord){
256
                    if ( C4::Context->preference("marcflavour") eq 'UNIMARC' ) {
257
                        $en = $marcrecord->subfield( '345', "b" );
258
                    } elsif ( C4::Context->preference("marcflavour") eq 'MARC21' ) {
259
                        $en = $marcrecord->subfield( '037', "a" );
260
                    }
261
                }
262
                if($en){
263
                    push(@ba_order, $en);
264
                } else {
265
                    push(@ba_order, undef);
266
                }
268
                }
267
            }
269
            }
270
271
            my $ba_order = {
272
                isbn => ($ord->{isbn} ? $ord->{isbn} : undef),
273
                itemtype => ( $ord->{itemtype} and $bib->{itemtype} ? $itemtypes->{$bib->{itemtype}}->{description} : undef ),
274
                en => ( $en ? $en : undef ),
275
            };
276
            for my $key ( qw/ gstrate author title itemtype publishercode discount quantity rrpgsti rrpgste gstgsti gstgste ecostgsti ecostgste gstvalue totalgste totalgsti / ) {
277
                $ba_order->{$key} = $ord->{$key};
278
            }
279
280
            push(@ba_orders, $ba_order);
268
        }
281
        }
269
        $orders{$basket->{basketno}}=\@ba_orders;
282
        $orders{$basket->{basketno}} = \@ba_orders;
270
    }
283
    }
271
    print $input->header(
284
    print $input->header(
272
        -type       => 'application/pdf',
285
        -type       => 'application/pdf',
(-)a/acqui/pdfformat/layout2pages.pm (-11 / +11 lines)
Lines 82-105 sub printorders { Link Here
82
    
82
    
83
    my $abaskets;
83
    my $abaskets;
84
    my $arrbasket;
84
    my $arrbasket;
85
    my @keys = ('Basket (N°)','Document','Qty','RRT GST Inc.','Discount','Discount price GST Exc.','GST', 'Total GST Inc.'); 
85
    my @keys = ('Basket (N°)', 'Document', 'Qty', 'RRP tax inc.', 'Discount', 'GST', 'Total tax exc.', 'Total tax inc.');
86
    for my $bkey (@keys) {
86
    for my $bkey (@keys) {
87
        push(@$arrbasket, $bkey);
87
        push(@$arrbasket, $bkey);
88
    }
88
    }
89
    push(@$abaskets, $arrbasket);
89
    push(@$abaskets, $arrbasket);
90
    
90
91
    for my $basket (@$baskets){
91
    for my $basket (@$baskets){
92
        for my $line (@{$orders->{$basket->{basketno}}}) {
92
        for my $line (@{$orders->{$basket->{basketno}}}) {
93
            $arrbasket = undef;
93
            $arrbasket = undef;
94
            push( @$arrbasket, 
94
            push( @$arrbasket,
95
                $basket->{basketno}, 
95
                $basket->{basketno},
96
                @$line[3]." / ".@$line[2].(@$line[0]?" ISBN : ".@$line[0]:'').(@$line[10]?" EN : ".@$line[10]:'').", ".@$line[1].(@$line[4]?' published by '.@$line[4]:''),
96
                $line->{title} . " / " . $line->{author} . ( $line->{isbn} ? " ISBN : " . $line->{isbn} : '' ) . ( $line->{en} ? " EN : " . $line->{en} : '' ) . ", " . $line->{itemtype} . ( $line->{publishercode} ? ' published by '. $line->{publishercode} : ""),
97
                @$line[5],
97
                $line->{quantity},
98
                $num->format_price(@$line[6]),
98
                $num->format_price($line->{rrpgsti}),
99
                $num->format_price(@$line[8]).'%',
99
                $num->format_price($line->{discount}).'%',
100
                $num->format_price(@$line[7]/(1+@$line[9]/100)),
100
                $num->format_price($line->{gstrate} * 100).'%',
101
                $num->format_price(@$line[9]).'%',
101
                $num->format_price($line->{totalgste}),
102
                $num->format_price($num->round(@$line[7])*@$line[5])
102
                $num->format_price($line->{totalgsti}),
103
            );
103
            );
104
            push(@$abaskets, $arrbasket);
104
            push(@$abaskets, $arrbasket);
105
        }
105
        }
(-)a/acqui/pdfformat/layout3pages.pm (-26 / +54 lines)
Lines 102-119 sub printorders { Link Here
102
        my $pdftable = new PDF::Table();
102
        my $pdftable = new PDF::Table();
103
        my $abaskets;
103
        my $abaskets;
104
        my $arrbasket;
104
        my $arrbasket;
105
        my @keys = ('Document','Qty','RRT GST Inc.','Discount','Discount price GST Exc.','GST', 'Total GST Inc.'); 
105
        my @keys = ('Document', 'Qty', 'RRP tax exc.', 'RRP tax inc.', 'Discount', 'Discount price', 'GST rate', 'Total tax exc.', 'Total tax inc.');
106
        for my $bkey (@keys) {
106
        for my $bkey (@keys) {
107
            push(@$arrbasket, $bkey);
107
            push(@$arrbasket, $bkey);
108
        }
108
        }
109
        push(@$abaskets, $arrbasket);
109
        push(@$abaskets, $arrbasket);
110
#         @{$orders->{$basket->{basketno}}});
111
        foreach my $line (@{$orders->{$basket->{basketno}}}) {
110
        foreach my $line (@{$orders->{$basket->{basketno}}}) {
112
            $arrbasket = undef;
111
            $arrbasket = undef;
113
            push(@$arrbasket, @$line[3]." / ".@$line[2].(@$line[0]?" ISBN : ".@$line[0]:'').(@$line[10]?" EN : ".@$line[10]:'').", ".@$line[1].(@$line[4]?' published by '.@$line[4]:''), @$line[5],$num->format_price(@$line[6]),$num->format_price(@$line[8]).'%',$num->format_price(@$line[7]/(1+@$line[9]/100)),$num->format_price(@$line[9]).'%',$num->format_price($num->round(@$line[7])*@$line[5]));
112
            push( @$arrbasket,
113
                $line->{title} . " / " . $line->{author} . ( $line->{isbn} ? " ISBN : " . $line->{isbn} : '' ) . ( $line->{en} ? " EN : " . $line->{en} : '' ) . ", " . $line->{itemtype} . ( $line->{publishercode} ? ' published by '. $line->{publishercode} : ""),
114
                $line->{quantity},
115
                $num->format_price($line->{rrpgste}),
116
                $num->format_price($line->{rrpgsti}),
117
                $num->format_price($line->{discount}).'%',
118
                $num->format_price($line->{rrpgste} - $line->{ecostgste}),
119
                $num->format_price($line->{gstrate} * 100).'%',
120
                $num->format_price($line->{totalgste}),
121
                $num->format_price($line->{totalgsti}),
122
            );
114
            push(@$abaskets, $arrbasket);
123
            push(@$abaskets, $arrbasket);
115
        }
124
        }
116
        
125
117
        $pdftable->table($pdf, $page, $abaskets,
126
        $pdftable->table($pdf, $page, $abaskets,
118
                                        x => 10/mm,
127
                                        x => 10/mm,
119
                                        w => ($width - 20)/mm,
128
                                        w => ($width - 20)/mm,
Lines 128-140 sub printorders { Link Here
128
                                        font_size => 3/mm,
137
                                        font_size => 3/mm,
129
                                        header_props   =>    {
138
                                        header_props   =>    {
130
                                            font       => $pdf->corefont("Times", -encoding => "utf8"),
139
                                            font       => $pdf->corefont("Times", -encoding => "utf8"),
131
                                            font_size  => 10,
140
                                            font_size  => 9,
132
                                            bg_color   => 'gray',
141
                                            bg_color   => 'gray',
133
                                            repeat     => 1,
142
                                            repeat     => 1,
134
                                        },
143
                                        },
135
                                        column_props => [
144
                                        column_props => [
136
                                            {
145
                                            {
137
                                                min_w => 100/mm,       # Minimum column width.
146
                                                min_w => 85/mm,       # Minimum column width.
147
                                            },
148
                                            {
149
                                                justify => 'right', # One of left|right ,
150
                                            },
151
                                            {
152
                                                justify => 'right', # One of left|right ,
138
                                            },
153
                                            },
139
                                            {
154
                                            {
140
                                                justify => 'right', # One of left|right ,
155
                                                justify => 'right', # One of left|right ,
Lines 203-236 sub printbaskets { Link Here
203
    my $abaskets;
218
    my $abaskets;
204
    my $arrbasket;
219
    my $arrbasket;
205
    # header of the table
220
    # header of the table
206
    my @keys = ('Lot',  'Basket (N°)', 'RRT GST Inc.', 'Discount', 'Discount price','GST rate', 'Total GST exc.','GST', 'Total GST Inc.');
221
    my @keys = ('Lot',  'Basket (N°)','Total RRP tax exc.', 'Total RRP tax inc.', 'GST rate', 'GST', 'Total discount', 'Total tax exc.', 'Total tax inc.');
207
    for my $bkey (@keys) {
222
    for my $bkey (@keys) {
208
        push(@$arrbasket, $bkey);
223
        push(@$arrbasket, $bkey);
209
    }
224
    }
210
    my $grandtotal=0;
225
    my ($grandtotalrrpgsti, $grandtotalrrpgste, $grandtotalgsti, $grandtotalgste, $grandtotalgstvalue, $grandtotaldiscount);
211
    my $grandgst=0;
226
    my @gst;
212
    # calculate each basket total
227
    # calculate each basket total
213
    push(@$abaskets, $arrbasket);
228
    push(@$abaskets, $arrbasket);
214
    for my $basket (@$hbaskets) {
229
    for my $basket (@$hbaskets) {
215
        $arrbasket = undef;
230
        $arrbasket = undef;
216
        my ($total, $gst, $totallist) = (0, 0, 0);
231
        my ($totalrrpgste, $totalrrpgsti, $totalgste, $totalgsti, $totalgstvalue, $totaldiscount);
217
        my $ords = $orders->{$basket->{basketno}};
232
        my $ords = $orders->{$basket->{basketno}};
218
        my $ordlength = @$ords;
233
        my $ordlength = @$ords;
219
        foreach my $ord (@$ords) {
234
        foreach my $ord (@$ords) {
220
            $total += @$ord[5] * @$ord[7];
235
            $totalgste += $ord->{totalgste};
221
            $gst   += (@$ord[5] * @$ord[7]) * $GSTrate/(1+$GSTrate);
236
            $totalgsti += $ord->{totalgsti};
222
            $totallist += @$ord[5]*@$ord[6];
237
            $totalgstvalue += $ord->{gstvalue};
238
            $totaldiscount += ($ord->{rrpgste} - $ord->{ecostgste} ) * $ord->{quantity};
239
            $totalrrpgste += $ord->{rrpgste} * $ord->{quantity};
240
            $totalrrpgsti += $ord->{rrpgsti} * $ord->{quantity};
241
            push @gst, $ord->{gstrate} * 100
242
                unless grep {$ord->{gstrate} * 100 == $_ ? $_ : ()} @gst;
223
        }
243
        }
224
        $total=$num->round($total);
244
        $totalgsti = $num->round($totalgsti);
225
        $gst=$num->round($gst);
245
        $totalgste = $num->round($totalgste);
226
        $grandtotal +=$total;
246
        $grandtotalrrpgste += $totalrrpgste;
227
        $grandgst +=$gst;
247
        $grandtotalrrpgsti += $totalrrpgsti;
228
        push(@$arrbasket, $basket->{contractname}, $basket->{basketname}.'(N°'.$basket->{basketno}.')',$num->format_price($totallist), $num->format_price($bookseller->{discount}).'%', $num->format_price($total), $num->format_price($GSTrate*100).'%', $num->format_price($total-$gst), $num->format_price($gst), $num->format_price($total));
248
        $grandtotalgsti += $totalgsti;
249
        $grandtotalgste += $totalgste;
250
        $grandtotalgstvalue += $totalgstvalue;
251
        $grandtotaldiscount += $totaldiscount;
252
        my @gst_string = map{$num->format_price( $_ ) . '%'} @gst;
253
        push(@$arrbasket,
254
            $basket->{contractname},
255
            $basket->{basketname} . ' (N°' . $basket->{basketno} . ')',
256
            $num->format_price($totalrrpgste),
257
            $num->format_price($totalrrpgsti),
258
            "@gst_string",
259
            $num->format_price($totalgstvalue),
260
            $num->format_price($totaldiscount),
261
            $num->format_price($totalgste),
262
            $num->format_price($totalgsti)
263
        );
229
        push(@$abaskets, $arrbasket);
264
        push(@$abaskets, $arrbasket);
230
    }
265
    }
231
    # now, push total
266
    # now, push total
232
    undef $arrbasket;
267
    undef $arrbasket;
233
    push @$arrbasket,'','','','Total',$num->format_price($grandtotal),'',$num->format_price($grandtotal-$grandgst), $num->format_price($grandgst),$num->format_price($grandtotal);
268
    push @$arrbasket,'','Total', $num->format_price($grandtotalrrpgste), $num->format_price($grandtotalrrpgsti), '', $num->format_price($grandtotalgstvalue), $num->format_price($grandtotaldiscount), $num->format_price($grandtotalgste), $num->format_price($grandtotalgsti);
234
    push @$abaskets,$arrbasket;
269
    push @$abaskets,$arrbasket;
235
    # height is width and width is height in this function, as the pdf is in landscape mode for the Tables.
270
    # height is width and width is height in this function, as the pdf is in landscape mode for the Tables.
236
271
Lines 270-281 sub printbaskets { Link Here
270
                                        {
305
                                        {
271
                                            justify => 'right',
306
                                            justify => 'right',
272
                                        },
307
                                        },
273
                                        {
274
                                            justify => 'right',
275
                                        },
276
                                        {
277
                                            justify => 'right',
278
                                        },
279
                                    ],
308
                                    ],
280
    );
309
    );
281
    $pdf->mediabox($height/mm, $width/mm);
310
    $pdf->mediabox($height/mm, $width/mm);
282
- 

Return to bug 9506