X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Far.pl;h=dc7074c615c51de3ebe4558dae70d2ac0f3ca83a;hb=af9a1f44788ded346d8510511d26a760d996ba14;hp=e1b10f63c0b5270e1a3b6444f8121f5446758f5a;hpb=a11d7a85a9b73798acb3a11b6ba4251ba331b19c;p=kivitendo-erp.git diff --git a/bin/mozilla/ar.pl b/bin/mozilla/ar.pl index e1b10f63c..dc7074c61 100644 --- a/bin/mozilla/ar.pl +++ b/bin/mozilla/ar.pl @@ -24,7 +24,8 @@ # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software -# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1335, USA. #====================================================================== # # Accounts Receivables @@ -33,17 +34,18 @@ use POSIX qw(strftime); use List::Util qw(sum first max); +use List::UtilsBy qw(sort_by); use SL::AR; use SL::FU; +use SL::GL; use SL::IS; -use SL::PE; use SL::DB::Default; +use SL::DB::Invoice; use SL::ReportGenerator; require "bin/mozilla/arap.pl"; require "bin/mozilla/common.pl"; -require "bin/mozilla/drafts.pl"; require "bin/mozilla/reportgenerator.pl"; use strict; @@ -80,13 +82,11 @@ use strict; sub add { $main::lxdebug->enter_sub(); - $main::auth->assert('general_ledger'); + $main::auth->assert('ar_transactions'); my $form = $main::form; my %myconfig = %main::myconfig; - return $main::lxdebug->leave_sub() if (load_draft_maybe()); - # saving the history if(!exists $form->{addition} && ($form->{id} ne "")) { $form->{snumbers} = qq|invnumber_| . $form->{invnumber}; @@ -96,12 +96,18 @@ sub add { # /saving the history $form->{title} = "Add"; - $form->{callback} = "ar.pl?action=add&DONT_LOAD_DRAFT=1" unless $form->{callback}; + $form->{callback} = "ar.pl?action=add" unless $form->{callback}; AR->get_transdate(\%myconfig, $form); $form->{initial_transdate} = $form->{transdate}; create_links(dont_save => 1); $form->{transdate} = $form->{initial_transdate}; + + if ($form->{customer_id}) { + my $last_used_ar_chart = SL::DB::Customer->load_cached($form->{customer_id})->last_used_ar_chart; + $form->{"AR_amount_chart_id_1"} = $last_used_ar_chart->id if $last_used_ar_chart; + } + &display_form; $main::lxdebug->leave_sub(); } @@ -109,7 +115,7 @@ sub add { sub edit { $main::lxdebug->enter_sub(); - $main::auth->assert('general_ledger'); + $main::auth->assert('ar_transactions'); my $form = $main::form; @@ -128,7 +134,7 @@ sub edit { sub display_form { $main::lxdebug->enter_sub(); - $main::auth->assert('general_ledger'); + $main::auth->assert('ar_transactions'); my $form = $main::form; @@ -138,21 +144,29 @@ sub display_form { $main::lxdebug->leave_sub(); } +sub _retrieve_invoice_object { + return undef if !$::form->{id}; + return $::form->{invoice_obj} if $::form->{invoice_obj} && $::form->{invoice_obj}->id == $::form->{id}; + return SL::DB::Invoice->new(id => $::form->{id})->load; +} + sub create_links { $main::lxdebug->enter_sub(); - $main::auth->assert('general_ledger'); + $main::auth->assert('ar_transactions'); my %params = @_; my $form = $main::form; my %myconfig = %main::myconfig; $form->create_links("AR", \%myconfig, "customer"); + $form->{invoice_obj} = _retrieve_invoice_object(); my %saved; if (!$params{dont_save}) { %saved = map { ($_ => $form->{$_}) } qw(direct_debit id taxincluded); $saved{duedate} = $form->{duedate} if $form->{duedate}; + $saved{currency} = $form->{currency} if $form->{currency}; } IS->get_customer(\%myconfig, \%$form); @@ -160,10 +174,12 @@ sub create_links { $form->{$_} = $saved{$_} for keys %saved; $form->{oldcustomer} = "$form->{customer}--$form->{customer_id}"; $form->{rowcount} = 1; + $form->{AR_chart_id} = $form->{acc_trans} && $form->{acc_trans}->{AR} ? $form->{acc_trans}->{AR}->[0]->{chart_id} : $form->{AR_links}->{AR}->[0]->{chart_id}; # currencies $form->{defaultcurrency} = $form->get_default_currency(\%myconfig); + $form->{selectcurrency} = ""; map { $form->{selectcurrency} .= "