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

(-)a/acqui/invoice.pl (-58 / +72 lines)
Lines 37-127 use C4::Bookseller qw/GetBookSellerFromId/; Link Here
37
use C4::Budgets;
37
use C4::Budgets;
38
38
39
my $input = new CGI;
39
my $input = new CGI;
40
my ($template, $loggedinuser, $cookie, $flags) = get_template_and_user( {
40
my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user(
41
    template_name   => 'acqui/invoice.tmpl',
41
    {
42
    query           => $input,
42
        template_name   => 'acqui/invoice.tmpl',
43
    type            => 'intranet',
43
        query           => $input,
44
    authnotrequired => 0,
44
        type            => 'intranet',
45
    flagsrequired   => { 'acquisition' => '*' },
45
        authnotrequired => 0,
46
    debug           => 1,
46
        flagsrequired   => { 'acquisition' => '*' },
47
} );
47
        debug           => 1,
48
    }
49
);
48
50
49
my $invoiceid = $input->param('invoiceid');
51
my $invoiceid = $input->param('invoiceid');
50
my $op = $input->param('op');
52
my $op        = $input->param('op');
51
53
52
if($op && $op eq 'close') {
54
if ( $op && $op eq 'close' ) {
53
    CloseInvoice($invoiceid);
55
    CloseInvoice($invoiceid);
54
    my $referer = $input->param('referer');
56
    my $referer = $input->param('referer');
55
    if($referer) {
57
    if ($referer) {
56
        print $input->redirect($referer);
58
        print $input->redirect($referer);
57
        exit 0;
59
        exit 0;
58
    }
60
    }
59
}elsif($op && $op eq 'reopen') {
61
}
62
elsif ( $op && $op eq 'reopen' ) {
60
    ReopenInvoice($invoiceid);
63
    ReopenInvoice($invoiceid);
61
    my $referer = $input->param('referer');
64
    my $referer = $input->param('referer');
62
    if($referer) {
65
    if ($referer) {
63
        print $input->redirect($referer);
66
        print $input->redirect($referer);
64
        exit 0;
67
        exit 0;
65
    }
68
    }
66
}elsif($op && $op eq 'mod') {
69
}
67
    my $shipmentdate = $input->param('shipmentdate');
70
elsif ( $op && $op eq 'mod' ) {
68
    my $billingdate = $input->param('billingdate');
71
    my $shipmentdate       = $input->param('shipmentdate');
69
    my $shipmentcost = $input->param('shipmentcost');
72
    my $billingdate        = $input->param('billingdate');
73
    my $shipmentcost       = $input->param('shipmentcost');
70
    my $shipment_budget_id = $input->param('shipment_budget_id');
74
    my $shipment_budget_id = $input->param('shipment_budget_id');
71
    ModInvoice(
75
    ModInvoice(
72
        invoiceid => $invoiceid,
76
        invoiceid             => $invoiceid,
73
        shipmentdate   => C4::Dates->new($shipmentdate)->output("iso"),
77
        shipmentdate          => C4::Dates->new($shipmentdate)->output("iso"),
74
        billingdate   => C4::Dates->new($billingdate)->output("iso"),
78
        billingdate           => C4::Dates->new($billingdate)->output("iso"),
75
        shipmentcost  => $shipmentcost,
79
        shipmentcost          => $shipmentcost,
76
        shipmentcost_budgetid => $shipment_budget_id
80
        shipmentcost_budgetid => $shipment_budget_id
77
    );
81
    );
78
    $template->param(modified => 1);
82
    $template->param( modified => 1 );
79
}
83
}
80
84
81
my $details = GetInvoiceDetails($invoiceid);
85
my $details     = GetInvoiceDetails($invoiceid);
82
my $bookseller = GetBookSellerFromId($details->{booksellerid});
86
my $bookseller  = GetBookSellerFromId( $details->{booksellerid} );
83
my @orders_loop = ();
87
my @orders_loop = ();
84
my $orders = $details->{'orders'};
88
my $orders      = $details->{'orders'};
85
my $qty_total;
89
my $qty_total;
86
my @books_loop;
90
my @books_loop;
87
my @book_foot_loop;
91
my @book_foot_loop;
88
my %foot;
92
my %foot;
89
my $total_quantity = 0;
93
my $total_quantity = 0;
90
my $total_rrp = 0;
94
my $total_rrp      = 0;
91
my $total_est = 0;
95
my $total_est      = 0;
96
92
foreach my $order (@$orders) {
97
foreach my $order (@$orders) {
93
    my $line = get_infos( $order, $bookseller);
98
    my $line = get_infos( $order, $bookseller );
94
99
95
    $total_quantity += $$line{quantity};
100
    $total_quantity += $$line{quantity};
96
    $total_rrp += $order->{quantity} * $order->{rrp};
101
    $total_rrp      += $order->{quantity} * $order->{rrp};
97
    $total_est += $order->{quantity} * $order->{'ecost'};
102
    $total_est      += $order->{quantity} * $order->{'ecost'};
98
103
99
    my %row = (%$order, %$line);
104
    my %row = ( %$order, %$line );
100
    push @orders_loop, \%row;
105
    push @orders_loop, \%row;
101
}
106
}
102
107
103
my $gist = $bookseller->{gstrate} // C4::Context->preference("gist") // 0;
108
my $gist = $bookseller->{gstrate} // C4::Context->preference("gist") // 0;
104
my $discount = $bookseller->{'discount'} ? ($bookseller->{discount} / 100) : 0;
109
my $discount =
110
  $bookseller->{'discount'} ? ( $bookseller->{discount} / 100 ) : 0;
