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 $auth->assert('vendor_invoice_edit');
54 return $lxdebug->leave_sub() if (load_draft_maybe());
56 $form->{title} = $locale->text('Add Vendor Invoice');
62 $lxdebug->leave_sub();
66 $lxdebug->enter_sub();
68 $auth->assert('vendor_invoice_edit');
71 $form->{javascript} = qq|<script type=text/javascript src=js/show_history.js></script>|;
72 #/show hhistory button
74 $form->{title} = $locale->text('Edit Vendor Invoice');
80 $lxdebug->leave_sub();
84 $lxdebug->enter_sub();
86 $auth->assert('vendor_invoice_edit');
89 $form->{webdav} = $webdav;
90 $form->{jsscript} = 1;
92 $form->create_links("AP", \%myconfig, "vendor");
94 #quote all_vendor Bug 133
95 foreach $ref (@{ $form->{all_vendor} }) {
96 $ref->{name} = $form->quote($ref->{name});
99 if ($form->{all_vendor}) {
100 unless ($form->{vendor_id}) {
101 $form->{vendor_id} = $form->{all_vendor}->[0]->{id};
104 if ($form->{payment_id}) {
105 $payment_id = $form->{payment_id};
107 if ($form->{language_id}) {
108 $language_id = $form->{language_id};
110 if ($form->{taxzone_id}) {
111 $taxzone_id = $form->{taxzone_id};
114 $cp_id = $form->{cp_id};
115 IR->get_vendor(\%myconfig, \%$form);
116 IR->retrieve_invoice(\%myconfig, \%$form);
117 $form->{cp_id} = $cp_id;
120 $form->{payment_id} = $payment_id;
123 $form->{language_id} = $language_id;
126 $form->{taxzone_id} = $taxzone_id;
129 map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
131 $form->{oldvendor} = "$form->{vendor}--$form->{vendor_id}";
134 if ($form->{all_departments}) {
135 $form->{selectdepartment} = "<option>\n";
136 $form->{department} = "$form->{department}--$form->{department_id}";
139 $form->{selectdepartment} .=
140 "<option>$_->{description}--$_->{id}\n"
141 } (@{ $form->{all_departments} });
145 $form->{forex} = $form->{exchangerate};
146 $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
148 foreach $key (keys %{ $form->{AP_links} }) {
150 foreach $ref (@{ $form->{AP_links}{$key} }) {
151 $form->{"select$key"} .= "<option>$ref->{accno}--$ref->{description}\n";
154 if ($key eq "AP_paid") {
155 for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) {
156 $form->{"AP_paid_$i"} =
157 "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}";
160 $form->{"paid_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{amount};
161 $form->{"datepaid_$i"} =
162 $form->{acc_trans}{$key}->[$i - 1]->{transdate};
163 $form->{"forex_$i"} = $form->{"exchangerate_$i"} =
164 $form->{acc_trans}{$key}->[$i - 1]->{exchangerate};
165 $form->{"source_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{source};
166 $form->{"memo_$i"} = $form->{acc_trans}{$key}->[$i - 1]->{memo};
168 $form->{paidaccounts} = $i;
172 "$form->{acc_trans}{$key}->[0]->{accno}--$form->{acc_trans}{$key}->[0]->{description}";
177 $form->{paidaccounts} = 1 unless (exists $form->{paidaccounts});
179 $form->{AP} = $form->{AP_1} unless $form->{id};
182 ($form->datetonum($form->{invdate}, \%myconfig) <=
183 $form->datetonum($form->{closedto}, \%myconfig));
185 $lxdebug->leave_sub();
188 sub prepare_invoice {
189 $lxdebug->enter_sub();
191 $auth->assert('vendor_invoice_edit');
195 map { $form->{$_} =~ s/\"/"/g } qw(invnumber ordnumber quonumber);
198 foreach $ref (@{ $form->{invoice_details} }) {
200 map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
202 ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);
204 $decimalplaces = ($dec > 2) ? $dec : 2;
206 $form->{"sellprice_$i"} =
207 $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
210 (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
211 $dec_qty = length $dec_qty;
214 $form->format_amount(\%myconfig, ($form->{"qty_$i"} * -1), $dec_qty);
216 $form->{rowcount} = $i;
220 $lxdebug->leave_sub();
224 $lxdebug->enter_sub();
226 $auth->assert('vendor_invoice_edit');
228 # set option selected
229 foreach $item (qw(AP vendor currency department)) {
230 $form->{"select$item"} =~ s/ selected//;
231 $form->{"select$item"} =~ s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
234 $form->{employee_id} = $form->{old_employee_id} if $form->{old_employee_id};
235 $form->{salesman_id} = $form->{old_salesman_id} if $form->{old_salesman_id};
236 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
237 $form->{radier} = ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
238 $form->{exchangerate} = $form->format_amount(\%myconfig, $form->{exchangerate});
239 $form->{creditlimit} = $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0");
240 $form->{creditremaining} = $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0");
243 if ($form->{currency} ne $form->{defaultcurrency}) {
244 if ($form->{forex}) {
245 $exchangerate .= qq| <th align=right nowrap>| . $locale->text('Exchangerate') . qq|</th>
246 <td>$form->{exchangerate}<input type=hidden name=exchangerate value=$form->{exchangerate}></td>\n|;
248 $exchangerate .= qq| <th align=right nowrap>| . $locale->text('Exchangerate') . qq|</th>
249 <td><input name=exchangerate size=10 value=$form->{exchangerate}></td>\n|;
252 $exchangerate .= qq| <input type=hidden name=forex value=$form->{forex}>\n|;
254 my @old_project_ids = ($form->{"globalproject_id"});
255 map { push @old_project_ids, $form->{"project_id_$_"} if $form->{"project_id_$_"}; } 1..$form->{"rowcount"};
257 $form->get_lists("contacts" => "ALL_CONTACTS",
258 "projects" => { "key" => "ALL_PROJECTS",
260 "old_id" => \@old_project_ids },
261 "taxzones" => "ALL_TAXZONES",
262 "employees" => "ALL_SALESMEN",
263 "currencies" => "ALL_CURRENCIES",
264 "vendors" => "ALL_VENDORS",
265 "price_factors" => "ALL_PRICE_FACTORS");
268 my @values = (undef);
269 foreach my $item (@{ $form->{"ALL_CONTACTS"} }) {
270 push(@values, $item->{"cp_id"});
271 $labels{$item->{"cp_id"}} = $item->{"cp_name"} . ($item->{"cp_abteilung"} ? " ($item->{cp_abteilung})" : "");
275 if (scalar @values > 1) {
278 <th align="right">| . $locale->text('Contact Person') . qq|</th>
279 <td>| . NTI($cgi->popup_menu('-name' => 'cp_id', '-values' => \@values, '-style' => 'width: 250px',
280 '-labels' => \%labels, '-default' => $form->{"cp_id"})) . qq|
287 foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
288 push(@values, $item->{"id"});
289 $labels{$item->{"id"}} = $item->{"projectnumber"};
291 my $globalprojectnumber = NTI($cgi->popup_menu('-name' => 'globalproject_id', '-values' => \@values, '-labels' => \%labels,
292 '-default' => $form->{"globalproject_id"}));
297 foreach my $item (@{ $form->{"ALL_CURRENCIES"} }) {
298 push(@values, $item);
299 $labels{$item} = $item;
302 $form->{currency} = $form->{defaultcurrency} unless $form->{currency};
304 if (scalar @values) {
307 <th align="right">| . $locale->text('Currency') . qq|</th>
308 <td>| . NTI($cgi->popup_menu('-name' => 'currency', '-default' => $form->{"currency"},
309 '-values' => \@values, '-labels' => \%labels)) . qq|
317 foreach my $item (@{ $form->{"ALL_SALESMEN"} }) {
318 push(@values, $item->{"id"});
319 $labels{$item->{"id"}} = $item->{"name"};
323 <th align="right">| . $locale->text('Employee') . qq|</th>
324 <td>| . NTI($cgi->popup_menu('-name' => 'employee_id', '-default' => $form->{"employee_id"},
325 '-values' => \@values, '-labels' => \%labels)) . qq|
332 foreach my $item (@{ $form->{"ALL_VENDORS"} }) {
333 push(@values, $item->{name}.qq|--|.$item->{"id"});
334 $labels{$item->{name}.qq|--|.$item->{"id"}} = $item->{"name"};
337 $form->{selectvendor} = ($myconfig{vclimit} > scalar(@values));
340 <th align="right">| . $locale->text('Vendor') . qq|</th>
342 (($myconfig{vclimit} <= scalar(@values))
343 ? qq|<input type="text" value="| . H($form->{vendor}) . qq|" name="vendor">|
344 : (NTI($cgi->popup_menu('-name' => 'vendor', '-default' => $form->{oldvendor},
345 '-onChange' => 'document.getElementById(\'update_button\').click();',
346 '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px')))) . qq|
347 <input type="button" value="?" onclick="show_vc_details('vendor')">
352 foreach my $item (@{ $form->{"ALL_TAXZONES"} }) {
353 push(@values, $item->{"id"});
354 $labels{$item->{"id"}} = $item->{"description"};
357 if (!$form->{"id"}) {
360 <th align="right">| . $locale->text('Steuersatz') . qq|</th>
361 <td>| . NTI($cgi->popup_menu('-name' => 'taxzone_id', '-default' => $form->{"taxzone_id"},
362 '-values' => \@values, '-labels' => \%labels, '-style' => 'width: 250px')) . qq|
368 <th align="right">| . $locale->text('Steuersatz') . qq|</th>
370 <input type="hidden" name="taxzone_id" value="| . H($form->{"taxzone_id"}) . qq|">
371 | . H($labels{$form->{"taxzone_id"}}) . qq|
378 <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
379 <td colspan="3"><select name="department" style="width: 250px">$form->{selectdepartment}</select>
380 <input type="hidden" name="selectdepartment" value="$form->{selectdepartment}">
382 </tr>\n| if $form->{selectdepartment};
384 $n = ($form->{creditremaining} =~ /-/) ? "0" : "1";
386 # use JavaScript Calendar or not
387 $form->{jsscript} = 1;
391 <td><input name=invdate id=invdate size=11 title="$myconfig{dateformat}" value="$form->{invdate}" onBlur=\"check_right_date_format(this)\">
392 <input type=button name=invdate id="trigger1" value=| . $locale->text('button') . qq|></td>\n|;
394 <td width="13"><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value="$form->{duedate}" onBlur=\"check_right_date_format(this)\">
395 <input type=button name=duedate id="trigger2" value=| . $locale->text('button') . qq|></td>\n|;
399 Form->write_trigger(\%myconfig, "2",
400 "invdate", "BL", "trigger1",
401 "duedate", "BL", "trigger2");
403 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_form_details.js"></script>|;
404 $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
405 $form->{javascript} .= qq|<script type="text/javascript" src="js/show_vc_details.js"></script>|;
407 $jsscript .= $form->write_trigger(\%myconfig, 2, "orddate", "BL", "trigger_orddate", "quodate", "BL", "trigger_quodate");
410 $onload = qq|focus()|;
411 $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|;
412 $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
414 <body onLoad="$onload">
416 <form method=post action=$form->{script}>
419 $form->hide_form(qw(id title vc type level creditlimit creditremaining closedto locked shippted storno storno_id
420 max_dunning_level dunning_amount vendor_id oldvendor selectvendor taxaccounts
421 fxgain_accno fxloss_accno taxpart taxservice),
422 map { $_.'_rate', $_.'_description' } split / /, $form->{taxaccounts} );
424 print qq|<p>$form->{saved_message}</p>| if $form->{saved_message};
428 <div class="listtop" width="100%">$form->{title}</div>
437 <td align="right">| . $locale->text('Credit Limit') . qq|</td>
438 <td>$form->{creditlimit}; | . $locale->text('Remaining') . qq| <span class="plus$n">$form->{creditremaining}</span></td>
441 <th align="right">| . $locale->text('Record in') . qq|</th>
442 <td colspan="3"><select name="AP" style="width: 250px">$form->{selectAP}</select></td>
443 <input type="hidden" name="selectAP" value="$form->{selectAP}">
457 <th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
458 <td><input name=invnumber size=11 value="$form->{invnumber}"></td>
461 <th align=right nowrap>| . $locale->text('Invoice Date') . qq|</th>
465 <th align=right nowrap>| . $locale->text('Due Date') . qq|</th>
469 <th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
470 <td><input name=ordnumber size=11 value="$form->{ordnumber}"></td>
471 <input type=hidden name=quonumber value="$form->{quonumber}">
474 <th align="right" nowrap>| . $locale->text('Order Date') . qq|</th>
475 <td><input name="orddate" id="orddate" size="11" title="$myconfig{dateformat}" value="| . Q($form->{orddate}) . qq|" onBlur=\"check_right_date_format(this)\">
476 <input type="button" name="b_orddate" id="trigger_orddate" value="?"></td>
479 <th align="right" nowrap>| . $locale->text('Quotation Date') . qq|</th>
480 <td><input name="quodate" id="quodate" size="11" title="$myconfig{dateformat}" value="| . Q($form->{quodate}) . qq|" onBlur=\"check_right_date_format(this)\">
481 <input type="button" name="b_quodate" id="trigger_quodate" value="?"></td>
484 <th align="right" nowrap>| . $locale->text('Project Number') . qq|</th>
485 <td>$globalprojectnumber</td>
496 <input type=hidden name=webdav value=$webdav>
499 foreach $item (split / /, $form->{taxaccounts}) {
501 <input type=hidden name="${item}_rate" value=$form->{"${item}_rate"}>
502 <input type=hidden name="${item}_description" value="$form->{"${item}_description"}">
506 $lxdebug->leave_sub();
510 $lxdebug->enter_sub();
512 $auth->assert('vendor_invoice_edit');
514 $form->{invtotal} = $form->{invsubtotal};
516 if (($rows = $form->numtextrows($form->{notes}, 25, 8)) < 2) {
519 if (($introws = $form->numtextrows($form->{intnotes}, 35, 8)) < 2) {
522 $rows = ($rows > $introws) ? $rows : $introws;
524 qq|<textarea name=notes rows=$rows cols=25 wrap=soft>$form->{notes}</textarea>|;
526 qq|<textarea name=intnotes rows=$rows cols=35 wrap=soft>$form->{intnotes}</textarea>|;
528 $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : "";
531 if ($form->{taxaccounts}) {
533 <input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}> <b>|
534 . $locale->text('Tax Included') . qq|</b>
538 if (!$form->{taxincluded}) {
540 foreach $item (split / /, $form->{taxaccounts}) {
541 if ($form->{"${item}_base"}) {
542 $form->{invtotal} += $form->{"${item}_total"} =
544 $form->{"${item}_base"} * $form->{"${item}_rate"},
546 $form->{"${item}_total"} =
547 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
551 <th align=right>$form->{"${item}_description"} |
552 . $form->{"${item}_rate"} * 100 .qq|%</th>
553 <td align=right>$form->{"${item}_total"}</td>
559 $form->{invsubtotal} =
560 $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0);
564 <th align=right>| . $locale->text('Subtotal') . qq|</th>
565 <td align=right>$form->{invsubtotal}</td>
571 if ($form->{taxincluded}) {
572 foreach $item (split / /, $form->{taxaccounts}) {
573 if ($form->{"${item}_base"}) {
574 $form->{"${item}_total"} =
576 ($form->{"${item}_base"} * $form->{"${item}_rate"} /
577 (1 + $form->{"${item}_rate"})
580 $form->{"${item}_base"} =
581 $form->round_amount($form->{"${item}_base"}, 2);
582 $form->{"${item}_netto"} =
584 ($form->{"${item}_base"} - $form->{"${item}_total"}),
586 $form->{"${item}_netto"} =
587 $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2);
588 $form->{"${item}_total"} =
589 $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2);
593 <th align=right>Enthaltene $form->{"${item}_description"} |
594 . $form->{"${item}_rate"} * 100 .qq|%</th>
595 <td align=right>$form->{"${item}_total"}</td>
598 <th align=right>Nettobetrag</th>
599 <td align=right>$form->{"${item}_netto"}</td>
607 $form->{oldinvtotal} = $form->{invtotal};
609 $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0);
613 <td colspan=$colspan>
614 <table cellspacing="0">
619 <th align=left>| . $locale->text('Notes') . qq|</th>
620 <th align=left>| . $locale->text('Internal Notes') . qq|</th>
628 <td colspan=2 align=right width=100%>
635 <th align=right>| . $locale->text('Total') . qq|</th>
636 <td align=right>$form->{invtotal}</td>
648 <td><hr size=3 noshade></td>
651 <th class=listtop align=left>Dokumente im Webdav-Repository</th>
654 <td align=left width=30%><b>Dateiname</b></td>
655 <td align=left width=70%><b>Webdavlink</b></td>
657 foreach $file (@{ $form->{WEBDAV} }) {
660 <td align="left">$file->{name}</td>
661 <td align="left"><a href="$file->{link}">$file->{type}</a></td>
674 <td colspan=$colspan>
677 <th colspan=6 class=listheading>| . $locale->text('Payments') . qq|</th>
681 if ($form->{currency} eq $form->{defaultcurrency}) {
682 @column_index = qw(datepaid source memo paid AP_paid);
684 @column_index = qw(datepaid source memo paid exchangerate AP_paid);
687 $column_data{datepaid} = "<th>" . $locale->text('Date') . "</th>";
688 $column_data{paid} = "<th>" . $locale->text('Amount') . "</th>";
689 $column_data{exchangerate} = "<th>" . $locale->text('Exch') . "</th>";
690 $column_data{AP_paid} = "<th>" . $locale->text('Account') . "</th>";
691 $column_data{source} = "<th>" . $locale->text('Source') . "</th>";
692 $column_data{memo} = "<th>" . $locale->text('Memo') . "</th>";
697 map { print "$column_data{$_}\n" } @column_index;
705 $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
706 for $i (1 .. $form->{paidaccounts}) {
712 $form->{"selectAP_paid_$i"} = $form->{selectAP_paid};
713 $form->{"selectAP_paid_$i"} =~
714 s/option>\Q$form->{"AP_paid_$i"}\E/option selected>$form->{"AP_paid_$i"}/;
716 $totalpaid += $form->{"paid_$i"};
719 if ($form->{"paid_$i"}) {
721 $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
723 $form->{"exchangerate_$i"} =
724 $form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
726 $exchangerate = qq| |;
727 if ($form->{currency} ne $form->{defaultcurrency}) {
728 if ($form->{"forex_$i"}) {
730 qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
733 qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
737 <input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
740 $column_data{"paid_$i"} =
741 qq|<td align=center><input name="paid_$i" size=11 value="$form->{"paid_$i"}" onBlur=\"check_right_number_format(this)\"></td>|;
742 $column_data{"exchangerate_$i"} = qq|<td align=center>$exchangerate</td>|;
743 $column_data{"AP_paid_$i"} =
744 qq|<td align=center><select name="AP_paid_$i">$form->{"selectAP_paid_$i"}</select></td>|;
745 $column_data{"datepaid_$i"} =
746 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)\">
747 <input type="button" name="datepaid_$i" id="trigger_datepaid_$i" value="?"></td>|;
748 $column_data{"source_$i"} =
749 qq|<td align=center><input name="source_$i" size=11 value=$form->{"source_$i"}></td>|;
750 $column_data{"memo_$i"} =
751 qq|<td align=center><input name="memo_$i" size=11 value=$form->{"memo_$i"}></td>|;
753 map { print qq|$column_data{"${_}_$i"}\n| } @column_index;
758 push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i");
761 my $paid_missing = $form->{oldinvtotal} - $totalpaid;
767 <td align="center">| . $locale->text('Total') . qq|</td>
768 <td align="center">| . H($form->format_amount(\%myconfig, $totalpaid, 2)) . qq|</td>
773 <td align="center">| . $locale->text('Missing amount') . qq|</td>
774 <td align="center">| . H($form->format_amount(\%myconfig, $paid_missing, 2)) . qq|</td>
777 <input type=hidden name=oldinvtotal value=$form->{oldinvtotal}>
778 <input type=hidden name=paidaccounts value=$form->{paidaccounts}>
779 <input type=hidden name=selectAP_paid value="$form->{selectAP_paid}">
784 <td><hr size=3 noshade></td>
790 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
791 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
793 print qq|<input class=submit type=submit name=action id=update_button value="|
794 . $locale->text('Update') . qq|">
798 my $show_storno = !$form->{storno} && !IS->has_storno(\%myconfig, $form, "ap");
800 print qq|<input class=submit type=submit name=action value="|
801 . $locale->text('Post Payment') . qq|">
803 print qq|<input class=submit type=submit name=action value="|
804 . $locale->text('Storno') . qq|">
806 if ($form->{radier}) {
808 <input class=submit type=submit name=action value="|
809 . $locale->text('Delete') . qq|">
812 print qq|<input class=submit type=submit name=action value="|
813 . $locale->text('Use As Template') . qq|">
818 if (!$form->{id} && ($invdate > $closedto)) {
819 print qq| <input class=submit type=submit name=action value="|
820 . $locale->text('Post') . qq|"> | .
821 NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'),
822 '-class' => 'submit'));
825 print $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers);
826 $form->hide_form(qw(rowcount callback draft_id draft_description));
828 # button for saving history
829 if($form->{id} ne "") {
831 <input type="button" class="submit" onclick="set_history_window(|
833 . qq|);" name="history" id="history" value="|
834 . $locale->text('history')
837 # /button for saving history
838 # mark_as_paid button
839 if($form->{id} ne "") {
840 print qq| <input type="submit" class="submit" name="action" value="|
841 . $locale->text('mark as paid') . qq|">|;
843 # /mark_as_paid button
850 $lxdebug->leave_sub();
854 $lxdebug->enter_sub();
856 $auth->assert('vendor_invoice_edit');
858 &mark_as_paid_common(\%myconfig,"ap");
860 $lxdebug->leave_sub();
864 $lxdebug->enter_sub();
866 $auth->assert('vendor_invoice_edit');
868 map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate creditlimit creditremaining);
872 $form->{exchangerate} = $exchangerate if
873 $form->{forex} = $exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{invdate}, 'sell');
875 for $i (1 .. $form->{paidaccounts}) {
876 next unless $form->{"paid_$i"};
877 map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(paid exchangerate);
878 $form->{"exchangerate_$i"} = $exchangerate if
879 $form->{"forex_$i"} = $exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'sell');
882 $i = $form->{rowcount};
883 $exchangerate = ($form->{exchangerate} * 1) || 1;
885 if ( ($form->{"partnumber_$i"} eq "")
886 && ($form->{"description_$i"} eq "")
887 && ($form->{"partsgroup_$i"} eq "")) {
888 $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid});
893 IR->retrieve_item(\%myconfig, \%$form);
895 my $rows = scalar @{ $form->{item_list} };
898 $form->{"qty_$i"} = 1 unless ($form->{"qty_$i"});
907 # override sellprice if there is one entered
908 $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"});
910 map { $form->{item_list}[$i]{$_} =~ s/\"/"/g } qw(partnumber description unit);
911 map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} } keys %{ $form->{item_list}[0] };
913 $form->{"marge_price_factor_$i"} = $form->{item_list}->[0]->{price_factor};
915 ($sellprice || $form->{"sellprice_$i"}) =~ /\.(\d+)/;
916 $decimalplaces = max 2, length $1;
919 $form->{"sellprice_$i"} = $sellprice;
921 # if there is an exchange rate adjust sellprice
922 $form->{"sellprice_$i"} /= $exchangerate;
925 $amount = $form->{"sellprice_$i"} * $form->{"qty_$i"} * (1 - $form->{"discount_$i"} / 100);
926 $form->{creditremaining} -= $amount;
927 $form->{"sellprice_$i"} = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}, $decimalplaces);
928 $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"}, $dec_qty);
935 # ok, so this is a new part
936 # ask if it is a part or service item
938 if ( $form->{"partsgroup_$i"}
939 && ($form->{"partsnumber_$i"} eq "")
940 && ($form->{"description_$i"} eq "")) {
942 $form->{"discount_$i"} = "";
946 $form->{"id_$i"} = 0;
951 $lxdebug->leave_sub();
955 $lxdebug->enter_sub();
957 $auth->assert('vendor_invoice_edit');
959 if ($form->{storno}) {
960 $form->error($locale->text('Cannot storno storno invoice!'));
963 if (IS->has_storno(\%myconfig, $form, "ap")) {
964 $form->error($locale->text("Invoice has already been storno'd!"));
967 my $employee_id = $form->{employee_id};
972 # Payments must not be recorded for the new storno invoice.
973 $form->{paidaccounts} = 0;
974 map { my $key = $_; delete $form->{$key} if grep { $key =~ /^$_/ } qw(datepaid_ source_ memo_ paid_ exchangerate_ AR_paid_) } keys %{ $form };
977 if(!exists $form->{addition} && $form->{id} ne "") {
978 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
979 $form->{addition} = "CANCELED";
980 $form->save_history($form->dbconnect(\%myconfig));
982 # /saving the history
984 $form->{storno_id} = $form->{id};
987 $form->{invnumber} = "Storno zu " . $form->{invnumber};
989 $form->{employee_id} = $employee_id;
991 $lxdebug->leave_sub();
995 sub use_as_template {
996 $lxdebug->enter_sub();
998 $auth->assert('vendor_invoice_edit');
1000 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);
1001 $form->{paidaccounts} = 1;
1002 $form->{rowcount}--;
1003 $form->{invdate} = $form->current_date(\%myconfig);
1006 $lxdebug->leave_sub();
1010 $lxdebug->enter_sub();
1012 $auth->assert('vendor_invoice_edit');
1014 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
1015 for $i (1 .. $form->{paidaccounts}) {
1016 if ($form->{"paid_$i"}) {
1017 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1019 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1021 $form->error($locale->text('Cannot post payment for a closed period!'))
1022 if ($datepaid <= $closedto);
1024 if ($form->{currency} ne $form->{defaultcurrency}) {
1025 $form->{"exchangerate_$i"} = $form->{exchangerate}
1026 if ($invdate == $datepaid);
1027 $form->isblank("exchangerate_$i",
1028 $locale->text('Exchangerate for payment missing!'));
1033 ($form->{AP}) = split /--/, $form->{AP};
1034 ($form->{AP_paid}) = split /--/, $form->{AP_paid};
1035 if (IR->post_payment(\%myconfig, \%$form)){
1036 if (!exists $form->{addition} && $form->{id} ne "") {
1037 # saving the history
1038 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1039 $form->{addition} = "PAYMENT POSTED";
1040 $form->{what_done} = $form->{currency} . qq| | . $form->{paid} . qq| | . $locale->text("POSTED");
1041 $form->save_history($form->dbconnect(\%myconfig));
1042 # /saving the history
1045 $form->redirect($locale->text('Payment posted!'));
1048 $form->error($locale->text('Cannot post payment!'));
1050 $lxdebug->leave_sub();
1054 $lxdebug->enter_sub();
1056 $auth->assert('vendor_invoice_edit');
1058 $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
1060 $form->isblank("invdate", $locale->text('Invoice Date missing!'));
1061 $form->isblank("vendor", $locale->text('Vendor missing!'));
1063 $form->{invnumber} =~ s/^\s*//g;
1064 $form->{invnumber} =~ s/\s*$//g;
1066 # if the vendor changed get new values
1067 if (&check_name(vendor)) {
1074 $closedto = $form->datetonum($form->{closedto}, \%myconfig);
1075 $invdate = $form->datetonum($form->{invdate}, \%myconfig);
1077 $form->error($locale->text('Cannot post invoice for a closed period!'))
1078 if ($invdate <= $closedto);
1080 $form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
1081 if ($form->{currency} ne $form->{defaultcurrency});
1083 for $i (1 .. $form->{paidaccounts}) {
1084 if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
1085 $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
1087 $form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
1089 $form->error($locale->text('Cannot post payment for a closed period!'))
1090 if ($datepaid <= $closedto);
1092 if ($form->{currency} ne $form->{defaultcurrency}) {
1093 $form->{"exchangerate_$i"} = $form->{exchangerate}
1094 if ($invdate == $datepaid);
1095 $form->isblank("exchangerate_$i",
1096 $locale->text('Exchangerate for payment missing!'));
1101 ($form->{AP}) = split /--/, $form->{AP};
1102 ($form->{AP_paid}) = split /--/, $form->{AP_paid};
1103 $form->{storno} = 0;
1105 $form->{id} = 0 if $form->{postasnew};
1109 if (IR->post_invoice(\%myconfig, \%$form)){
1110 # saving the history
1111 if(!exists $form->{addition} && $form->{id} ne "") {
1112 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1113 $form->{addition} = "POSTED";
1114 #$form->{what_done} = $locale->text("Rechnungsnummer") . qq| | . $form->{invnumber};
1115 $form->save_history($form->dbconnect(\%myconfig));
1117 # /saving the history
1118 remove_draft() if $form->{remove_draft};
1119 $form->redirect( $locale->text('Invoice')
1120 . " $form->{invnumber} "
1121 . $locale->text('posted!'));
1123 $form->error($locale->text('Cannot post invoice!'));
1125 $lxdebug->leave_sub();
1129 $lxdebug->enter_sub();
1131 $auth->assert('vendor_invoice_edit');
1137 <form method=post action=$form->{script}>
1140 # delete action variable
1141 map { delete $form->{$_} } qw(action header);
1143 foreach $key (keys %$form) {
1144 next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
1145 $form->{$key} =~ s/\"/"/g;
1146 print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
1150 <h2 class=confirm>| . $locale->text('Confirm!') . qq|</h2>
1153 . $locale->text('Are you sure you want to delete Invoice Number')
1154 . qq| $form->{invnumber}</h4>
1156 <input name=action class=submit type=submit value="|
1157 . $locale->text('Yes') . qq|">
1161 $lxdebug->leave_sub();
1165 $lxdebug->enter_sub();
1167 $auth->assert('vendor_invoice_edit');
1169 if (IR->delete_invoice(\%myconfig, \%$form)) {
1170 # saving the history
1171 if(!exists $form->{addition}) {
1172 $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
1173 $form->{addition} = "DELETED";
1174 $form->save_history($form->dbconnect(\%myconfig));
1176 # /saving the history
1177 $form->redirect($locale->text('Invoice deleted!'));
1179 $form->error($locale->text('Cannot delete invoice!'));
1181 $lxdebug->leave_sub();