X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Far.pl;h=da4315b2ec7838a6c2ced993b8af5285d4db5fa0;hb=9fd46de37d7906b7c104c17112b34bae7d534d67;hp=3b4540457d2ebe1c896af59fde1d83db05806979;hpb=e6346d3f9b5d3e24727def67274f39c02b2ed12b;p=kivitendo-erp.git diff --git a/bin/mozilla/ar.pl b/bin/mozilla/ar.pl index 3b4540457..da4315b2e 100644 --- a/bin/mozilla/ar.pl +++ b/bin/mozilla/ar.pl @@ -37,6 +37,8 @@ use SL::PE; use Data::Dumper; require "$form->{path}/arap.pl"; +require "bin/mozilla/common.pl"; +require "bin/mozilla/drafts.pl"; 1; @@ -73,19 +75,31 @@ require "$form->{path}/arap.pl"; sub add { $lxdebug->enter_sub(); + return $lxdebug->leave_sub() if (load_draft_maybe()); + + # saving the history + if(!exists $form->{addition} && ($form->{id} ne "")) { + $form->{addition} = "ADDED"; + $form->save_history($form->dbconnect(\%myconfig)); + } + # /saving the history + $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(); + # show history button + $form->{javascript} = qq||; + #/show hhistory button $form->{title} = "Edit"; @@ -157,31 +171,10 @@ sub create_links { # build the popup menus $form->{taxincluded} = ($form->{id}) ? $form->{taxincluded} : "checked"; - 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"; - } else { - $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 my $j = 0; my $k = 0; @@ -189,8 +182,7 @@ sub create_links { 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}"; + $form->{"AR_paid_$j"} = $form->{acc_trans}{$key}->[$i-1]->{accno}; # reverse paid $form->{"paid_$j"} = $form->{acc_trans}{$key}->[$i - 1]->{amount} * -1; @@ -201,8 +193,9 @@ sub create_links { $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->{"paid_project_id_$j"} = $form->{acc_trans}{$key}->[$i - 1]->{project_id}; $form->{paidaccounts}++; + } else { $akey = $key; @@ -247,25 +240,25 @@ sub create_links { $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; + + if ($akey eq "AR") { + $form->{ARselected} = $form->{acc_trans}{$key}->[$i-1]->{accno}; + + } elsif ($akey eq "amount") { + $form->{"${key}_$k"} = $form->{acc_trans}{$key}->[$i-1]->{accno} . + "--" . $form->{acc_trans}{$key}->[$i-1]->{id}; + $form->{"taxchart_$k"} = $form->{acc_trans}{$key}->[$i-1]->{id} . + "--" . $form->{acc_trans}{$key}->[$i-1]->{rate}; } } } } } + $lxdebug->message(0, "1 ARselected $form->{ARselected}"); + $form->{taxincluded} = $taxincluded if ($form->{id}); $form->{paidaccounts} = 1 if not defined $form->{paidaccounts}; @@ -323,6 +316,9 @@ sub form_header { }; //--> |; + # show history button js + $form->{javascript} .= qq||; + #/show history button js $readonly = ($form->{id}) ? "readonly" : ""; @@ -336,10 +332,6 @@ sub form_header { $form->{"select$item"} =~ s/option>\Q$form->{$item}\E/option selected>$form->{$item}/; } - $selectAR_amount_unquoted = $form->{selectAR_amount}; - $taxchart = $form->{taxchart}; - map { $form->{$_} =~ s/\"/"/g } - qw(AR_amount selectAR_amount AR taxchart); # format amounts $form->{exchangerate} = @@ -412,6 +404,61 @@ sub form_header { |; } + my @old_project_ids = (); + map({ push(@old_project_ids, $form->{"project_id_$_"}) + if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"})); + + $form->get_lists("projects" => { "key" => "ALL_PROJECTS", + "all" => 0, + "old_id" => \@old_project_ids }, + "charts" => { "key" => "ALL_CHARTS", + "transdate" => $form->{transdate} }, + "taxcharts" => "ALL_TAXCHARTS"); + + map({ $_->{link_split} = [ split(/:/, $_->{link}) ]; } + @{ $form->{ALL_CHARTS} }); + + my %project_labels = (); + my @project_values = (""); + foreach my $item (@{ $form->{"ALL_PROJECTS"} }) { + push(@project_values, $item->{"id"}); + $project_labels{$item->{"id"}} = $item->{"projectnumber"}; + } + + my (%AR_amount_labels, @AR_amount_values); + my (%AR_labels, @AR_values); + my (%AR_paid_labels, @AR_paid_values); + my $taxchart_init; + + foreach my $item (@{ $form->{ALL_CHARTS} }) { + if (grep({ $_ eq "AR_amount" } @{ $item->{link_split} })) { + $taxchart_init = $item->{tax_id} if ($taxchart_init eq ""); + my $key = "$item->{accno}--$item->{tax_id}"; + push(@AR_amount_values, $key); + $AR_amount_labels{$key} = + "$item->{accno}--$item->{description}"; + + } elsif (grep({ $_ eq "AR" } @{ $item->{link_split} })) { + push(@AR_values, $item->{accno}); + $AR_labels{$item->{accno}} = "$item->{accno}--$item->{description}"; + + } elsif (grep({ $_ eq "AR_paid" } @{ $item->{link_split} })) { + push(@AR_paid_values, $item->{accno}); + $AR_paid_labels{$item->{accno}} = + "$item->{accno}--$item->{description}"; + } + } + + my %taxchart_labels = (); + my @taxchart_values = (); + foreach my $item (@{ $form->{ALL_TAXCHARTS} }) { + my $key = "$item->{id}--$item->{rate}"; + $taxchart_init = $key if ($taxchart_init eq $item->{id}); + push(@taxchart_values, $key); + $taxchart_labels{$key} = + "$item->{taxdescription} " . ($item->{rate} * 100) . ' %'; + } + $form->{fokus} = "arledger.customer"; # use JavaScript Calendar or not @@ -457,6 +504,8 @@ sub form_header { {locked}> +| . ($form->{saved_message} ? qq|$form->{saved_message}| : "") . qq| + $form->{title} @@ -523,7 +572,7 @@ sub form_header { | . $locale->text('Due Date') . qq| $button2 - + @@ -531,9 +580,6 @@ sub form_header { $jsscript - - - {rowcount}> @@ -563,26 +609,42 @@ $jsscript $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|; + + $selectAR_amount = + NTI($cgi->popup_menu('-name' => "AR_amount_$i", + '-id' => "AR_amount_$i", + '-style' => 'width:400px', + '-onChange' => "setTaxkey(this, $i)", + '-values' => \@AR_amount_values, + '-labels' => \%AR_amount_labels, + '-default' => $form->{"AR_amount_$i"})); + + $tax = qq|| . + NTI($cgi->popup_menu('-name' => "taxchart_$i", + '-id' => "taxchart_$i", + '-style' => 'width:200px', + '-values' => \@taxchart_values, + '-labels' => \%taxchart_labels, + '-default' => $form->{"taxchart_$i"} eq "" ? + $taxchart_init : $form->{"taxchart_$i"})) + . qq||; + $korrektur_checked = ($form->{"korrektur_$i"} ? 'checked' : ''); + my $projectnumber = + NTI($cgi->popup_menu('-name' => "project_id_$i", + '-values' => \@project_values, + '-labels' => \%project_labels, + '-default' => $form->{"project_id_$i"} )); + print qq| - $selectAR_amount + $selectAR_amount {"amount_$i"}> {"tax_$i"}> $tax - - {"project_id_$i"}> - + $projectnumber |; $amount = ""; @@ -591,6 +653,12 @@ $jsscript $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2); + $ARselected = + NTI($cgi->popup_menu('-name' => "ARselected", '-id' => "ARselected", + '-style' => 'width:400px', + '-values' => \@AR_values, '-labels' => \%AR_labels, + '-default' => $form->{ARselected})); + print qq| @@ -598,8 +666,7 @@ $jsscript - $form->{selectAR} - + ${ARselected} $form->{invtotal} {oldinvtotal}> @@ -628,15 +695,15 @@ $jsscript - | + | . $locale->text('Incoming Payments') . qq| |; if ($form->{currency} eq $form->{defaultcurrency}) { - @column_index = qw(datepaid source memo paid AR_paid); + @column_index = qw(datepaid source memo paid AR_paid paid_project_id); } else { - @column_index = qw(datepaid source memo paid exchangerate AR_paid); + @column_index = qw(datepaid source memo paid exchangerate AR_paid paid_project_id); } $column_data{datepaid} = "" . $locale->text('Date') . ""; @@ -644,7 +711,8 @@ $jsscript $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{memo} = "" . $locale->text('Memo') . ""; + $column_data{paid_project_id} = "" . $locale->text('Project Number') . ""; print " @@ -654,15 +722,19 @@ $jsscript "; + my @triggers = (); $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"}); for $i (1 .. $form->{paidaccounts}) { print " "; - $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>/; + $selectAR_paid = + NTI($cgi->popup_menu('-name' => "AR_paid_$i", + '-id' => "AR_paid_$i", + '-values' => \@AR_paid_values, + '-labels' => \%AR_paid_labels, + '-default' => $form->{"AR_paid_$i"})); # format amounts if ($form->{"paid_$i"}) { @@ -690,25 +762,35 @@ $jsscript $column_data{paid} = qq|{"paid_$i"}>|; $column_data{AR_paid} = - qq|$form->{"selectAR_paid_$i"}|; + qq|${selectAR_paid}|; $column_data{exchangerate} = qq|$exchangerate|; $column_data{datepaid} = - qq|{"datepaid_$i"}>|; + qq|{"datepaid_$i"}> + |; $column_data{source} = qq||; $column_data{memo} = qq||; + $column_data{paid_project_id} = + qq|| + . NTI($cgi->popup_menu('-name' => "paid_project_id_$i", + '-values' => \@project_values, + '-labels' => \%project_labels, + '-default' => $form->{"paid_project_id_$i"} )) + . 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| + + print $form->write_trigger(\%myconfig, scalar(@triggers) / 3, @triggers) . + qq| {paidaccounts}> - @@ -727,11 +809,17 @@ sub form_footer { print qq| + + {path}> {login}> {password}> +| +. $cgi->hidden('-name' => 'draft_id', '-default' => [$form->{draft_id}]) +. $cgi->hidden('-name' => 'draft_description', '-default' => [$form->{draft_description}]) +. qq| |; @@ -739,32 +827,35 @@ sub form_footer { $transdate = $form->datetonum($form->{transdate}, \%myconfig); $closedto = $form->datetonum($form->{closedto}, \%myconfig); + print qq| +|; if ($form->{id}) { if ($form->{radier}) { - print qq| - |; - - print qq| + print qq| |; - } - if ($transdate > $closedto) { - print qq| + } + if ($transdate > $closedto) { + print qq| |; - } - + } + print qq| + + |; + } else { if ($transdate > $closedto) { print qq| - |; + . $locale->text('Post') . qq|"> | . + NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'), + '-class' => 'submit')); } } @@ -772,7 +863,16 @@ sub form_footer { require "$form->{path}/menu.pl"; &menubar; } - + # button for saving history + if($form->{id} ne "") { + print qq| + {id} + . qq|); name=history id=history value=| + . $locale->text('history') + . qq|>|; + } + # /button for saving history print " @@ -788,29 +888,8 @@ sub update { my $display = shift; - # 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/; - - ($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); @@ -862,8 +941,6 @@ sub update { &check_name(customer); $form->{AR} = $save_AR; - &check_project; - $form->{invtotal} = ($form->{taxincluded}) ? $form->{invtotal} : $form->{invtotal} + $totaltax; @@ -897,6 +974,36 @@ sub update { $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(); @@ -941,20 +1048,22 @@ sub post { exit; } - ($creditaccno, $credittaxkey) = split /--/, $form->{AR_amountselected}; - ($taxkey, $NULL) = split /--/, $form->{taxchartselected}; - ($receivablesaccno, $payablestaxkey) = split /--/, $form->{ARselected}; - $form->{AR}{amount_1} = $creditaccno; - $form->{AR}{receivables} = $receivablesaccno; - $form->{taxkey} = $taxkey; + $form->{AR}{receivables} = $form->{ARselected}; $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)); + if (AR->post_transaction(\%myconfig, \%$form)) { + # saving the history + if(!exists $form->{addition} && $form->{id} ne "") { + $form->{addition} = "POSTED"; + $form->save_history($form->dbconnect(\%myconfig)); + } + # /saving the history + remove_draft() if $form->{remove_draft}; + $form->redirect($locale->text('Transaction posted!')); + } $form->error($locale->text('Cannot post transaction!')); $lxdebug->leave_sub(); @@ -964,6 +1073,12 @@ sub post_as_new { $lxdebug->enter_sub(); $form->{postasnew} = 1; + # saving the history + if(!exists $form->{addition} && $form->{id} ne "") { + $form->{addition} = "POSTED AS NEW"; + $form->save_history($form->dbconnect(\%myconfig)); + } + # /saving the history &post; $lxdebug->leave_sub(); @@ -1021,9 +1136,15 @@ sub delete { sub yes { $lxdebug->enter_sub(); - - $form->redirect($locale->text('Transaction deleted!')) - if (AR->delete_transaction(\%myconfig, \%$form, $spool)); + if (AR->delete_transaction(\%myconfig, \%$form, $spool)) { + # saving the history + if(!exists $form->{addition}) { + $form->{addition} = "DELETED"; + $form->save_history($form->dbconnect(\%myconfig)); + } + # /saving the history + $form->redirect($locale->text('Transaction deleted!')); + } $form->error($locale->text('Cannot delete transaction!')); $lxdebug->leave_sub(); @@ -1092,6 +1213,19 @@ sub search { |; } + $form->get_lists("projects" => { "key" => "ALL_PROJECTS", + "all" => 1 }); + + my %labels = (); + my @values = (""); + foreach my $item (@{ $form->{"ALL_PROJECTS"} }) { + push(@values, $item->{"id"}); + $labels{$item->{"id"}} = $item->{"projectnumber"}; + } + my $projectnumber = + NTI($cgi->popup_menu('-name' => 'project_id', '-values' => \@values, + '-labels' => \%labels)); + $form->{fokus} = "search.customer"; $form->header; @@ -1123,6 +1257,10 @@ sub search { | . $locale->text('Notes') . qq| + + | . $locale->text("Project Number") . qq| + $projectnumber + | . $locale->text('From') . qq| $button1 @@ -1189,6 +1327,8 @@ sub search { | . $locale->text('Subtotal') . qq| + + | . $locale->text('Project Number') . qq| @@ -1294,10 +1434,15 @@ sub ar_transactions { $option .= "\n" if ($option); $option .= $locale->text('Closed'); } + if ($form->{globalproject_id}) { + $callback .= "&globalproject_id=" . E($form->{globalproject_id}); + $href .= "&globalproject_id=" . E($form->{globalproject_id}); + } - @columns = $form->sort_columns( - qw(transdate id type invnumber ordnumber name netamount tax amount paid datepaid due duedate notes employee shippingpoint shipvia) - ); + @columns = + qw(transdate id type invnumber ordnumber name netamount tax amount paid + datepaid due duedate notes employee shippingpoint shipvia + globalprojectnumber); $form->{"l_type"} = "Y"; @@ -1370,6 +1515,8 @@ sub ar_transactions { "" . $locale->text('Ship via') . ""; + $column_header{globalprojectnumber} = + qq|| . $locale->text('Project Number') . qq||; $form->{title} = $locale->text('AR Transactions'); @@ -1468,6 +1615,8 @@ sub ar_transactions { $column_data{shippingpoint} = "$ar->{shippingpoint} "; $column_data{shipvia} = "$ar->{shipvia} "; $column_data{employee} = "$ar->{employee} "; + $column_data{globalprojectnumber} = + "" . H($ar->{globalprojectnumber}) . ""; $i++; $i %= 2; @@ -1535,14 +1684,8 @@ sub ar_transactions { |; + . $locale->text('Sales Invoice') . qq|"> - if ($form->{menubar}) { - require "$form->{path}/menu.pl"; - &menubar; - } - - print qq|
$form->{saved_message}