X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;ds=inline;f=bin%2Fmozilla%2Far.pl;h=fc3b252a7615e9baaaec7685d84240ec121f1576;hb=27ffa16a85221662dee49da0f210312383341240;hp=a8937506f6356b0626e3ad20e142f39ee57b9aff;hpb=57bf9c89a037036fcf433de39643778854defe51;p=kivitendo-erp.git diff --git a/bin/mozilla/ar.pl b/bin/mozilla/ar.pl index a8937506f..fc3b252a7 100644 --- a/bin/mozilla/ar.pl +++ b/bin/mozilla/ar.pl @@ -76,8 +76,6 @@ use strict; # $locale->text('Nov') # $locale->text('Dec') -my $totalpaid; - sub add { $main::lxdebug->enter_sub(); @@ -91,13 +89,13 @@ sub add { # saving the history if(!exists $form->{addition} && ($form->{id} ne "")) { $form->{snumbers} = qq|invnumber_| . $form->{invnumber}; - $form->{addition} = "ADDED"; - $form->save_history($form->dbconnect(\%myconfig)); + $form->{addition} = "ADDED"; + $form->save_history; } # /saving the history $form->{title} = "Add"; - $form->{callback} = "ar.pl?action=add" unless $form->{callback}; + $form->{callback} = "ar.pl?action=add&DONT_LOAD_DRAFT=1" unless $form->{callback}; AR->get_transdate(\%myconfig, $form); $form->{initial_transdate} = $form->{transdate}; @@ -147,7 +145,7 @@ sub create_links { my $form = $main::form; my %myconfig = %main::myconfig; - my ($duedate, $taxincluded, @curr); + my ($duedate, $taxincluded); $form->create_links("AR", \%myconfig, "customer"); $duedate = $form->{duedate}; @@ -166,37 +164,35 @@ sub create_links { $form->{notes} = $form->{intnotes} unless $form->{notes}; # currencies - @curr = split(/:/, $form->{currencies}); - chomp $curr[0]; - $form->{defaultcurrency} = $curr[0]; + $form->{defaultcurrency} = $form->get_default_currency(\%myconfig); - map { $form->{selectcurrency} .= "$_\n" } @curr; + map { $form->{selectcurrency} .= "$_\n" } $form->get_all_currencies(\%myconfig); # customers - if (@{ $form->{all_customer} }) { + if (@{ $form->{all_customer} || [] }) { $form->{customer} = "$form->{customer}--$form->{customer_id}"; map { $form->{selectcustomer} .= "$_->{name}--$_->{id}\n" } (@{ $form->{all_customer} }); } # departments - if (@{ $form->{all_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->{all_departments} || [] }); } $form->{employee} = "$form->{employee}--$form->{employee_id}"; # sales staff - if (@{ $form->{all_employees} }) { + if (@{ $form->{all_employees} || [] }) { $form->{selectemployee} = ""; map { $form->{selectemployee} .= "$_->{name}--$_->{id}\n" } - (@{ $form->{all_employees} }); + (@{ $form->{all_employees} || [] }); } # build the popup menus @@ -275,26 +271,18 @@ sub form_header { $form->{exchangerate} = $form->{forex} if $form->{forex}; # format amounts - $form->{exchangerate} = - $form->format_amount(\%myconfig, $form->{exchangerate}); - - if ($form->{exchangerate} == 0) { - $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->{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}> |; - if ($form->{currency} ne $form->{defaultcurrency}) { + if ($form->{defaultcurrency} && ($form->{currency} ne $form->{defaultcurrency})) { if ($form->{forex}) { $exchangerate .= qq| - | . $locale->text('Exchangerate') . qq| - {exchangerate}>$form->{exchangerate} + | . $locale->text('Exchangerate') . qq| + {exchangerate}>$form->{exchangerate} |; } else { $exchangerate .= qq| @@ -305,10 +293,10 @@ sub form_header { } $taxincluded = qq| - - {taxincluded}> - | . $locale->text('Tax Included') . qq| - + + {taxincluded}> + | . $locale->text('Tax Included') . qq| + |; if (($rows = $form->numtextrows($form->{notes}, 50)) < 2) { @@ -318,12 +306,12 @@ sub form_header { qq|$form->{notes}|; $department = qq| - - | . $locale->text('Department') . qq| - $form->{selectdepartment} - - - + + | . $locale->text('Department') . qq| + $form->{selectdepartment} + + + | if $form->{selectdepartment}; my $n = ($form->{creditremaining} =~ /-/) ? "0" : "1"; @@ -338,11 +326,11 @@ sub form_header { if ($form->{selectemployee}) { $employee = qq| - - | . $locale->text('Salesperson') . qq| - $form->{selectemployee} - - + + | . $locale->text('Salesperson') . qq| + $form->{selectemployee} + + |; } @@ -478,66 +466,66 @@ sub form_header { - - - - | . $locale->text('Customer') . qq| - $customer - - - - {terms}> - - - - - - - | . $locale->text('Credit Limit') . qq| - $form->{creditlimit} - | . $locale->text('Remaining') . qq| - $form->{creditremaining} - {creditlimit}> - {creditremaining}> - - - - - - | . $locale->text('Currency') . qq| - $form->{selectcurrency} - - {defaultcurrency}> - {fxgain_accno}> - {fxloss_accno}> - $exchangerate - - $department - $taxincluded - - - - - $employee - - | . $locale->text('Invoice Number') . qq| - - - - | . $locale->text('Order Number') . qq| - - - - | . $locale->text('Invoice Date') . qq| + + + + | . $locale->text('Customer') . qq| + $customer + + + + {terms}> + + + + + + + | . $locale->text('Credit Limit') . qq| + $form->{creditlimit} + | . $locale->text('Remaining') . qq| + $form->{creditremaining} + {creditlimit}> + {creditremaining}> + + + + + + | . $locale->text('Currency') . qq| + $form->{selectcurrency} + + {defaultcurrency}> + {fxgain_accno}> + {fxloss_accno}> + $exchangerate + + $department + $taxincluded + + + + + $employee + + | . $locale->text('Invoice Number') . qq| + + + + | . $locale->text('Order Number') . qq| + + + + | . $locale->text('Invoice Date') . qq| $button1 - - - | . $locale->text('Due Date') . qq| + + + | . $locale->text('Due Date') . qq| $button2 - + - - + + @@ -547,10 +535,10 @@ $jsscript - - | + + | . $locale->text('Account') . qq| - | + | . $locale->text('Amount') . qq| | . $locale->text('Tax') . qq| @@ -558,7 +546,7 @@ $jsscript . $locale->text('Taxkey') . qq| | . $locale->text('Project') . qq| - + |; $amount = $locale->text('Amount'); @@ -622,13 +610,13 @@ $jsscript '-default' => $form->{"project_id_$i"} )); print qq| - + $selectAR_amount {"amount_$i"}> $form->{"tax_$i"} $tax $projectnumber - + |; $amount = ""; $project = ""; @@ -650,15 +638,15 @@ $jsscript - ${ARselected} - $form->{invtotal} + ${ARselected} + $form->{invtotal} - {oldinvtotal}> - {oldtotalpaid}> + {oldinvtotal}> + {oldtotalpaid}> - + - + @@ -669,22 +657,22 @@ $jsscript - | . $locale->text('Notes') . qq| - $notes - + | . $locale->text('Notes') . qq| + $notes + - - | + + | . $locale->text('Incoming Payments') . qq| - + |; - if ($form->{currency} eq $form->{defaultcurrency}) { + if ($form->{defaultcurrency} && ($form->{currency} eq $form->{defaultcurrency})) { @column_index = qw(datepaid source memo paid AR_paid paid_project_id); } else { @column_index = qw(datepaid source memo paid exchangerate AR_paid paid_project_id); @@ -707,7 +695,7 @@ $jsscript "; my @triggers = (); - my $totalpaid = 0; + $form->{totalpaid} = 0; $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"}); for my $i (1 .. $form->{paidaccounts}) { @@ -722,7 +710,7 @@ $jsscript '-labels' => \%AR_paid_labels, '-default' => $form->{"AR_paid_$i"})); - $totalpaid += $form->{"paid_$i"}; + $form->{totalpaid} += $form->{"paid_$i"}; # format amounts if ($form->{"paid_$i"}) { @@ -737,7 +725,7 @@ $jsscript } $exchangerate = qq| |; - if ($form->{currency} ne $form->{defaultcurrency}) { + if ($form->{defaultcurrency} && ($form->{currency} ne $form->{defaultcurrency})) { if ($form->{"forex_$i"}) { $exchangerate = qq|{"exchangerate_$i"}>$form->{"exchangerate_$i"}|; @@ -780,14 +768,14 @@ $jsscript push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i"); } - my $paid_missing = $form->{invtotal_unformatted} - $totalpaid; + my $paid_missing = $form->{invtotal_unformatted} - $form->{totalpaid}; print qq| | . $locale->text('Total') . qq| - | . H($form->format_amount(\%myconfig, $totalpaid, 2)) . qq| + | . H($form->format_amount(\%myconfig, $form->{totalpaid}, 2)) . qq| @@ -864,7 +852,7 @@ $follow_ups_block # ToDO: - insert a global check for stornos, so that a storno is only possible a limited time after saving it print qq| | - if ($form->{id} && !IS->has_storno(\%myconfig, $form, 'ar') && !IS->is_storno(\%myconfig, $form, 'ar') && (($totalpaid == 0) || ($totalpaid eq ""))); + if ($form->{id} && !IS->has_storno(\%myconfig, $form, 'ar') && !IS->is_storno(\%myconfig, $form, 'ar') && (($form->{totalpaid} == 0) || ($form->{totalpaid} eq ""))); if ($form->{id}) { if ($form->{radier}) { @@ -986,10 +974,14 @@ sub update { $form->{invdate} = $form->{transdate}; - my %saved_variables = map +( $_ => $form->{$_} ), qw(AR AR_amount_1 taxchart_1); + my %saved_variables = map +( $_ => $form->{$_} ), qw(AR AR_amount_1 taxchart_1 oldcustomer); &check_name("customer"); + # check_name ruft get_customer auf, oldcustomer wird überschrieben, daher wird dies vorher gemerkt + # get_customer holt Bemerkungen als intnotes, für Debitorenbuchungen gibt es aber nur das Feld notes + $form->{notes} = $form->{intnotes} if $saved_variables{oldcustomer} ne $form->{customer}; + $form->{AR} = $saved_variables{AR}; if ($saved_variables{AR_amount_1} =~ m/.--./) { map { $form->{$_} = $saved_variables{$_} } qw(AR_amount_1 taxchart_1); @@ -1007,7 +999,7 @@ sub update { $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(paid exchangerate); - $totalpaid += $form->{"paid_$i"}; + $form->{totalpaid} += $form->{"paid_$i"}; $form->{"forex_$i"} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy'); $form->{"exchangerate_$i"} = $form->{"forex_$i"} if $form->{"forex_$i"}; @@ -1015,10 +1007,10 @@ sub update { } $form->{creditremaining} -= - ($form->{invtotal} - $totalpaid + $form->{oldtotalpaid} - + ($form->{invtotal} - $form->{totalpaid} + $form->{oldtotalpaid} - $form->{oldinvtotal}); $form->{oldinvtotal} = $form->{invtotal}; - $form->{oldtotalpaid} = $totalpaid; + $form->{oldtotalpaid} = $form->{totalpaid}; &display_form; @@ -1039,6 +1031,8 @@ sub post_payment { $form->{defaultcurrency} = $form->get_default_currency(\%myconfig); + my $invdate = $form->datetonum($form->{transdate}, \%myconfig); + for my $i (1 .. $form->{paidaccounts}) { if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) { @@ -1048,7 +1042,7 @@ sub post_payment { $form->error($locale->text('Cannot post payment for a closed period!')) if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig)); - if ($form->{currency} ne $form->{defaultcurrency}) { + if ($form->{defaultcurrency} && ($form->{currency} ne $form->{defaultcurrency})) { # $form->{"exchangerate_$i"} = $form->{exchangerate} if ($invdate == $datepaid); $form->isblank("exchangerate_$i", $locale->text('Exchangerate for payment missing!')); } @@ -1091,6 +1085,12 @@ sub post { $form->isblank("duedate", $locale->text('Due Date missing!')); $form->isblank("customer", $locale->text('Customer missing!')); + if ($myconfig{mandatory_departments} && !$form->{department}) { + $form->{saved_message} = $::locale->text('You have to specify a department.'); + update(); + exit; + } + my $closedto = $form->datetonum($form->{closedto}, \%myconfig); my $transdate = $form->datetonum($form->{transdate}, \%myconfig); $form->error($locale->text('Cannot post transaction for a closed period!')) if ($form->date_closed($form->{"transdate"}, \%myconfig)); @@ -1099,7 +1099,7 @@ sub post { unless grep $_*1, map $form->parse_amount(\%myconfig, $form->{"amount_$_"}), 1..$form->{rowcount}; $form->isblank("exchangerate", $locale->text('Exchangerate missing!')) - if ($form->{currency} ne $form->{defaultcurrency}); + if ($form->{defaultcurrency} && ($form->{currency} ne $form->{defaultcurrency})); delete($form->{AR}); @@ -1112,7 +1112,7 @@ sub post { $form->error($locale->text('Cannot post payment for a closed period!')) if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig)); - if ($form->{currency} ne $form->{defaultcurrency}) { + if ($form->{defaultcurrency} && ($form->{currency} ne $form->{defaultcurrency})) { $form->{"exchangerate_$i"} = $form->{exchangerate} if ($transdate == $datepaid); $form->isblank("exchangerate_$i", $locale->text('Exchangerate for payment missing!')); } @@ -1123,13 +1123,12 @@ sub post { my ($customer) = split /--/, $form->{customer}; if ($form->{oldcustomer} ne "$customer--$form->{customer_id}") { update(); - exit; + ::end_of_request(); } $form->{AR}{receivables} = $form->{ARselected}; $form->{storno} = 0; - $main::lxdebug->message(0, $form->{amount}); $form->{id} = 0 if $form->{postasnew}; $form->error($locale->text('Cannot post transaction!')) unless AR->post_transaction(\%myconfig, \%$form); @@ -1137,7 +1136,7 @@ sub post { if(!exists $form->{addition} && $form->{id} ne "") { $form->{snumbers} = "invnumber_$form->{invnumber}"; $form->{addition} = "POSTED"; - $form->save_history($form->dbconnect(\%myconfig)); + $form->save_history; } # /saving the history remove_draft() if $form->{remove_draft}; @@ -1159,8 +1158,8 @@ sub post_as_new { # saving the history if(!exists $form->{addition} && $form->{id} ne "") { $form->{snumbers} = qq|invnumber_| . $form->{invnumber}; - $form->{addition} = "POSTED AS NEW"; - $form->save_history($form->dbconnect(\%myconfig)); + $form->{addition} = "POSTED AS NEW"; + $form->save_history; } # /saving the history &post; @@ -1242,8 +1241,8 @@ sub yes { # saving the history if(!exists $form->{addition}) { $form->{snumbers} = qq|invnumber_| . $form->{invnumber}; - $form->{addition} = "DELETED"; - $form->save_history($form->dbconnect(\%myconfig)); + $form->{addition} = "DELETED"; + $form->save_history; } # /saving the history $form->redirect($locale->text('Transaction deleted!')); @@ -1269,243 +1268,26 @@ sub search { # setup customer selection $form->all_vc(\%myconfig, "customer", "AR"); - if (@{ $form->{all_customer} }) { - map { $customer .= "$_->{name}--$_->{id}\n" } - @{ $form->{all_customer} }; - $customer = qq|\n$customer|; - } else { - $customer = qq||; - } - - # departments - if (@{ $form->{all_departments} }) { - $form->{selectdepartment} = "\n"; - - map { - $form->{selectdepartment} .= - "$_->{description}--$_->{id}\n" - } (@{ $form->{all_departments} }); - } - - $department = qq| - - | . $locale->text('Department') . qq| - $form->{selectdepartment} - -| if $form->{selectdepartment}; - - $form->{title} = $locale->text('AR Transactions'); - - $form->{javascript} .= qq||; - - # use JavaScript Calendar or not + $form->{title} = $locale->text('AR Transactions'); $form->{jsscript} = 1; - $jsscript = ""; - if ($form->{jsscript}) { - # with JavaScript Calendar - $button1 = qq| - - text('button') . qq|> - |; - $button2 = qq| - - text('button') . qq|> - |; + # Auch in Rechnungsübersicht nach Kundentyp filtern - jan + $form->get_lists("projects" => { "key" => "ALL_PROJECTS", "all" => 1 }, + "departments" => "ALL_DEPARTMENTS", + "customers" => "ALL_VC", + "employees" => "ALL_EMPLOYEES", + "salesmen" => "ALL_SALESMEN", + "business_types" => "ALL_BUSINESS_TYPES"); + $form->{SHOW_BUSINESS_TYPES} = scalar @{ $form->{ALL_BUSINESS_TYPES} } > 0; + + # constants and subs for template + $form->{jsscript} = 1; + $form->{vc_keys} = sub { "$_[0]->{name}--$_[0]->{id}" }; + $form->{employee_labels} = sub { $_[0]->{"name"} || $_[0]->{"login"} }; + $form->{salesman_labels} = $form->{employee_labels}; - #write Trigger - $jsscript = - Form->write_trigger(\%myconfig, "2", "transdatefrom", "BR", "trigger1", - "transdateto", "BL", "trigger2"); - } else { - - # without JavaScript Calendar - $button1 = qq| - |; - $button2 = qq| - |; - } - - $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; - $onload = qq|focus()|; - $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|; - $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|; - print qq| - - -{script}> - - - $form->{title} - - - - - - | . $locale->text('Customer') . qq| - $customer - - $department - - | . $locale->text('Invoice Number') . qq| - - - - | . $locale->text('Order Number') . qq| - - - - | . $locale->text('Transaction description') . qq| - - - - | . $locale->text('Notes') . qq| - - - - | . $locale->text("Project Number") . qq| - $projectnumber - - - | . $locale->text('From') . qq| - $button1 - | . $locale->text('Bis') . qq| - $button2 - - - - - - - - - - | . $locale->text('Include in Report') . qq| - - - - - | . $locale->text('Open') . qq| - - | . $locale->text('Closed') . qq| - - - - | . $locale->text('ID') . qq| - - | . $locale->text('Invoice Number') . qq| - - | . $locale->text('Order Number') . qq| - - | . $locale->text('Invoice Date') . qq| - - - - | . $locale->text('Customer') . qq| - - | . $locale->text('Amount') . qq| - - | . $locale->text('Tax') . qq| - - | . $locale->text('Total') . qq| - - - - | . $locale->text('Date Paid') . qq| - - | . $locale->text('Paid') . qq| - - | . $locale->text('Due Date') . qq| - - | . $locale->text('Amount Due') . qq| - - - - | . $locale->text('Notes') . qq| - - | . $locale->text('Salesperson') . qq| - - | . $locale->text('Shipping Point') . qq| - - | . $locale->text('Ship via') . qq| - - - - | . $locale->text('Ertrag') . qq| - - | . $locale->text('Ertrag prozentual') . qq| - - | . $locale->text('Employee') . qq| - - - - | . $locale->text('Subtotal') . qq| - - | . $locale->text('Project Number') . qq| - - | . $locale->text('Transaction description') . qq| - - - | . $locale->text('Customer') . qq| - - - - | . $locale->text('Customer Number') . qq| - - | . $locale->text('Country') . qq| - - | . $locale->text('USt-IdNr.') . qq| - - | . $locale->text('Steuersatz') . qq| - - - - | . $locale->text('Payment Terms') . qq| - - | . $locale->text('Buchungskonto') . qq| - - - - - - - - - - - - - -{nextsub}> - - - - - - - - -$jsscript - -