kivitendo/bin/mozilla/ap.pl @ 056888bc
d319704a | Moritz Bunkus | #=====================================================================
|
||
# LX-Office ERP
|
||||
# Copyright (C) 2004
|
||||
# Based on SQL-Ledger Version 2.1.9
|
||||
# Web http://www.lx-office.org
|
||||
#
|
||||
#=====================================================================
|
||||
# SQL-Ledger Accounting
|
||||
# Copyright (c) 2001
|
||||
#
|
||||
# Author: Dieter Simader
|
||||
# Email: dsimader@sql-ledger.org
|
||||
# Web: http://www.sql-ledger.org
|
||||
#
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# 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
|
||||
f7b15d43 | Christian Wittmer | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||
# MA 02110-1335, USA.
|
||||
d319704a | Moritz Bunkus | #======================================================================
|
||
#
|
||||
# Accounts Payables
|
||||
#
|
||||
#======================================================================
|
||||
e71494c1 | Moritz Bunkus | use POSIX qw(strftime);
|
||
0d37f1e8 | Moritz Bunkus | use List::Util qw(max sum);
|
||
use List::UtilsBy qw(sort_by);
|
||||
e71494c1 | Moritz Bunkus | |||
d319704a | Moritz Bunkus | use SL::AP;
|
||
7a7f33b5 | Moritz Bunkus | use SL::FU;
|
||
d319704a | Moritz Bunkus | use SL::IR;
|
||
6d544157 | Sven Schöling | use SL::IS;
|
||
e71494c1 | Moritz Bunkus | use SL::ReportGenerator;
|
||
97954312 | Bernd Bleßmann | use SL::DB::Default;
|
||
267cb279 | Moritz Bunkus | use SL::DB::PurchaseInvoice;
|
||
d319704a | Moritz Bunkus | |||
d629acd8 | Sven Schöling | require "bin/mozilla/arap.pl";
|
||
a4b22a8f | Moritz Bunkus | require "bin/mozilla/common.pl";
|
||
18da4a96 | Moritz Bunkus | require "bin/mozilla/reportgenerator.pl";
|
||
d319704a | Moritz Bunkus | |||
088b52b5 | Sven Schöling | use strict;
|
||
d319704a | Moritz Bunkus | 1;
|
||
# end of main
|
||||
# this is for our long dates
|
||||
# $locale->text('January')
|
||||
# $locale->text('February')
|
||||
# $locale->text('March')
|
||||
# $locale->text('April')
|
||||
# $locale->text('May ')
|
||||
# $locale->text('June')
|
||||
# $locale->text('July')
|
||||
# $locale->text('August')
|
||||
# $locale->text('September')
|
||||
# $locale->text('October')
|
||||
# $locale->text('November')
|
||||
# $locale->text('December')
|
||||
# this is for our short month
|
||||
# $locale->text('Jan')
|
||||
# $locale->text('Feb')
|
||||
# $locale->text('Mar')
|
||||
# $locale->text('Apr')
|
||||
# $locale->text('May')
|
||||
# $locale->text('Jun')
|
||||
# $locale->text('Jul')
|
||||
# $locale->text('Aug')
|
||||
# $locale->text('Sep')
|
||||
# $locale->text('Oct')
|
||||
# $locale->text('Nov')
|
||||
# $locale->text('Dec')
|
||||
sub add {
|
||||
088b52b5 | Sven Schöling | $main::lxdebug->enter_sub();
|
||
my $form = $main::form;
|
||||
my %myconfig = %main::myconfig;
|
||||
d319704a | Moritz Bunkus | |||
25d67207 | Martin Helmling | $main::auth->assert('ap_transactions');
|
||
8c7e4493 | Moritz Bunkus | |||
d319704a | Moritz Bunkus | $form->{title} = "Add";
|
||
62726dfd | Sven Schöling | $form->{callback} = "ap.pl?action=add" unless $form->{callback};
|
||
d319704a | Moritz Bunkus | |||
2387a1fc | Moritz Bunkus | AP->get_transdate(\%myconfig, $form);
|
||
d0b49f67 | Moritz Bunkus | $form->{initial_transdate} = $form->{transdate};
|
||
d623e974 | Moritz Bunkus | create_links(dont_save => 1);
|
||
d0b49f67 | Moritz Bunkus | $form->{transdate} = $form->{initial_transdate};
|
||
d319704a | Moritz Bunkus | &display_form;
|
||
088b52b5 | Sven Schöling | $main::lxdebug->leave_sub();
|
||
d319704a | Moritz Bunkus | }
|
||
sub edit {
|
||||
088b52b5 | Sven Schöling | $main::lxdebug->enter_sub();
|
||
my $form = $main::form;
|
||||
d319704a | Moritz Bunkus | |||
25d67207 | Martin Helmling | $main::auth->assert('ap_transactions');
|
||
8c7e4493 | Moritz Bunkus | |||
d319704a | Moritz Bunkus | $form->{title} = "Edit";
|
||
d623e974 | Moritz Bunkus | create_links();
|
||
d319704a | Moritz Bunkus | &display_form;
|
||
088b52b5 | Sven Schöling | $main::lxdebug->leave_sub();
|
||
d319704a | Moritz Bunkus | }
|
||
sub display_form {
|
||||
088b52b5 | Sven Schöling | $main::lxdebug->enter_sub();
|
||
d319704a | Moritz Bunkus | |||
088b52b5 | Sven Schöling | my $form = $main::form;
|
||
25d67207 | Martin Helmling | $main::auth->assert('ap_transactions');
|
||
8c7e4493 | Moritz Bunkus | |||
d319704a | Moritz Bunkus | &form_header;
|
||
&form_footer;
|
||||
088b52b5 | Sven Schöling | $main::lxdebug->leave_sub();
|
||
d319704a | Moritz Bunkus | }
|
||
sub create_links {
|
||||
088b52b5 | Sven Schöling | $main::lxdebug->enter_sub();
|
||
d623e974 | Moritz Bunkus | my %params = @_;
|
||
088b52b5 | Sven Schöling | my $form = $main::form;
|
||
my %myconfig = %main::myconfig;
|
||||
d319704a | Moritz Bunkus | |||
25d67207 | Martin Helmling | $main::auth->assert('ap_transactions');
|
||
8c7e4493 | Moritz Bunkus | |||
d319704a | Moritz Bunkus | $form->create_links("AP", \%myconfig, "vendor");
|
||
d623e974 | Moritz Bunkus | my %saved;
|
||
if (!$params{dont_save}) {
|
||||
%saved = map { ($_ => $form->{$_}) } qw(direct_debit taxincluded);
|
||||
$saved{duedate} = $form->{duedate} if $form->{duedate};
|
||||
76785737 | Geoffrey Richardson | $saved{currency} = $form->{currency} if $form->{currency};
|
||
e50ac26b | Geoffrey Richardson | $saved{taxincluded} = $form->{taxincluded} if $form->{taxincluded};
|
||
d623e974 | Moritz Bunkus | }
|
||
d319704a | Moritz Bunkus | |||
IR->get_vendor(\%myconfig, \%$form);
|
||||
d623e974 | Moritz Bunkus | |||
$form->{$_} = $saved{$_} for keys %saved;
|
||||
d319704a | Moritz Bunkus | $form->{oldvendor} = "$form->{vendor}--$form->{vendor_id}";
|
||
30175d89 | Philip Reetz | $form->{rowcount} = 1;
|
||
d319704a | Moritz Bunkus | |||
# build the popup menus
|
||||
$form->{taxincluded} = ($form->{id}) ? $form->{taxincluded} : "checked";
|
||||
# currencies
|
||||
bea3f989 | Moritz Bunkus | $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
|
||
d319704a | Moritz Bunkus | |||
56f92e7f | Martin Helmling | $form->{selectcurrency} = "";
|
||
c83c61d2 | Moritz Bunkus | map { my $quoted = H($_); $form->{selectcurrency} .= "<option value=\"${quoted}\">${quoted}\n" } $form->get_all_currencies(\%myconfig);
|
||
d319704a | Moritz Bunkus | |||
# vendors
|
||||
1f110e87 | Sven Schöling | if (@{ $form->{all_vendor} || [] }) {
|
||
d319704a | Moritz Bunkus | $form->{vendor} = qq|$form->{vendor}--$form->{vendor_id}|;
|
||
c83c61d2 | Moritz Bunkus | map { my $quoted = H($_->{name} . "--" . $_->{id}); $form->{selectvendor} .= "<option value=\"${quoted}\">${quoted}\n" }
|
||
d319704a | Moritz Bunkus | (@{ $form->{all_vendor} });
|
||
}
|
||||
# departments
|
||||
e2b9e173 | Sven Schöling | if (@{ $form->{all_departments} || [] }) {
|
||
d319704a | Moritz Bunkus | $form->{department} = "$form->{department}--$form->{department_id}";
|
||
c83c61d2 | Moritz Bunkus | $form->{selectdepartment} = "<option>\n" . join('', map { my $quoted = H("$_->{description}--$_->{id}"); "<option value=\"${quoted}\">${quoted}\n"} @{ $form->{all_departments} || [] });
|
||
d319704a | Moritz Bunkus | }
|
||
$form->{employee} = "$form->{employee}--$form->{employee_id}";
|
||||
1118dab9 | Moritz Bunkus | AP->setup_form($form);
|
||
d319704a | Moritz Bunkus | |||
$form->{locked} =
|
||||
($form->datetonum($form->{transdate}, \%myconfig) <=
|
||||
$form->datetonum($form->{closedto}, \%myconfig));
|
||||
088b52b5 | Sven Schöling | $main::lxdebug->leave_sub();
|
||
d319704a | Moritz Bunkus | }
|
||
0d37f1e8 | Moritz Bunkus | sub _sort_payments {
|
||
83b760fb | Martin Helmling | my @fields = qw(acc_trans_id gldate datepaid source memo paid AP_paid paid_project_id);
|
||
0d37f1e8 | Moritz Bunkus | my @payments =
|
||
grep { $_->{paid} != 0 }
|
||||
map {
|
||||
my $idx = $_;
|
||||
+{ map { ($_ => delete($::form->{"${_}_${idx}"})) } @fields }
|
||||
} (1..$::form->{paidaccounts});
|
||||
@payments = sort_by { DateTime->from_kivitendo($_->{datepaid}) } @payments;
|
||||
$::form->{paidaccounts} = max scalar(@payments), 1;
|
||||
foreach my $idx (1 .. scalar(@payments)) {
|
||||
my $payment = $payments[$idx - 1];
|
||||
$::form->{"${_}_${idx}"} = $payment->{$_} for @fields;
|
||||
}
|
||||
}
|
||||
d319704a | Moritz Bunkus | sub form_header {
|
||
088b52b5 | Sven Schöling | $main::lxdebug->enter_sub();
|
||
d319704a | Moritz Bunkus | |||
088b52b5 | Sven Schöling | my $form = $main::form;
|
||
my %myconfig = %main::myconfig;
|
||||
my $locale = $main::locale;
|
||||
5494f687 | Sven Schöling | my $cgi = $::request->{cgi};
|
||
8c7e4493 | Moritz Bunkus | |||
25d67207 | Martin Helmling | $main::auth->assert('ap_transactions');
|
||
088b52b5 | Sven Schöling | |||
267cb279 | Moritz Bunkus | $::form->{invoice_obj} = SL::DB::PurchaseInvoice->new(id => $::form->{id})->load if $::form->{id};
|
||
46231fcc | Thomas Heck | $form->{title_} = $form->{title};
|
||
6959bb5e | Moritz Bunkus | $form->{title} = $form->{title} eq 'Add' ? $locale->text('Add Accounts Payables Transaction') : $locale->text('Edit Accounts Payables Transaction');
|
||
d319704a | Moritz Bunkus | |||
# type=submit $locale->text('Add Accounts Payables Transaction')
|
||||
# type=submit $locale->text('Edit Accounts Payables Transaction')
|
||||
# set option selected
|
||||
088b52b5 | Sven Schöling | foreach my $item (qw(vendor currency department)) {
|
||
c83c61d2 | Moritz Bunkus | my $to_replace = H($form->{$item});
|
||
d319704a | Moritz Bunkus | $form->{"select$item"} =~ s/ selected//;
|
||
c83c61d2 | Moritz Bunkus | $form->{"select$item"} =~ s/>\Q${to_replace}\E/ selected>${to_replace}/;
|
||
d319704a | Moritz Bunkus | }
|
||
46231fcc | Thomas Heck | my $readonly = $form->{id} ? "readonly" : "";
|
||
d319704a | Moritz Bunkus | |||
4ac2976f | Bernd Bleßmann | $form->{radier} = ($::instance_conf->get_ap_changeable == 2)
|
||
? ($form->current_date(\%myconfig) eq $form->{gldate})
|
||||
: ($::instance_conf->get_ap_changeable == 1);
|
||||
46231fcc | Thomas Heck | $readonly = $form->{radier} ? "" : $readonly;
|
||
$form->{readonly} = $readonly;
|
||||
d319704a | Moritz Bunkus | |||
46231fcc | Thomas Heck | $form->{forex} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{transdate}, 'sell');
|
||
if ( $form->{forex} ) {
|
||||
$form->{exchangerate} = $form->{forex};
|
||||
}
|
||||
fb37acdc | Moritz Bunkus | |||
d319704a | Moritz Bunkus | # format amounts
|
||
ae45c5b7 | Sven Schöling | $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");
|
||||
d319704a | Moritz Bunkus | |||
088b52b5 | Sven Schöling | my $rows;
|
||
d319704a | Moritz Bunkus | if (($rows = $form->numtextrows($form->{notes}, 50)) < 2) {
|
||
$rows = 2;
|
||||
}
|
||||
46231fcc | Thomas Heck | $form->{textarea_rows} = $rows;
|
||
$form->{creditremaining_plus} = ($form->{creditremaining} =~ /-/) ? "0" : "1";
|
||||
d319704a | Moritz Bunkus | |||
f01741e3 | Moritz Bunkus | my @old_project_ids = ();
|
||
46231fcc | Thomas Heck | map(
|
||
{
|
||||
if ($form->{"project_id_$_"}) {
|
||||
push(@old_project_ids, $form->{"project_id_$_"});
|
||||
}
|
||||
}
|
||||
(1..$form->{"rowcount"})
|
||||
);
|
||||
f01741e3 | Moritz Bunkus | |||
797ad4c5 | Moritz Bunkus | $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
|
||
"all" => 0,
|
||||
"old_id" => \@old_project_ids },
|
||||
"charts" => { "key" => "ALL_CHARTS",
|
||||
"transdate" => $form->{transdate} },
|
||||
"taxcharts" => { "key" => "ALL_TAXCHARTS",
|
||||
"module" => "AP" },);
|
||||
d0b49f67 | Moritz Bunkus | |||
46231fcc | Thomas Heck | map(
|
||
{ $_->{link_split} = [ split(/:/, $_->{link}) ]; }
|
||||
@{ $form->{ALL_CHARTS} }
|
||||
);
|
||||
f01741e3 | Moritz Bunkus | |||
my %project_labels = ();
|
||||
foreach my $item (@{ $form->{"ALL_PROJECTS"} }) {
|
||||
46231fcc | Thomas Heck | $project_labels{$item->{id}} = $item->{projectnumber};
|
||
f01741e3 | Moritz Bunkus | }
|
||
d0b49f67 | Moritz Bunkus | my %charts;
|
||
my $taxchart_init;
|
||||
foreach my $item (@{ $form->{ALL_CHARTS} }) {
|
||||
9fe00490 | Thomas Heck | if ( grep({ $_ eq 'AP_amount' } @{ $item->{link_split} }) ) {
|
||
if ( $taxchart_init eq '' ) {
|
||||
$taxchart_init = $item->{tax_id};
|
||||
}
|
||||
push(@{ $form->{ALL_CHARTS_AP_amount} }, $item);
|
||||
}
|
||||
elsif ( grep({ $_ eq 'AP' } @{ $item->{link_split} }) ) {
|
||||
push(@{ $form->{ALL_CHARTS_AP} }, $item);
|
||||
}
|
||||
elsif ( grep({ $_ eq 'AP_paid' } @{ $item->{link_split} }) ) {
|
||||
push(@{ $form->{ALL_CHARTS_AP_paid} }, $item);
|
||||
d0b49f67 | Moritz Bunkus | }
|
||
$charts{$item->{accno}} = $item;
|
||||
}
|
||||
my %taxcharts = ();
|
||||
foreach my $item (@{ $form->{ALL_TAXCHARTS} }) {
|
||||
9fe00490 | Thomas Heck | my $key = $item->{id} .'--'. $item->{rate};
|
||
if ( $taxchart_init eq $item->{id} ) {
|
||||
$taxchart_init = $key;
|
||||
}
|
||||
d0b49f67 | Moritz Bunkus | $taxcharts{$item->{id}} = $item;
|
||
}
|
||||
7a7f33b5 | Moritz Bunkus | my $follow_up_vc = $form->{vendor};
|
||
$follow_up_vc =~ s/--.*?//;
|
||||
my $follow_up_trans_info = "$form->{invnumber} ($follow_up_vc)";
|
||||
be4e11d3 | Thomas Kasulke | $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
|
||
fb4d2ffa | Moritz Bunkus | $form->{javascript} .= qq|<script type="text/javascript" src="js/show_vc_details.js"></script>|;
|
||
7a7f33b5 | Moritz Bunkus | $form->{javascript} .= qq|<script type="text/javascript" src="js/follow_up.js"></script>|;
|
||
62726dfd | Sven Schöling | $form->{javascript} .= qq|<script type="text/javascript" src="js/kivi.Draft.js"></script>|;
|
||
fb4d2ffa | Moritz Bunkus | |||
9fe00490 | Thomas Heck | $form->header();
|
||
d319704a | Moritz Bunkus | |||
088b52b5 | Sven Schöling | for my $i (1 .. $form->{rowcount}) {
|
||
d319704a | Moritz Bunkus | |||
# format amounts
|
||||
46231fcc | Thomas Heck | $form->{"amount_$i"} = $form->format_amount(\%myconfig, $form->{"amount_$i"}, 2);
|
||
30175d89 | Philip Reetz | $form->{"tax_$i"} = $form->format_amount(\%myconfig, $form->{"tax_$i"}, 2);
|
||
d0b49f67 | Moritz Bunkus | |||
my $selected_accno_full;
|
||||
my ($accno_row) = split(/--/, $form->{"AP_amount_$i"});
|
||||
my $item = $charts{$accno_row};
|
||||
$selected_accno_full = "$item->{accno}--$item->{tax_id}";
|
||||
my $selected_taxchart = $form->{"taxchart_$i"};
|
||||
my ($selected_accno, $selected_tax_id) = split(/--/, $selected_accno_full);
|
||||
my ($previous_accno, $previous_tax_id) = split(/--/, $form->{"previous_AP_amount_$i"});
|
||||
if ($previous_accno &&
|
||||
($previous_accno eq $selected_accno) &&
|
||||
($previous_tax_id ne $selected_tax_id)) {
|
||||
my $item = $taxcharts{$selected_tax_id};
|
||||
$selected_taxchart = "$item->{id}--$item->{rate}";
|
||||
}
|
||||
$selected_taxchart = $taxchart_init unless ($form->{"taxchart_$i"});
|
||||
9fe00490 | Thomas Heck | $form->{'selected_accno_full_'. $i} = $selected_accno_full;
|
||
$form->{'selected_taxchart_'. $i} = $selected_taxchart;
|
||||
d319704a | Moritz Bunkus | }
|
||
9fe00490 | Thomas Heck | $form->{AP_amount_value_title_sub} = sub {
|
||
my $item = shift;
|
||||
return [
|
||||
$item->{accno} .'--'. $item->{tax_id},
|
||||
$item->{accno} .'--'. $item->{description},
|
||||
];
|
||||
};
|
||||
$form->{taxchart_value_title_sub} = sub {
|
||||
my $item = shift;
|
||||
return [
|
||||
$item->{id} .'--'. $item->{rate},
|
||||
$item->{taxdescription} .' '. ($item->{rate} * 100) .' %',
|
||||
];
|
||||
};
|
||||
$form->{AP_paid_value_title_sub} = sub {
|
||||
my $item = shift;
|
||||
return [
|
||||
$item->{accno},
|
||||
$item->{accno} .'--'. $item->{description}
|
||||
];
|
||||
};
|
||||
$form->{APselected_value_title_sub} = sub {
|
||||
my $item = shift;
|
||||
return [
|
||||
$item->{accno},
|
||||
$item->{accno} .'--'. $item->{description}
|
||||
];
|
||||
};
|
||||
d319704a | Moritz Bunkus | |||
4d20c181 | Moritz Bunkus | $form->{invtotal_unformatted} = $form->{invtotal};
|
||
30175d89 | Philip Reetz | $form->{invtotal} = $form->format_amount(\%myconfig, $form->{invtotal}, 2);
|
||
d319704a | Moritz Bunkus | |||
e6ffa928 | Moritz Bunkus | $form->{totalpaid} = 0;
|
||
4d20c181 | Moritz Bunkus | |||
0d37f1e8 | Moritz Bunkus | _sort_payments();
|
||
46231fcc | Thomas Heck | if ( $form->{'paid_'. $form->{paidaccounts}} ) {
|
||
$form->{paidaccounts}++;
|
||||
}
|
||||
5be8f312 | Jan Büren | |||
# default account for current assets (i.e. 1801 - SKR04)
|
||||
$form->{accno_arap} = IS->get_standard_accno_current_assets(\%myconfig, \%$form);
|
||||
088b52b5 | Sven Schöling | for my $i (1 .. $form->{paidaccounts}) {
|
||
e6ffa928 | Moritz Bunkus | $form->{totalpaid} += $form->{"paid_$i"};
|
||
4d20c181 | Moritz Bunkus | |||
d319704a | Moritz Bunkus | # format amounts
|
||
53beea8b | Philip Reetz | if ($form->{"paid_$i"}) {
|
||
46231fcc | Thomas Heck | $form->{"paid_$i"} = $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2);
|
||
53beea8b | Philip Reetz | }
|
||
fb37acdc | Moritz Bunkus | if ($form->{"exchangerate_$i"} == 0) {
|
||
$form->{"exchangerate_$i"} = "";
|
||||
f9c86f3f | Bernd Bleßmann | } else {
|
||
$form->{"exchangerate_$i"} =
|
||||
$form->format_amount(\%myconfig, $form->{"exchangerate_$i"});
|
||||
fb37acdc | Moritz Bunkus | }
|
||
d319704a | Moritz Bunkus | |||
890e057f | Bernd Bleßmann | my $changeable = 1;
|
||
97954312 | Bernd Bleßmann | if (SL::DB::Default->get->payments_changeable == 0) {
|
||
890e057f | Bernd Bleßmann | # never
|
||
$changeable = ($form->{"acc_trans_id_$i"})? 0 : 1;
|
||||
}
|
||||
97954312 | Bernd Bleßmann | if (SL::DB::Default->get->payments_changeable == 2) {
|
||
890e057f | Bernd Bleßmann | # on the same day
|
||
$changeable = (($form->{"gldate_$i"} eq '') || $form->current_date(\%myconfig) eq $form->{"gldate_$i"});
|
||||
}
|
||||
79b83b02 | Bernd Bleßmann | |||
60fd9199 | Frank Messerschmidt | #deaktivieren von gebuchten Zahlungen ausserhalb der Bücherkontrolle, vorher prüfen ob heute eingegeben
|
||
if ($form->date_closed($form->{"gldate_$i"})) {
|
||||
$changeable = 0;
|
||||
}
|
||||
46231fcc | Thomas Heck | $form->{'paidaccount_changeable_'. $i} = $changeable;
|
||
79b83b02 | Bernd Bleßmann | |||
9fe00490 | Thomas Heck | $form->{'labelpaid_project_id_'. $i} = $project_labels{$form->{'paid_project_id_'. $i}};
|
||
d319704a | Moritz Bunkus | }
|
||
4d20c181 | Moritz Bunkus | |||
46231fcc | Thomas Heck | $form->{paid_missing} = $form->{invtotal_unformatted} - $form->{totalpaid};
|
||
8c204ce4 | Moritz Bunkus | print $form->parse_html_template('ap/form_header', {
|
||
today => DateTime->today,
|
||||
});
|
||||
d319704a | Moritz Bunkus | |||
088b52b5 | Sven Schöling | $main::lxdebug->leave_sub();
|
||
d319704a | Moritz Bunkus | }
|
||
sub form_footer {
|
||||
8c8f6da3 | Thomas Heck | $::lxdebug->enter_sub;
|
||
25d67207 | Martin Helmling | $::auth->assert('ap_transactions');
|
||
088b52b5 | Sven Schöling | |||
8c8f6da3 | Thomas Heck | my $num_due;
|
||
my $num_follow_ups;
|
||||
if ($::form->{id}) {
|
||||
a7b92129 | Waldemar Toews | my $follow_ups = FU->follow_ups('trans_id' => $::form->{id}, 'not_done' => 1);
|
||
8c7e4493 | Moritz Bunkus | |||
8c8f6da3 | Thomas Heck | if (@{ $follow_ups }) {
|
||
$num_due = sum map { $_->{due} * 1 } @{ $follow_ups };
|
||||
$num_follow_ups = scalar @{ $follow_ups }
|
||||
7a7f33b5 | Moritz Bunkus | }
|
||
}
|
||||
8c8f6da3 | Thomas Heck | my $transdate = $::form->datetonum($::form->{transdate}, \%::myconfig);
|
||
my $closedto = $::form->datetonum($::form->{closedto}, \%::myconfig);
|
||||
d319704a | Moritz Bunkus | |||
8c8f6da3 | Thomas Heck | my $storno = $::form->{id}
|
||
&& !IS->has_storno(\%::myconfig, $::form, 'ap')
|
||||
&& !IS->is_storno( \%::myconfig, $::form, 'ap', $::form->{id})
|
||||
&& ($::form->{totalpaid} == 0 || $::form->{totalpaid} eq '');
|
||||
d319704a | Moritz Bunkus | |||
8c8f6da3 | Thomas Heck | $::form->header;
|
||
print $::form->parse_html_template('ap/form_footer', {
|
||||
50c2f228 | Bernd Bleßmann | num_due => $num_due,
|
||
num_follow_ups => $num_follow_ups,
|
||||
show_post_draft => ($transdate > $closedto) && !$::form->{id},
|
||||
show_storno => $storno,
|
||||
8c8f6da3 | Thomas Heck | });
|
||
1118dab9 | Moritz Bunkus | |||
8c8f6da3 | Thomas Heck | $::lxdebug->leave_sub;
|
||
d319704a | Moritz Bunkus | }
|
||
ce47a234 | Thomas Kasulke | sub mark_as_paid {
|
||
088b52b5 | Sven Schöling | $main::lxdebug->enter_sub();
|
||
my $form = $main::form;
|
||||
my %myconfig = %main::myconfig;
|
||||
8c7e4493 | Moritz Bunkus | |||
25d67207 | Martin Helmling | $main::auth->assert('ap_transactions');
|
||
8c7e4493 | Moritz Bunkus | |||
7011fd23 | Sven Schöling | &mark_as_paid_common(\%myconfig,"ap");
|
||
8c7e4493 | Moritz Bunkus | |||
088b52b5 | Sven Schöling | $main::lxdebug->leave_sub();
|
||
ce47a234 | Thomas Kasulke | }
|
||
46aa98a9 | Martin Helmling | sub show_draft {
|
||
$::form->{transdate} = DateTime->today_local->to_kivitendo if !$::form->{transdate};
|
||||
$::form->{gldate} = $::form->{transdate} if !$::form->{gldate};
|
||||
update();
|
||||
}
|
||||
d319704a | Moritz Bunkus | sub update {
|
||
088b52b5 | Sven Schöling | $main::lxdebug->enter_sub();
|
||
d319704a | Moritz Bunkus | |||
088b52b5 | Sven Schöling | my $form = $main::form;
|
||
my %myconfig = %main::myconfig;
|
||||
25d67207 | Martin Helmling | $main::auth->assert('ap_transactions');
|
||
8c7e4493 | Moritz Bunkus | |||
d319704a | Moritz Bunkus | my $display = shift;
|
||
$form->{invtotal} = 0;
|
||||
8f8ad003 | Moritz Bunkus | delete @{ $form }{ grep { m/^tax_\d+$/ } keys %{ $form } };
|
||
d319704a | Moritz Bunkus | map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
|
||
qw(exchangerate creditlimit creditremaining);
|
||||
088b52b5 | Sven Schöling | my @flds = qw(amount AP_amount projectnumber oldprojectnumber project_id taxchart);
|
||
my $count = 0;
|
||||
my (@a, $j, $totaltax);
|
||||
for my $i (1 .. $form->{rowcount}) {
|
||||
0e68056c | Geoffrey Richardson | $form->{"amount_$i"} = $form->parse_amount(\%myconfig, $form->{"amount_$i"});
|
||
d319704a | Moritz Bunkus | if ($form->{"amount_$i"}) {
|
||
push @a, {};
|
||||
30175d89 | Philip Reetz | $j = $#a;
|
||
088b52b5 | Sven Schöling | my ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
|
||
0e68056c | Geoffrey Richardson | |||
# calculate tax exactly the same way as AP in post_transaction via form->calculate_tax
|
||||
my $tmpnetamount;
|
||||
($tmpnetamount,$form->{"tax_$i"}) = $form->calculate_tax($form->{"amount_$i"},$rate,$form->{taxincluded},2);
|
||||
30175d89 | Philip Reetz | |||
$totaltax += $form->{"tax_$i"};
|
||||
d319704a | Moritz Bunkus | map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
|
||
$count++;
|
||||
}
|
||||
}
|
||||
$form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
|
||||
30175d89 | Philip Reetz | map { $form->{invtotal} += $form->{"amount_$_"} } (1 .. $form->{rowcount});
|
||
d319704a | Moritz Bunkus | |||
a53233e5 | Sven Schöling | $form->{forex} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{transdate}, 'sell');
|
||
$form->{exchangerate} = $form->{forex} if $form->{forex};
|
||||
d319704a | Moritz Bunkus | |||
$form->{invdate} = $form->{transdate};
|
||||
f612f63e | Moritz Bunkus | my %saved_variables = map +( $_ => $form->{$_} ), qw(AP AP_amount_1 taxchart_1 notes);
|
||
84783219 | Moritz Bunkus | |||
029d9955 | Sven Schöling | my $vendor_changed = &check_name("vendor");
|
||
84783219 | Moritz Bunkus | |||
$form->{AP} = $saved_variables{AP};
|
||||
if ($saved_variables{AP_amount_1} =~ m/.--./) {
|
||||
map { $form->{$_} = $saved_variables{$_} } qw(AP_amount_1 taxchart_1);
|
||||
} else {
|
||||
delete $form->{taxchart_1};
|
||||
}
|
||||
d319704a | Moritz Bunkus | |||
30175d89 | Philip Reetz | $form->{rowcount} = $count + 1;
|
||
d319704a | Moritz Bunkus | |||
$form->{invtotal} =
|
||||
($form->{taxincluded}) ? $form->{invtotal} : $form->{invtotal} + $totaltax;
|
||||
088b52b5 | Sven Schöling | my $totalpaid;
|
||
for my $i (1 .. $form->{paidaccounts}) {
|
||||
04a2f2e7 | Moritz Bunkus | if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
|
||
d319704a | Moritz Bunkus | map {
|
||
$form->{"${_}_$i"} =
|
||||
$form->parse_amount(\%myconfig, $form->{"${_}_$i"})
|
||||
} qw(paid exchangerate);
|
||||
$totalpaid += $form->{"paid_$i"};
|
||||
a53233e5 | Sven Schöling | $form->{"forex_$i"} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'sell');
|
||
$form->{"exchangerate_$i"} = $form->{"forex_$i"} if $form->{"forex_$i"};
|
||||
d319704a | Moritz Bunkus | }
|
||
}
|
||||
$form->{creditremaining} -=
|
||||
($form->{invtotal} - $totalpaid + $form->{oldtotalpaid} -
|
||||
$form->{oldinvtotal});
|
||||
$form->{oldinvtotal} = $form->{invtotal};
|
||||
$form->{oldtotalpaid} = $totalpaid;
|
||||
&display_form;
|
||||
088b52b5 | Sven Schöling | $main::lxdebug->leave_sub();
|
||
d319704a | Moritz Bunkus | }
|
||
bdaa8c2f | Philip Reetz | |||
sub post_payment {
|
||||
088b52b5 | Sven Schöling | $main::lxdebug->enter_sub();
|
||
my $form = $main::form;
|
||||
my %myconfig = %main::myconfig;
|
||||
my $locale = $main::locale;
|
||||
a326f385 | Moritz Bunkus | |||
25d67207 | Martin Helmling | $main::auth->assert('ap_transactions');
|
||
d735aab3 | Martin Helmling | $form->mtime_ischanged('ap');
|
||
8c7e4493 | Moritz Bunkus | |||
a326f385 | Moritz Bunkus | $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
|
||
662ded38 | Sven Schöling | my $invdate = $form->datetonum($form->{transdate}, \%myconfig);
|
||
088b52b5 | Sven Schöling | for my $i (1 .. $form->{paidaccounts}) {
|
||
eb8bed3f | Moritz Bunkus | if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
|
||
088b52b5 | Sven Schöling | my $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
|
||
bdaa8c2f | Philip Reetz | |||
$form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
|
||||
60fd9199 | Frank Messerschmidt | $form->error($locale->text('Cannot post transaction above the maximum future booking date!'))
|
||
if ($form->date_max_future($form->{"datepaid_$i"}, \%myconfig));
|
||||
#Zusätzlich noch das Buchungsdatum in die Bücherkontrolle einbeziehen
|
||||
# (Dient zur Prüfung ob ZE oder ZA geprüft werden soll)
|
||||
bdaa8c2f | Philip Reetz | $form->error($locale->text('Cannot post payment for a closed period!'))
|
||
60fd9199 | Frank Messerschmidt | if ($form->date_closed($form->{"datepaid_$i"}) && !$form->date_closed($form->{"gldate_$i"}, \%myconfig));
|
||
bdaa8c2f | Philip Reetz | |||
bea3f989 | Moritz Bunkus | if ($form->{defaultcurrency} && ($form->{currency} ne $form->{defaultcurrency})) {
|
||
bdaa8c2f | Philip Reetz | $form->{"exchangerate_$i"} = $form->{exchangerate}
|
||
662ded38 | Sven Schöling | if ($invdate == $datepaid);
|
||
bdaa8c2f | Philip Reetz | $form->isblank("exchangerate_$i",
|
||
$locale->text('Exchangerate for payment missing!'));
|
||||
}
|
||||
}
|
||||
}
|
||||
($form->{AP}) = split /--/, $form->{AP};
|
||||
($form->{AP_paid}) = split /--/, $form->{AP_paid};
|
||||
7a98647b | Geoffrey Richardson | if (AP->post_payment(\%myconfig, \%$form)) {
|
||
$form->{snumbers} = qq|invnumber_| . $form->{invnumber};
|
||||
$form->{what_done} = 'invoice';
|
||||
$form->{addition} = "PAYMENT POSTED";
|
||||
$form->save_history;
|
||||
$form->redirect($locale->text('Payment posted!'))
|
||||
} else {
|
||||
bdaa8c2f | Philip Reetz | $form->error($locale->text('Cannot post payment!'));
|
||
7a98647b | Geoffrey Richardson | };
|
||
bdaa8c2f | Philip Reetz | |||
088b52b5 | Sven Schöling | $main::lxdebug->leave_sub();
|
||
bdaa8c2f | Philip Reetz | }
|
||
d319704a | Moritz Bunkus | sub post {
|
||
088b52b5 | Sven Schöling | $main::lxdebug->enter_sub();
|
||
d319704a | Moritz Bunkus | |||
088b52b5 | Sven Schöling | my $form = $main::form;
|
||
my %myconfig = %main::myconfig;
|
||||
my $locale = $main::locale;
|
||||
25d67207 | Martin Helmling | $main::auth->assert('ap_transactions');
|
||
d735aab3 | Martin Helmling | $form->mtime_ischanged('ap');
|
||
8c7e4493 | Moritz Bunkus | |||
55a380fc | Bernd Bleßmann | my ($inline) = @_;
|
||
4e9b1b02 | Geoffrey Richardson | # check if there is a vendor, invoice, due date and invnumber
|
||
d319704a | Moritz Bunkus | $form->isblank("transdate", $locale->text("Invoice Date missing!"));
|
||
$form->isblank("duedate", $locale->text("Due Date missing!"));
|
||||
$form->isblank("vendor", $locale->text('Vendor missing!'));
|
||||
4e9b1b02 | Geoffrey Richardson | $form->isblank("invnumber", $locale->text('Invoice Number missing!'));
|
||
d319704a | Moritz Bunkus | |||
05174f19 | Sven Schöling | if ($myconfig{mandatory_departments} && !$form->{department}) {
|
||
$form->{saved_message} = $::locale->text('You have to specify a department.');
|
||||
update();
|
||||
exit;
|
||||
}
|
||||
088b52b5 | Sven Schöling | my $closedto = $form->datetonum($form->{closedto}, \%myconfig);
|
||
my $transdate = $form->datetonum($form->{transdate}, \%myconfig);
|
||||
a11d7a85 | Jan Büren | |||
$form->error($locale->text('Cannot post transaction above the maximum future booking date!'))
|
||||
if ($form->date_max_future($form->{"transdate"}, \%myconfig));
|
||||
9e06d0e4 | Philip Reetz | $form->error($locale->text('Cannot post transaction for a closed period!')) if ($form->date_closed($form->{"transdate"}, \%myconfig));
|
||
eb8bed3f | Moritz Bunkus | |||
my $zero_amount_posting = 1;
|
||||
088b52b5 | Sven Schöling | for my $i (1 .. $form->{rowcount}) {
|
||
eb8bed3f | Moritz Bunkus | if ($form->parse_amount(\%myconfig, $form->{"amount_$i"})) {
|
||
$zero_amount_posting = 0;
|
||||
last;
|
||||
}
|
||||
}
|
||||
d319704a | Moritz Bunkus | |||
eb8bed3f | Moritz Bunkus | $form->error($locale->text('Zero amount posting!')) if $zero_amount_posting;
|
||
d319704a | Moritz Bunkus | |||
$form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
|
||||
bea3f989 | Moritz Bunkus | if ($form->{defaultcurrency} && ($form->{currency} ne $form->{defaultcurrency}));
|
||
d319704a | Moritz Bunkus | delete($form->{AP});
|
||
088b52b5 | Sven Schöling | for my $i (1 .. $form->{paidaccounts}) {
|
||
04a2f2e7 | Moritz Bunkus | if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
|
||
088b52b5 | Sven Schöling | my $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
|
||
d319704a | Moritz Bunkus | |||
$form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
|
||||
60fd9199 | Frank Messerschmidt | $form->error($locale->text('Cannot post transaction above the maximum future booking date!'))
|
||
if ($form->date_max_future($form->{"datepaid_$i"}, \%myconfig));
|
||||
#Zusätzlich noch das Buchungsdatum in die Bücherkontrolle einbeziehen
|
||||
# (Dient zur Prüfung ob ZE oder ZA geprüft werden soll)
|
||||
d319704a | Moritz Bunkus | $form->error($locale->text('Cannot post payment for a closed period!'))
|
||
60fd9199 | Frank Messerschmidt | if ($form->date_closed($form->{"datepaid_$i"}) && !$form->date_closed($form->{"gldate_$i"}, \%myconfig));
|
||
d319704a | Moritz Bunkus | |||
bea3f989 | Moritz Bunkus | if ($form->{defaultcurrency} && ($form->{currency} ne $form->{defaultcurrency})) {
|
||
d319704a | Moritz Bunkus | $form->{"exchangerate_$i"} = $form->{exchangerate}
|
||
if ($transdate == $datepaid);
|
||||
$form->isblank("exchangerate_$i",
|
||||
$locale->text('Exchangerate for payment missing!'));
|
||||
}
|
||||
}
|
||||
}
|
||||
# if old vendor ne vendor redo form
|
||||
088b52b5 | Sven Schöling | my ($vendor) = split /--/, $form->{vendor};
|
||
d319704a | Moritz Bunkus | if ($form->{oldvendor} ne "$vendor--$form->{vendor_id}") {
|
||
&update;
|
||||
09479f02 | Moritz Bunkus | $::dispatcher->end_request;
|
||
d319704a | Moritz Bunkus | }
|
||
088b52b5 | Sven Schöling | my ($debitaccno, $debittaxkey) = split /--/, $form->{AP_amountselected};
|
||
my ($taxkey, $NULL) = split /--/, $form->{taxchartselected};
|
||||
my ($payablesaccno, $payablestaxkey) = split /--/, $form->{APselected};
|
||||
e9e28dd2 | Sven Schöling | # $form->{AP_amount_1} = $debitaccno;
|
||
$form->{AP_payables} = $payablesaccno;
|
||||
d319704a | Moritz Bunkus | $form->{taxkey} = $taxkey;
|
||
91ea86b4 | Moritz Bunkus | $form->{storno} = 0;
|
||
d319704a | Moritz Bunkus | |||
$form->{id} = 0 if $form->{postasnew};
|
||||
bde667c2 | Moritz Bunkus | if (AP->post_transaction(\%myconfig, \%$form)) {
|
||
# saving the history
|
||||
if(!exists $form->{addition} && $form->{id} ne "") {
|
||||
281696eb | Geoffrey Richardson | $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
|
||
$form->{addition} = "POSTED";
|
||||
$form->{what_done} = "invoice";
|
||||
a590a651 | Sven Schöling | $form->save_history;
|
||
bde667c2 | Moritz Bunkus | }
|
||
7011fd23 | Sven Schöling | # /saving the history
|
||
92483c53 | Jan Büren | # Dieser Text wird niemals ausgegeben: Probleme beim redirect?
|
||
55a380fc | Bernd Bleßmann | $form->redirect($locale->text('Transaction posted!')) unless $inline;
|
||
92483c53 | Jan Büren | } else {
|
||
$form->error($locale->text('Cannot post transaction!'));
|
||||
bde667c2 | Moritz Bunkus | }
|
||
d319704a | Moritz Bunkus | |||
088b52b5 | Sven Schöling | $main::lxdebug->leave_sub();
|
||
d319704a | Moritz Bunkus | }
|
||
sub post_as_new {
|
||||
088b52b5 | Sven Schöling | $main::lxdebug->enter_sub();
|
||
my $form = $main::form;
|
||||
my %myconfig = %main::myconfig;
|
||||
d319704a | Moritz Bunkus | |||
25d67207 | Martin Helmling | $main::auth->assert('ap_transactions');
|
||
8c7e4493 | Moritz Bunkus | |||
d319704a | Moritz Bunkus | $form->{postasnew} = 1;
|
||
dacb62eb | Thomas Kasulke | # saving the history
|
||
if(!exists $form->{addition} && $form->{id} ne "") {
|
||||
281696eb | Geoffrey Richardson | # does this work? post_as_new for ap doesn't immediately save the
|
||
# invoice, because the invnumber has to be entered by hand.
|
||||
# And the value of $form->{postasnew} isn't checked when calling post
|
||||
$form->{snumbers} = qq|invnumber_| . $form->{invnumber};
|
||||
$form->{addition} = "POSTED AS NEW";
|
||||
$form->{what_done} = "invoice";
|
||||
a590a651 | Sven Schöling | $form->save_history;
|
||
dacb62eb | Thomas Kasulke | }
|
||
7011fd23 | Sven Schöling | # /saving the history
|
||
d319704a | Moritz Bunkus | &post;
|
||
088b52b5 | Sven Schöling | $main::lxdebug->leave_sub();
|
||
d319704a | Moritz Bunkus | }
|
||
3cd3e832 | Moritz Bunkus | sub use_as_new {
|
||
088b52b5 | Sven Schöling | $main::lxdebug->enter_sub();
|
||
my $form = $main::form;
|
||||
my %myconfig = %main::myconfig;
|
||||
98764afa | Philip Reetz | |||
25d67207 | Martin Helmling | $main::auth->assert('ap_transactions');
|
||
8c7e4493 | Moritz Bunkus | |||
890e057f | Bernd Bleßmann | map { delete $form->{$_} } qw(printed emailed queued invnumber invdate deliverydate id datepaid_1 gldate_1 acc_trans_id_1 source_1 memo_1 paid_1 exchangerate_1 AP_paid_1 storno);
|
||
98764afa | Philip Reetz | $form->{paidaccounts} = 1;
|
||
$form->{rowcount}--;
|
||||
$form->{invdate} = $form->current_date(\%myconfig);
|
||||
&update;
|
||||
088b52b5 | Sven Schöling | $main::lxdebug->leave_sub();
|
||
98764afa | Philip Reetz | }
|
||
d319704a | Moritz Bunkus | sub delete {
|
||
088b52b5 | Sven Schöling | $main::lxdebug->enter_sub();
|
||
d319704a | Moritz Bunkus | |||
088b52b5 | Sven Schöling | my $form = $main::form;
|
||
my $locale = $main::locale;
|
||||
25d67207 | Martin Helmling | $main::auth->assert('ap_transactions');
|
||
8c7e4493 | Moritz Bunkus | |||
d319704a | Moritz Bunkus | $form->{title} = $locale->text('Confirm!');
|
||
$form->header;
|
||||
delete $form->{header};
|
||||
print qq|
|
||||
<form method=post action=$form->{script}>
|
||||
|;
|
||||
088b52b5 | Sven Schöling | foreach my $key (keys %$form) {
|
||
8c7e4493 | Moritz Bunkus | next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
|
||
d319704a | Moritz Bunkus | $form->{$key} =~ s/\"/"/g;
|
||
print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
|
||||
}
|
||||
print qq|
|
||||
<h2 class=confirm>$form->{title}</h2>
|
||||
<h4>|
|
||||
. $locale->text('Are you sure you want to delete Transaction')
|
||||
. qq| $form->{invnumber}</h4>
|
||||
<input name=action class=submit type=submit value="|
|
||||
. $locale->text('Yes') . qq|">
|
||||
</form>
|
||||
|;
|
||||
088b52b5 | Sven Schöling | $main::lxdebug->leave_sub();
|
||
d319704a | Moritz Bunkus | }
|
||
sub yes {
|
||||
088b52b5 | Sven Schöling | $main::lxdebug->enter_sub();
|
||
my $form = $main::form;
|
||||
my %myconfig = %main::myconfig;
|
||||
my $locale = $main::locale;
|
||||
8c7e4493 | Moritz Bunkus | |||
25d67207 | Martin Helmling | $main::auth->assert('ap_transactions');
|
||
8c7e4493 | Moritz Bunkus | |||
8cd05ad6 | Moritz Bunkus | if (AP->delete_transaction(\%myconfig, \%$form)) {
|
||
dacb62eb | Thomas Kasulke | # saving the history
|
||
if(!exists $form->{addition}) {
|
||||
281696eb | Geoffrey Richardson | $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
|
||
$form->{addition} = "DELETED";
|
||||
$form->{what_done} = "invoice";
|
||||
a590a651 | Sven Schöling | $form->save_history;
|
||
dacb62eb | Thomas Kasulke | }
|
||
7011fd23 | Sven Schöling | # /saving the history
|
||
dacb62eb | Thomas Kasulke | $form->redirect($locale->text('Transaction deleted!'));
|
||
}
|
||||
d319704a | Moritz Bunkus | $form->error($locale->text('Cannot delete transaction!'));
|
||
088b52b5 | Sven Schöling | $main::lxdebug->leave_sub();
|
||
d319704a | Moritz Bunkus | }
|
||
sub search {
|
||||
088b52b5 | Sven Schöling | $main::lxdebug->enter_sub();
|
||
d319704a | Moritz Bunkus | |||
916aae37 | Niclas Zimmermann | $main::auth->assert('vendor_invoice_edit');
|
||
ddaf7f50 | Sven Schöling | |||
088b52b5 | Sven Schöling | my $form = $main::form;
|
||
my %myconfig = %main::myconfig;
|
||||
my $locale = $main::locale;
|
||||
8c7e4493 | Moritz Bunkus | |||
ddaf7f50 | Sven Schöling | # setup customer selection
|
||
d319704a | Moritz Bunkus | $form->all_vc(\%myconfig, "vendor", "AP");
|
||
ddaf7f50 | Sven Schöling | $form->{title} = $locale->text('AP Transactions');
|
||
d319704a | Moritz Bunkus | |||
ddaf7f50 | Sven Schöling | $form->get_lists("projects" => { "key" => "ALL_PROJECTS", "all" => 1 },
|
||
"departments" => "ALL_DEPARTMENTS",
|
||||
"vendors" => "ALL_VC");
|
||||
d319704a | Moritz Bunkus | |||
ddaf7f50 | Sven Schöling | # constants and subs for template
|
||
$form->{vc_keys} = sub { "$_[0]->{name}--$_[0]->{id}" };
|
||||
a4b22a8f | Moritz Bunkus | |||
d319704a | Moritz Bunkus | $form->header;
|
||
ddaf7f50 | Sven Schöling | print $form->parse_html_template('ap/search', { %myconfig });
|
||
d319704a | Moritz Bunkus | |||
088b52b5 | Sven Schöling | $main::lxdebug->leave_sub();
|
||
d319704a | Moritz Bunkus | }
|
||
e71494c1 | Moritz Bunkus | sub create_subtotal_row {
|
||
088b52b5 | Sven Schöling | $main::lxdebug->enter_sub();
|
||
e71494c1 | Moritz Bunkus | |||
my ($totals, $columns, $column_alignment, $subtotal_columns, $class) = @_;
|
||||
088b52b5 | Sven Schöling | my $form = $main::form;
|
||
my %myconfig = %main::myconfig;
|
||||
e71494c1 | Moritz Bunkus | my $row = { map { $_ => { 'data' => '', 'class' => $class, 'align' => $column_alignment->{$_}, } } @{ $columns } };
|
||
map { $row->{$_}->{data} = $form->format_amount(\%myconfig, $totals->{$_}, 2) } @{ $subtotal_columns };
|
||||
$row->{tax}->{data} = $form->format_amount(\%myconfig, $totals->{amount} - $totals->{netamount}, 2);
|
||||
map { $totals->{$_} = 0 } @{ $subtotal_columns };
|
||||
088b52b5 | Sven Schöling | $main::lxdebug->leave_sub();
|
||
e71494c1 | Moritz Bunkus | |||
return $row;
|
||||
}
|
||||
d319704a | Moritz Bunkus | sub ap_transactions {
|
||
088b52b5 | Sven Schöling | $main::lxdebug->enter_sub();
|
||
d319704a | Moritz Bunkus | |||
088b52b5 | Sven Schöling | my $form = $main::form;
|
||
my %myconfig = %main::myconfig;
|
||||
my $locale = $main::locale;
|
||||
916aae37 | Niclas Zimmermann | $main::auth->assert('vendor_invoice_edit');
|
||
8c7e4493 | Moritz Bunkus | |||
d319704a | Moritz Bunkus | ($form->{vendor}, $form->{vendor_id}) = split(/--/, $form->{vendor});
|
||
262108d0 | Moritz Bunkus | report_generator_set_default_sort('transdate', 1);
|
||
e71494c1 | Moritz Bunkus | |||
d319704a | Moritz Bunkus | AP->ap_transactions(\%myconfig, \%$form);
|
||
e71494c1 | Moritz Bunkus | $form->{title} = $locale->text('AP Transactions');
|
||
d319704a | Moritz Bunkus | |||
e71494c1 | Moritz Bunkus | my $report = SL::ReportGenerator->new(\%myconfig, $form);
|
||
my @columns =
|
||||
qw(transdate id type invnumber ordnumber name netamount tax amount paid datepaid
|
||||
875f08f3 | Sven Schöling | due duedate transaction_description notes employee globalprojectnumber
|
||
c98c318c | Moritz Bunkus | vendornumber country ustid taxzone payment_terms charts direct_debit);
|
||
e71494c1 | Moritz Bunkus | |||
my @hidden_variables = map { "l_${_}" } @columns;
|
||||
612e3ebe | Moritz Bunkus | push @hidden_variables, "l_subtotal", qw(open closed vendor invnumber ordnumber transaction_description notes project_id transdatefrom transdateto department
|
||
parts_partnumber parts_description);
|
||||
e71494c1 | Moritz Bunkus | |||
my $href = build_std_url('action=ap_transactions', grep { $form->{$_} } @hidden_variables);
|
||||
my %column_defs = (
|
||||
'transdate' => { 'text' => $locale->text('Date'), },
|
||||
'id' => { 'text' => $locale->text('ID'), },
|
||||
'type' => { 'text' => $locale->text('Type'), },
|
||||
'invnumber' => { 'text' => $locale->text('Invoice'), },
|
||||
'ordnumber' => { 'text' => $locale->text('Order'), },
|
||||
'name' => { 'text' => $locale->text('Vendor'), },
|
||||
'netamount' => { 'text' => $locale->text('Amount'), },
|
||||
'tax' => { 'text' => $locale->text('Tax'), },
|
||||
'amount' => { 'text' => $locale->text('Total'), },
|
||||
'paid' => { 'text' => $locale->text('Paid'), },
|
||||
'datepaid' => { 'text' => $locale->text('Date Paid'), },
|
||||
'due' => { 'text' => $locale->text('Amount Due'), },
|
||||
'duedate' => { 'text' => $locale->text('Due Date'), },
|
||||
'transaction_description' => { 'text' => $locale->text('Transaction description'), },
|
||||
'notes' => { 'text' => $locale->text('Notes'), },
|
||||
e31afd79 | Geoffrey Richardson | 'employee' => { 'text' => $locale->text('Employee'), },
|
||
d8e0c6d8 | Bernd Bleßmann | 'globalprojectnumber' => { 'text' => $locale->text('Document Project Number'), },
|
||
875f08f3 | Sven Schöling | 'vendornumber' => { 'text' => $locale->text('Vendor Number'), },
|
||
'country' => { 'text' => $locale->text('Country'), },
|
||||
'ustid' => { 'text' => $locale->text('USt-IdNr.'), },
|
||||
88f11e29 | Geoffrey Richardson | 'taxzone' => { 'text' => $locale->text('Tax rate'), },
|
||
875f08f3 | Sven Schöling | 'payment_terms' => { 'text' => $locale->text('Payment Terms'), },
|
||
d8f857c7 | Sven Schöling | 'charts' => { 'text' => $locale->text('Buchungskonto'), },
|
||
c98c318c | Moritz Bunkus | 'direct_debit' => { 'text' => $locale->text('direct debit'), },
|
||
e71494c1 | Moritz Bunkus | );
|
||
c98c318c | Moritz Bunkus | foreach my $name (qw(id transdate duedate invnumber ordnumber name datepaid employee shippingpoint shipvia transaction_description direct_debit)) {
|
||
262108d0 | Moritz Bunkus | my $sortdir = $form->{sort} eq $name ? 1 - $form->{sortdir} : $form->{sortdir};
|
||
$column_defs{$name}->{link} = $href . "&sort=$name&sortdir=$sortdir";
|
||||
e71494c1 | Moritz Bunkus | }
|
||
my %column_alignment = map { $_ => 'right' } qw(netamount tax amount paid due);
|
||||
$form->{"l_type"} = "Y";
|
||||
map { $column_defs{$_}->{visible} = $form->{"l_${_}"} ? 1 : 0 } @columns;
|
||||
$report->set_columns(%column_defs);
|
||||
$report->set_column_order(@columns);
|
||||
19688fca | Moritz Bunkus | $report->set_export_options('ap_transactions', @hidden_variables, qw(sort sortdir));
|
||
e71494c1 | Moritz Bunkus | |||
262108d0 | Moritz Bunkus | $report->set_sort_indicator($form->{sort}, $form->{sortdir});
|
||
f5e4c22b | Moritz Bunkus | |||
e71494c1 | Moritz Bunkus | my @options;
|
||
58265754 | Moritz Bunkus | push @options, $locale->text('Vendor') . " : $form->{vendor}" if ($form->{vendor});
|
||
b98b8e3f | Sven Schöling | push @options, $locale->text('Contact Person') . " : $form->{cp_name}" if ($form->{cp_name});
|
||
58265754 | Moritz Bunkus | push @options, $locale->text('Department') . " : " . (split /--/, $form->{department})[0] if ($form->{department});
|
||
push @options, $locale->text('Invoice Number') . " : $form->{invnumber}" if ($form->{invnumber});
|
||||
push @options, $locale->text('Order Number') . " : $form->{ordnumber}" if ($form->{ordnumber});
|
||||
push @options, $locale->text('Notes') . " : $form->{notes}" if ($form->{notes});
|
||||
push @options, $locale->text('Transaction description') . " : $form->{transaction_description}" if ($form->{transaction_description});
|
||||
612e3ebe | Moritz Bunkus | push @options, $locale->text('Part Description') . " : $form->{parts_description}" if $form->{parts_description};
|
||
push @options, $locale->text('Part Number') . " : $form->{parts_partnumber}" if $form->{parts_partnumber};
|
||||
58265754 | Moritz Bunkus | push @options, $locale->text('From') . " " . $locale->date(\%myconfig, $form->{transdatefrom}, 1) if ($form->{transdatefrom});
|
||
push @options, $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{transdateto}, 1) if ($form->{transdateto});
|
||||
push @options, $locale->text('Open') if ($form->{open});
|
||||
push @options, $locale->text('Closed') if ($form->{closed});
|
||||
d319704a | Moritz Bunkus | |||
e71494c1 | Moritz Bunkus | $report->set_options('top_info_text' => join("\n", @options),
|
||
9aaca433 | Moritz Bunkus | 'raw_bottom_info_text' => $form->parse_html_template('ap/ap_transactions_bottom'),
|
||
e71494c1 | Moritz Bunkus | 'output_format' => 'HTML',
|
||
'title' => $form->{title},
|
||||
19688fca | Moritz Bunkus | 'attachment_basename' => $locale->text('vendor_invoice_list') . strftime('_%Y%m%d', localtime time),
|
||
e71494c1 | Moritz Bunkus | );
|
||
$report->set_options_from_form();
|
||||
a873249c | Moritz Bunkus | $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv';
|
||
d319704a | Moritz Bunkus | |||
e71494c1 | Moritz Bunkus | # add sort and escape callback, this one we use for the add sub
|
||
$form->{callback} = $href .= "&sort=$form->{sort}";
|
||||
84bed7a6 | Moritz Bunkus | |||
e71494c1 | Moritz Bunkus | # escape callback for href
|
||
088b52b5 | Sven Schöling | my $callback = $form->escape($href);
|
||
d319704a | Moritz Bunkus | |||
e71494c1 | Moritz Bunkus | my @subtotal_columns = qw(netamount amount paid due);
|
||
d319704a | Moritz Bunkus | |||
e71494c1 | Moritz Bunkus | my %totals = map { $_ => 0 } @subtotal_columns;
|
||
my %subtotals = map { $_ => 0 } @subtotal_columns;
|
||||
d319704a | Moritz Bunkus | |||
e71494c1 | Moritz Bunkus | my $idx = 0;
|
||
d319704a | Moritz Bunkus | |||
088b52b5 | Sven Schöling | foreach my $ap (@{ $form->{AP} }) {
|
||
e71494c1 | Moritz Bunkus | $ap->{tax} = $ap->{amount} - $ap->{netamount};
|
||
$ap->{due} = $ap->{amount} - $ap->{paid};
|
||||
d319704a | Moritz Bunkus | |||
e71494c1 | Moritz Bunkus | map { $subtotals{$_} += $ap->{$_};
|
||
$totals{$_} += $ap->{$_} } @subtotal_columns;
|
||||
d319704a | Moritz Bunkus | |||
e71494c1 | Moritz Bunkus | map { $ap->{$_} = $form->format_amount(\%myconfig, $ap->{$_}, 2) } qw(netamount tax amount paid due);
|
||
d319704a | Moritz Bunkus | |||
09685616 | Moritz Bunkus | my $is_storno = $ap->{storno} && $ap->{storno_id};
|
||
my $has_storno = $ap->{storno} && !$ap->{storno_id};
|
||||
if ($ap->{invoice}) {
|
||||
$ap->{type} =
|
||||
$has_storno ? $locale->text("Invoice with Storno (abbreviation)")
|
||||
: $is_storno ? $locale->text("Storno (one letter abbreviation)")
|
||||
: $locale->text("Invoice (one letter abbreviation)");
|
||||
} else {
|
||||
$ap->{type} =
|
||||
$has_storno ? $locale->text("AP Transaction with Storno (abbreviation)")
|
||||
: $is_storno ? $locale->text("AP Transaction Storno (one letter abbreviation)")
|
||||
: $locale->text("AP Transaction (abbreviation)");
|
||||
}
|
||||
d319704a | Moritz Bunkus | |||
c98c318c | Moritz Bunkus | $ap->{direct_debit} = $ap->{direct_debit} ? $::locale->text('yes') : $::locale->text('no');
|
||
e71494c1 | Moritz Bunkus | my $row = { };
|
||
d319704a | Moritz Bunkus | |||
e71494c1 | Moritz Bunkus | foreach my $column (@columns) {
|
||
$row->{$column} = {
|
||||
'data' => $ap->{$column},
|
||||
'align' => $column_alignment{$column},
|
||||
};
|
||||
d319704a | Moritz Bunkus | }
|
||
e71494c1 | Moritz Bunkus | $row->{invnumber}->{link} = build_std_url("script=" . ($ap->{invoice} ? 'ir.pl' : 'ap.pl'), 'action=edit')
|
||
. "&id=" . E($ap->{id}) . "&callback=${callback}";
|
||||
d319704a | Moritz Bunkus | |||
e71494c1 | Moritz Bunkus | my $row_set = [ $row ];
|
||
d319704a | Moritz Bunkus | |||
e71494c1 | Moritz Bunkus | if (($form->{l_subtotal} eq 'Y')
|
||
&& (($idx == (scalar @{ $form->{AP} } - 1))
|
||||
|| ($ap->{ $form->{sort} } ne $form->{AP}->[$idx + 1]->{ $form->{sort} }))) {
|
||||
push @{ $row_set }, create_subtotal_row(\%subtotals, \@columns, \%column_alignment, \@subtotal_columns, 'listsubtotal');
|
||||
}
|
||||
d319704a | Moritz Bunkus | |||
e71494c1 | Moritz Bunkus | $report->add_data($row_set);
|
||
d319704a | Moritz Bunkus | |||
e71494c1 | Moritz Bunkus | $idx++;
|
||
d319704a | Moritz Bunkus | }
|
||
e71494c1 | Moritz Bunkus | $report->add_separator();
|
||
$report->add_data(create_subtotal_row(\%totals, \@columns, \%column_alignment, \@subtotal_columns, 'listtotal'));
|
||||
d319704a | Moritz Bunkus | |||
e71494c1 | Moritz Bunkus | $report->generate_with_headers();
|
||
d319704a | Moritz Bunkus | |||
088b52b5 | Sven Schöling | $main::lxdebug->leave_sub();
|
||
d319704a | Moritz Bunkus | }
|
||
6d544157 | Sven Schöling | |||
sub storno {
|
||||
088b52b5 | Sven Schöling | $main::lxdebug->enter_sub();
|
||
my $form = $main::form;
|
||||
my %myconfig = %main::myconfig;
|
||||
my $locale = $main::locale;
|
||||
6d544157 | Sven Schöling | |||
25d67207 | Martin Helmling | $main::auth->assert('ap_transactions');
|
||
8c7e4493 | Moritz Bunkus | |||
6d544157 | Sven Schöling | if (IS->has_storno(\%myconfig, $form, 'ap')) {
|
||
$form->{title} = $locale->text("Cancel Accounts Payables Transaction");
|
||||
$form->error($locale->text("Transaction has already been cancelled!"));
|
||||
}
|
||||
16a12c3c | Niclas Zimmermann | $form->error($locale->text('Cannot post storno for a closed period!'))
|
||
if ( $form->date_closed($form->{transdate}, \%myconfig));
|
||||
2b3f8b3a | Sven Schöling | AP->storno($form, \%myconfig, $form->{id});
|
||
6d544157 | Sven Schöling | |||
# saving the history
|
||||
if(!exists $form->{addition} && $form->{id} ne "") {
|
||||
281696eb | Geoffrey Richardson | $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
|
||
$form->{addition} = "STORNO";
|
||||
$form->{what_done} = "invoice";
|
||||
a590a651 | Sven Schöling | $form->save_history;
|
||
6d544157 | Sven Schöling | }
|
||
7011fd23 | Sven Schöling | # /saving the history
|
||
6d544157 | Sven Schöling | |||
7011fd23 | Sven Schöling | $form->redirect(sprintf $locale->text("Transaction %d cancelled."), $form->{storno_id});
|
||
2b3f8b3a | Sven Schöling | |||
088b52b5 | Sven Schöling | $main::lxdebug->leave_sub();
|
||
6d544157 | Sven Schöling | }
|