X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Fis.pl;h=0334843f9ddd7cbcbf26b0642b4705dff1bc88c9;hb=a1e47d425a58b8342992daab4907591506949f07;hp=a043e07bb655b4bbb147502769149a3a7ecf48c6;hpb=4dbb09950c9f5596646537c12d991c99086fe7c1;p=kivitendo-erp.git diff --git a/bin/mozilla/is.pl b/bin/mozilla/is.pl index a043e07bb..0334843f9 100644 --- a/bin/mozilla/is.pl +++ b/bin/mozilla/is.pl @@ -31,32 +31,42 @@ # #====================================================================== - use SL::IS; use SL::PE; +use Data::Dumper; require "$form->{path}/io.pl"; require "$form->{path}/arap.pl"; - 1; -# end of main - +# end of main sub add { $lxdebug->enter_sub(); + + if ($form->{type} eq "credit_note") { + $form->{title} = $locale->text('Add Credit Note'); + + if ($form->{storno}) { + $form->{title} = $locale->text('Add Storno Credit Note'); + } + } else { + $form->{title} = $locale->text('Add Sales Invoice'); + + } - $form->{title} = $locale->text('Add Sales Invoice'); - $form->{callback} = "$form->{script}?action=add&type=$form->{type}&login=$form->{login}&path=$form->{path}&password=$form->{password}" unless $form->{callback}; + $form->{callback} = + "$form->{script}?action=add&type=$form->{type}&login=$form->{login}&path=$form->{path}&password=$form->{password}" + unless $form->{callback}; $form{jsscript} = "date"; - - if ($myconfig{acs} =~ "AR--Add Sales Invoice" || $myconfig{acs} =~ "AR--AR") { - $form->error("Access Denied") - } - + + if ($myconfig{acs} =~ "AR--Add Sales Invoice" || $myconfig{acs} =~ "AR--AR") + { + $form->error("Access Denied"); + } &invoice_links; &prepare_invoice; &display_form; @@ -64,31 +74,40 @@ sub add { $lxdebug->leave_sub(); } - sub edit { $lxdebug->enter_sub(); - $form->{title} = $locale->text('Edit Sales Invoice'); - - if ($myconfig{acs} =~ "AR--Add Sales Invoice" || $myconfig{acs} =~ "AR--AR") { - $form->error("Access Denied") - } - + + if ($myconfig{acs} =~ "AR--Add Sales Invoice" || $myconfig{acs} =~ "AR--AR") + { + $form->error("Access Denied"); + } + $edit = 1; + if ($form->{print_and_post}) { + $form->{action} = "print"; + $form->{resubmit} = 1; + $language_id = $form->{language_id}; + $printer_id = $form->{printer_id}; + } &invoice_links; &prepare_invoice; + if ($form->{print_and_post}) { + $form->{language_id} = $language_id; + $form->{printer_id} = $printer_id; + } + &display_form; $lxdebug->leave_sub(); } - sub invoice_links { $lxdebug->enter_sub(); $form->{vc} = 'customer'; # create links - $form->{webdav} = $webdav; + $form->{webdav} = $webdav; $form->{lizenzen} = $lizenzen; $form->create_links("AR", \%myconfig, "customer"); @@ -98,14 +117,51 @@ sub invoice_links { $form->{customer_id} = $form->{all_customer}->[0]->{id}; } } + + if ($form->{payment_id}) { + $payment_id = $form->{payment_id}; + } + if ($form->{language_id}) { + $language_id = $form->{language_id}; + } + if ($form->{taxzone_id}) { + $taxzone_id = $form->{taxzone_id}; + } + if ($form->{id}) { + $id = $form->{id}; + } + if ($form->{shipto_id}) { + $shipto_id = $form->{shipto_id}; + } + $cp_id = $form->{cp_id}; IS->get_customer(\%myconfig, \%$form); - + + #quote all_customer Bug 133 + foreach $ref (@{ $form->{all_customer} }) { + $ref->{name} = $form->quote($ref->{name}); + } + if ($id) { + $form->{id} = $id; + } IS->retrieve_invoice(\%myconfig, \%$form); $form->{cp_id} = $cp_id; + if ($payment_id) { + $form->{payment_id} = $payment_id; + } + if ($language_id) { + $form->{language_id} = $language_id; + } + if ($taxzone_id) { + $form->{taxzone_id} = $taxzone_id; + } + if ($shipto_id) { + $form->{shipto_id} = $shipto_id; + } + # currencies - @curr = split /:/, $form->{currencies}; + @curr = split(/:/, $form->{currencies}); chomp $curr[0]; $form->{defaultcurrency} = $curr[0]; @@ -113,30 +169,36 @@ sub invoice_links { $form->{oldcustomer} = "$form->{customer}--$form->{customer_id}"; - if ($form->{all_customer}) { + if (@{ $form->{all_customer} }) { $form->{customer} = "$form->{customer}--$form->{customer_id}"; - map { $form->{selectcustomer} .= "|; + foreach $item (@{ $form->{payment_terms} }) { + if ($form->{payment_id} eq $item->{id}) { + $payment .= qq||; + } else { + $payment .= qq||; + } + } + + my $set_duedate_url = + "$form->{script}?login=$form->{login}&path=$form->{path}&password=$form->{password}&action=set_duedate"; + + my $pjx = new CGI::Ajax( 'set_duedate' => $set_duedate_url ); + push(@ { $form->{AJAX} }, $pjx); + + if (@{ $form->{TAXZONE} }) { + $form->{selecttaxzone} = ""; + foreach $item (@{ $form->{TAXZONE} }) { + if ($item->{id} == $form->{taxzone_id}) { + $form->{selecttaxzone} .= + ""; + } else { + $form->{selecttaxzone} .= + ""; + } + + } + } else { + $form->{selecttaxzone} =~ s/ selected//g; + if ($form->{taxzone_id} ne "") { + $form->{selecttaxzone} =~ s/value=$form->{taxzone_id}/value=$form->{taxzone_id} selected/; + } + } + + $taxzone = qq| + + | . $locale->text('Steuersatz') . qq| + + + |; + + + if (@{ $form->{SHIPTO} }) { + $form->{selectshipto} = ""; + foreach $item (@{ $form->{SHIPTO} }) { + if ($item->{shipto_id} == $form->{shipto_id}) { + $form->{selectshipto} .= + ""; + } else { + $form->{selectshipto} .= + ""; + } + + } + } else { + $form->{selectshipto} = $form->unquote($form->{selectshipto}); + $form->{selectshipto} =~ s/ selected//g; + if ($form->{shipto_id} ne "") { + $form->{selectshipto} =~ s/value=$form->{shipto_id}/value=$form->{shipto_id} selected/; + } + } + + $shipto = qq| + | . $locale->text('Shipping Address') . qq| + |; + $form->{selectshipto} = $form->quote($form->{selectshipto}); + $shipto .= qq| |; + + + # set option selected - foreach $item (qw(AR customer currency department employee contact)) { + foreach $item (qw(AR customer currency department employee)) { $form->{"select$item"} =~ s/ selected//; - $form->{"select$item"} =~ s/option>\Q$form->{$item}\E/option selected>$form->{$item}/; + $form->{"select$item"} =~ + s/option>\Q$form->{$item}\E/option selected>$form->{$item}/; } + + #quote customer Bug 133 + $form->{selectcustomer} = $form->quote($form->{selectcustomer}); #build contacts if ($form->{all_contacts}) { - - $form->{selectcontact} = ""; - foreach $item (@{$form->{all_contacts}}) { - if ($form->{cp_id} == $item->{cp_id}) - { - $form->{selectcontact} .= ""; + foreach $item (@{ $form->{all_contacts} }) { + my $department = ($item->{cp_abteilung}) ? "--$item->{cp_abteilung}" : ""; + if ($form->{cp_id} == $item->{cp_id}) { + $form->{selectcontact} .= + ""; + } else { + $form->{selectcontact} .= ""; } - } - #else {$form->{all_contacts} = 0;} + } + } else { + $form->{selectcontact} =~ s/ selected//g; + if ($form->{cp_id} ne "") { + $form->{selectcontact} =~ s/value=$form->{cp_id}/value=$form->{cp_id} selected/; + } + } - $form->{exchangerate} = $form->format_amount(\%myconfig, $form->{exchangerate}); - $form->{creditlimit} = $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0"); - $form->{creditremaining} = $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0"); + if (($form->{creditlimit} != 0) && ($form->{creditremaining} < 0) && !$form->{update}) { + $creditwarning = 1; + } else { + $creditwarning = 0; + } + + #else {$form->{all_contacts} = 0;} + $form->{exchangerate} = + $form->format_amount(\%myconfig, $form->{exchangerate}); + + $form->{creditlimit} = + $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0"); + $form->{creditremaining} = + $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0"); $exchangerate = ""; if ($form->{currency} ne $form->{defaultcurrency}) { if ($form->{forex}) { - $exchangerate .= qq||.$locale->text('Exchangerate').qq|$form->{exchangerate}{exchangerate}>|; + $exchangerate .= + qq|| + . $locale->text('Exchangerate') + . qq|$form->{exchangerate}{exchangerate}>|; } else { - $exchangerate .= qq||.$locale->text('Exchangerate').qq|{exchangerate}>|; + $exchangerate .= + qq|| + . $locale->text('Exchangerate') + . qq|{exchangerate}>|; } } $exchangerate .= qq| {forex}> |; - - $customer = ($form->{selectcustomer}) ? qq|\n| : qq||; + + $customer = + ($form->{selectcustomer}) + ? qq|\n| + : qq||; #sk - $contact = ($form->{selectcontact}) ? qq|\n| : qq||; - + $contact = + ($form->{selectcontact}) + ? qq|\n| + : qq||; + $department = qq| - |.$locale->text('Department').qq| + | . $locale->text('Department') . qq| | if $form->{selectdepartment}; - $n = ($form->{creditremaining} =~ /-/) ? "0" : "1"; - if ($form->{business}) { $business = qq| - |.$locale->text('Business').qq| + | . $locale->text('Business') . qq| $form->{business} - |.$locale->text('Trade Discount').qq| - |.$form->format_amount(\%myconfig, $form->{tradediscount} * 100).qq| % + | . $locale->text('Trade Discount') . qq| + | + . $form->format_amount(\%myconfig, $form->{tradediscount} * 100) + . qq| % + +|; + } + + if ($form->{max_dunning_level}) { + $dunning = qq| + + + + + + + + +
| . $locale->text('Max. Dunning Level') . qq|:$form->{max_dunning_level}| . $locale->text('Dunning Amount') . qq|:| + . $form->format_amount(\%myconfig, $form->{dunning_amount},2) + . qq|
+ + |; } $form->{fokus} = "invoice.customer"; - + # use JavaScript Calendar or not $form->{jsscript} = $jscalendar; $jsscript = ""; - if ($form->{jsscript}) - { - # with JavaScript Calendar - $button1 = qq| - {invdate}> - text('button').qq|> - |; - $button2 = qq| - {duedate}> - text('button').qq|> - |; - - #write Trigger - $jsscript = Form->write_trigger(\%myconfig, "2","invdate","BL","trigger1","duedate","BL","trigger2"); - } - else - { + if ($form->{type} eq "credit_note") { + if ($form->{jsscript}) { + + # with JavaScript Calendar + $button1 = qq| + {invdate}> + text('button') . qq|> + |; + + #write Trigger + $jsscript = + Form->write_trigger(\%myconfig, "1", + "invdate", "BL", + "trigger1"); + } else { + # without JavaScript Calendar - $button1 = qq|{invdate}>|; - $button2 = qq|{duedate}>|; + $button1 = + qq|{invdate}>|; + $button2 = + qq|{duedate}>|; } + } else { + if ($form->{jsscript}) { - $form->header; + # with JavaScript Calendar + $button1 = qq| + {invdate}> + text('button') . qq|> + |; + $button2 = qq| + {duedate}> + text('button') . qq|> + |; + $button3 = qq| + {deliverydate}> + text('button') . qq|> + |; + #write Trigger + $jsscript = + Form->write_trigger(\%myconfig, "3", + "invdate", "BL", + "trigger1", "duedate", + "BL", "trigger2", + "deliverydate", "BL", + "trigger3"); + } else { + + # without JavaScript Calendar + $button1 = + qq|{invdate}>|; + $button2 = + qq|{duedate}>|; + } + } + if ($form->{resubmit} && ($form->{format} eq "html")) { + $onload = + qq|window.open('about:blank','Beleg'); document.invoice.target = 'Beleg';document.invoice.submit()|; + } elsif ($form->{resubmit}) { + $onload = qq|document.invoice.submit()|; + } else { + $onload = "fokus()"; + } + + $credittext = $locale->text('Credit Limit exceeded!!!'); + if ($creditwarning) { + $onload = qq|alert('$credittext')|; + } + + $form->{"javascript"} .= qq||; + + $form->header; + print qq| - + + + + +
{script}> {id}> +{action}> {type}> {media}> @@ -337,6 +620,10 @@ sub form_header { {shipped}> +{storno}> +{storno_id}> + + @@ -350,11 +637,13 @@ sub form_header { |; +# +# +# +print qq|
- + + {customer_klass}> {customer_id}> - + @@ -362,24 +651,27 @@ sub form_header { + $shipto $business + $dunning - - + + + $taxzone $department - + {defaultcurrency}> @@ -388,45 +680,80 @@ sub form_header { $exchangerate - + - + - -
|.$locale->text('Customer').qq|| . $locale->text('Customer') . qq| $customer|.$locale->text('Contact Person').qq|| + . $locale->text('Contact Person') . qq| $contact
- + - +
|.$locale->text('Credit Limit').qq|| . $locale->text('Credit Limit') . qq| $form->{creditlimit} |.$locale->text('Remaining').qq|| . $locale->text('Remaining') . qq| $form->{creditremaining}
|.$locale->text('Record in').qq|| . $locale->text('Record in') . qq|
|.$locale->text('Currency').qq|| . $locale->text('Currency') . qq|
|.$locale->text('Shipping Point').qq|| . $locale->text('Shipping Point') . qq|
|.$locale->text('Ship via').qq|| . $locale->text('Ship via') . qq|
+
+# +# +# +# +# +# +# +# +# +#
+# +# +#
+# +# +#
+#
- + + |; +if ($form->{type} eq "credit_note") { +print qq| + + - + + $button1 + |; +} else { +print qq| + - + $button1 - + $button2 - + + $button3 + |; +} +print qq| + - + - +
|.$locale->text('Salesperson').qq|| . $locale->text('Salesperson') . qq|
| . $locale->text('Credit Note Number') . qq|
|.$locale->text('Invoice Number').qq|| . $locale->text('Credit Note Date') . qq|
| . $locale->text('Invoice Number') . qq|
|.$locale->text('Invoice Date').qq|| . $locale->text('Invoice Date') . qq|
|.$locale->text('Due Date').qq|| . $locale->text('Due Date') . qq|
|.$locale->text('Order Number').qq|| . $locale->text('Delivery Date') . qq|
| . $locale->text('Order Number') . qq|
|.$locale->text('Quotation Number').qq|| . $locale->text('Quotation Number') . qq|
|.$locale->text('Customer Order Number').qq|| . $locale->text('Customer Order Number') . qq|
@@ -441,7 +768,7 @@ sub form_header { $jsscript - + @@ -474,8 +801,6 @@ $jsscript $lxdebug->leave_sub(); } - - sub form_footer { $lxdebug->enter_sub(); @@ -488,26 +813,33 @@ sub form_footer { $introws = 2; } $rows = ($rows > $introws) ? $rows : $introws; - $notes = qq||; - $intnotes = qq||; + $notes = + qq||; + $intnotes = + qq||; $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : ""; $taxincluded = ""; if ($form->{taxaccounts}) { $taxincluded = qq| - {taxincluded}> |.$locale->text('Tax Included').qq|

|; + {taxincluded}> | + . $locale->text('Tax Included') . qq|

|; } if (!$form->{taxincluded}) { foreach $item (split / /, $form->{taxaccounts}) { if ($form->{"${item}_base"}) { - $form->{"${item}_total"} = $form->round_amount($form->{"${item}_base"} * $form->{"${item}_rate"}, 2); - $form->{invtotal} += $form->{"${item}_total"}; - $form->{"${item}_total"} = $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2); - - $tax .= qq| + $form->{"${item}_total"} = + $form->round_amount( + $form->{"${item}_base"} * $form->{"${item}_rate"}, + 2); + $form->{invtotal} += $form->{"${item}_total"}; + $form->{"${item}_total"} = + $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2); + + $tax .= qq| $form->{"${item}_description"} $form->{"${item}_total"} @@ -516,27 +848,37 @@ sub form_footer { } } - $form->{invsubtotal} = $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0); + $form->{invsubtotal} = + $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0); $subtotal = qq| - |.$locale->text('Subtotal').qq| + | . $locale->text('Subtotal') . qq| $form->{invsubtotal} |; } - - if ($form->{taxincluded}) { - foreach $item (split / /, $form->{taxaccounts}) { - if ($form->{"${item}_base"}) { - $form->{"${item}_total"} = $form->round_amount(($form->{"${item}_base"} * $form->{"${item}_rate"} / (1 + $form->{"${item}_rate"})) , 2); - $form->{"${item}_netto"} = $form->round_amount(($form->{"${item}_base"}-$form->{"${item}_total"}), 2); - $form->{"${item}_total"} = $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2); - $form->{"${item}_netto"} = $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2); - - $tax .= qq| + if ($form->{taxincluded}) { + foreach $item (split / /, $form->{taxaccounts}) { + if ($form->{"${item}_base"}) { + $form->{"${item}_total"} = + $form->round_amount( + ($form->{"${item}_base"} * $form->{"${item}_rate"} / + (1 + $form->{"${item}_rate"}) + ), + 2); + $form->{"${item}_netto"} = + $form->round_amount( + ($form->{"${item}_base"} - $form->{"${item}_total"}), + 2); + $form->{"${item}_total"} = + $form->format_amount(\%myconfig, $form->{"${item}_total"}, 2); + $form->{"${item}_netto"} = + $form->format_amount(\%myconfig, $form->{"${item}_netto"}, 2); + + $tax .= qq| Enthaltene $form->{"${item}_description"} $form->{"${item}_total"} @@ -548,13 +890,12 @@ sub form_footer { |; } } - - + } - $form->{oldinvtotal} = $form->{invtotal}; - $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0); + $form->{invtotal} = + $form->format_amount(\%myconfig, $form->{invtotal}, 2, 0); print qq| @@ -564,12 +905,15 @@ sub form_footer { - - + + + +
|.$locale->text('Notes').qq||.$locale->text('Internal Notes').qq|| . $locale->text('Notes') . qq|| . $locale->text('Internal Notes') . qq|| . $locale->text('Payment Terms') . qq|
$notes $intnotes
@@ -579,7 +923,7 @@ sub form_footer { $subtotal $tax - |.$locale->text('Total').qq| + | . $locale->text('Total') . qq| $form->{invtotal} @@ -590,41 +934,53 @@ sub form_footer { |; if ($webdav) { - $webdav_list = qq| + $webdav_list = qq|
- + Dokumente im Webdav-Repository |; - foreach $file (keys %{ $form->{WEBDAV}}) { - $webdav_list .= qq| - + foreach $file (keys %{ $form->{WEBDAV} }) { + $webdav_list .= qq| + |; - } - $webdav_list .= qq| + } + $webdav_list .= qq|
Dateiname Webdavlink
$file $form->{WEBDAV}{$file}
|; -print $webdav_list; -} -print qq| + print $webdav_list; + } +if ($form->{type} eq "credit_note") { + print qq| - + |; +} else { + print qq| + +
|.$locale->text('Incoming Payments') - .qq|| + . $locale->text('Payments') . qq|
+ + + + +|; +} if ($form->{currency} eq $form->{defaultcurrency}) { @column_index = qw(datepaid source memo paid AR_paid); @@ -632,12 +988,12 @@ print qq| @column_index = qw(datepaid source memo paid exchangerate AR_paid); } - $column_data{datepaid} = ""; - $column_data{paid} = ""; - $column_data{exchangerate} = ""; - $column_data{AR_paid} = ""; - $column_data{source} = ""; - $column_data{memo} = ""; + $column_data{datepaid} = ""; + $column_data{paid} = ""; + $column_data{exchangerate} = ""; + $column_data{AR_paid} = ""; + $column_data{source} = ""; + $column_data{memo} = ""; print " @@ -647,6 +1003,8 @@ print qq| "; + my @triggers = (); + $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"}); for $i (1 .. $form->{paidaccounts}) { @@ -654,44 +1012,58 @@ print qq| \n"; $form->{"selectAR_paid_$i"} = $form->{selectAR_paid}; - $form->{"selectAR_paid_$i"} =~ s/option>\Q$form->{"AR_paid_$i"}\E/option selected>$form->{"AR_paid_$i"}/; + $form->{"selectAR_paid_$i"} =~ + s/option>\Q$form->{"AR_paid_$i"}\E/option selected>$form->{"AR_paid_$i"}/; # format amounts $totalpaid += $form->{"paid_$i"}; - $form->{"paid_$i"} = $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2); - $form->{"exchangerate_$i"} = $form->format_amount(\%myconfig, $form->{"exchangerate_$i"}); + if ($form->{"paid_$i"}) { + $form->{"paid_$i"} = + $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2); + } + $form->{"exchangerate_$i"} = + $form->format_amount(\%myconfig, $form->{"exchangerate_$i"}); $exchangerate = qq| |; if ($form->{currency} ne $form->{defaultcurrency}) { if ($form->{"forex_$i"}) { - $exchangerate = qq|{"exchangerate_$i"}>$form->{"exchangerate_$i"}|; + $exchangerate = + qq|{"exchangerate_$i"}>$form->{"exchangerate_$i"}|; } else { - $exchangerate = qq|{"exchangerate_$i"}>|; + $exchangerate = + qq|{"exchangerate_$i"}>|; } } - + $exchangerate .= qq| {"forex_$i"}> |; - $column_data{"paid_$i"} = qq||; + $column_data{"paid_$i"} = + qq||; $column_data{"exchangerate_$i"} = qq||; - $column_data{"AR_paid_$i"} = qq||; - $column_data{"datepaid_$i"} = qq||; - $column_data{"source_$i"} = qq||; - $column_data{"memo_$i"} = qq||; + $column_data{"AR_paid_$i"} = + qq||; + $column_data{"datepaid_$i"} = + qq||; + $column_data{"source_$i"} = + qq||; + $column_data{"memo_$i"} = + qq||; map { print qq|$column_data{"${_}_$i"}\n| } @column_index; print " \n"; + push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i"); } - + print qq| {paidaccounts}> {oldinvtotal}> -
| + . $locale->text('Incoming Payments') . qq|
".$locale->text('Date')."".$locale->text('Amount')."".$locale->text('Exch')."".$locale->text('Account')."".$locale->text('Source')."".$locale->text('Memo')."" . $locale->text('Date') . "" . $locale->text('Amount') . "" . $locale->text('Exch') . "" . $locale->text('Account') . "" . $locale->text('Source') . "" . $locale->text('Memo') . "
{"paid_$i"}>{"paid_$i"}>$exchangerate{"datepaid_$i"}>{"datepaid_$i"}> +
+
@@ -700,62 +1072,76 @@ print qq| |; - - - &print_options; + &print_options; - print qq| |; - - $invdate = $form->datetonum($form->{invdate}, \%myconfig); + $invdate = $form->datetonum($form->{invdate}, \%myconfig); $closedto = $form->datetonum($form->{closedto}, \%myconfig); if ($form->{id}) { print qq| - - - - + + + + |; + print qq|| unless ($form->{storno}); + print qq| |; - - if (!$form->{revtrans}) { - if (!$form->{locked}) { - print qq| - - + print qq| |; - } - } + if ($form->{id} && !($form->{type} eq "credit_note")) { + print qq| + +|; + } + if ($form->{radier}) { + print qq| + +|; + } + if ($invdate > $closedto) { print qq| - - + |; } } else { if ($invdate > $closedto) { - print qq| - - - - |; + print qq| + + + + + |; } } - if ($form->{menubar}) { - require "$form->{path}/menu.pl"; - &menubar; - } - - print qq| + print $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) . + qq| {rowcount}> @@ -775,31 +1161,53 @@ print qq| $lxdebug->leave_sub(); } - sub update { $lxdebug->enter_sub(); - map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate creditlimit creditremaining); + map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } + qw(exchangerate creditlimit creditremaining); + if ($form->{second_run}) { + $form->{print_and_post} = 0; + } + + $form->{update} = 1; &check_name(customer); &check_project; - $form->{exchangerate} = $exchangerate if ($form->{forex} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{invdate}, 'buy'))); + $form->{exchangerate} = $exchangerate + if ( + $form->{forex} = ( + $exchangerate = + $form->check_exchangerate( + \%myconfig, $form->{currency}, $form->{invdate}, 'buy' + ))); for $i (1 .. $form->{paidaccounts}) { if ($form->{"paid_$i"}) { - map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(paid exchangerate); - - $form->{"exchangerate_$i"} = $exchangerate if ($form->{"forex_$i"} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy'))); + map { + $form->{"${_}_$i"} = + $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) + } qw(paid exchangerate); + + $form->{"exchangerate_$i"} = $exchangerate + if ( + $form->{"forex_$i"} = ( + $exchangerate = + $form->check_exchangerate( + \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy' + ))); } } - $i = $form->{rowcount}; + $i = $form->{rowcount}; $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1; # if last row empty, check the form otherwise retrieve new item - if (($form->{"partnumber_$i"} eq "") && ($form->{"description_$i"} eq "") && ($form->{"partsgroup_$i"} eq "")) { + if ( ($form->{"partnumber_$i"} eq "") + && ($form->{"description_$i"} eq "") + && ($form->{"partsgroup_$i"} eq "")) { $form->{creditremaining} += ($form->{oldinvtotal} - $form->{oldtotalpaid}); &check_form; @@ -810,94 +1218,148 @@ sub update { $rows = scalar @{ $form->{item_list} }; - $form->{"discount_$i"} = $form->format_amount(\%myconfig, $form->{discount} * 100); + $form->{"discount_$i"} = + $form->format_amount(\%myconfig, $form->{discount} * 100); if ($rows) { - $form->{"qty_$i"} = ($form->{"qty_$i"} * 1) ? $form->{"qty_$i"} : 1; + $form->{"qty_$i"} = ($form->{"qty_$i"} * 1) ? $form->{"qty_$i"} : 1; if ($rows > 1) { - &select_item; - exit; + &select_item; + exit; } else { - $sellprice = $form->format_amount(\%myconfig, $form->{"sellprice_$i"}); - - map { $form->{item_list}[$i]{$_} =~ s/\"/"/g } qw(partnumber description unit); - map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} } keys %{ $form->{item_list}[0] }; - - $form->{"discount_$i"} = $form->{discount} * 100; - - $s = ($sellprice) ? $sellprice : $form->{"sellprice_$i"}; - ($dec) = ($s =~ /\.(\d+)/); - $dec = length $dec; - $decimalplaces = ($dec > 2) ? $dec : 2; - - if ($sellprice) { - $form->{"sellprice_$i"} = $sellprice; - } else { - # if there is an exchange rate adjust sellprice - $form->{"sellprice_$i"} *= (1 - $form->{tradediscount}); - $form->{"sellprice_$i"} /= $exchangerate; - } - - $form->{"listprice_$i"} /= $exchangerate; - - $amount = $form->{"sellprice_$i"} * $form->{"qty_$i"} * (1 - $form->{"discount_$i"} / 100); - map { $form->{"${_}_base"} = 0 } (split / /, $form->{taxaccounts}); - map { $form->{"${_}_base"} += $amount } (split / /, $form->{"taxaccounts_$i"}); - map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } split / /, $form->{"taxaccounts_$i"} if !$form->{taxincluded}; + $sellprice = $form->parse_amount(\%myconfig, $form->{"sellprice_$i"}); + + map { $form->{item_list}[$i]{$_} =~ s/\"/"/g } + qw(partnumber description unit); + map { $form->{"${_}_$i"} = $form->{item_list}[0]{$_} } + keys %{ $form->{item_list}[0] }; + if ($form->{"part_payment_id_$i"} ne "") { + $form->{payment_id} = $form->{"part_payment_id_$i"}; + } + + if ($form->{"not_discountable_$i"}) { + $form->{"discount_$i"} = 0; + } + + $s = ($sellprice) ? $sellprice : $form->{"sellprice_$i"}; + ($dec) = ($s =~ /\.(\d+)/); + $dec = length $dec; + $decimalplaces = ($dec > 2) ? $dec : 2; + + if ($sellprice) { + $form->{"sellprice_$i"} = $sellprice; + } else { + + # if there is an exchange rate adjust sellprice + $form->{"sellprice_$i"} *= (1 - $form->{tradediscount}); + $form->{"sellprice_$i"} /= $exchangerate; + } + + $form->{"listprice_$i"} /= $exchangerate; + + $amount = + $form->{"sellprice_$i"} * $form->{"qty_$i"} * + (1 - $form->{"discount_$i"} / 100); + map { $form->{"${_}_base"} = 0 } (split / /, $form->{taxaccounts}); + map { $form->{"${_}_base"} += $amount } + (split / /, $form->{"taxaccounts_$i"}); + map { $amount += ($form->{"${_}_base"} * $form->{"${_}_rate"}) } + split / /, $form->{"taxaccounts_$i"} + if !$form->{taxincluded}; $form->{creditremaining} -= $amount; + map { + $form->{"${_}_$i"} = + $form->format_amount(\%myconfig, $form->{"${_}_$i"}, + $decimalplaces) + } qw(sellprice listprice); + + $form->{"qty_$i"} = + $form->format_amount(\%myconfig, $form->{"qty_$i"}); + + if ($lizenzen) { + if ($form->{"inventory_accno_$i"} ne "") { + $form->{"lizenzen_$i"} = qq||; + foreach $item (@{ $form->{LIZENZEN}{ $form->{"id_$i"} } }) { + $form->{"lizenzen_$i"} .= + qq||; + } + $form->{"lizenzen_$i"} .= + qq||; + } + } - map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, $decimalplaces) } qw(sellprice listprice); - - $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"}); - - if ($lizenzen) { - if ($form->{"inventory_accno_$i"} ne "") { - $form->{"lizenzen_$i"} = qq||; - foreach $item (@{ $form->{LIZENZEN}{$form->{"id_$i"}}}) { - $form->{"lizenzen_$i"} .= qq||; - } - $form->{"lizenzen_$i"} .= qq||; - } - } - + # get pricegroups for parts + IS->get_pricegroups_for_parts(\%myconfig, \%$form); + # build up html code for prices_$i + &set_pricegroup($i); } &display_form; } else { + # ok, so this is a new part # ask if it is a part or service item - if ($form->{"partsgroup_$i"} && ($form->{"partsnumber_$i"} eq "") && ($form->{"description_$i"} eq "")) { - $form->{rowcount}--; - $form->{"discount_$i"} = ""; - &display_form; - } else { + if ( $form->{"partsgroup_$i"} + && ($form->{"partsnumber_$i"} eq "") + && ($form->{"description_$i"} eq "")) { + $form->{rowcount}--; + $form->{"discount_$i"} = ""; + &display_form; + } else { - $form->{"id_$i"} = 0; - $form->{"unit_$i"} = $locale->text('ea'); + $form->{"id_$i"} = 0; + $form->{"unit_$i"} = $locale->text('ea'); - &new_item; + &new_item; } } } $lxdebug->leave_sub(); } +sub post_payment { + $lxdebug->enter_sub(); + for $i (1 .. $form->{paidaccounts}) { + if ($form->{"paid_$i"}) { + $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig); + + $form->isblank("datepaid_$i", $locale->text('Payment date missing!')); + + $form->error($locale->text('Cannot post payment for a closed period!')) + if ($datepaid <= $closedto); + + if ($form->{currency} ne $form->{defaultcurrency}) { + $form->{"exchangerate_$i"} = $form->{exchangerate} + if ($invdate == $datepaid); + $form->isblank("exchangerate_$i", + $locale->text('Exchangerate for payment missing!')); + } + } + } + ($form->{AR}) = split /--/, $form->{AR}; + ($form->{AR_paid}) = split /--/, $form->{AR_paid}; + relink_accounts(); + $form->redirect($locale->text(' Payment posted!')) + if (IS->post_payment(\%myconfig, \%$form)); + $form->error($locale->text('Cannot post payment!')); + $lxdebug->leave_sub(); +} + sub post { $lxdebug->enter_sub(); - - $form->isblank("invdate", $locale->text('Invoice Date missing!')); + $form->isblank("invdate", $locale->text('Invoice Date missing!')); $form->isblank("customer", $locale->text('Customer missing!')); # if oldcustomer ne customer redo form @@ -905,53 +1367,129 @@ sub post { &update; exit; } - + if ($form->{second_run}) { + $form->{print_and_post} = 0; + } + &validate_items; $closedto = $form->datetonum($form->{closedto}, \%myconfig); - $invdate = $form->datetonum($form->{invdate}, \%myconfig); - - $form->error($locale->text('Cannot post invoice for a closed period!')) if ($invdate <= $closedto); + $invdate = $form->datetonum($form->{invdate}, \%myconfig); + + $form->error($locale->text('Cannot post invoice for a closed period!')) + if ($invdate <= $closedto); + + $form->isblank("exchangerate", $locale->text('Exchangerate missing!')) + if ($form->{currency} ne $form->{defaultcurrency}); - $form->isblank("exchangerate", $locale->text('Exchangerate missing!')) if ($form->{currency} ne $form->{defaultcurrency}); - for $i (1 .. $form->{paidaccounts}) { - if ($form->{"paid_$i"}) { + if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) { $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig); $form->isblank("datepaid_$i", $locale->text('Payment date missing!')); - - $form->error($locale->text('Cannot post payment for a closed period!')) if ($datepaid <= $closedto); + + $form->error($locale->text('Cannot post payment for a closed period!')) + if ($datepaid <= $closedto); if ($form->{currency} ne $form->{defaultcurrency}) { - $form->{"exchangerate_$i"} = $form->{exchangerate} if ($invdate == $datepaid); - $form->isblank("exchangerate_$i", $locale->text('Exchangerate for payment missing!')); + $form->{"exchangerate_$i"} = $form->{exchangerate} + if ($invdate == $datepaid); + $form->isblank("exchangerate_$i", + $locale->text('Exchangerate for payment missing!')); } } } - - ($form->{AR}) = split /--/, $form->{AR}; + ($form->{AR}) = split /--/, $form->{AR}; ($form->{AR_paid}) = split /--/, $form->{AR_paid}; - + $form->{label} = $locale->text('Invoice'); $form->{id} = 0 if $form->{postasnew}; - - $form->{invnumber} = $form->update_defaults(\%myconfig, "invnumber") unless $form->{invnumber}; - - $form->redirect($form->{label}." $form->{invnumber} ".$locale->text('posted!')) if (IS->post_invoice(\%myconfig, \%$form)); - $form->error($locale->text('Cannot post invoice!')); - + + # get new invnumber in sequence if no invnumber is given or if posasnew was requested + if (!$form->{invnumber} || $form->{postasnew}) { + if ($form->{type} eq "credit_note") { + $form->{invnumber} = $form->update_defaults(\%myconfig, "cnnumber"); + } else { + $form->{invnumber} = $form->update_defaults(\%myconfig, "invnumber"); + } + } + relink_accounts(); + if ($print_post) { + if (!(IS->post_invoice(\%myconfig, \%$form))) { + $form->error($locale->text('Cannot post invoice!')); + } + } else { + $form->redirect( + $form->{label} . " $form->{invnumber} " . $locale->text('posted!')) + if (IS->post_invoice(\%myconfig, \%$form)); + $form->error($locale->text('Cannot post invoice!')); + } + $lxdebug->leave_sub(); } +sub print_and_post { + $lxdebug->enter_sub(); + $old_form = new Form; + $print_post = 1; + $form->{print_and_post} = 1; + &post(); + &edit(); + $lxdebug->leave_sub(); -sub delete { +} + +sub use_as_template { + $lxdebug->enter_sub(); + + 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); + $form->{paidaccounts} = 1; + $form->{rowcount}--; + $form->{invdate} = $form->current_date(\%myconfig); + &display_form; + + $lxdebug->leave_sub(); +} + +sub storno { + $lxdebug->enter_sub(); + + if ($form->{storno}) { + $form->error($locale->text('Cannot storno storno invoice!')); + } + + $form->{storno_id} = $form->{id}; + $form->{storno} = 1; + $form->{id} = ""; + $form->{invnumber} = "Storno zu " . $form->{invnumber}; + + &post(); + $lxdebug->leave_sub(); + +} + +sub preview { $lxdebug->enter_sub(); + $form->{preview} = 1; + $old_form = new Form; + for (keys %$form) { $old_form->{$_} = $form->{$_} } + $old_form->{rowcount}++; + + &print_form($old_form); + $lxdebug->leave_sub(); + +} + +sub delete { + $lxdebug->enter_sub(); + if ($form->{second_run}) { + $form->{print_and_post} = 0; + } $form->header; print qq| @@ -969,28 +1507,82 @@ sub delete { } print qq| -

