Die Fehlermeldung "Customer not on file or locked!" übersetzt ausgeben.
[kivitendo-erp.git] / bin / mozilla / arap.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 #=====================================================================
8 # SQL-Ledger Accounting
9 # Copyright (c) 2002
10 #
11 #  Author: Dieter Simader
12 #   Email: dsimader@sql-ledger.org
13 #     Web: http://www.sql-ledger.org
14 #
15 #
16 # This program is free software; you can redistribute it and/or modify
17 # it under the terms of the GNU General Public License as published by
18 # the Free Software Foundation; either version 2 of the License, or
19 # (at your option) any later version.
20 #
21 # This program is distributed in the hope that it will be useful,
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24 # GNU General Public License for more details.
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write to the Free Software
27 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #======================================================================
29 #
30 # common routines for gl, ar, ap, is, ir, oe
31 #
32
33 # any custom scripts for this one
34 if (-f "$form->{path}/custom_arap.pl") {
35   eval { require "$form->{path}/custom_arap.pl"; };
36 }
37 if (-f "$form->{path}/$form->{login}_arap.pl") {
38   eval { require "$form->{path}/$form->{login}_arap.pl"; };
39 }
40
41 1;
42
43 # end of main
44
45 sub check_name {
46   $lxdebug->enter_sub();
47
48   my ($name) = @_;
49
50   my ($new_name, $new_id) = split /--/, $form->{$name};
51   my $i = 0;
52   # if we use a selection
53   if ($form->{"select$name"}) {
54     if ($form->{"old$name"} ne $form->{$name}) {
55
56       # this is needed for is, ir and oe
57       $form->{update} = 0;
58       # for credit calculations
59       $form->{oldinvtotal}  = 0;
60       $form->{oldtotalpaid} = 0;
61       $form->{calctax}      = 1;
62
63       $form->{"${name}_id"} = $new_id;
64
65       IS->get_customer(\%myconfig, \%$form) if ($name eq 'customer');
66       IR->get_vendor(\%myconfig, \%$form) if ($name eq 'vendor');
67
68       $form->{$name} = $form->{"old$name"} = "$new_name--$new_id";
69
70       $i = 1;
71     }
72   } else {
73
74     # check name, combine name and id
75     if ($form->{"old$name"} ne qq|$form->{$name}--$form->{"${name}_id"}|) {
76
77       # this is needed for is, ir and oe
78       $form->{update} = 0;
79
80       # for credit calculations
81       $form->{oldinvtotal}  = 0;
82       $form->{oldtotalpaid} = 0;
83       $form->{calctax}      = 1;
84
85       # return one name or a list of names in $form->{name_list}
86       if (($i = $form->get_name(\%myconfig, $name)) > 1) {
87         &select_name($name);
88         exit;
89       }
90
91       if ($i == 1) {
92
93         # we got one name
94         $form->{"${name}_id"} = $form->{name_list}[0]->{id};
95         $form->{$name}        = $form->{name_list}[0]->{name};
96         $form->{"old$name"}   = qq|$form->{$name}--$form->{"${name}_id"}|;
97
98         IS->get_customer(\%myconfig, \%$form) if ($name eq 'customer');
99         IR->get_vendor(\%myconfig, \%$form) if ($name eq 'vendor');
100
101       } else {
102
103         # name is not on file
104         # $locale->text('Customer not on file or locked!')
105         # $locale->text('Vendor not on file or locked!')
106         $msg = ucfirst $name . " not on file or locked!";
107         $form->error($locale->text($msg));
108       }
109     }
110   }
111   $form->language_payment(\%myconfig);
112
113   $lxdebug->leave_sub();
114
115   return $i;
116 }
117
118 # $locale->text('Customer not on file!')
119 # $locale->text('Vendor not on file!')
120
121 sub select_name {
122   $lxdebug->enter_sub();
123
124   my ($table) = @_;
125
126   @column_index = qw(ndx name address);
127
128   $label             = ucfirst $table;
129   $column_data{ndx}  = qq|<th>&nbsp;</th>|;
130   $column_data{name} =
131     qq|<th class=listheading>| . $locale->text($label) . qq|</th>|;
132   $column_data{address} =
133     qq|<th class=listheading>| . $locale->text('Address') . qq|</th>|;
134
135   # list items with radio button on a form
136   $form->header;
137
138   $title = $locale->text('Select from one of the names below');
139
140   print qq|
141 <body>
142
143 <form method=post action=$form->{script}>
144
145 <table width=100%>
146   <tr>
147     <th class=listtop>$title</th>
148   </tr>
149   <tr space=5></tr>
150   <tr>
151     <td>
152       <table width=100%>
153         <tr class=listheading>|;
154
155   map { print "\n$column_data{$_}" } @column_index;
156
157   print qq|
158         </tr>
159 |;
160
161   my $i = 0;
162   foreach $ref (@{ $form->{name_list} }) {
163     $checked = ($i++) ? "" : "checked";
164
165     $ref->{name} =~ s/\"/&quot;/g;
166
167     $column_data{ndx} =
168       qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|;
169     $column_data{name} =
170       qq|<td><input name="new_name_$i" type=hidden value="$ref->{name}">$ref->{name}</td>|;
171     $column_data{address} = qq|<td>$ref->{address}&nbsp;</td>|;
172
173     $j++;
174     $j %= 2;
175     print qq|
176         <tr class=listrow$j>|;
177
178     map { print "\n$column_data{$_}" } @column_index;
179
180     print qq|
181         </tr>
182
183 <input name="new_id_$i" type=hidden value=$ref->{id}>
184
185 |;
186
187   }
188
189   print qq|
190       </table>
191     </td>
192   </tr>
193   <tr>
194     <td><hr size=3 noshade></td>
195   </tr>
196 </table>
197
198 <input name=lastndx type=hidden value=$i>
199
200 |;
201
202   # delete variables
203   map { delete $form->{$_} } qw(action name_list header);
204
205   # save all other form variables
206   foreach $key (keys %${form}) {
207     $form->{$key} =~ s/\"/&quot;/g;
208     print qq|<input name=$key type=hidden value="$form->{$key}">\n|;
209   }
210
211   print qq|
212 <input type=hidden name=nextsub value=name_selected>
213
214 <input type=hidden name=vc value=$table>
215 <br>
216 <input class=submit type=submit name=action value="|
217     . $locale->text('Continue') . qq|">
218 </form>
219
220 </body>
221 </html>
222 |;
223
224   $lxdebug->leave_sub();
225 }
226
227 sub name_selected {
228   $lxdebug->enter_sub();
229
230   # replace the variable with the one checked
231
232   # index for new item
233   $i = $form->{ndx};
234
235   $form->{ $form->{vc} }    = $form->{"new_name_$i"};
236   $form->{"$form->{vc}_id"} = $form->{"new_id_$i"};
237   $form->{"old$form->{vc}"} =
238     qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
239
240   # delete all the new_ variables
241   for $i (1 .. $form->{lastndx}) {
242     map { delete $form->{"new_${_}_$i"} } qw(id name);
243   }
244
245   map { delete $form->{$_} } qw(ndx lastndx nextsub);
246
247   IS->get_customer(\%myconfig, \%$form) if ($form->{vc} eq 'customer');
248   IR->get_vendor(\%myconfig, \%$form) if ($form->{vc} eq 'vendor');
249
250   &update(1);
251
252   $lxdebug->leave_sub();
253 }
254
255 sub add_transaction {
256   $lxdebug->enter_sub();
257
258   my ($module) = @_;
259
260   delete $form->{script};
261   $form->{action} = "add";
262   $form->{type}   = "invoice" if $module =~ /(is|ir)/;
263
264   $form->{callback} = $form->escape($form->{callback}, 1);
265   map { $argv .= "$_=$form->{$_}&" } keys %$form;
266
267   $form->{callback} = "$module.pl?$argv";
268
269   $form->redirect;
270
271   $lxdebug->leave_sub();
272 }
273
274 sub check_project {
275   $lxdebug->enter_sub();
276
277   for $i (1 .. $form->{rowcount}) {
278     my $suffix = $i ? "_$i" : "";
279     my $prefix = $i ? "" : "global";
280     $form->{"${prefix}project_id${suffix}"} = "" unless $form->{"${prefix}projectnumber$suffix"};
281     if ($form->{"${prefix}projectnumber${suffix}"} ne $form->{"old${prefix}projectnumber${suffix}"}) {
282       if ($form->{"${prefix}projectnumber${suffix}"}) {
283
284         # get new project
285         $form->{projectnumber} = $form->{"${prefix}projectnumber${suffix}"};
286         if (($rows = PE->projects(\%myconfig, $form)) > 1) {
287
288           # check form->{project_list} how many there are
289           $form->{rownumber} = $i;
290           &select_project($i ? undef : 1);
291           exit;
292         }
293
294         if ($rows == 1) {
295           $form->{"${prefix}project_id${suffix}"} =
296             $form->{project_list}->[0]->{id};
297           $form->{"${prefix}projectnumber${suffix}"} =
298             $form->{project_list}->[0]->{projectnumber};
299           $form->{"old${prefix}projectnumber${suffix}"} =
300             $form->{project_list}->[0]->{projectnumber};
301         } else {
302
303           # not on file
304           $form->error($locale->text('Project not on file!'));
305         }
306       } else {
307         $form->{"old${prefix}projectnumber${suffix}"} = "";
308       }
309     }
310   }
311
312   $lxdebug->leave_sub();
313 }
314
315 sub select_project {
316   $lxdebug->enter_sub();
317
318   my ($is_global) = @_;
319
320   @column_index = qw(ndx projectnumber description);
321
322   $column_data{ndx}           = qq|<th>&nbsp;</th>|;
323   $column_data{projectnumber} = qq|<th>| . $locale->text('Number') . qq|</th>|;
324   $column_data{description}   =
325     qq|<th>| . $locale->text('Description') . qq|</th>|;
326
327   # list items with radio button on a form
328   $form->header;
329
330   $title = $locale->text('Select from one of the projects below');
331
332   print qq|
333 <body>
334
335 <form method=post action=$form->{script}>
336
337 <input type=hidden name=rownumber value=$form->{rownumber}>
338
339 <table width=100%>
340   <tr>
341     <th class=listtop>$title</th>
342   </tr>
343   <tr space=5></tr>
344   <tr>
345     <td>
346       <table width=100%>
347         <tr class=listheading>|;
348
349   map { print "\n$column_data{$_}" } @column_index;
350
351   print qq|
352         </tr>
353 |;
354
355   my $i = 0;
356   foreach $ref (@{ $form->{project_list} }) {
357     $checked = ($i++) ? "" : "checked";
358
359     $ref->{name} =~ s/\"/&quot;/g;
360
361     $column_data{ndx} =
362       qq|<td><input name=ndx class=radio type=radio value=$i $checked></td>|;
363     $column_data{projectnumber} =
364       qq|<td><input name="new_projectnumber_$i" type=hidden value="$ref->{projectnumber}">$ref->{projectnumber}</td>|;
365     $column_data{description} = qq|<td>$ref->{description}</td>|;
366
367     $j++;
368     $j %= 2;
369     print qq|
370         <tr class=listrow$j>|;
371
372     map { print "\n$column_data{$_}" } @column_index;
373
374     print qq|
375         </tr>
376
377 <input name="new_id_$i" type=hidden value=$ref->{id}>
378
379 |;
380
381   }
382
383   print qq|
384       </table>
385     </td>
386   </tr>
387   <tr>
388     <td><hr size=3 noshade></td>
389   </tr>
390 </table>
391
392 <input name=lastndx type=hidden value=$i>
393
394 |;
395
396   # delete action variable
397   map { delete $form->{$_} } qw(action project_list header update);
398
399   # save all other form variables
400   foreach $key (keys %${form}) {
401     $form->{$key} =~ s/\"/&quot;/g;
402     print qq|<input name=$key type=hidden value="$form->{$key}">\n|;
403   }
404
405   print qq|
406 <input type="hidden" name="is_global" value="$is_global">
407 <input type=hidden name=nextsub value=project_selected>
408
409 <br>
410 <input class=submit type=submit name=action value="|
411     . $locale->text('Continue') . qq|">
412 </form>
413
414 </body>
415 </html>
416 |;
417
418   $lxdebug->leave_sub();
419 }
420
421 sub project_selected {
422   $lxdebug->enter_sub();
423
424   # replace the variable with the one checked
425
426   # index for new item
427   $i = $form->{ndx};
428
429   my $prefix = $form->{"is_global"} ? "global" : "";
430   my $suffix = $form->{"is_global"} ? "" : "_$form->{rownumber}";
431
432   $form->{"${prefix}projectnumber${suffix}"} =
433     $form->{"new_projectnumber_$i"};
434   $form->{"old${prefix}projectnumber${suffix}"} =
435     $form->{"new_projectnumber_$i"};
436   $form->{"${prefix}project_id${suffix}"} = $form->{"new_id_$i"};
437
438   # delete all the new_ variables
439   for $i (1 .. $form->{lastndx}) {
440     map { delete $form->{"new_${_}_$i"} } qw(id projectnumber description);
441   }
442
443   map { delete $form->{$_} } qw(ndx lastndx nextsub is_global);
444
445   if ($form->{update}) {
446     &{ $form->{update} };
447   } else {
448     &update;
449   }
450
451   $lxdebug->leave_sub();
452 }
453
454 sub continue       { &{ $form->{nextsub} } }
455 sub gl_transaction { &add }
456 sub ar_transaction { &add_transaction('ar') }
457 sub ap_transaction { &add_transaction('ap') }
458 sub sales_invoice  { &add_transaction('is') }
459 sub vendor_invoice { &add_transaction('ir') }
460