105
my $total_est_gste;
111
my $total_est_gste;
106
my $total_est_gsti;
112
my $total_est_gsti;
107
my $total_rrp_gsti; # RRP Total, GST included
113
my $total_rrp_gsti;    # RRP Total, GST included
108
my $total_rrp_gste; # RRP Total, GST excluded
114
my $total_rrp_gste;    # RRP Total, GST excluded
109
my $gist_est;
115
my $gist_est;
110
my $gist_rrp;
116
my $gist_rrp;
111
if ($gist){
117
if ($gist) {
118
112
    # if we have GST
119
    # if we have GST
113
    if ( $bookseller->{'listincgst'} ) {
120
    if ( $bookseller->{'listincgst'} ) {
121
114
        # if prices already includes GST
122
        # if prices already includes GST
115
123
116
        # we know $total_rrp_gsti
124
        # we know $total_rrp_gsti
117
        $total_rrp_gsti = $total_rrp;
125
        $total_rrp_gsti = $total_rrp;
126
118
        # and can reverse compute other values
127
        # and can reverse compute other values
119
        $total_rrp_gste = $total_rrp_gsti / ( $gist + 1 );
128
        $total_rrp_gste = $total_rrp_gsti / ( $gist + 1 );
120
129
121
        $gist_rrp       = $total_rrp_gsti - $total_rrp_gste;
130
        $gist_rrp       = $total_rrp_gsti - $total_rrp_gste;
122
        $total_est_gste = $total_rrp_gste - ( $total_rrp_gste * $discount );
131
        $total_est_gste = $total_rrp_gste - ( $total_rrp_gste * $discount );
123
        $total_est_gsti = $total_est;
132
        $total_est_gsti = $total_est;
124
    } else {
133
    }
134
    else {
125
        # if prices does not include GST
135
        # if prices does not include GST
126
136
127
        # then we use the common way to compute other values
137
        # then we use the common way to compute other values
Lines 130-163 if ($gist){ Link Here
130
        $total_rrp_gsti = $total_rrp_gste + $gist_rrp;
140
        $total_rrp_gsti = $total_rrp_gste + $gist_rrp;
131
        $total_est_gste = $total_est;
141
        $total_est_gste = $total_est;
132
        $total_est_gsti = $total_rrp_gsti - ( $total_rrp_gsti * $discount );
142
        $total_est_gsti = $total_rrp_gsti - ( $total_rrp_gsti * $discount );
133
   }
143
    }
134
   $gist_est = $gist_rrp - ( $gist_rrp * $discount );
144
    $gist_est = $gist_rrp - ( $gist_rrp * $discount );
135
} else {
145
}
146
else {
136
    $total_rrp_gste = $total_rrp_gsti = $total_rrp;
147
    $total_rrp_gste = $total_rrp_gsti = $total_rrp;
137
    $total_est_gste = $total_est_gsti = $total_est;
148
    $total_est_gste = $total_est_gsti = $total_est;
138
    $gist_rrp = $gist_est = 0;
149
    $gist_rrp       = $gist_est       = 0;
139
}
150
}
140
my $total_gsti_shipment = $total_est_gsti + $details->{shipmentcost};
151
my $total_gsti_shipment = $total_est_gsti + $details->{shipmentcost};
141
152
142
my $format = "%.2f";
153
my $format = "%.2f";
143
$template->param(
154
$template->param(
144
    total_rrp_gste => sprintf($format, $total_rrp_gste),
155
    total_rrp_gste      => sprintf( $format, $total_rrp_gste ),
145
    total_rrp_gsti => sprintf($format, $total_rrp_gsti),
156
    total_rrp_gsti      => sprintf( $format, $total_rrp_gsti ),
146
    total_est_gste => sprintf($format, $total_est_gste),
157
    total_est_gste      => sprintf( $format, $total_est_gste ),
147
    total_est_gsti => sprintf($format, $total_est_gsti),
158
    total_est_gsti      => sprintf( $format, $total_est_gsti ),
148
    gist_rrp => sprintf($format, $gist_rrp),
159
    gist_rrp            => sprintf( $format, $gist_rrp ),
149
    gist_est => sprintf($format, $gist_est),
160
    gist_est            => sprintf( $format, $gist_est ),
150
    total_gsti_shipment => sprintf($format, $total_gsti_shipment),
161
    total_gsti_shipment => sprintf( $format, $total_gsti_shipment ),
151
    gist => sprintf($format, $gist * 100),
162
    gist                => sprintf( $format, $gist * 100 ),
152
);
163
);
153
164
154
my $budgets = GetBudgets();
165
my $budgets = GetBudgets();
155
my @budgets_loop;
166
my @budgets_loop;
156
my $shipmentcost_budgetid = $details->{shipmentcost_budgetid};
167
my $shipmentcost_budgetid = $details->{shipmentcost_budgetid};
157
foreach my $budget (@$budgets) {
168
foreach my $budget (@$budgets) {
158
    next unless CanUserUseBudget($loggedinuser, $budget, $flags);
169
    next unless CanUserUseBudget( $loggedinuser, $budget, $flags );
159
    my %line = %{ $budget };
170
    my %line = %{$budget};
160
    if($shipmentcost_budgetid and $budget->{budget_id} == $shipmentcost_budgetid) {
171
    if (    $shipmentcost_budgetid
172
        and $budget->{budget_id} == $shipmentcost_budgetid )
173
    {
161
        $line{selected} = 1;
174
        $line{selected} = 1;
162
    }
175
    }
163
    push @budgets_loop, \%line;
176
    push @budgets_loop, \%line;
Lines 172-199 $template->param( Link Here
172
    shipmentdate     => $details->{'shipmentdate'},
185
    shipmentdate     => $details->{'shipmentdate'},
173
    billingdate      => $details->{'billingdate'},
186
    billingdate      => $details->{'billingdate'},
174
    invoiceclosedate => $details->{'closedate'},
187
    invoiceclosedate => $details->{'closedate'},
175
    shipmentcost     => sprintf($format, $details->{'shipmentcost'} || 0),
188
    shipmentcost     => sprintf( $format, $details->{'shipmentcost'} || 0 ),
176
    orders_loop      => \@orders_loop,
189
    orders_loop      => \@orders_loop,
177
    total_quantity   => $total_quantity,
190
    total_quantity   => $total_quantity,
178
    invoiceincgst    => $bookseller->{invoiceincgst},
191
    invoiceincgst    => $bookseller->{invoiceincgst},
179
    currency         => $bookseller->{listprice},
192
    currency         => $bookseller->{listprice},
180
    DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
193
    DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
181
    budgets_loop     => \@budgets_loop,
194
    budgets_loop             => \@budgets_loop,
182
);
195
);
183
196
184
sub get_infos {
197
sub get_infos {
185
    my $order = shift;
198
    my $order      = shift;
186
    my $bookseller = shift;
199
    my $bookseller = shift;
187
    my $qty = $order->{'quantity'} || 0;
200
    my $qty        = $order->{'quantity'} || 0;
188
    if ( !defined $order->{quantityreceived} ) {
201
    if ( !defined $order->{quantityreceived} ) {
189
        $order->{quantityreceived} = 0;
202
        $order->{quantityreceived} = 0;
190
    }
203
    }
191
    my $budget = GetBudget( $order->{'budget_id'} );
204
    my $budget = GetBudget( $order->{'budget_id'} );
192
205
193
    my %line = %{ $order };
206
    my %line = %{$order};
194
    $line{order_received} = ( $qty == $order->{'quantityreceived'} );
207
    $line{order_received} = ( $qty == $order->{'quantityreceived'} );
195
    $line{budget_name}    = $budget->{budget_name};
208
    $line{budget_name}    = $budget->{budget_name};
196
    $line{total} = $qty * $order->{ecost};
209
    $line{total}          = $qty * $order->{ecost};
197
210
198
    if ( $line{uncertainprice} ) {
211
    if ( $line{uncertainprice} ) {
199
        $line{rrp} .= ' (Uncertain)';
212
        $line{rrp} .= ' (Uncertain)';
Lines 203-209 sub get_infos { Link Here
203
        my $seriestitle = $order->{'seriestitle'};
216
        my $seriestitle = $order->{'seriestitle'};
204
        $line{'title'} .= " / $seriestitle" if $seriestitle;
217
        $line{'title'} .= " / $seriestitle" if $seriestitle;
205
        $line{'title'} .= " / $volume"      if $volume;
218
        $line{'title'} .= " / $volume"      if $volume;
206
    } else {
219
    }
220
    else {
207
        $line{'title'} = "Deleted bibliographic notice, can't find title.";
221
        $line{'title'} = "Deleted bibliographic notice, can't find title.";
208
    }
222
    }
209
223
(-)a/acqui/invoices.pl (-63 / +63 lines)
Lines 38-85 use C4::Bookseller qw/GetBookSeller/; Link Here
38
use C4::Branch;
38
use C4::Branch;
39
39
40
my $input = new CGI;
40
my $input = new CGI;
41
my ($template, $loggedinuser, $cookie, $flags) = get_template_and_user( {
41
my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user(
42
    template_name   => 'acqui/invoices.tmpl',
42
    {
43
    query           => $input,
43
        template_name   => 'acqui/invoices.tmpl',
44
    type            => 'intranet',
44
        query           => $input,
45
    authnotrequired => 0,
45
        type            => 'intranet',
46
    flagsrequired   => { 'acquisition' => '*' },
46
        authnotrequired => 0,
47
    debug           => 1,
47
        flagsrequired   => { 'acquisition' => '*' },
48
} );
48
        debug           => 1,
49
49
    }
50
my $invoicenumber   = $input->param('invoicenumber');
50
);
51
my $supplier        = $input->param('supplier');
51
52
my $invoicenumber    = $input->param('invoicenumber');
53
my $supplier         = $input->param('supplier');
52
my $shipmentdatefrom = $input->param('shipmentdatefrom');
54
my $shipmentdatefrom = $input->param('shipmentdatefrom');
53
my $shipmentdateto  = $input->param('shipmentdateto');
55
my $shipmentdateto   = $input->param('shipmentdateto');
54
my $billingdatefrom = $input->param('billingdatefrom');
56
my $billingdatefrom  = $input->param('billingdatefrom');
55
my $billingdateto   = $input->param('billingdateto');
57
my $billingdateto    = $input->param('billingdateto');
56
my $isbneanissn     = $input->param('isbneanissn');
58
my $isbneanissn      = $input->param('isbneanissn');
57
my $title           = $input->param('title');
59
my $title            = $input->param('title');
58
my $author          = $input->param('author');
60
my $author           = $input->param('author');
59
my $publisher       = $input->param('publisher');
61
my $publisher        = $input->param('publisher');
60
my $publicationyear = $input->param('publicationyear');
62
my $publicationyear  = $input->param('publicationyear');
61
my $branch          = $input->param('branch');
63
my $branch           = $input->param('branch');
62
my $op              = $input->param('op');
64
my $op               = $input->param('op');
63
65
64
my @results_loop = ();
66
my @results_loop = ();
65
if($op and $op eq "do_search") {
67
if ( $op and $op eq "do_search" ) {
66
    my $shipmentdatefrom_iso = C4::Dates->new($shipmentdatefrom)->output("iso");
68
    my $shipmentdatefrom_iso = C4::Dates->new($shipmentdatefrom)->output("iso");
67
    my $shipmentdateto_iso = C4::Dates->new($shipmentdateto)->output("iso");
69
    my $shipmentdateto_iso   = C4::Dates->new($shipmentdateto)->output("iso");
68
    my $billingdatefrom_iso = C4::Dates->new($billingdatefrom)->output("iso");
70
    my $billingdatefrom_iso  = C4::Dates->new($billingdatefrom)->output("iso");
69
    my $billingdateto_iso = C4::Dates->new($billingdateto)->output("iso");
71
    my $billingdateto_iso    = C4::Dates->new($billingdateto)->output("iso");
70
    my @invoices = GetInvoices(
72
    my @invoices             = GetInvoices(
71
        invoicenumber => $invoicenumber,
73
        invoicenumber    => $invoicenumber,
72
        suppliername => $supplier,
74
        suppliername     => $supplier,
73
        shipmentdatefrom => $shipmentdatefrom_iso,
75
        shipmentdatefrom => $shipmentdatefrom_iso,
74
        shipmentdateto => $shipmentdateto_iso,
76
        shipmentdateto   => $shipmentdateto_iso,
75
        billingdatefrom => $billingdatefrom_iso,
77
        billingdatefrom  => $billingdatefrom_iso,
76
        billingdateto => $billingdateto_iso,
78
        billingdateto    => $billingdateto_iso,
77
        isbneanissn => $isbneanissn,
79
        isbneanissn      => $isbneanissn,
78
        title => $title,
80
        title            => $title,
79
        author => $author,
81
        author           => $author,
80
        publisher => $publisher,
82
        publisher        => $publisher,
81
        publicationyear => $publicationyear,
83
        publicationyear  => $publicationyear,
82
        branchcode => $branch
84
        branchcode       => $branch
83
    );
85
    );
84
    foreach (@invoices) {
86
    foreach (@invoices) {
85
        my %row = (
87
        my %row = (
Lines 90-110 if($op and $op eq "do_search") { Link Here
90
            receivedbiblios => $_->{receivedbiblios},
92
            receivedbiblios => $_->{receivedbiblios},
91
            receiveditems   => $_->{receiveditems},
93
            receiveditems   => $_->{receiveditems},
92
            subscriptionid  => $_->{subscriptionid},
94
            subscriptionid  => $_->{subscriptionid},
93
            closedate => $_->{closedate},
95
            closedate       => $_->{closedate},
94
        );
96
        );
95
        push @results_loop, \%row;
97
        push @results_loop, \%row;
96
    }
98
    }
97
}
99
}
98
100
99
100
# Build suppliers list
101
# Build suppliers list
101
my @suppliers = GetBookSeller(undef);
102
my @suppliers      = GetBookSeller(undef);
102
my @suppliers_loop = ();
103
my @suppliers_loop = ();
103
my $suppliername;
104
my $suppliername;
104
foreach (@suppliers) {
105
foreach (@suppliers) {
105
    my $selected = 0;
106
    my $selected = 0;
106
    if ($supplier && $supplier == $_->{'id'}) {
107
    if ( $supplier && $supplier == $_->{'id'} ) {
107
        $selected = 1;
108
        $selected     = 1;
108
        $suppliername = $_->{'name'};
109
        $suppliername = $_->{'name'};
109
    }
110
    }
110
    my %row = (
111
    my %row = (
Lines 116-128 foreach (@suppliers) { Link Here
116
}
117
}
117
118
118
# Build branches list
119
# Build branches list
119
my $branches = GetBranches();
120
my $branches      = GetBranches();
120
my @branches_loop = ();
121
my @branches_loop = ();
121
my $branchname;
122
my $branchname;
122
foreach (sort keys %$branches) {
123
foreach ( sort keys %$branches ) {
123
    my $selected = 0;
124
    my $selected = 0;
124
    if ($branch && $branch eq $_) {
125
    if ( $branch && $branch eq $_ ) {
125
        $selected = 1;
126
        $selected   = 1;
126
        $branchname = $branches->{$_}->{'branchname'};
127
        $branchname = $branches->{$_}->{'branchname'};
127
    }
128
    }
128
    my %row = (
129
    my %row = (
Lines 134-155 foreach (sort keys %$branches) { Link Here
134
}
135
}
135
136
136
$template->param(
137
$template->param(
137
    do_search       => ($op and $op eq "do_search") ? 1 : 0,
138
    do_search => ( $op and $op eq "do_search" ) ? 1 : 0,
138
    results_loop    => \@results_loop,
139
    results_loop             => \@results_loop,
139
    invoicenumber   => $invoicenumber,
140
    invoicenumber            => $invoicenumber,
140
    supplier        => $supplier,
141
    supplier                 => $supplier,
141
    suppliername    => $suppliername,
142
    suppliername             => $suppliername,
142
    billingdatefrom => $billingdatefrom,
143
    billingdatefrom          => $billingdatefrom,
143
    billingdateto   => $billingdateto,
144
    billingdateto            => $billingdateto,
144
    isbneanissn     => $isbneanissn,
145
    isbneanissn              => $isbneanissn,
145
    title           => $title,
146
    title                    => $title,
146
    author          => $author,
147
    author                   => $author,
147
    publisher       => $publisher,
148
    publisher                => $publisher,
148
    publicationyear => $publicationyear,
149
    publicationyear          => $publicationyear,
149
    branch          => $branch,
150
    branch                   => $branch,
150
    branchname      => $branchname,
151
    branchname               => $branchname,
151
    suppliers_loop  => \@suppliers_loop,
152
    suppliers_loop           => \@suppliers_loop,
152
    branches_loop   => \@branches_loop,
153
    branches_loop            => \@branches_loop,
153
    DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
154
    DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
154
);
155
);
155
156
156
- 

Return to bug 5339