epic-ts
[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 List::Util qw(max);
38
39 use SL::Common;
40 use SL::CT;
41 use SL::IC;
42
43 require "bin/mozilla/common.pl";
44
45 use strict;
46
47 # any custom scripts for this one
48 if (-f "bin/mozilla/custom_invoice_io.pl") {
49   eval { require "bin/mozilla/custom_invoice_io.pl"; };
50 }
51 if (-f "bin/mozilla/$::myconfig{login}_invoice_io.pl") {
52   eval { require "bin/mozilla/$::myconfig{login}_invoice_io.pl"; };
53 }
54
55 1;
56
57 # end of main
58
59 # this is for our long dates
60 # $locale->text('January')
61 # $locale->text('February')
62 # $locale->text('March')
63 # $locale->text('April')
64 # $locale->text('May ')
65 # $locale->text('June')
66 # $locale->text('July')
67 # $locale->text('August')
68 # $locale->text('September')
69 # $locale->text('October')
70 # $locale->text('November')
71 # $locale->text('December')
72
73 # this is for our short month
74 # $locale->text('Jan')
75 # $locale->text('Feb')
76 # $locale->text('Mar')
77 # $locale->text('Apr')
78 # $locale->text('May')
79 # $locale->text('Jun')
80 # $locale->text('Jul')
81 # $locale->text('Aug')
82 # $locale->text('Sep')
83 # $locale->text('Oct')
84 # $locale->text('Nov')
85 # $locale->text('Dec')
86 use SL::IS;
87 use SL::PE;
88 use SL::AM;
89 use Data::Dumper;
90
91 sub display_form {
92   $main::lxdebug->enter_sub();
93
94   my $form     = $main::form;
95   my %myconfig = %main::myconfig;
96
97   $main::auth->assert('part_service_assembly_edit   | vendor_invoice_edit       | sales_order_edit    | invoice_edit |' .
98                 'request_quotation_edit       | sales_quotation_edit      | purchase_order_edit | '.
99                 'purchase_delivery_order_edit | sales_delivery_order_edit | part_service_assembly_details');
100
101   relink_accounts();
102   retrieve_partunits() if ($form->{type} =~ /_delivery_order$/);
103
104   my $new_rowcount = $form->{"rowcount"} * 1 + 1;
105   $form->{"project_id_${new_rowcount}"} = $form->{"globalproject_id"};
106
107   $form->language_payment(\%myconfig);
108
109   # if we have a display_form
110   if ($form->{display_form}) {
111     call_sub($form->{"display_form"});
112     ::end_of_request();
113   }
114
115   Common::webdav_folder($form);
116
117   #   if (   $form->{print_and_post}
118   #       && $form->{second_run}
119   #       && ($form->{action} eq "display_form")) {
120   #     for (keys %$form) { $old_form->{$_} = $form->{$_} }
121   #     $old_form->{rowcount}++;
122   #
123   #     #$form->{rowcount}--;
124   #     #$form->{rowcount}--;
125   #
126   #     $form->{print_and_post} = 0;
127   #
128   #     &print_form($old_form);
129   #     ::end_of_request();
130   #   }
131   #
132   #   $form->{action}   = "";
133   #   $form->{resubmit} = 0;
134   #
135   #   if ($form->{print_and_post} && !$form->{second_run}) {
136   #     $form->{second_run} = 1;
137   #     $form->{action}     = "display_form";
138   #     $form->{rowcount}--;
139   #     my $rowcount = $form->{rowcount};
140   #
141   #     $form->{resubmit} = 1;
142   #
143   #   }
144   &form_header;
145
146   {
147     no strict 'refs';
148
149     my $numrows    = ++$form->{rowcount};
150     my $subroutine = "display_row";
151
152     if ($form->{item} =~ /(part|service)/) {
153       #set preisgruppenanzahl
154       $numrows    = $form->{price_rows};
155       $subroutine = "price_row";
156
157       &{$subroutine}($numrows);
158
159       $numrows    = ++$form->{makemodel_rows};
160       $subroutine = "makemodel_row";
161     }
162     if ($form->{item} eq 'assembly') {
163       $numrows    = $form->{price_rows};
164       $subroutine = "price_row";
165
166       &{$subroutine}($numrows);
167
168       $numrows    = ++$form->{makemodel_rows};
169       $subroutine = "makemodel_row";
170
171       # assemblies are built from components, they aren't purchased from a vendor
172       # also the lastcost_$i from makemodel conflicted with the component lastcost_$i
173       # so we don't need the makemodel rows for assemblies
174       # create makemodel rows
175       # &{$subroutine}($numrows);
176
177       $numrows    = ++$form->{assembly_rows};
178       $subroutine = "assembly_row";
179     }
180
181     # create rows
182     &{$subroutine}($numrows) if $numrows;
183   }
184
185   &form_footer;
186
187   $main::lxdebug->leave_sub();
188 }