|.$locale->text('Confirm!').qq|

+

| . $locale->text('Confirm!') . qq|

-

|.$locale->text('Are you sure you want to delete Invoice Number').qq| $form->{invnumber} +

| + . $locale->text('Are you sure you want to delete Invoice Number') + . qq| $form->{invnumber}

- +

|; - $lxdebug->leave_sub(); } +sub credit_note { + $lxdebug->enter_sub(); + + $form->{transdate} = $form->{invdate} = $form->current_date(\%myconfig); + $form->{duedate} = + $form->current_date(\%myconfig, $form->{invdate}, $form->{terms} * 1); + + $form->{id} = ''; + $form->{rowcount}--; + $form->{shipto} = 1; + $form->{title} = $locale->text('Add Credit Note'); + $form->{script} = 'is.pl'; + $script = "is"; + $buysell = 'buy'; + + + # bo creates the id, reset it + map { delete $form->{$_} } + qw(id invnumber subject message cc bcc printed emailed queued); + $form->{ $form->{vc} } =~ s/--.*//g; + $form->{type} = "credit_note"; + + + map { $form->{"select$_"} = "" } ($form->{vc}, currency); + + map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } + qw(creditlimit creditremaining); + + $currency = $form->{currency}; + &invoice_links; + + $form->{currency} = $currency; + $form->{exchangerate} = ""; + $form->{forex} = ""; + $form->{exchangerate} = $exchangerate + if ( + $form->{forex} = ( + $exchangerate = + $form->check_exchangerate( + \%myconfig, $form->{currency}, $form->{invdate}, $buysell + ))); + + $form->{creditremaining} -= ($form->{oldinvtotal} - $form->{ordtotal}); + + &prepare_invoice; + + + &display_form; + + $lxdebug->leave_sub(); +} + sub yes { $lxdebug->enter_sub(); - $form->redirect($locale->text('Invoice deleted!')) if (IS->delete_invoice(\%myconfig, \%$form, $spool)); + $form->redirect($locale->text('Invoice deleted!')) + if (IS->delete_invoice(\%myconfig, \%$form, $spool)); $form->error($locale->text('Cannot delete invoice!')); $lxdebug->leave_sub(); } -