Globale Variablen für Systemeinstellungen und Features nach %::lx_office_conf verschoben
[kivitendo-erp.git] / bin / mozilla / invoice_io.pl
1 #=====================================================================
2 # LX-Office ERP
3 # Copyright (C) 2004
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
6 #############################################################################
7 # Veraendert 2005-01-05 - Marco Welter <mawe@linux-studio.de> - Neue Optik  #
8 #############################################################################
9 # SQL-Ledger, Accounting
10 # Copyright (c) 1998-2002
11 #
12 #  Author: Dieter Simader
13 #   Email: dsimader@sql-ledger.org
14 #     Web: http://www.sql-ledger.org
15 #
16 #
17 # This program is free software; you can redistribute it and/or modify
18 # it under the terms of the GNU General Public License as published by
19 # the Free Software Foundation; either version 2 of the License, or
20 # (at your option) any later version.
21 #
22 # This program is distributed in the hope that it will be useful,
23 # but WITHOUT ANY WARRANTY; without even the implied warranty of
24 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25 # GNU General Public License for more details.
26 # You should have received a copy of the GNU General Public License
27 # along with this program; if not, write to the Free Software
28 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 #
30 #######################################################################
31 #
32 # common routines used in is, ir but not in oe
33 #
34 #######################################################################
35
36 use CGI;
37 use CGI::Ajax;
38 use List::Util qw(max);
39
40 use SL::Common;
41 use SL::CT;
42 use SL::IC;
43
44 require "bin/mozilla/common.pl";
45
46 use strict;
47
48 # any custom scripts for this one
49 if (-f "bin/mozilla/custom_invoice_io.pl") {
50   eval { require "bin/mozilla/custom_invoice_io.pl"; };
51 }
52 if (-f "bin/mozilla/$main::form->{login}_invoice_io.pl") {
53   eval { require "bin/mozilla/$main::form->{login}_invoice_io.pl"; };
54 }
55
56 1;
57
58 # end of main
59
60 # this is for our long dates
61 # $locale->text('January')
62 # $locale->text('February')
63 # $locale->text('March')
64 # $locale->text('April')
65 # $locale->text('May ')
66 # $locale->text('June')
67 # $locale->text('July')
68 # $locale->text('August')
69 # $locale->text('September')
70 # $locale->text('October')
71 # $locale->text('November')
72 # $locale->text('December')
73
74 # this is for our short month
75 # $locale->text('Jan')
76 # $locale->text('Feb')
77 # $locale->text('Mar')
78 # $locale->text('Apr')
79 # $locale->text('May')
80 # $locale->text('Jun')
81 # $locale->text('Jul')
82 # $locale->text('Aug')
83 # $locale->text('Sep')
84 # $locale->text('Oct')
85 # $locale->text('Nov')
86 # $locale->text('Dec')
87 use SL::IS;
88 use SL::PE;
89 use SL::AM;
90 use Data::Dumper;
91
92 sub set_pricegroup {
93   $main::lxdebug->enter_sub();
94
95   my $form     = $main::form;
96   my %myconfig = %main::myconfig;
97   my $locale   = $main::locale;
98
99   my $rowcount = shift;
100   for my $j (1 .. $rowcount) {
101     my $pricegroup_old = $form->{"pricegroup_old_$j"};
102     if ($form->{PRICES}{$j}) {
103       my $len    = 0;
104       my $prices = '<option value="--">' . $locale->text("none (pricegroup)") . '</option>';
105       my $price  = 0;
106       foreach my $item (@{ $form->{PRICES}{$j} }) {
107
108         #$price = $form->round_amount($myconfig,  $item->{price}, 5);
109         #$price = $form->format_amount($myconfig, $item->{price}, 2);
110         my $price         = $item->{price};
111         my $pricegroup_id = $item->{pricegroup_id};
112         my $pricegroup    = $item->{pricegroup};
113
114         # build drop down list for pricegroups
115         $prices .=
116           qq|<option value="$price--$pricegroup_id"$item->{selected}>$pricegroup</option>\n|;
117
118         $len += 1;
119
120         #        map {
121         #               $form->{"${_}_$j"} =
122         #               $form->format_amount(\%myconfig, $form->{"${_}_$j"})
123         #              } qw(sellprice price_new price_old);
124
125         # set new selectedpricegroup_id and prices for "Preis"
126         if ($item->{selected} && ($pricegroup_id != 0)) {
127           $form->{"pricegroup_old_$j"} = $pricegroup_id;
128           $form->{"price_new_$j"}      = $price;
129           # edit: don't change the sellprice here
130           # $form->{"sellprice_$j"}      = $price;   # this must only be updated for existing articles, not new ones
131         }
132         if ($pricegroup_id == 0) {
133           $form->{"price_new_$j"} = $form->{"sellprice_$j"};
134         }
135       }
136       $form->{"prices_$j"} = $prices;
137     }
138   }
139   $main::lxdebug->leave_sub();
140 }
141
142 sub display_form {
143   $main::lxdebug->enter_sub();
144
145   my $form     = $main::form;
146   my %myconfig = %main::myconfig;
147
148   $main::auth->assert('part_service_assembly_edit   | vendor_invoice_edit       | sales_order_edit    | invoice_edit |' .
149                 'request_quotation_edit       | sales_quotation_edit      | purchase_order_edit | '.
150                 'purchase_delivery_order_edit | sales_delivery_order_edit');
151
152   relink_accounts();
153   retrieve_partunits() if ($form->{type} =~ /_delivery_order$/);
154
155   my $new_rowcount = $form->{"rowcount"} * 1 + 1;
156   $form->{"project_id_${new_rowcount}"} = $form->{"globalproject_id"};
157
158   $form->language_payment(\%myconfig);
159
160   # if we have a display_form
161   if ($form->{display_form}) {
162     call_sub($form->{"display_form"});
163     ::end_of_request();
164   }
165
166   Common::webdav_folder($form);
167
168   #   if (   $form->{print_and_post}
169   #       && $form->{second_run}
170   #       && ($form->{action} eq "display_form")) {
171   #     for (keys %$form) { $old_form->{$_} = $form->{$_} }
172   #     $old_form->{rowcount}++;
173   #
174   #     #$form->{rowcount}--;
175   #     #$form->{rowcount}--;
176   #
177   #     $form->{print_and_post} = 0;
178   #
179   #     &print_form($old_form);
180   #     ::end_of_request();
181   #   }
182   #
183   #   $form->{action}   = "";
184   #   $form->{resubmit} = 0;
185   #
186   #   if ($form->{print_and_post} && !$form->{second_run}) {
187   #     $form->{second_run} = 1;
188   #     $form->{action}     = "display_form";
189   #     $form->{rowcount}--;
190   #     my $rowcount = $form->{rowcount};
191   #
192   #     # get pricegroups for parts
193   #     IS->get_pricegroups_for_parts(\%myconfig, \%$form);
194   #
195   #     # build up html code for prices_$i
196   #     set_pricegroup($rowcount);
197   #
198   #     $form->{resubmit} = 1;
199   #
200   #   }
201   &form_header;
202
203   {
204     no strict 'refs';
205
206     my $numrows    = ++$form->{rowcount};
207     my $subroutine = "display_row";
208
209     if ($form->{item} eq 'part') {
210
211       #set preisgruppenanzahl
212       $numrows    = $form->{price_rows};
213       $subroutine = "price_row";
214
215       &{$subroutine}($numrows);
216
217       $numrows    = ++$form->{makemodel_rows};
218       $subroutine = "makemodel_row";
219     }
220     if ($form->{item} eq 'assembly') {
221       $numrows    = $form->{price_rows};
222       $subroutine = "price_row";
223
224       &{$subroutine}($numrows);
225
226       $numrows    = ++$form->{makemodel_rows};
227       $subroutine = "makemodel_row";
228
229       # create makemodel rows
230       &{$subroutine}($numrows);
231
232       $numrows    = ++$form->{assembly_rows};
233       $subroutine = "assembly_row";
234     }
235     if ($form->{item} eq 'service') {
236       $numrows    = $form->{price_rows};
237       $subroutine = "price_row";
238
239       &{$subroutine}($numrows);
240
241       $numrows = 0;
242     }
243
244     # create rows
245     &{$subroutine}($numrows) if $numrows;
246   }
247
248   &form_footer;
249
250   $main::lxdebug->leave_sub();
251 }