X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;ds=sidebyside;f=bin%2Fmozilla%2Far.pl;h=4634cb19d48ffe550a69c89833e23f381c62aa3e;hb=828bd68326ee5bd732d3d01e9f166dacb7424657;hp=a6ecec82fcf626c15d1dd0c8cf44b9e650921426;hpb=4dbb09950c9f5596646537c12d991c99086fe7c1;p=kivitendo-erp.git diff --git a/bin/mozilla/ar.pl b/bin/mozilla/ar.pl index a6ecec82f..4634cb19d 100644 --- a/bin/mozilla/ar.pl +++ b/bin/mozilla/ar.pl @@ -31,14 +31,15 @@ # #====================================================================== - use SL::AR; use SL::IS; use SL::PE; +use Data::Dumper; require "$form->{path}/arap.pl"; 1; + # end of main # this is for our long dates @@ -69,25 +70,24 @@ require "$form->{path}/arap.pl"; # $locale->text('Nov') # $locale->text('Dec') - sub add { $lxdebug->enter_sub(); - - $form->{title} = "Add"; - $form->{callback} = "$form->{script}?action=add&path=$form->{path}&login=$form->{login}&password=$form->{password}" unless $form->{callback}; + $form->{title} = "Add"; + $form->{callback} = + "$form->{script}?action=add&path=$form->{path}&login=$form->{login}&password=$form->{password}" + unless $form->{callback}; &create_links; + AR->get_transdate(\%myconfig, $form); &display_form; - + $lxdebug->leave_sub(); } - sub edit { $lxdebug->enter_sub(); - $form->{title} = "Edit"; &create_links; @@ -96,34 +96,33 @@ sub edit { $lxdebug->leave_sub(); } - sub display_form { $lxdebug->enter_sub(); - &form_header; &form_footer; $lxdebug->leave_sub(); } - sub create_links { $lxdebug->enter_sub(); - $form->create_links("AR", \%myconfig, "customer"); $duedate = $form->{duedate}; - + $taxincluded = $form->{taxincluded}; - + my $id = $form->{id}; IS->get_customer(\%myconfig, \%$form); + $form->{taxincluded} = $taxincluded; + $form->{id} = $id; - $form->{duedate} = $duedate if $duedate; + $form->{duedate} = $duedate if $duedate; $form->{oldcustomer} = "$form->{customer}--$form->{customer_id}"; + $form->{rowcount} = 1; # currencies - @curr = split /:/, $form->{currencies}; + @curr = split(/:/, $form->{currencies}); chomp $curr[0]; $form->{defaultcurrency} = $curr[0]; @@ -132,169 +131,232 @@ sub create_links { # customers if (@{ $form->{all_customer} }) { $form->{customer} = "$form->{customer}--$form->{customer_id}"; - map { $form->{selectcustomer} .= "$_->{name}--$_->{id}\n" } (@{ $form->{all_customer} }); + map { $form->{selectcustomer} .= "$_->{name}--$_->{id}\n" } + (@{ $form->{all_customer} }); } - + # departments if (@{ $form->{all_departments} }) { $form->{selectdepartment} = "\n"; - $form->{department} = "$form->{department}--$form->{department_id}"; - - map { $form->{selectdepartment} .= "$_->{description}--$_->{id}\n" } (@{ $form->{all_departments} }); + $form->{department} = "$form->{department}--$form->{department_id}"; + + map { + $form->{selectdepartment} .= + "$_->{description}--$_->{id}\n" + } (@{ $form->{all_departments} }); } - + $form->{employee} = "$form->{employee}--$form->{employee_id}"; + # sales staff if (@{ $form->{all_employees} }) { $form->{selectemployee} = ""; - map { $form->{selectemployee} .= "$_->{name}--$_->{id}\n" } (@{ $form->{all_employees} }); + map { $form->{selectemployee} .= "$_->{name}--$_->{id}\n" } + (@{ $form->{all_employees} }); } + # build the popup menus $form->{taxincluded} = ($form->{id}) ? $form->{taxincluded} : "checked"; - - map { $tax .= qq|{taxkey}--$_->{rate}\">$_->{taxdescription} |.($_->{rate} * 100).qq| %|} @{ $form->{TAX} }; - $form->{taxchart} = $tax; + + map { + $tax .= + qq|{id}--$_->{rate}\">$_->{taxdescription} | + . ($_->{rate} * 100) . qq| %| + } @{ $form->{TAX} }; + $form->{taxchart} = $tax; $form->{selecttaxchart} = $tax; - + # forex $form->{forex} = $form->{exchangerate}; $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1; foreach $key (keys %{ $form->{AR_links} }) { - + foreach $ref (@{ $form->{AR_links}{$key} }) { if ($key eq "AR_paid") { - $form->{"select$key"} .= "{accno}\">$ref->{accno}--$ref->{description}\n"; + $form->{"select$key"} .= + "{accno}\">$ref->{accno}--$ref->{description}\n"; } else { - $form->{"select$key"} .= "{accno}--$ref->{taxkey}\">$ref->{accno}--$ref->{description}\n"; + $form->{"select$key"} .= + "{accno}--$ref->{tax_id}\">$ref->{accno}--$ref->{description}\n"; } } $form->{$key} = $form->{"select$key"}; + # if there is a value we have an old entry - $j = 0; + my $j = 0; + my $k = 0; + for $i (1 .. scalar @{ $form->{acc_trans}{$key} }) { if ($key eq "AR_paid") { $j++; - $form->{"AR_paid_$j"} = "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}"; - # reverse paid - $form->{"paid_$j"} = $form->{acc_trans}{$key}->[$i-1]->{amount} * -1; - $form->{"datepaid_$j"} = $form->{acc_trans}{$key}->[$i-1]->{transdate}; - $form->{"source_$j"} = $form->{acc_trans}{$key}->[$i-1]->{source}; - $form->{"memo_$j"} = $form->{acc_trans}{$key}->[$i-1]->{memo}; - - $form->{"forex_$j"} = $form->{"exchangerate_$i"} = $form->{acc_trans}{$key}->[$i-1]->{exchangerate}; - $form->{"AR_paid_$j"} = "$form->{acc_trans}{$key}->[$i-1]->{accno}"; - $form->{paidaccounts}++; + $form->{"AR_paid_$j"} = + "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}"; + + # reverse paid + $form->{"paid_$j"} = $form->{acc_trans}{$key}->[$i - 1]->{amount} * -1; + $form->{"datepaid_$j"} = + $form->{acc_trans}{$key}->[$i - 1]->{transdate}; + $form->{"source_$j"} = $form->{acc_trans}{$key}->[$i - 1]->{source}; + $form->{"memo_$j"} = $form->{acc_trans}{$key}->[$i - 1]->{memo}; + + $form->{"forex_$j"} = $form->{"exchangerate_$i"} = + $form->{acc_trans}{$key}->[$i - 1]->{exchangerate}; + $form->{"AR_paid_$j"} = "$form->{acc_trans}{$key}->[$i-1]->{accno}"; + $form->{paidaccounts}++; } else { - - $akey = $key; - $akey =~ s/AR_//; - - if ($key eq "AR_tax") { - $form->{"${key}_$form->{acc_trans}{$key}->[$i-1]->{accno}"} = "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}"; - $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"} = $form->round_amount($form->{acc_trans}{$key}->[$i-1]->{amount} / $exchangerate, 2); - - if ($form->{"$form->{acc_trans}{$key}->[$i-1]->{accno}_rate"} > 0) { - $totaltax += $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"}; - $taxrate += $form->{"$form->{acc_trans}{$key}->[$i-1]->{accno}_rate"}; - } else { - $totalwithholding += $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"}; - $withholdingrate += $form->{"$form->{acc_trans}{$key}->[$i-1]->{accno}_rate"}; - } - - } else { - $form->{"${akey}_$i"} = $form->round_amount($form->{acc_trans}{$key}->[$i-1]->{amount} / $exchangerate, 2); - if ($akey eq 'amount') { - $form->{rowcount}++; - $totalamount += $form->{"${akey}_$i"}; - - $form->{"oldprojectnumber_$i"} = $form->{"projectnumber_$i"} = "$form->{acc_trans}{$key}->[$i-1]->{projectnumber}"; - $form->{taxrate} = $form->{acc_trans}{$key}->[$i-1]->{rate}; - $form->{"project_id_$i"} = "$form->{acc_trans}{$key}->[$i-1]->{project_id}"; - } - $form->{"${key}_$i"} = "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}"; - $form->{"${key}_$i"} = "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}"; - $form->{"select${key}"} =~ /({acc_trans}{$key}->[$i-1]->{accno}--[^\"]*\">$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}<\/option>\n)/; - $test = $1; - $form->{"select${key}"} = $1; - if ($akey eq 'amount') { - $form->{selecttaxchart} =~ /({acc_trans}{$key}->[$i-1]->{taxkey}--[^<]*)/; - $form->{selecttaxchart} = $1; - } - } + + $akey = $key; + $akey =~ s/AR_//; + + if ($key eq "AR_tax" || $key eq "AP_tax") { + $form->{"${key}_$form->{acc_trans}{$key}->[$i-1]->{accno}"} = + "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}"; + $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"} = + $form->round_amount( + $form->{acc_trans}{$key}->[$i - 1]->{amount} / $exchangerate, + 2); + + if ($form->{"$form->{acc_trans}{$key}->[$i-1]->{accno}_rate"} > 0) { + $totaltax += + $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"}; + $taxrate += + $form->{"$form->{acc_trans}{$key}->[$i-1]->{accno}_rate"}; + } else { + $totalwithholding += + $form->{"${akey}_$form->{acc_trans}{$key}->[$i-1]->{accno}"}; + $withholdingrate += + $form->{"$form->{acc_trans}{$key}->[$i-1]->{accno}_rate"}; + } + $index = $form->{acc_trans}{$key}->[$i - 1]->{index}; + $form->{"tax_$index"} = $form->{acc_trans}{$key}->[$i - 1]->{amount}; + $totaltax += $form->{"tax_$index"}; + + } else { + $k++; + $form->{"${akey}_$k"} = + $form->round_amount( + $form->{acc_trans}{$key}->[$i - 1]->{amount} / $exchangerate, + 2); + if ($akey eq 'amount') { + $form->{rowcount}++; + $totalamount += $form->{"${akey}_$i"}; + + $form->{"oldprojectnumber_$k"} = $form->{"projectnumber_$k"} = + "$form->{acc_trans}{$key}->[$i-1]->{projectnumber}"; + $form->{taxrate} = $form->{acc_trans}{$key}->[$i - 1]->{rate}; + $form->{"project_id_$k"} = + "$form->{acc_trans}{$key}->[$i-1]->{project_id}"; + } + $form->{"${key}_$k"} = + "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}"; + $form->{"${key}_$i"} = + "$form->{acc_trans}{$key}->[$i-1]->{accno}--$form->{acc_trans}{$key}->[$i-1]->{description}"; + my $q_description = quotemeta($form->{acc_trans}{$key}->[$i-1]->{description}); + $form->{"select${key}"} =~ + /{acc_trans}{$key}->[$i-1]->{accno}--[^\"]*)\">$form->{acc_trans}{$key}->[$i-1]->{accno}--${q_description}<\/option>\n/; + $form->{"${key}_$k"} = $1; + if ($akey eq 'amount') { + $form->{"taxchart_$k"} = $form->{taxchart}; + $form->{"taxchart_$k"} =~ + /{acc_trans}{$key}->[$i-1]->{id}--[^\"]*)/; + $form->{"taxchart_$k"} = $1; + } + } } } } - $form->{taxincluded} = $taxincluded if ($form->{id}); - $form->{paidaccounts} = 1 if not defined $form->{paidaccounts}; - + $form->{taxincluded} = $taxincluded if ($form->{id}); + $form->{paidaccounts} = 1 if not defined $form->{paidaccounts}; + if ($form->{taxincluded} && $form->{taxrate} && $totalamount) { - # add tax to amounts and invtotal - for $i (1 .. 1) { - $taxamount = ($totaltax + $totalwithholding) * $form->{"amount_$i"} / $totalamount; + + # add tax to amounts and invtotal + for $i (1 .. $form->{rowcount}) { + $taxamount = + ($totaltax + $totalwithholding) * $form->{"amount_$i"} / $totalamount; $tax = $form->round_amount($taxamount, 2); - $diff += ($taxamount - $tax); - $form->{"amount_$i"} += $tax; + $diff += ($taxamount - $tax); + $form->{"amount_$i"} += $form->{"tax_$i"}; } $form->{amount_1} += $form->round_amount($diff, 2); } - # check if calculated is equal to stored - if ($form->{taxincluded} && $form->{taxrate} && $withholdingrate) { - if ($form->{"taxrate"} > 0) { - $taxamount = $form->round_amount(($form->{amount_1} - ($form->{amount_1} / ($form->{taxrate} + 1))), 2); - } else { - $taxamount = $form->round_amount(($totalamount + $totaltax + $totalwithholding) * $withholdingrate / (1 - $withholdingrate), 2) * $form->{"taxrate"} / $withholdingrate; - } - } else { - $taxamount = $totalamount * $form->{"taxrate"}; - } $taxamount = $form->round_amount($taxamount, 2); $form->{tax} = $taxamount; - $form->{invtotal} = $totalamount + $totaltax + $totalwithholding; - - - $form->{locked} = ($form->datetonum($form->{transdate}, \%myconfig) <= $form->datetonum($form->{closedto}, \%myconfig)); + $form->{invtotal} = $totalamount + $totaltax; + + $form->{locked} = + ($form->datetonum($form->{transdate}, \%myconfig) <= + $form->datetonum($form->{closedto}, \%myconfig)); + $form->{"ARselected"} = $form->{"AR_1"}; $lxdebug->leave_sub(); } - sub form_header { $lxdebug->enter_sub(); - $title = $form->{title}; $form->{title} = $locale->text("$title Accounts Receivables Transaction"); $form->{taxincluded} = ($form->{taxincluded}) ? "checked" : ""; + # $locale->text('Add Accounts Receivables Transaction') + # $locale->text('Edit Accounts Receivables Transaction') + $form->{javascript} = qq||; + + $readonly = ($form->{id}) ? "readonly" : ""; -# $locale->text('Add Accounts Receivables Transaction') -# $locale->text('Edit Accounts Receivables Transaction') - - - $readonly = ($form->{id}) ? "readonly" : ""; - - $form->{radier} = ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0; + $form->{radier} = + ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0; $readonly = ($form->{radier}) ? "" : $readonly; + my $ARselected_quoted = quotemeta($form->{"ARselected"}); + $form->{selectAR} = $form->{AR}; + $form->{selectAR} =~ + s/value=\"${ARselected_quoted}\"/value=\"$form->{ARselected}\" selected/; + # set option selected foreach $item (qw(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}/; } - - map { $form->{$_} =~ s/\"/"/g } qw(AR_amount AR taxchart); - + $selectAR_amount_unquoted = $form->{selectAR_amount}; + $taxchart = $form->{taxchart}; + map { $form->{$_} =~ s/\"/"/g } + qw(AR_amount selectAR_amount AR taxchart); + # format amounts - $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"); + $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 = qq| {forex}> @@ -302,46 +364,47 @@ sub form_header { if ($form->{currency} ne $form->{defaultcurrency}) { if ($form->{forex}) { $exchangerate .= qq| - |.$locale->text('Exchangerate').qq| + | . $locale->text('Exchangerate') . qq| {exchangerate}>$form->{exchangerate} |; } else { $exchangerate .= qq| - |.$locale->text('Exchangerate').qq| + | . $locale->text('Exchangerate') . qq| {exchangerate}> |; } } - + $taxincluded = ""; $taxincluded = qq| {taxincluded}> - |.$locale->text('Tax Included').qq| + | . $locale->text('Tax Included') . qq| |; - - if (($rows = $form->numtextrows($form->{notes}, 50)) < 2) { $rows = 2; } - $notes = qq|$form->{notes}|; - + $notes = + qq|$form->{notes}|; + $department = qq| - |.$locale->text('Department').qq| + | . $locale->text('Department') . qq| $form->{selectdepartment} | if $form->{selectdepartment}; - $n = ($form->{creditremaining} =~ /-/) ? "0" : "1"; - $customer = ($form->{selectcustomer}) ? qq|$form->{selectcustomer}| : qq||; + $customer = + ($form->{selectcustomer}) + ? qq|$form->{selectcustomer}| + : qq||; $employee = qq| @@ -350,7 +413,7 @@ sub form_header { if ($form->{selectemployee}) { $employee = qq| - |.$locale->text('Salesperson').qq| + | . $locale->text('Salesperson') . qq| $form->{selectemployee} @@ -358,33 +421,39 @@ sub form_header { } $form->{fokus} = "arledger.customer"; - + # use JavaScript Calendar or not $form->{jsscript} = $jscalendar; $jsscript = ""; - if ($form->{jsscript}) - { + if ($form->{jsscript}) { + # with JavaScript Calendar $button1 = qq| {transdate}> - text('button').qq|> + text('button') . qq|> |; - $button2 = qq| + $button2 = qq| {duedate}> - text('button').qq|> + text('button') . qq|> |; + #write Trigger - $jsscript = Form->write_trigger(\%myconfig,"2","transdate","BL","trigger1","duedate","BL","trigger2"); - } - else - { - # without JavaScript Calendar - $button1 = qq|{transdate}>|; - $button2 = qq|{duedate}>|; - } - + $jsscript = + Form->write_trigger(\%myconfig, "2", "transdate", "BL", "trigger1", + "duedate", "BL", "trigger2"); + } else { + + # without JavaScript Calendar + $button1 = + qq|{transdate}>|; + $button2 = + qq|{duedate}>|; + } + $form->header; - + print qq| @@ -408,7 +477,7 @@ sub form_header { - |.$locale->text('Customer').qq| + | . $locale->text('Customer') . qq| $customer @@ -420,9 +489,9 @@ sub form_header { - |.$locale->text('Credit Limit').qq| + | . $locale->text('Credit Limit') . qq| $form->{creditlimit} - |.$locale->text('Remaining').qq| + | . $locale->text('Remaining') . qq| $form->{creditremaining} {creditlimit}> {creditremaining}> @@ -431,7 +500,7 @@ sub form_header { - |.$locale->text('Currency').qq| + | . $locale->text('Currency') . qq| $form->{selectcurrency} {defaultcurrency}> @@ -447,19 +516,19 @@ sub form_header { $employee - |.$locale->text('Invoice Number').qq| + | . $locale->text('Invoice Number') . qq| - |.$locale->text('Order Number').qq| + | . $locale->text('Order Number') . qq| - |.$locale->text('Invoice Date').qq| + | . $locale->text('Invoice Date') . qq| $button1 - |.$locale->text('Due Date').qq| + | . $locale->text('Due Date') . qq| $button2 @@ -468,63 +537,77 @@ sub form_header { - - - $jsscript - + {rowcount}> + + + + + | + . $locale->text('Account') . qq| + | + . $locale->text('Amount') . qq| + | + . $locale->text('Tax') . qq| + | + . $locale->text('Korrektur') . qq| + | + . $locale->text('Taxkey') . qq| + | + . $locale->text('Project') . qq| + |; - $form->{"tax"} = $form->format_amount(\%myconfig, $form->{"tax"}, 2); - - $amount = $locale->text('Amount'); + $amount = $locale->text('Amount'); $project = $locale->text('Project'); - - for $i (1 .. 1) { - - + + for $i (1 .. $form->{rowcount}) { + # format amounts - $form->{"amount_$i"} = $form->format_amount(\%myconfig, $form->{"amount_$i"}, 2); + $form->{"amount_$i"} = + $form->format_amount(\%myconfig, $form->{"amount_$i"}, 2); + $form->{"tax_$i"} = $form->format_amount(\%myconfig, $form->{"tax_$i"}, 2); + $selectAR_amount = $selectAR_amount_unquoted; + $selectAR_amount =~ + s/option value=\"$form->{"AR_amount_$i"}\"/option value=\"$form->{"AR_amount_$i"}\" selected/; + $tax = $taxchart; + $tax_selected = $form->{"taxchart_$i"}; + $tax =~ s/value=\"$tax_selected\"/value=\"$tax_selected\" selected/; + $tax = + qq|$tax|; + $korrektur_checked = ($form->{"korrektur_$i"} ? 'checked' : ''); print qq| - $amount - {"amount_$i"}> - $project + $selectAR_amount + {"amount_$i"}> + {"tax_$i"}> + + $tax {"project_id_$i"}> - $form->{"selectAR_amount"} |; - $amount = ""; + $amount = ""; $project = ""; } - $taxlabel = ($form->{taxincluded}) ? $locale->text('Tax Included') : $locale->text('Tax'); - - print qq| - - $taxlabel - {"tax"}> - - - $form->{"selecttaxchart"} - -|; - - - $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2); print qq| - - |.$locale->text('Total').qq| + + + + + + $form->{selectAR} + $form->{invtotal} {oldinvtotal}> @@ -532,14 +615,19 @@ $jsscript - - $form->{selectAR} - - + + + + + + + + + - |.$locale->text('Notes').qq| - $notes + | . $locale->text('Notes') . qq| + $notes @@ -548,7 +636,8 @@ $jsscript - |.$locale->text('Incoming Payments').qq| + | + . $locale->text('Incoming Payments') . qq| |; @@ -558,13 +647,13 @@ $jsscript @column_index = qw(datepaid source memo paid exchangerate AR_paid); } - $column_data{datepaid} = "".$locale->text('Date').""; - $column_data{paid} = "".$locale->text('Amount').""; - $column_data{exchangerate} = "".$locale->text('Exch').""; - $column_data{AR_paid} = "".$locale->text('Account').""; - $column_data{source} = "".$locale->text('Source').""; - $column_data{memo} = "".$locale->text('Memo').""; - + $column_data{datepaid} = "" . $locale->text('Date') . ""; + $column_data{paid} = "" . $locale->text('Amount') . ""; + $column_data{exchangerate} = "" . $locale->text('Exch') . ""; + $column_data{AR_paid} = "" . $locale->text('Account') . ""; + $column_data{source} = "" . $locale->text('Source') . ""; + $column_data{memo} = "" . $locale->text('Memo') . ""; + print " "; @@ -573,7 +662,7 @@ $jsscript "; - + my @triggers = (); $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"}); for $i (1 .. $form->{paidaccounts}) { print " @@ -581,40 +670,56 @@ $jsscript "; $form->{"selectAR_paid_$i"} = $form->{selectAR_paid}; - $form->{"selectAR_paid_$i"} =~ s/option value=\"$form->{"AR_paid_$i"}\">/option value=\"$form->{"AR_paid_$i"}\" selected>/; + $form->{"selectAR_paid_$i"} =~ + s/option value=\"$form->{"AR_paid_$i"}\">/option value=\"$form->{"AR_paid_$i"}\" selected>/; # format amounts - $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} = qq|{"paid_$i"}>|; - $column_data{AR_paid} = qq|$form->{"selectAR_paid_$i"}|; + $column_data{paid} = + qq|{"paid_$i"}>|; + $column_data{AR_paid} = + qq|$form->{"selectAR_paid_$i"}|; $column_data{exchangerate} = qq|$exchangerate|; - $column_data{datepaid} = qq|{"datepaid_$i"}>|; - $column_data{source} = qq||; - $column_data{memo} = qq||; + $column_data{datepaid} = + qq|{"datepaid_$i"}> + |; + $column_data{source} = + qq||; + $column_data{memo} = + qq||; map { print qq|$column_data{$_}\n| } @column_index; - + print " "; + push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i"); } - map { $form->{$_} =~ s/\"/"/g } qw(selectAR_paid); - print qq| + map { $form->{$_} =~ s/\"/"/g } qw(selectAR_paid); + + print $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) . + qq| {paidaccounts}> @@ -630,11 +735,9 @@ $jsscript $lxdebug->leave_sub(); } - sub form_footer { $lxdebug->enter_sub(); - print qq| @@ -647,40 +750,41 @@ sub form_footer { |; $transdate = $form->datetonum($form->{transdate}, \%myconfig); - $closedto = $form->datetonum($form->{closedto}, \%myconfig); - - if ($form->{id} && $form->{radier}) { - - print qq| -|; - - if (!$form->{revtrans}) { - if (!$form->{locked}) { - print qq| - - -|; + $closedto = $form->datetonum($form->{closedto}, \%myconfig); + + if ($form->{id}) { + if ($form->{radier}) { + print qq| + |; + + print qq| + + + |; + } + if ($transdate > $closedto) { + print qq| + + |; } - } - - if ($transdate > $closedto) { - print qq| - -|; - } - + print qq| + + |; + } else { if ($transdate > $closedto) { - print qq| - |; + print qq| + |; } } - if ($form->{menubar}) { - require "$form->{path}/menu.pl"; - &menubar; - } - print " @@ -691,55 +795,74 @@ sub form_footer { $lxdebug->leave_sub(); } - sub update { $lxdebug->enter_sub(); my $display = shift; -# if ($display) { -# goto TAXCALC; -# } - + # if ($display) { + # goto TAXCALC; + # } - $form->{invtotal} = 0; - $form->{selectAR_amount} = $form->{AR_amount}; - $form->{selectAR_amount} =~ s/value=\"$form->{AR_amountselected}\"/value=\"$form->{AR_amountselected}\" selected/; - - $form->{selectAR} = $form->{AR}; - - $form->{selectAR} =~ s/value=\"$form->{ARselected}\"/value=\"$form->{ARselected}\" selected/; + # $form->{selectAR_amount} = $form->{AR_amount}; + # $form->{selectAR_amount} =~ + # s/value=\"$form->{AR_amountselected}\"/value=\"$form->{AR_amountselected}\" selected/; - ($AR_amountaccno, $AR_amounttaxkey) = split(/--/, $form->{AR_amountselected}); + ($AR_amountaccno, $AR_amounttaxkey) = + split(/--/, $form->{AR_amountselected}); $form->{selecttaxchart} = $form->{taxchart}; - $form->{selecttaxchart} =~ s/value=\"$AR_amounttaxkey--([^\"]*)\"/value=\"$AR_amounttaxkey--$1\" selected/; - - $form->{rate} = $1; - - map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate creditlimit creditremaining); + $form->{selecttaxchart} =~ + s/value=\"$AR_amounttaxkey--([^\"]*)\"/value=\"$AR_amounttaxkey--$1\" selected/; + + $form->{rate} = $1; - @flds = qw(amount AR_amount projectnumber oldprojectnumber project_id); + map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } + qw(exchangerate creditlimit creditremaining); + + @flds = qw(amount AR_amount projectnumber oldprojectnumber project_id); $count = 0; - @a = (); - for $i (1 .. 1) { - $form->{"amount_$i"} = $form->parse_amount(\%myconfig, $form->{"amount_$i"}); + @a = (); + + for $i (1 .. $form->{rowcount}) { + $form->{"amount_$i"} = + $form->parse_amount(\%myconfig, $form->{"amount_$i"}); + $form->{"tax_$i"} = $form->parse_amount(\%myconfig, $form->{"tax_$i"}); if ($form->{"amount_$i"}) { push @a, {}; $j = $#a; + if (!$form->{"korrektur_$i"}) { + ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"}); + if ($taxkey > 1) { + if ($form->{taxincluded}) { + $form->{"tax_$i"} = $form->{"amount_$i"} / ($rate + 1) * $rate; + } else { + $form->{"tax_$i"} = $form->{"amount_$i"} * $rate; + } + } else { + $form->{"tax_$i"} = 0; + } + } + $form->{"tax_$i"} = $form->round_amount($form->{"tax_$i"}, 2); + $totaltax += $form->{"tax_$i"}; map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds; $count++; } } $form->redo_rows(\@flds, \@a, $count, $form->{rowcount}); + $form->{rowcount} = $count + 1; + map { $form->{invtotal} += $form->{"amount_$_"} } (1 .. $form->{rowcount}); - map { $form->{invtotal} += $form->{"amount_$_"} } (1 .. 1); - - $form->{exchangerate} = $exchangerate if ($form->{forex} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{transdate}, 'buy'))); - + $form->{exchangerate} = $exchangerate + if ( + $form->{forex} = ( + $exchangerate = + $form->check_exchangerate( + \%myconfig, $form->{currency}, $form->{transdate}, 'buy' + ))); $form->{invdate} = $form->{transdate}; $save_AR = $form->{AR}; @@ -748,86 +871,102 @@ sub update { &check_project; - -TAXCALC: - # recalculate taxes - - @taxaccounts = split / /, $form->{taxaccounts}; - - $form->{"tax"} = $form->parse_amount(\%myconfig, $form->{"tax"}); - - if ($form->{taxincluded} && $form->{"rate"}) { - $taxrate = $form->{"rate"}; - $withholdingrate = 0; - - $amount = $form->round_amount(($form->{invtotal} - ($form->{invtotal} / ($taxrate + 1))), 2); - $form->{"tax"} = $form->round_amount($amount, 2); - $taxdiff += ($amount - $form->{"tax"}); - - - if (abs $taxdiff >= 0.005) { - $form->{"tax"} += $form->round_amount($taxdiff, 2); - $taxdiff = 0; - } - $totaltax += $form->{"tax"}; - - } else { - $form->{"tax"} = $form->round_amount($form->{invtotal} * $form->{"rate"}, 2); - $totaltax += $form->{"tax"}; - - } - - $form->{invtotal} = ($form->{taxincluded}) ? $form->{invtotal} : $form->{invtotal} + $totaltax; + $form->{invtotal} = + ($form->{taxincluded}) ? $form->{invtotal} : $form->{invtotal} + $totaltax; for $i (1 .. $form->{paidaccounts}) { - if ($form->{"paid_$i"}) { - map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(paid exchangerate); + if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) { + map { + $form->{"${_}_$i"} = + $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) + } qw(paid exchangerate); $totalpaid += $form->{"paid_$i"}; - $form->{"exchangerate_$i"} = $exchangerate if ($form->{"forex_$i"} = ($exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy'))); + $form->{"exchangerate_$i"} = $exchangerate + if ( + $form->{"forex_$i"} = ( + $exchangerate = + $form->check_exchangerate( + \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy' + ))); } } - $form->{creditremaining} -= ($form->{invtotal} - $totalpaid + $form->{oldtotalpaid} - $form->{oldinvtotal}); - $form->{oldinvtotal} = $form->{invtotal}; + $form->{creditremaining} -= + ($form->{invtotal} - $totalpaid + $form->{oldtotalpaid} - + $form->{oldinvtotal}); + $form->{oldinvtotal} = $form->{invtotal}; $form->{oldtotalpaid} = $totalpaid; - + &display_form; - + $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}; + $form->redirect($locale->text(' Payment posted!')) + if (AR->post_payment(\%myconfig, \%$form)); + $form->error($locale->text('Cannot post payment!')); + + + $lxdebug->leave_sub(); +} sub post { $lxdebug->enter_sub(); - # check if there is an invoice number, invoice and due date $form->isblank("transdate", $locale->text('Invoice Date missing!')); - $form->isblank("duedate", $locale->text('Due Date missing!')); - $form->isblank("customer", $locale->text('Customer missing!')); + $form->isblank("duedate", $locale->text('Due Date missing!')); + $form->isblank("customer", $locale->text('Customer missing!')); - $closedto = $form->datetonum($form->{closedto}, \%myconfig); + $closedto = $form->datetonum($form->{closedto}, \%myconfig); $transdate = $form->datetonum($form->{transdate}, \%myconfig); - - $form->error($locale->text('Cannot post transaction for a closed period!')) if ($transdate <= $closedto); - $form->isblank("exchangerate", $locale->text('Exchangerate missing!')) if ($form->{currency} ne $form->{defaultcurrency}); - - delete ($form->{AR}); - + $form->error($locale->text('Cannot post transaction for a closed period!')) + if ($transdate <= $closedto); + + $form->isblank("exchangerate", $locale->text('Exchangerate missing!')) + if ($form->{currency} ne $form->{defaultcurrency}); + + delete($form->{AR}); + 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 ($transdate == $datepaid); - $form->isblank("exchangerate_$i", $locale->text('Exchangerate for payment missing!')); + $form->{"exchangerate_$i"} = $form->{exchangerate} + if ($transdate == $datepaid); + $form->isblank("exchangerate_$i", + $locale->text('Exchangerate for payment missing!')); } } } @@ -839,42 +978,51 @@ sub post { exit; } - ($creditaccno, $credittaxkey) = split /--/, $form->{AR_amountselected}; - ($taxkey, $NULL) = split /--/, $form->{taxchartselected}; - ($receivablesaccno, $payablestaxkey) = split /--/, $form->{ARselected}; - $form->{AR}{amount_1} = $creditaccno; + ($taxkey, $NULL) = split /--/, $form->{taxchartselected}; + ($receivablesaccno, $payablestaxkey) = split /--/, $form->{ARselected}; + $form->{AR}{amount_1} = $creditaccno; $form->{AR}{receivables} = $receivablesaccno; - $form->{taxkey} = $taxkey; - - $form->{invnumber} = $form->update_defaults(\%myconfig, "invnumber") unless $form->{invnumber}; + $form->{taxkey} = $taxkey; + + $form->{invnumber} = $form->update_defaults(\%myconfig, "invnumber") + unless $form->{invnumber}; $form->{id} = 0 if $form->{postasnew}; - $form->redirect($locale->text('Transaction posted!')) if (AR->post_transaction(\%myconfig, \%$form)); + $form->redirect($locale->text('Transaction posted!')) + if (AR->post_transaction(\%myconfig, \%$form)); $form->error($locale->text('Cannot post transaction!')); $lxdebug->leave_sub(); } - sub post_as_new { $lxdebug->enter_sub(); - $form->{postasnew} = 1; &post; $lxdebug->leave_sub(); } +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); + &update; + + $lxdebug->leave_sub(); +} sub delete { $lxdebug->enter_sub(); - $form->{title} = $locale->text('Confirm!'); - + $form->header; delete $form->{header}; @@ -886,16 +1034,19 @@ sub delete { |; foreach $key (keys %$form) { - $form->{$key} =~ s/\"/"/g; + $form->{$key} =~ s/\"/"/g; print qq|\n|; } print qq| $form->{title} -|.$locale->text('Are you sure you want to delete Transaction').qq| $form->{invnumber} +| + . $locale->text('Are you sure you want to delete Transaction') + . qq| $form->{invnumber} - + @@ -905,78 +1056,82 @@ sub delete { $lxdebug->leave_sub(); } - - sub yes { $lxdebug->enter_sub(); - - $form->redirect($locale->text('Transaction deleted!')) if (AR->delete_transaction(\%myconfig, \%$form, $spool)); + $form->redirect($locale->text('Transaction deleted!')) + if (AR->delete_transaction(\%myconfig, \%$form, $spool)); $form->error($locale->text('Cannot delete transaction!')); $lxdebug->leave_sub(); } - sub search { $lxdebug->enter_sub(); - # setup customer selection $form->all_vc(\%myconfig, "customer", "AR"); - if (@{ $form->{all_customer} }) { - map { $customer .= "$_->{name}--$_->{id}\n" } @{ $form->{all_customer} }; + if (@{ $form->{all_customer} }) { + map { $customer .= "$_->{name}--$_->{id}\n" } + @{ $form->{all_customer} }; $customer = qq|\n$customer|; } else { $customer = qq||; } - # departments + # departments if (@{ $form->{all_departments} }) { $form->{selectdepartment} = "\n"; - map { $form->{selectdepartment} .= "$_->{description}--$_->{id}\n" } (@{ $form->{all_departments} }); + map { + $form->{selectdepartment} .= + "$_->{description}--$_->{id}\n" + } (@{ $form->{all_departments} }); } - $department = qq| - - |.$locale->text('Department').qq| + $department = qq| + + | . $locale->text('Department') . qq| $form->{selectdepartment} | if $form->{selectdepartment}; - + $form->{title} = $locale->text('AR Transactions'); - + # use JavaScript Calendar or not $form->{jsscript} = $jscalendar; - $jsscript = ""; - if ($form->{jsscript}) - { + $jsscript = ""; + if ($form->{jsscript}) { + # with JavaScript Calendar $button1 = qq| - text('button').qq|> + text('button') . qq|> |; - $button2 = qq| + $button2 = qq| - text('button').qq|> + text('button') . qq|> |; - #write Trigger - $jsscript = Form->write_trigger(\%myconfig,"2","transdatefrom","BR","trigger1","transdateto","BL","trigger2"); - } - else - { - # without JavaScript Calendar - $button1 = qq| + + #write Trigger + $jsscript = + Form->write_trigger(\%myconfig, "2", "transdatefrom", "BR", "trigger1", + "transdateto", "BL", "trigger2"); + } else { + + # without JavaScript Calendar + $button1 = qq| |; - $button2 = qq| + $button2 = qq| |; - } - - $form->{fokus} = "search.customer"; + } + + $form->{fokus} = "search.customer"; $form->header; - + print qq| @@ -989,26 +1144,26 @@ sub search { - |.$locale->text('Customer').qq| + | . $locale->text('Customer') . qq| $customer $department - |.$locale->text('Invoice Number').qq| + | . $locale->text('Invoice Number') . qq| - |.$locale->text('Order Number').qq| + | . $locale->text('Order Number') . qq| - |.$locale->text('Notes').qq| + | . $locale->text('Notes') . qq| - |.$locale->text('From').qq| + | . $locale->text('From') . qq| $button1 - |.$locale->text('Bis').qq| + | . $locale->text('Bis') . qq| $button2 @@ -1019,58 +1174,58 @@ sub search { - |.$locale->text('Include in Report').qq| + | . $locale->text('Include in Report') . qq| - |.$locale->text('Open').qq| + | . $locale->text('Open') . qq| - |.$locale->text('Closed').qq| + | . $locale->text('Closed') . qq| - |.$locale->text('ID').qq| + | . $locale->text('ID') . qq| - |.$locale->text('Invoice Number').qq| + | . $locale->text('Invoice Number') . qq| - |.$locale->text('Order Number').qq| + | . $locale->text('Order Number') . qq| - |.$locale->text('Invoice Date').qq| + | . $locale->text('Invoice Date') . qq| - |.$locale->text('Customer').qq| + | . $locale->text('Customer') . qq| - |.$locale->text('Amount').qq| + | . $locale->text('Amount') . qq| - |.$locale->text('Tax').qq| + | . $locale->text('Tax') . qq| - |.$locale->text('Total').qq| + | . $locale->text('Total') . qq| - |.$locale->text('Date Paid').qq| + | . $locale->text('Date Paid') . qq| - |.$locale->text('Paid').qq| + | . $locale->text('Paid') . qq| - |.$locale->text('Due Date').qq| + | . $locale->text('Due Date') . qq| - |.$locale->text('Amount Due').qq| + | . $locale->text('Amount Due') . qq| - |.$locale->text('Notes').qq| + | . $locale->text('Notes') . qq| - |.$locale->text('Salesperson').qq| + | . $locale->text('Salesperson') . qq| - |.$locale->text('Shipping Point').qq| + | . $locale->text('Shipping Point') . qq| - |.$locale->text('Ship via').qq| + | . $locale->text('Ship via') . qq| - |.$locale->text('Subtotal').qq| + | . $locale->text('Subtotal') . qq| @@ -1090,7 +1245,8 @@ sub search { {password}> - + @@ -1104,111 +1260,153 @@ $jsscript $lxdebug->leave_sub(); } - sub ar_transactions { $lxdebug->enter_sub(); - $form->{customer} = $form->unescape($form->{customer}); ($form->{customer}, $form->{customer_id}) = split(/--/, $form->{customer}); - AR->ar_transactions(\%myconfig, \%$form); - $callback = "$form->{script}?action=ar_transactions&path=$form->{path}&login=$form->{login}&password=$form->{password}"; + $callback = + "$form->{script}?action=ar_transactions&path=$form->{path}&login=$form->{login}&password=$form->{password}"; $href = $callback; if ($form->{customer}) { - $callback .= "&customer=".$form->escape($form->{customer},1); - $href .= "&customer=".$form->escape($form->{customer}); - $option = $locale->text('Customer')." : $form->{customer}"; + $callback .= "&customer=" . $form->escape($form->{customer}, 1); + $href .= "&customer=" . $form->escape($form->{customer}); + $option = $locale->text('Customer') . " : $form->{customer}"; } if ($form->{department}) { - $callback .= "&department=".$form->escape($form->{department},1); - $href .= "&department=".$form->escape($form->{department}); + $callback .= "&department=" . $form->escape($form->{department}, 1); + $href .= "&department=" . $form->escape($form->{department}); ($department) = split /--/, $form->{department}; $option .= "\n" if ($option); - $option .= $locale->text('Department')." : $department"; + $option .= $locale->text('Department') . " : $department"; } if ($form->{invnumber}) { - $callback .= "&invnumber=".$form->escape($form->{invnumber},1); - $href .= "&invnumber=".$form->escape($form->{invnumber}); + $callback .= "&invnumber=" . $form->escape($form->{invnumber}, 1); + $href .= "&invnumber=" . $form->escape($form->{invnumber}); $option .= "\n" if ($option); - $option .= $locale->text('Invoice Number')." : $form->{invnumber}"; + $option .= $locale->text('Invoice Number') . " : $form->{invnumber}"; } if ($form->{ordnumber}) { - $callback .= "&ordnumber=".$form->escape($form->{ordnumber},1); - $href .= "&ordnumber=".$form->escape($form->{ordnumber}); + $callback .= "&ordnumber=" . $form->escape($form->{ordnumber}, 1); + $href .= "&ordnumber=" . $form->escape($form->{ordnumber}); $option .= "\n" if ($option); - $option .= $locale->text('Order Number')." : $form->{ordnumber}"; + $option .= $locale->text('Order Number') . " : $form->{ordnumber}"; } if ($form->{notes}) { - $callback .= "¬es=".$form->escape($form->{notes},1); - $href .= "¬es=".$form->escape($form->{notes}); + $callback .= "¬es=" . $form->escape($form->{notes}, 1); + $href .= "¬es=" . $form->escape($form->{notes}); $option .= "\n" if $option; - $option .= $locale->text('Notes')." : $form->{notes}"; + $option .= $locale->text('Notes') . " : $form->{notes}"; } - + if ($form->{transdatefrom}) { $callback .= "&transdatefrom=$form->{transdatefrom}"; - $href .= "&transdatefrom=$form->{transdatefrom}"; - $option .= "\n" if ($option); - $option .= $locale->text('From')." ".$locale->date(\%myconfig, $form->{transdatefrom}, 1); + $href .= "&transdatefrom=$form->{transdatefrom}"; + $option .= "\n" if ($option); + $option .= + $locale->text('From') . " " + . $locale->date(\%myconfig, $form->{transdatefrom}, 1); } if ($form->{transdateto}) { $callback .= "&transdateto=$form->{transdateto}"; - $href .= "&transdateto=$form->{transdateto}"; - $option .= "\n" if ($option); - $option .= $locale->text('Bis')." ".$locale->date(\%myconfig, $form->{transdateto}, 1); + $href .= "&transdateto=$form->{transdateto}"; + $option .= "\n" if ($option); + $option .= + $locale->text('Bis') . " " + . $locale->date(\%myconfig, $form->{transdateto}, 1); } if ($form->{open}) { $callback .= "&open=$form->{open}"; - $href .= "&open=$form->{open}"; - $option .= "\n" if ($option); - $option .= $locale->text('Open'); + $href .= "&open=$form->{open}"; + $option .= "\n" if ($option); + $option .= $locale->text('Open'); } if ($form->{closed}) { $callback .= "&closed=$form->{closed}"; - $href .= "&closed=$form->{closed}"; - $option .= "\n" if ($option); - $option .= $locale->text('Closed'); + $href .= "&closed=$form->{closed}"; + $option .= "\n" if ($option); + $option .= $locale->text('Closed'); } - @columns = $form->sort_columns(qw(transdate id invnumber ordnumber name netamount tax amount paid datepaid due duedate notes employee shippingpoint shipvia)); - + @columns = $form->sort_columns( + qw(transdate id type invnumber ordnumber name netamount tax amount paid datepaid due duedate notes employee shippingpoint shipvia) + ); + + $form->{"l_type"} = "Y"; + foreach $item (@columns) { if ($form->{"l_$item"} eq "Y") { push @column_index, $item; # add column to href and callback $callback .= "&l_$item=Y"; - $href .= "&l_$item=Y"; + $href .= "&l_$item=Y"; } } if ($form->{l_subtotal} eq 'Y') { $callback .= "&l_subtotal=Y"; - $href .= "&l_subtotal=Y"; + $href .= "&l_subtotal=Y"; } - - - $column_header{id} = "".$locale->text('ID').""; - $column_header{transdate} = "".$locale->text('Date').""; - $column_header{duedate} = "".$locale->text('Due Date').""; - $column_header{invnumber} = "".$locale->text('Invoice').""; - $column_header{ordnumber} = "".$locale->text('Order').""; - $column_header{name} = "".$locale->text('Customer').""; - $column_header{netamount} = "" . $locale->text('Amount') . ""; - $column_header{tax} = "" . $locale->text('Tax') . ""; - $column_header{amount} = "" . $locale->text('Total') . ""; - $column_header{paid} = "" . $locale->text('Paid') . ""; - $column_header{datepaid} = "" . $locale->text('Date Paid') . ""; - $column_header{due} = "" . $locale->text('Amount Due') . ""; - $column_header{notes} = "".$locale->text('Notes').""; - $column_header{employee} = "".$locale->text('Salesperson').""; - - $column_header{shippingpoint} = "" . $locale->text('Shipping Point') . ""; - $column_header{shipvia} = "" . $locale->text('Ship via') . ""; + + $column_header{id} = + "" + . $locale->text('ID') + . ""; + $column_header{transdate} = + "" + . $locale->text('Date') + . ""; + $column_header{duedate} = + "" + . $locale->text('Due Date') + . ""; + $column_header{type} = + "" . $locale->text('Type') . ""; + $column_header{invnumber} = + "" + . $locale->text('Invoice') + . ""; + $column_header{ordnumber} = + "" + . $locale->text('Order') + . ""; + $column_header{name} = + "" + . $locale->text('Customer') + . ""; + $column_header{netamount} = + "" . $locale->text('Amount') . ""; + $column_header{tax} = + "" . $locale->text('Tax') . ""; + $column_header{amount} = + "" . $locale->text('Total') . ""; + $column_header{paid} = + "" . $locale->text('Paid') . ""; + $column_header{datepaid} = + "" + . $locale->text('Date Paid') + . ""; + $column_header{due} = + "" . $locale->text('Amount Due') . ""; + $column_header{notes} = + "" . $locale->text('Notes') . ""; + $column_header{employee} = + "" + . $locale->text('Salesperson') . ""; + + $column_header{shippingpoint} = + "" + . $locale->text('Shipping Point') + . ""; + $column_header{shipvia} = + "" + . $locale->text('Ship via') + . ""; $form->{title} = $locale->text('AR Transactions'); @@ -1237,60 +1435,79 @@ sub ar_transactions { |; - # add sort and escape callback, this one we use for the add sub $form->{callback} = $callback .= "&sort=$form->{sort}"; # escape callback for href $callback = $form->escape($callback); - + if (@{ $form->{AR} }) { - $sameitem = $form->{AR}->[0]->{$form->{sort}}; + $sameitem = $form->{AR}->[0]->{ $form->{sort} }; } - + # sums and tax on reports by Antonio Gallardo # foreach $ar (@{ $form->{AR} }) { if ($form->{l_subtotal} eq 'Y') { - if ($sameitem ne $ar->{$form->{sort}}) { - &ar_subtotal; + if ($sameitem ne $ar->{ $form->{sort} }) { + &ar_subtotal; } } - - $column_data{netamount} = "".$form->format_amount(\%myconfig, $ar->{netamount}, 2, " ").""; - $column_data{tax} = "".$form->format_amount(\%myconfig, $ar->{amount} - $ar->{netamount}, 2, " ").""; - $column_data{amount} = "".$form->format_amount(\%myconfig, $ar->{amount}, 2, " ").""; - $column_data{paid} = "".$form->format_amount(\%myconfig, $ar->{paid}, 2, " ").""; - $column_data{due} = "".$form->format_amount(\%myconfig, $ar->{amount} - $ar->{paid}, 2, " ").""; - + + $column_data{netamount} = + "" + . $form->format_amount(\%myconfig, $ar->{netamount}, 2, " ") + . ""; + $column_data{tax} = "" + . $form->format_amount(\%myconfig, $ar->{amount} - $ar->{netamount}, + 2, " ") + . ""; + $column_data{amount} = + "" + . $form->format_amount(\%myconfig, $ar->{amount}, 2, " ") . ""; + $column_data{paid} = + "" + . $form->format_amount(\%myconfig, $ar->{paid}, 2, " ") . ""; + $column_data{due} = "" + . $form->format_amount(\%myconfig, $ar->{amount} - $ar->{paid}, + 2, " ") + . ""; + $subtotalnetamount += $ar->{netamount}; - $subtotalamount += $ar->{amount}; - $subtotalpaid += $ar->{paid}; - $subtotaldue += $ar->{amount} - $ar->{paid}; - + $subtotalamount += $ar->{amount}; + $subtotalpaid += $ar->{paid}; + $subtotaldue += $ar->{amount} - $ar->{paid}; + $totalnetamount += $ar->{netamount}; - $totalamount += $ar->{amount}; - $totalpaid += $ar->{paid}; - $totaldue += ($ar->{amount} - $ar->{paid}); - + $totalamount += $ar->{amount}; + $totalpaid += $ar->{paid}; + $totaldue += ($ar->{amount} - $ar->{paid}); + $column_data{transdate} = "$ar->{transdate} "; - $column_data{id} = "$ar->{id}"; - $column_data{datepaid} = "$ar->{datepaid} "; - $column_data{duedate} = "$ar->{duedate} "; + $column_data{id} = "$ar->{id}"; + $column_data{datepaid} = "$ar->{datepaid} "; + $column_data{duedate} = "$ar->{duedate} "; $module = ($ar->{invoice}) ? "is.pl" : $form->{script}; - $column_data{invnumber} = "{id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ar->{invnumber}"; + $column_data{invnumber} = + "{id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$callback>$ar->{invnumber}"; + $column_data{type} = "" . + ($ar->{storno} ? $locale->text("Storno (one letter abbreviation)") : + $ar->{amount} < 0 ? + $locale->text("Credit note (one letter abbreviation)") : + $locale->text("Invoice (one letter abbreviation)")) . ""; $column_data{ordnumber} = "$ar->{ordnumber} "; - $column_data{name} = "$ar->{name}"; + $column_data{name} = "$ar->{name}"; $ar->{notes} =~ s/\r\n//g; - $column_data{notes} = "$ar->{notes} "; + $column_data{notes} = "$ar->{notes} "; $column_data{shippingpoint} = "$ar->{shippingpoint} "; - $column_data{shipvia} = "$ar->{shipvia} "; - $column_data{employee} = "$ar->{employee} "; + $column_data{shipvia} = "$ar->{shipvia} "; + $column_data{employee} = "$ar->{employee} "; - $i++; $i %= 2; + $i++; + $i %= 2; print " "; @@ -1301,7 +1518,6 @@ sub ar_transactions { |; - } if ($form->{l_subtotal} eq 'Y') { @@ -1314,12 +1530,23 @@ sub ar_transactions { |; map { $column_data{$_} = " " } @column_index; - - $column_data{netamount} = "".$form->format_amount(\%myconfig, $totalnetamount, 2, " ").""; - $column_data{tax} = "".$form->format_amount(\%myconfig, $totalamount - $totalnetamount, 2, " ").""; - $column_data{amount} = "".$form->format_amount(\%myconfig, $totalamount, 2, " ").""; - $column_data{paid} = "".$form->format_amount(\%myconfig, $totalpaid, 2, " ").""; - $column_data{due} = "".$form->format_amount(\%myconfig, $totaldue, 2, " ").""; + + $column_data{netamount} = + "" + . $form->format_amount(\%myconfig, $totalnetamount, 2, " ") . ""; + $column_data{tax} = "" + . $form->format_amount(\%myconfig, $totalamount - $totalnetamount, + 2, " ") + . ""; + $column_data{amount} = + "" + . $form->format_amount(\%myconfig, $totalamount, 2, " ") . ""; + $column_data{paid} = + "" + . $form->format_amount(\%myconfig, $totalpaid, 2, " ") . ""; + $column_data{due} = + "" + . $form->format_amount(\%myconfig, $totaldue, 2, " ") . ""; map { print "\n$column_data{$_}" } @column_index; @@ -1342,15 +1569,11 @@ sub ar_transactions { {login}> {password}> - -|; + + - if ($form->{menubar}) { - require "$form->{path}/menu.pl"; - &menubar; - } - - print qq| @@ -1360,35 +1583,39 @@ sub ar_transactions { $lxdebug->leave_sub(); } - sub ar_subtotal { $lxdebug->enter_sub(); - map { $column_data{$_} = " " } @column_index; - - $column_data{tax} = "".$form->format_amount(\%myconfig, $subtotalamount - $subtotalnetamount, 2, " ").""; - $column_data{amount} = "".$form->format_amount(\%myconfig, $subtotalamount, 2, " ").""; - $column_data{paid} = "".$form->format_amount(\%myconfig, $subtotalpaid, 2, " ").""; - $column_data{due} = "".$form->format_amount(\%myconfig, $subtotaldue, 2, " ").""; - + + $column_data{tax} = "" + . $form->format_amount(\%myconfig, $subtotalamount - $subtotalnetamount, + 2, " ") + . ""; + $column_data{amount} = + "" + . $form->format_amount(\%myconfig, $subtotalamount, 2, " ") . ""; + $column_data{paid} = + "" + . $form->format_amount(\%myconfig, $subtotalpaid, 2, " ") . ""; + $column_data{due} = + "" + . $form->format_amount(\%myconfig, $subtotaldue, 2, " ") . ""; + $subtotalnetamount = 0; - $subtotalamount = 0; - $subtotalpaid = 0; - $subtotaldue = 0; + $subtotalamount = 0; + $subtotalpaid = 0; + $subtotaldue = 0; + + $sameitem = $ar->{ $form->{sort} }; - $sameitem = $ar->{$form->{sort}}; - print ""; map { print "\n$column_data{$_}" } @column_index; -print " + print " "; - + $lxdebug->leave_sub(); } - - -