X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Far.pl;h=16be58c0925462284a2f29d4dd87ebeb07bb7d7e;hb=aa63ebae1c0a758ec438c594acb328b1f0e5e001;hp=11b73b225c9972b771435230448f757b32110161;hpb=a14a3ff56b00e22c39a2cfb0e465f8c7764a4cd4;p=kivitendo-erp.git diff --git a/bin/mozilla/ar.pl b/bin/mozilla/ar.pl index 11b73b225..16be58c09 100644 --- a/bin/mozilla/ar.pl +++ b/bin/mozilla/ar.pl @@ -24,23 +24,35 @@ # 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 # #====================================================================== +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 Data::Dumper; - -require "$form->{path}/arap.pl"; +use SL::DB::Business; +use SL::DB::Currency; +use SL::DB::Default; +use SL::DB::Employee; +use SL::DB::Invoice; +use SL::ReportGenerator; -1; +require "bin/mozilla/arap.pl"; +require "bin/mozilla/common.pl"; +require "bin/mozilla/reportgenerator.pl"; -# end of main +use strict; +#use warnings; # this is for our long dates # $locale->text('January') @@ -71,779 +83,399 @@ require "$form->{path}/arap.pl"; # $locale->text('Dec') sub add { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + $main::auth->assert('ar_transactions'); + + my $form = $main::form; + my %myconfig = %main::myconfig; + + # saving the history + if(!exists $form->{addition} && ($form->{id} ne "")) { + $form->{snumbers} = qq|invnumber_| . $form->{invnumber}; + $form->{addition} = "ADDED"; + $form->save_history; + } + # /saving the history $form->{title} = "Add"; - $form->{callback} = - "$form->{script}?action=add&path=$form->{path}&login=$form->{login}&password=$form->{password}" - unless $form->{callback}; + $form->{callback} = "ar.pl?action=add" unless $form->{callback}; - &create_links; AR->get_transdate(\%myconfig, $form); - &display_form; + $form->{initial_transdate} = $form->{transdate}; + create_links(dont_save => 1); + $form->{transdate} = $form->{initial_transdate}; - $lxdebug->leave_sub(); + 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(); } sub edit { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + $main::auth->assert('ar_transactions'); + my $form = $main::form; + + # show history button + $form->{javascript} = qq||; + #/show hhistory button + $form->{javascript} .= qq||; $form->{title} = "Edit"; - &create_links; + create_links(); &display_form; - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub display_form { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + $main::auth->assert('ar_transactions'); + + my $form = $main::form; &form_header; &form_footer; - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } -sub create_links { - $lxdebug->enter_sub(); - - $form->create_links("AR", \%myconfig, "customer"); - $duedate = $form->{duedate}; +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; +} - $taxincluded = $form->{taxincluded}; - my $id = $form->{id}; - IS->get_customer(\%myconfig, \%$form); - $form->{taxincluded} = $taxincluded; - $form->{id} = $id; +sub create_links { + $main::lxdebug->enter_sub(); - $form->{duedate} = $duedate if $duedate; - $form->{oldcustomer} = "$form->{customer}--$form->{customer_id}"; - $form->{rowcount} = 1; + $main::auth->assert('ar_transactions'); - # currencies - @curr = split(/:/, $form->{currencies}); - chomp $curr[0]; - $form->{defaultcurrency} = $curr[0]; + my %params = @_; + my $form = $main::form; + my %myconfig = %main::myconfig; - map { $form->{selectcurrency} .= "\n"; - } else { - $form->{"select$key"} .= - "\n"; - } - } - - $form->{$key} = $form->{"select$key"}; - - # if there is a value we have an old entry - 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}++; - } else { - - $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}"} =~ - /