X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Fap.pl;h=dc02d137bbe825d1f652aca1aa6a95f2a57c555f;hb=863eb4303398caba2ab429475a69e09601919150;hp=c84b6146e5d3d641bee163014b9e1bbaa5e503bc;hpb=ce47a2340ef118b494854deae1b0ddc74b1d1c5a;p=kivitendo-erp.git diff --git a/bin/mozilla/ap.pl b/bin/mozilla/ap.pl index c84b6146e..dc02d137b 100644 --- a/bin/mozilla/ap.pl +++ b/bin/mozilla/ap.pl @@ -24,21 +24,34 @@ # 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 Payables # #====================================================================== +use POSIX qw(strftime); +use List::Util qw(max sum); +use List::UtilsBy qw(sort_by); + use SL::AP; +use SL::FU; +use SL::GL; use SL::IR; use SL::IS; -use SL::PE; +use SL::ReportGenerator; +use SL::DB::Default; +use SL::DB::PurchaseInvoice; +use SL::Webdav; +use SL::Locale::String qw(t8); require "bin/mozilla/arap.pl"; require "bin/mozilla/common.pl"; -require "bin/mozilla/drafts.pl"; +require "bin/mozilla/reportgenerator.pl"; + +use strict; 1; @@ -73,88 +86,116 @@ require "bin/mozilla/drafts.pl"; # $locale->text('Dec') sub add { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); - return $lxdebug->leave_sub() if (load_draft_maybe()); + my $form = $main::form; + my %myconfig = %main::myconfig; + + $main::auth->assert('ap_transactions'); $form->{title} = "Add"; - $form->{callback} = - "$form->{script}?action=add&login=$form->{login}&password=$form->{password}" - unless $form->{callback}; + $form->{callback} = "ap.pl?action=add" unless $form->{callback}; AP->get_transdate(\%myconfig, $form); $form->{initial_transdate} = $form->{transdate}; - &create_links; + create_links(dont_save => 1); $form->{transdate} = $form->{initial_transdate}; + + if ($form->{vendor_id}) { + my $last_used_ap_chart = SL::DB::Vendor->load_cached($form->{vendor_id})->last_used_ap_chart; + $form->{"AP_amount_chart_id_1"} = $last_used_ap_chart->id if $last_used_ap_chart; + } + &display_form; - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub edit { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + my $form = $main::form; + + $main::auth->assert('ap_transactions'); $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(); + + my $form = $main::form; + + $main::auth->assert('ap_transactions'); + + # get all files stored in the webdav folder + if ($form->{invnumber} && $::instance_conf->get_webdav) { + my $webdav = SL::Webdav->new( + type => 'accounts_payable', + number => $form->{invnumber}, + ); + my $webdav_path = $webdav->webdav_path; + my @all_objects = $webdav->get_all_objects; + @{ $form->{WEBDAV} } = map { { name => $_->filename, + type => t8('File'), + link => File::Spec->catfile($_->full_filedescriptor), + } } @all_objects; + } &form_header; &form_footer; - $lxdebug->leave_sub(); + $main::lxdebug->leave_sub(); } sub create_links { - $lxdebug->enter_sub(); + $main::lxdebug->enter_sub(); + + my %params = @_; + + my $form = $main::form; + my %myconfig = %main::myconfig; + + $main::auth->assert('ap_transactions'); $form->create_links("AP", \%myconfig, "vendor"); - $taxincluded = $form->{taxincluded}; - $duedate = $form->{duedate}; + my %saved; + if (!$params{dont_save}) { + %saved = map { ($_ => $form->{$_}) } qw(direct_debit taxincluded); + $saved{duedate} = $form->{duedate} if $form->{duedate}; + $saved{currency} = $form->{currency} if $form->{currency}; + $saved{taxincluded} = $form->{taxincluded} if $form->{taxincluded}; + } IR->get_vendor(\%myconfig, \%$form); - $form->{taxincluded} = $taxincluded; - $form->{duedate} = $duedate if $duedate; + + $form->{$_} = $saved{$_} for keys %saved; $form->{oldvendor} = "$form->{vendor}--$form->{vendor_id}"; $form->{rowcount} = 1; + $form->{AP_chart_id} = $form->{acc_trans} && $form->{acc_trans}->{AP} ? $form->{acc_trans}->{AP}->[0]->{chart_id} : $form->{AP_links}->{AP}->[0]->{chart_id}; # build the popup menus $form->{taxincluded} = ($form->{id}) ? $form->{taxincluded} : "checked"; - # notes - $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} .= "