1 #=====================================================================
4 # Based on SQL-Ledger Version 2.1.9
5 # Web http://www.lx-office.org
7 #=====================================================================
8 # SQL-Ledger, Accounting
9 # Copyright (c) 1998-2002
11 # Author: Dieter Simader
12 # Email: dsimader@sql-ledger.org
13 # Web: http://www.sql-ledger.org
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.
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 #======================================================================
30 # Inventory received module
32 #======================================================================
37 use List::Util qw(max);
39 require "bin/mozilla/io.pl";
40 require "bin/mozilla/invoice_io.pl";
41 require "bin/mozilla/arap.pl";
42 require "bin/mozilla/common.pl";
43 require "bin/mozilla/drafts.pl";
50 $lxdebug->enter_sub();
52 return $lxdebug->leave_sub() if (load_draft_maybe());
54 $form->{title} = $locale->text('Add Vendor Invoice');
60 $lxdebug->leave_sub();
64 $lxdebug->enter_sub();
67 $form->{javascript} = qq|<script type=text/javascript src=js/show_history.js></script>|;
68 #/show hhistory button
70 $form->{title} = $locale->text('Edit Vendor Invoice');
76 $lxdebug->leave_sub();
80 $lxdebug->enter_sub();
83 $form->{webdav} = $webdav;
84 $form->{jsscript} = 1;
86 $form->create_links("AP", \%myconfig, "vendor");
88 #quote all_vendor Bug 133
89 foreach $ref (@{ $form->{all_vendor} }) {
90 $ref->{name} = $form->quote($ref->{name});
93 if ($form->{all_vendor}) {
94 unless ($form->{vendor_id}) {
95 $form->{vendor_id} = $form->{all_vendor}->[0]->{id};
98 if ($form->{payment_id}) {
99 $payment_id = $form->{payment_id};
101 if ($form->{language_id}) {
102 $language_id = $form->{language_id};
104 if ($form->{taxzone_id}) {
105 $taxzone_id = $form->{taxzone_id};
108 $cp_id = $form->{cp_id};
109 IR->get_vendor(\%myconfig, \%$form);
110 IR->retrieve_invoice(\%myconfig, \%$form);
111 $form->{cp_id} = $cp_id;
114 $form->{payment_id} = $payment_id;
117 $form->{language_id} = $language_id;
120 $form->{taxzone_id} = $taxzone_id;
123 map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
125 $form->{oldvendor} = "$form->{vendor}--$form->{vendor_id}";
128 if ($form->{all_departments}) {
129 $form->{selectdepartment} = "<option>\n";
130 $form->{department} = "$form->{department}--$form->{department_id}";
133 $form->{selectdepartment} .=
134 "<option>$_->{description}--$_->{id}\n"
135 } (@{ $form->{all_departments} });
139 $form->{forex} = $form->{exchangerate};
140 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
142 foreach $key (keys %{ $form->{AP_links} }) {
144 foreach $ref (@{ $form->{AP_links}{$key} }) {
145 $form->{"select$key"} .= "<option>$ref->{accno}--$ref->{description}\n";
148 if ($key eq "AP_paid") {
149 for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
150 $form->{"AP_paid_$i"} =
151 "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
154 $form->{"paid_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{amount};
155 $form->{"datepaid_$i"} =
156 $form->{acc_trans}{$key}->[$i - 1]->{transdate};
157 $form->{"forex_$i"} = $form->{"exchangerate_$i"} =
158 $form->{acc_trans}{$key}->[$i - 1]->{exchangerate};
159 $form->{"source_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{source};
160 $form->{"memo_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{memo};
162 $form->{paidaccounts} = $i;
166 "$form->{acc_trans}{$key}->[0]->{accno}--$form->{acc_trans}{$key}->[0]->{description}";
171 $form->{paidaccounts} = 1 unless (exists $form->{paidaccounts});
173 $form->{AP} = $form->{AP_1} unless $form->{id};
176 ($form->datetonum($form->{invdate}, \%myconfig) <=
177 $form->datetonum($form->{closedto}, \%myconfig));
179 $lxdebug->leave_sub();
182 sub prepare_invoice {
183 $lxdebug->enter_sub();
187 map { $form->{$_} =~ s/\"/"/g } qw(invnumber ordnumber quonumber);
190 foreach $ref (@{ $form->{invoice_details} }) {
192 map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
194 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
196 $decimalplaces = ($dec > 2) ? $dec : 2;
198 $form->{"sellprice_$i"} =
199 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
202 (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
203 $dec_qty = length $dec_qty;
206 $form->format_amount(\%myconfig, ($form->{"qty_$i"} * -1), $dec_qty);
208 $form->{rowcount} = $i;
212 $lxdebug->leave_sub();
216 $lxdebug->enter_sub();
218 # set option selected
219 foreach $item (qw(AP vendor currency department)) {
220 $form->{"select$item"} =~ s/ selected//;
221 $form->{"select$item"} =~ s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
224 $form->{employee_id} = $form->{old_employee_id} if $form->{old_employee_id};
225 $form->{salesman_id} = $form->{old_salesman_id} if $form->{old_salesman_id};
226 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
227 $form->{radier} = ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
228 $form->{exchangerate} = $form->format_amount(\%myconfig, $form->{exchangerate});
229 $form->{creditlimit} = $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
230 $form->{creditremaining} = $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
233 if ($form->{currency} ne $form->{defaultcurrency}) {
234 if ($form->{forex}) {
235 $exchangerate .= qq| <th align=right nowrap>| . $locale->text('Exchangerate') . qq|</th>
236 <td>$form->{exchangerate}<input type=hidden name=exchangerate value=$form->{exchangerate}></td>\n|;
238 $exchangerate .= qq| <th align=right nowrap>| . $locale->text('Exchangerate') . qq|</th>
239 <td><input name=exchangerate size=10 value=$form->{exchangerate}></td>\n|;
242 $exchangerate .= qq| <input type=hidden name=forex value=$form->{forex}>\n|;
244 my @old_project_ids = ($form->{"globalproject_id"});
245 map { push @old_project_ids, $form->{"project_id_$_"} if $form->{"project_id_$_"}; } 1..$form->{"rowcount"};
247 $form->get_lists("contacts" => "ALL_CONTACTS",
248 "projects" => { "key" => "ALL_PROJECTS",
250 "old_id" => \@old_project_ids },
251 "taxzones" => "ALL_TAXZONES",
252 "employees" => "ALL_SALESMEN",
253 "currencies" => "ALL_CURRENCIES",
254 "vendors" => "ALL_VENDORS",
255 "price_factors" => "ALL_PRICE_FACTORS");
258 my @values = (undef);
259 foreach my $item (@{ $form->{"ALL_CONTACTS"} }) {
260 push(@values, $item->{"cp_id"});
261 $labels{$item->{"cp_id"}} = $item->{"cp_name"} . ($item->{"cp_abteilung"} ? " ($item->{cp_abteilung})" : "");
265 if (scalar @values > 1) {
268 <th align="right">| . $locale->text('Contact Person') . qq|</th>
269 <td>| . NTI($cgi->popup_menu('-name' => 'cp_id', '-values' => \@values, '-style' => 'width: 250px',
270 '-labels' => \%labels, '-default' => $form->{"cp_id"})) . qq|
277 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
278 push(@values, $item->{"id"});
279 $labels{$item->{"id"}} = $item->{"projectnumber"};
281 my $globalprojectnumber = NTI($cgi->popup_menu('-name' => 'globalproject_id', '-values' => \@values, '-labels' => \%labels,
282 '-default' => $form->{"globalproject_id"}));
287 foreach my $item (@{ $form->{"ALL_CURRENCIES"} }) {
288 push(@values, $item);
289 $labels{$item} = $item;
292 $form->{currency} = $form->{defaultcurrency} unless $form->{currency};
294 if (scalar @values) {
297 <th align="right">| . $locale->text('Currency') . qq|</th>
298 <td>| . NTI($cgi->popup_menu('-name' => 'currency', '-default' => $form->{"currency"},
299 '-values' => \@values, '-labels' => \%labels)) . qq|
307 foreach my $item (@{ $form->{"ALL_SALESMEN"} }) {
308 push(@values, $item->{"id"});
309 $labels{$item->{"id"}} = $item->{"name"};
313 <th align="right">| . $locale->text('Employee') . qq|</th>
314 <td>| . NTI($cgi->popup_menu('-name' => 'employee_id', '-default' => $form->{"employee_id"},
315 '-values' => \@values, '-labels' => \%labels)) . qq|
322 foreach my $item (@{ $form->{"ALL_VENDORS"} }) {
323 push(@values, $item->{name}.qq|--|.$item->{"id"});
324 $labels{$item->{name}.qq|--|.$item->{"id"}} = $item->{"name"};
327 $form->{selectvendor} = ($myconfig{vclimit} > scalar(@values));
330 <th align="right">| . $locale->text('Vendor') . qq|</th>
332 (($myconfig{vclimit} <= scalar(@values))
333 ? qq|<input type="text" value="| . H($form->{vendor}) . qq|" name="vendor">|
334 : (NTI($cgi->popup_menu('-name' => 'vendor', '-default' => $form->{oldvendor},
335 '-onChange' => 'document.getElementById(\'update_button\').click();',
336 '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px')))) . qq|
337 <input type="button" value="?" onclick="show_vc_details('vendor')">
342 foreach my $item (@{ $form->{"ALL_TAXZONES"} }) {
343 push(@values, $item->{"id"});
344 $labels{$item->{"id"}} = $item->{"description"};
347 if (!$form->{"id"}) {
350 <th align="right">| . $locale->text('Steuersatz') . qq|</th>
351 <td>| . NTI($cgi->popup_menu('-name' => 'taxzone_id', '-default' => $form->{"taxzone_id"},
352 '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px')) . qq|
358 <th align="right">| . $locale->text('Steuersatz') . qq|</th>
360 <input type="hidden" name="taxzone_id" value="| . H($form->{"taxzone_id"}) . qq|">
361 | . H($labels{$form->{"taxzone_id"}}) . qq|
368 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
369 <td colspan="3"><select name="department" style="width: 250px">$form->{selectdepartment}</select>
370 <input type="hidden" name="selectdepartment" value="$form->{selectdepartment}">
372 </tr>\n| if $form->{selectdepartment};
374 $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
376 # use JavaScript Calendar or not
377 $form->{jsscript} = 1;
381 <td><input name=invdate id=invdate size=11 title="$myconfig{dateformat}" value="$form->{invdate}" onBlur=\"check_right_date_format(this)\">
382 <input type=button name=invdate id="trigger1" value=| . $locale->text('button') . qq|></td>\n|;
384 <td width="13"><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value="$form->{duedate}" onBlur=\"check_right_date_format(this)\">
385 <input type=button name=duedate id="trigger2" value=| . $locale->text('button') . qq|></td></td>\n|;
389 Form->write_trigger(\%myconfig, "2",
390 "invdate", "BL", "trigger1",
391 "duedate", "BL", "trigger2");
393 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_form_details.js"></script>|;
394 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
395 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_vc_details.js"></script>|;
397 $jsscript .= $form->write_trigger(\%myconfig, 2, "orddate", "BL", "trigger_orddate", "quodate", "BL", "trigger_quodate");
400 $onload = qq|focus()|;
401 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
402 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
404 <body onLoad="$onload">
406 <form method=post action=$form->{script}>
409 $form->hide_form(qw(id title vc type level creditlimit creditremaining closedto locked shippted storno storno_id
410 max_dunning_level dunning_amount vendor_id oldvendor selectvendor taxaccounts
411 fxgain_accno fxloss_accno taxpart taxservice),
412 map { $_.'_rate', $_.'_description' } split / /, $form->{taxaccounts} );
414 print qq|<p>$form->{saved_message}</p>| if $form->{saved_message};
418 <div class="listtop" width="100%">$form->{title}</div>
427 <td align="right">| . $locale->text('Credit Limit') . qq|</td>
428 <td>$form->{creditlimit}; | . $locale->text('Remaining') . qq| <span class="plus$n">$form->{creditremaining}</span></td>
431 <th align="right">| . $locale->text('Record in') . qq|</th>
432 <td colspan="3"><select name="AP" style="width: 250px">$form->{selectAP}</select></td>
433 <input type="hidden" name="selectAP" value="$form->{selectAP}">
447 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
448 <td><input name=invnumber size=11 value="$form->{invnumber}"></td>
451 <th align=right nowrap>| . $locale->text('Invoice Date') . qq|</th>
455 <th align=right nowrap>| . $locale->text('Due Date') . qq|</th>
459 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
460 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
461 <input type=hidden name=quonumber value="$form->{quonumber}">
464 <th align="right" nowrap>| . $locale->text('Order Date') . qq|</th>
465 <td><input name="orddate" id="orddate" size="11" title="$myconfig{dateformat}" value="| . Q($form->{orddate}) . qq|" onBlur=\"check_right_date_format(this)\">
466 <input type="button" name="b_orddate" id="trigger_orddate" value="?"></td>
469 <th align="right" nowrap>| . $locale->text('Quotation Date') . qq|</th>
470 <td><input name="quodate" id="quodate" size="11" title="$myconfig{dateformat}" value="| . Q($form->{quodate}) . qq|" onBlur=\"check_right_date_format(this)\">
471 <input type="button" name="b_quodate" id="trigger_quodate" value="?"></td>
474 <th align="right" nowrap>| . $locale->text('Project Number') . qq|</th>
475 <td>$globalprojectnumber</td>
486 <input type=hidden name=webdav value=$webdav>
489 foreach $item (split / /, $form->{taxaccounts}) {
491 <input type=hidden name="${item}_rate" value=$form->{"${item}_rate"}>
492 <input type=hidden name="${item}_description" value="$form->{"${item}_description"}">
496 $lxdebug->leave_sub();
500 $lxdebug->enter_sub();
502 $form->{invtotal} = $form->{invsubtotal};
504 if (($rows = $form->numtextrows($form->{notes}, 25, 8)) < 2) {
507 if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
510 $rows = ($rows > $introws) ? $rows : $introws;
512 qq|<textarea name=notes rows=$rows cols=25 wrap=soft>$form->{notes}</textarea>|;
514 qq|<textarea name=intnotes rows=$rows cols=35 wrap=soft>$form->{intnotes}</textarea>|;
516 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
519 if ($form->{taxaccounts}) {
521 <input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}> <b>|
522 . $locale->text('Tax Included') . qq|</b>
526 if (!$form->{taxincluded}) {
528 foreach $item (split / /, $form->{taxaccounts}) {
529 if ($form->{"${item}_base"}) {
530 $form->{invtotal} += $form->{"${item}_total"} =
532 $form->{"${item}_base"} * $form->{"${item}_rate"},
534 $form->{"${item}_total"} =
535 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
539 <th align=right>$form->{"${item}_description"} |
540 . $form->{"${item}_rate"} * 100 .qq|%</th>
541 <td align=right>$form->{"${item}_total"}</td>
547 $form->{invsubtotal} =
548 $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
552 <th align=right>| . $locale->text('Subtotal') . qq|</th>
553 <td align=right>$form->{invsubtotal}</td>
559 if ($form->{taxincluded}) {
560 foreach $item (split / /, $form->{taxaccounts}) {
561 if ($form->{"${item}_base"}) {
562 $form->{"${item}_total"} =
564 ($form->{"${item}_base"} * $form->{"${item}_rate"} /
565 (1 + $form->{"${item}_rate"})
568 $form->{"${item}_base"} =
569 $form->round_amount($form->{"${item}_base"}, 2);
570 $form->{"${item}_netto"} =
572 ($form->{"${item}_base"} - $form->{"${item}_total"}),
574 $form->{"${item}_netto"} =
575 $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
576 $form->{"${item}_total"} =
577 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
581 <th align=right>Enthaltene $form->{"${item}_description"} |
582 . $form->{"${item}_rate"} * 100 .qq|%</th>
583 <td align=right>$form->{"${item}_total"}</td>
586 <th align=right>Nettobetrag</th>
587 <td align=right>$form->{"${item}_netto"}</td>
595 $form->{oldinvtotal} = $form->{invtotal};
597 $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
601 <td colspan=$colspan>
602 <table cellspacing="0">
607 <th align=left>| . $locale->text('Notes') . qq|</th>
608 <th align=left>| . $locale->text('Internal Notes') . qq|</th>
616 <td colspan=2 align=right width=100%>
623 <th align=right>| . $locale->text('Total') . qq|</th>
624 <td align=right>$form->{invtotal}</td>
636 <td><hr size=3 noshade></td>
639 <th class=listtop align=left>Dokumente im Webdav-Repository</th>
642 <td align=left width=30%><b>Dateiname</b></td>
643 <td align=left width=70%><b>Webdavlink</b></td>
645 foreach $file (@{ $form->{WEBDAV} }) {
648 <td align="left">$file->{name}</td>
649 <td align="left"><a href="$file->{link}">$file->{type}</a></td>
662 <td colspan=$colspan>
665 <th colspan=6 class=listheading>| . $locale->text('Payments') . qq|</th>
669 if ($form->{currency} eq $form->{defaultcurrency}) {
670 @column_index = qw(datepaid source memo paid AP_paid);
672 @column_index = qw(datepaid source memo paid exchangerate AP_paid);
675 $column_data{datepaid} = "<th>" . $locale->text('Date') . "</th>";
676 $column_data{paid} = "<th>" . $locale->text('Amount') . "</th>";
677 $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
678 $column_data{AP_paid} = "<th>" . $locale->text('Account') . "</th>";
679 $column_data{source} = "<th>" . $locale->text('Source') . "</th>";
680 $column_data{memo} = "<th>" . $locale->text('Memo') . "</th>";
685 map { print "$column_data{$_}\n" } @column_index;
693 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
694 for $i (1 .. $form->{paidaccounts}) {
700 $form->{"selectAP_paid_$i"} = $form->{selectAP_paid};
701 $form->{"selectAP_paid_$i"} =~
702 s/option>\Q$form->{"AP_paid_$i"}\E/option selected>$form->{"AP_paid_$i"}/;
704 $totalpaid += $form->{"paid_$i"};
707 if ($form->{"paid_$i"}) {
709 $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
711 $form->{"exchangerate_$i"} =
712 $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
714 $exchangerate = qq| |;
715 if ($form->{currency} ne $form->{defaultcurrency}) {
716 if ($form->{"forex_$i"}) {
718 qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
721 qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
725 <input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
728 $column_data{"paid_$i"} =
729 qq|<td align=center><input name="paid_$i" size=11 value="$form->{"paid_$i"}" onBlur=\"check_right_number_format(this)\"></td>|;
730 $column_data{"exchangerate_$i"} = qq|<td align=center>$exchangerate</td>|;
731 $column_data{"AP_paid_$i"} =
732 qq|<td align=center><select name="AP_paid_$i">$form->{"selectAP_paid_$i"}</select></td>|;
733 $column_data{"datepaid_$i"} =
734 qq|<td align=center><input name="datepaid_$i" id="datepaid_$i" size=11 title="$myconfig{dateformat}" value="$form->{"datepaid_$i"}" onBlur=\"check_right_date_format(this)\">
735 <input type="button" name="datepaid_$i" id="trigger_datepaid_$i" value="?"></td>|;
736 $column_data{"source_$i"} =
737 qq|<td align=center><input name="source_$i" size=11 value=$form->{"source_$i"}></td>|;
738 $column_data{"memo_$i"} =
739 qq|<td align=center><input name="memo_$i" size=11 value=$form->{"memo_$i"}></td>|;
741 map { print qq|$column_data{"${_}_$i"}\n| } @column_index;
746 push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
749 my $paid_missing = $form->{oldinvtotal} - $totalpaid;
755 <td align="center">| . $locale->text('Total') . qq|</td>
756 <td align="center">| . H($form->format_amount(\%myconfig, $totalpaid, 2)) . qq|</td>
761 <td align="center">| . $locale->text('Missing amount') . qq|</td>
762 <td align="center">| . H($form->format_amount(\%myconfig, $paid_missing, 2)) . qq|</td>
765 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
766 <input type=hidden name=paidaccounts value=$form->{paidaccounts}>
767 <input type=hidden name=selectAP_paid value="$form->{selectAP_paid}">
772 <td><hr size=3 noshade></td>
778 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
779 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
781 print qq|<input class=submit type=submit name=action id=update_button value="|
782 . $locale->text('Update') . qq|">
786 my $show_storno = !$form->{storno} && !IS->has_storno(\%myconfig, $form, "ap");
788 print qq|<input class=submit type=submit name=action value="|
789 . $locale->text('Post Payment') . qq|">
791 print qq|<input class=submit type=submit name=action value="|
792 . $locale->text('Storno') . qq|">
794 if ($form->{radier}) {
796 <input class=submit type=submit name=action value="|
797 . $locale->text('Delete') . qq|">
800 print qq|<input class=submit type=submit name=action value="|
801 . $locale->text('Use As Template') . qq|">
806 if (!$form->{id} && ($invdate > $closedto)) {
807 print qq| <input class=submit type=submit name=action value="|
808 . $locale->text('Post') . qq|"> | .
809 NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'),
810 '-class' => 'submit'));
813 print $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers);
814 $form->hide_form(qw(rowcount callback draft_id draft_description login password));
816 # button for saving history
817 if($form->{id} ne "") {
819 <input type="button" class="submit" onclick="set_history_window(|
821 . qq|);" name="history" id="history" value="|
822 . $locale->text('history')
825 # /button for saving history
826 # mark_as_paid button
827 if($form->{id} ne "") {
828 print qq| <input type="submit" class="submit" name="action" value="|
829 . $locale->text('mark as paid') . qq|">|;
831 # /mark_as_paid button
838 $lxdebug->leave_sub();
842 $lxdebug->enter_sub();
843 &mark_as_paid_common(\%myconfig,"ap");
844 $lxdebug->leave_sub();
848 $lxdebug->enter_sub();
850 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate creditlimit creditremaining);
854 $form->{exchangerate} = $exchangerate if
855 $form->{forex} = $exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{invdate}, 'sell');
857 for $i (1 .. $form->{paidaccounts}) {
858 next unless $form->{"paid_$i"};
859 map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(paid exchangerate);
860 $form->{"exchangerate_$i"} = $exchangerate if
861 $form->{"forex_$i"} = $exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'sell');
864 $i = $form->{rowcount};
865 $exchangerate = ($form->{exchangerate} * 1) || 1;
867 if ( ($form->{"partnumber_$i"} eq "")
868 && ($form->{"description_$i"} eq "")
869 && ($form->{"partsgroup_$i"} eq "")) {
870 $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
875 IR->retrieve_item(\%myconfig, \%$form);
877 my $rows = scalar @{ $form->{item_list} };
880 $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
889 # override sellprice if there is one entered
890 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
892 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g } qw(partnumber description unit);
893 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} } keys %{ $form->{item_list}[0] };
895 $form->{"marge_price_factor_$i"} = $form->{item_list}->[0]->{price_factor};
897 ($sellprice || $form->{"sellprice_$i"}) =~ /\.(\d+)/;
898 $decimalplaces = max 2, length $1;
901 $form->{"sellprice_$i"} = $sellprice;
903 # if there is an exchange rate adjust sellprice
904 $form->{"sellprice_$i"} /= $exchangerate;
907 $amount = $form->{"sellprice_$i"} * $form->{"qty_$i"} * (1 - $form->{"discount_$i"} / 100);
908 $form->{creditremaining} -= $amount;
909 $form->{"sellprice_$i"} = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces);
910 $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
917 # ok, so this is a new part
918 # ask if it is a part or service item
920 if ( $form->{"partsgroup_$i"}
921 && ($form->{"partsnumber_$i"} eq "")
922 && ($form->{"description_$i"} eq "")) {
924 $form->{"discount_$i"} = "";
928 $form->{"id_$i"} = 0;
933 $lxdebug->leave_sub();
937 $lxdebug->enter_sub();
939 if ($form->{storno}) {
940 $form->error($locale->text('Cannot storno storno invoice!'));
943 if (IS->has_storno(\%myconfig, $form, "ap")) {
944 $form->error($locale->text("Invoice has already been storno'd!"));
947 my $employee_id = $form->{employee_id};
952 # Payments must not be recorded for the new storno invoice.
953 $form->{paidaccounts} = 0;
954 map { my $key = $_; delete $form->{$key} if grep { $key =~ /^$_/ } qw(datepaid_ source_ memo_ paid_ exchangerate_ AR_paid_) } keys %{ $form };
957 if(!exists $form->{addition} && $form->{id} ne "") {
958 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
959 $form->{addition} = "CANCELED";
960 $form->save_history($form->dbconnect(\%myconfig));
962 # /saving the history
964 $form->{storno_id} = $form->{id};
967 $form->{invnumber} = "Storno zu " . $form->{invnumber};
969 $form->{employee_id} = $employee_id;
971 $lxdebug->leave_sub();
975 sub use_as_template {
976 $lxdebug->enter_sub();
978 map { delete $form->{$_} } qw(printed emailed queued invnumber invdate deliverydate id datepaid_1 source_1 memo_1 paid_1 exchangerate_1 AP_paid_1 storno);
979 $form->{paidaccounts} = 1;
981 $form->{invdate} = $form->current_date(\%myconfig);
984 $lxdebug->leave_sub();
988 $lxdebug->enter_sub();
990 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
991 for $i (1 .. $form->{paidaccounts}) {
992 if ($form->{"paid_$i"}) {
993 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
995 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
997 $form->error($locale->text('Cannot post payment for a closed period!'))
998 if ($datepaid <= $closedto);
1000 if ($form->{currency} ne $form->{defaultcurrency}) {
1001 $form->{"exchangerate_$i"} = $form->{exchangerate}
1002 if ($invdate == $datepaid);
1003 $form->isblank("exchangerate_$i",
1004 $locale->text('Exchangerate for payment missing!'));
1009 ($form->{AP}) = split /--/, $form->{AP};
1010 ($form->{AP_paid}) = split /--/, $form->{AP_paid};
1011 if (IR->post_payment(\%myconfig, \%$form)){
1012 if (!exists $form->{addition} && $form->{id} ne "") {
1013 # saving the history
1014 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1015 $form->{addition} = "PAYMENT POSTED";
1016 $form->{what_done} = $form->{currency} . qq| | . $form->{paid} . qq| | . $locale->text("POSTED");
1017 $form->save_history($form->dbconnect(\%myconfig));
1018 # /saving the history
1021 $form->redirect($locale->text('Payment posted!'));
1024 $form->error($locale->text('Cannot post payment!'));
1026 $lxdebug->leave_sub();
1030 $lxdebug->enter_sub();
1032 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
1034 $form->isblank("invdate", $locale->text('Invoice Date missing!'));
1035 $form->isblank("vendor", $locale->text('Vendor missing!'));
1037 $form->{invnumber} =~ s/^\s*//g;
1038 $form->{invnumber} =~ s/\s*$//g;
1040 # if the vendor changed get new values
1041 if (&check_name(vendor)) {
1048 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1049 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
1051 $form->error($locale->text('Cannot post invoice for a closed period!'))
1052 if ($invdate <= $closedto);
1054 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1055 if ($form->{currency} ne $form->{defaultcurrency});
1057 for $i (1 .. $form->{paidaccounts}) {
1058 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
1059 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1061 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1063 $form->error($locale->text('Cannot post payment for a closed period!'))
1064 if ($datepaid <= $closedto);
1066 if ($form->{currency} ne $form->{defaultcurrency}) {
1067 $form->{"exchangerate_$i"} = $form->{exchangerate}
1068 if ($invdate == $datepaid);
1069 $form->isblank("exchangerate_$i",
1070 $locale->text('Exchangerate for payment missing!'));
1075 ($form->{AP}) = split /--/, $form->{AP};
1076 ($form->{AP_paid}) = split /--/, $form->{AP_paid};
1077 $form->{storno} = 0;
1079 $form->{id} = 0 if $form->{postasnew};
1083 if (IR->post_invoice(\%myconfig, \%$form)){
1084 # saving the history
1085 if(!exists $form->{addition} && $form->{id} ne "") {
1086 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1087 $form->{addition} = "POSTED";
1088 #$form->{what_done} = $locale->text("Rechnungsnummer") . qq| | . $form->{invnumber};
1089 $form->save_history($form->dbconnect(\%myconfig));
1091 # /saving the history
1092 remove_draft() if $form->{remove_draft};
1093 $form->redirect( $locale->text('Invoice')
1094 . " $form->{invnumber} "
1095 . $locale->text('posted!'));
1097 $form->error($locale->text('Cannot post invoice!'));
1099 $lxdebug->leave_sub();
1103 $lxdebug->enter_sub();
1109 <form method=post action=$form->{script}>
1112 # delete action variable
1113 map { delete $form->{$_} } qw(action header);
1115 foreach $key (keys %$form) {
1116 $form->{$key} =~ s/\"/"/g;
1117 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1121 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
1124 . $locale->text('Are you sure you want to delete Invoice Number')
1125 . qq| $form->{invnumber}</h4>
1127 <input name=action class=submit type=submit value="|
1128 . $locale->text('Yes') . qq|">
1132 $lxdebug->leave_sub();
1136 $lxdebug->enter_sub();
1137 if (IR->delete_invoice(\%myconfig, \%$form)) {
1138 # saving the history
1139 if(!exists $form->{addition}) {
1140 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1141 $form->{addition} = "DELETED";
1142 $form->save_history($form->dbconnect(\%myconfig));
1144 # /saving the history
1145 $form->redirect($locale->text('Invoice deleted!'));
1147 $form->error($locale->text('Cannot delete invoice!'));
1149 $lxdebug->leave_sub();