kivitendo/bin/mozilla/ar.pl @ 10c58e4e
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
|
||||
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
#======================================================================
|
||||
#
|
||||
# Accounts Receivables
|
||||
#
|
||||
#======================================================================
|
||||
971c9727 | Moritz Bunkus | use POSIX qw(strftime);
|
||
cf5fe23a | Sven Schöling | use List::Util qw(sum first max);
|
||
971c9727 | Moritz Bunkus | |||
d319704a | Moritz Bunkus | use SL::AR;
|
||
7a7f33b5 | Moritz Bunkus | use SL::FU;
|
||
d319704a | Moritz Bunkus | use SL::IS;
|
||
use SL::PE;
|
||||
97954312 | Bernd Bleßmann | use SL::DB::Default;
|
||
971c9727 | Moritz Bunkus | use SL::ReportGenerator;
|
||
d319704a | Moritz Bunkus | |||
d629acd8 | Sven Schöling | require "bin/mozilla/arap.pl";
|
||
a4b22a8f | Moritz Bunkus | require "bin/mozilla/common.pl";
|
||
bde667c2 | Moritz Bunkus | require "bin/mozilla/drafts.pl";
|
||
18da4a96 | Moritz Bunkus | require "bin/mozilla/reportgenerator.pl";
|
||
d319704a | Moritz Bunkus | |||
ebdc6e13 | Sven Schöling | use strict;
|
||
#use warnings;
|
||||
d319704a | Moritz Bunkus | # 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 {
|
||||
ebdc6e13 | Sven Schöling | $main::lxdebug->enter_sub();
|
||
$main::auth->assert('general_ledger');
|
||||
bde667c2 | Moritz Bunkus | |||
ebdc6e13 | Sven Schöling | my $form = $main::form;
|
||
my %myconfig = %main::myconfig;
|
||||
8c7e4493 | Moritz Bunkus | |||
ebdc6e13 | Sven Schöling | return $main::lxdebug->leave_sub() if (load_draft_maybe());
|
||
bde667c2 | Moritz Bunkus | |||
590f737f | Thomas Kasulke | # saving the history
|
||
if(!exists $form->{addition} && ($form->{id} ne "")) {
|
||||
8cef58b2 | Thomas Kasulke | $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
|
||
b65a230d | Sven Schöling | $form->{addition} = "ADDED";
|
||
a590a651 | Sven Schöling | $form->save_history;
|
||
590f737f | Thomas Kasulke | }
|
||
3b3ef5ba | Sven Schöling | # /saving the history
|
||
d319704a | Moritz Bunkus | $form->{title} = "Add";
|
||
595799f4 | Moritz Bunkus | $form->{callback} = "ar.pl?action=add&DONT_LOAD_DRAFT=1" unless $form->{callback};
|
||
d319704a | Moritz Bunkus | |||
2387a1fc | Moritz Bunkus | AR->get_transdate(\%myconfig, $form);
|
||
f1c1921d | Moritz Bunkus | $form->{initial_transdate} = $form->{transdate};
|
||
fa2cbb11 | Moritz Bunkus | create_links(dont_save => 1);
|
||
f1c1921d | Moritz Bunkus | $form->{transdate} = $form->{initial_transdate};
|
||
d319704a | Moritz Bunkus | &display_form;
|
||
ebdc6e13 | Sven Schöling | $main::lxdebug->leave_sub();
|
||
d319704a | Moritz Bunkus | }
|
||
sub edit {
|
||||
ebdc6e13 | Sven Schöling | $main::lxdebug->enter_sub();
|
||
8c7e4493 | Moritz Bunkus | |||
ebdc6e13 | Sven Schöling | $main::auth->assert('general_ledger');
|
||
my $form = $main::form;
|
||||
8c7e4493 | Moritz Bunkus | |||
590f737f | Thomas Kasulke | # show history button
|
||
$form->{javascript} = qq|<script type="text/javascript" src="js/show_history.js"></script>|;
|
||||
#/show hhistory button
|
||||
be4e11d3 | Thomas Kasulke | $form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
|
||
d319704a | Moritz Bunkus | $form->{title} = "Edit";
|
||
fa2cbb11 | Moritz Bunkus | create_links();
|
||
d319704a | Moritz Bunkus | &display_form;
|
||
ebdc6e13 | Sven Schöling | $main::lxdebug->leave_sub();
|
||
d319704a | Moritz Bunkus | }
|
||
sub display_form {
|
||||
ebdc6e13 | Sven Schöling | $main::lxdebug->enter_sub();
|
||
$main::auth->assert('general_ledger');
|
||||
d319704a | Moritz Bunkus | |||
ebdc6e13 | Sven Schöling | my $form = $main::form;
|
||
8c7e4493 | Moritz Bunkus | |||
d319704a | Moritz Bunkus | &form_header;
|
||
&form_footer;
|
||||
ebdc6e13 | Sven Schöling | $main::lxdebug->leave_sub();
|
||
d319704a | Moritz Bunkus | }
|
||
sub create_links {
|
||||
ebdc6e13 | Sven Schöling | $main::lxdebug->enter_sub();
|
||
$main::auth->assert('general_ledger');
|
||||
d319704a | Moritz Bunkus | |||
fa2cbb11 | Moritz Bunkus | my %params = @_;
|
||
ebdc6e13 | Sven Schöling | my $form = $main::form;
|
||
my %myconfig = %main::myconfig;
|
||||
8c7e4493 | Moritz Bunkus | |||
d319704a | Moritz Bunkus | $form->create_links("AR", \%myconfig, "customer");
|
||
fa2cbb11 | Moritz Bunkus | my %saved;
|
||
if (!$params{dont_save}) {
|
||||
%saved = map { ($_ => $form->{$_}) } qw(direct_debit id taxincluded);
|
||||
$saved{duedate} = $form->{duedate} if $form->{duedate};
|
||||
}
|
||||
ee2b1ef3 | Moritz Bunkus | |||
d319704a | Moritz Bunkus | IS->get_customer(\%myconfig, \%$form);
|
||
ee2b1ef3 | Moritz Bunkus | $form->{$_} = $saved{$_} for keys %saved;
|
||
d319704a | Moritz Bunkus | $form->{oldcustomer} = "$form->{customer}--$form->{customer_id}";
|
||
f921dcbb | Stephan Köhler | $form->{rowcount} = 1;
|
||
d319704a | Moritz Bunkus | # currencies
|
||
bea3f989 | Moritz Bunkus | $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
|
||
d319704a | Moritz Bunkus | |||
bea3f989 | Moritz Bunkus | map { $form->{selectcurrency} .= "<option>$_\n" } $form->get_all_currencies(\%myconfig);
|
||
d319704a | Moritz Bunkus | |||
# customers
|
||||
65df2ecc | Sven Schöling | if (@{ $form->{all_customer} || [] }) {
|
||
d319704a | Moritz Bunkus | $form->{customer} = "$form->{customer}--$form->{customer_id}";
|
||
map { $form->{selectcustomer} .= "<option>$_->{name}--$_->{id}\n" }
|
||||
(@{ $form->{all_customer} });
|
||||
}
|
||||
# departments
|
||||
e2b9e173 | Sven Schöling | if (@{ $form->{all_departments} || [] }) {
|
||
d319704a | Moritz Bunkus | $form->{selectdepartment} = "<option>\n";
|
||
$form->{department} = "$form->{department}--$form->{department_id}";
|
||||
map {
|
||||
$form->{selectdepartment} .=
|
||||
"<option>$_->{description}--$_->{id}\n"
|
||||
e2b9e173 | Sven Schöling | } (@{ $form->{all_departments} || [] });
|
||
d319704a | Moritz Bunkus | }
|
||
$form->{employee} = "$form->{employee}--$form->{employee_id}";
|
||||
# sales staff
|
||||
e2b9e173 | Sven Schöling | if (@{ $form->{all_employees} || [] }) {
|
||
d319704a | Moritz Bunkus | $form->{selectemployee} = "";
|
||
map { $form->{selectemployee} .= "<option>$_->{name}--$_->{id}\n" }
|
||||
e2b9e173 | Sven Schöling | (@{ $form->{all_employees} || [] });
|
||
d319704a | Moritz Bunkus | }
|
||
# build the popup menus
|
||||
$form->{taxincluded} = ($form->{id}) ? $form->{taxincluded} : "checked";
|
||||
f36eb9fc | Moritz Bunkus | AR->setup_form($form);
|
||
d319704a | Moritz Bunkus | |||
$form->{locked} =
|
||||
($form->datetonum($form->{transdate}, \%myconfig) <=
|
||||
$form->datetonum($form->{closedto}, \%myconfig));
|
||||
ebdc6e13 | Sven Schöling | $main::lxdebug->leave_sub();
|
||
d319704a | Moritz Bunkus | }
|
||
sub form_header {
|
||||
ebdc6e13 | Sven Schöling | $main::lxdebug->enter_sub();
|
||
d319704a | Moritz Bunkus | |||
ebdc6e13 | Sven Schöling | $main::auth->assert('general_ledger');
|
||
my $form = $main::form;
|
||||
my %myconfig = %main::myconfig;
|
||||
my $locale = $main::locale;
|
||||
5494f687 | Sven Schöling | my $cgi = $::request->{cgi};
|
||
8c7e4493 | Moritz Bunkus | |||
1ae70a98 | Sven Schöling | my ($title, $readonly, $exchangerate, $rows);
|
||
cf5fe23a | Sven Schöling | my ($notes, $department, $customer, $employee, $amount, $project);
|
||
my ($ARselected);
|
||||
1ae70a98 | Sven Schöling | |||
d319704a | Moritz Bunkus | $title = $form->{title};
|
||
# $locale->text('Add Accounts Receivables Transaction')
|
||||
# $locale->text('Edit Accounts Receivables Transaction')
|
||||
cf5fe23a | Sven Schöling | $form->{title} = $locale->text("$title Accounts Receivables Transaction");
|
||
de651621 | Stephan Köhler | $form->{javascript} = qq|<script type="text/javascript">
|
||
<!--
|
||||
function setTaxkey(accno, row) {
|
||||
var taxkey = accno.options[accno.selectedIndex].value;
|
||||
1182c721 | Philip Reetz | var reg = /--([0-9]*)/;
|
||
de651621 | Stephan Köhler | var found = reg.exec(taxkey);
|
||
var index = found[1];
|
||||
index = parseInt(index);
|
||||
var tax = 'taxchart_' + row;
|
||||
for (var i = 0; i < document.getElementById(tax).options.length; ++i) {
|
||||
var reg2 = new RegExp("^"+ index, "");
|
||||
if (reg2.exec(document.getElementById(tax).options[i].value)) {
|
||||
document.getElementById(tax).options[i].selected = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
//-->
|
||||
</script>|;
|
||||
590f737f | Thomas Kasulke | # show history button js
|
||
$form->{javascript} .= qq|<script type="text/javascript" src="js/show_history.js"></script>|;
|
||||
#/show history button js
|
||||
d319704a | Moritz Bunkus | $readonly = ($form->{id}) ? "readonly" : "";
|
||
4ac2976f | Bernd Bleßmann | $form->{radier} = ($::instance_conf->get_ar_changeable == 2)
|
||
? ($form->current_date(\%myconfig) eq $form->{gldate})
|
||||
: ($::instance_conf->get_ar_changeable == 1);
|
||||
d319704a | Moritz Bunkus | $readonly = ($form->{radier}) ? "" : $readonly;
|
||
# set option selected
|
||||
1ae70a98 | Sven Schöling | foreach my $item (qw(customer currency department employee)) {
|
||
d319704a | Moritz Bunkus | $form->{"select$item"} =~ s/ selected//;
|
||
cf5fe23a | Sven Schöling | $form->{"select$item"} =~ s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
|
||
d319704a | Moritz Bunkus | }
|
||
a53233e5 | Sven Schöling | $form->{forex} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{transdate}, 'buy');
|
||
$form->{exchangerate} = $form->{forex} if $form->{forex};
|
||||
fb37acdc | Moritz Bunkus | |||
cf5fe23a | Sven Schöling | $rows = max 2, $form->numtextrows($form->{notes}, 50);
|
||
d319704a | Moritz Bunkus | |||
cf5fe23a | Sven Schöling | my @old_project_ids = grep { $_ } map { $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" => "AR" },);
|
||||
f01741e3 | Moritz Bunkus | |||
cf5fe23a | Sven Schöling | $_->{link_split} = { map { $_ => 1 } split/:/, $_->{link} } for @{ $form->{ALL_CHARTS} };
|
||
3253777d | Moritz Bunkus | |||
cf5fe23a | Sven Schöling | my %project_labels = map { $_->{id} => $_->{projectnumber} } @{ $form->{"ALL_PROJECTS"} };
|
||
f01741e3 | Moritz Bunkus | |||
cf5fe23a | Sven Schöling | my (@AR_amount_values);
|
||
my (@AR_values);
|
||||
my (@AR_paid_values);
|
||||
my %chart_labels;
|
||||
6aefd19d | Moritz Bunkus | my %charts;
|
||
3253777d | Moritz Bunkus | my $taxchart_init;
|
||
foreach my $item (@{ $form->{ALL_CHARTS} }) {
|
||||
cf5fe23a | Sven Schöling | if ($item->{link_split}{AR_amount}) {
|
||
3253777d | Moritz Bunkus | $taxchart_init = $item->{tax_id} if ($taxchart_init eq "");
|
||
my $key = "$item->{accno}--$item->{tax_id}";
|
||||
push(@AR_amount_values, $key);
|
||||
cf5fe23a | Sven Schöling | } elsif ($item->{link_split}{AR}) {
|
||
3253777d | Moritz Bunkus | push(@AR_values, $item->{accno});
|
||
cf5fe23a | Sven Schöling | } elsif ($item->{link_split}{AR_paid}) {
|
||
3253777d | Moritz Bunkus | push(@AR_paid_values, $item->{accno});
|
||
}
|
||||
6aefd19d | Moritz Bunkus | |||
cf5fe23a | Sven Schöling | # weirdness for AR_amount
|
||
$chart_labels{$item->{accno}} = "$item->{accno}--$item->{description}";
|
||||
$chart_labels{"$item->{accno}--$item->{tax_id}"} = "$item->{accno}--$item->{description}";
|
||||
6aefd19d | Moritz Bunkus | $charts{$item->{accno}} = $item;
|
||
3253777d | Moritz Bunkus | }
|
||
289ea7d7 | Moritz Bunkus | my %taxchart_labels = ();
|
||
my @taxchart_values = ();
|
||||
6aefd19d | Moritz Bunkus | my %taxcharts = ();
|
||
289ea7d7 | Moritz Bunkus | foreach my $item (@{ $form->{ALL_TAXCHARTS} }) {
|
||
3253777d | Moritz Bunkus | my $key = "$item->{id}--$item->{rate}";
|
||
$taxchart_init = $key if ($taxchart_init eq $item->{id});
|
||||
289ea7d7 | Moritz Bunkus | push(@taxchart_values, $key);
|
||
cf5fe23a | Sven Schöling | $taxchart_labels{$key} = "$item->{taxdescription} " . ($item->{rate} * 100) . ' %';
|
||
6aefd19d | Moritz Bunkus | $taxcharts{$item->{id}} = $item;
|
||
289ea7d7 | Moritz Bunkus | }
|
||
7a7f33b5 | Moritz Bunkus | my $follow_up_vc = $form->{customer};
|
||
$follow_up_vc =~ s/--.*?//;
|
||||
my $follow_up_trans_info = "$form->{invnumber} ($follow_up_vc)";
|
||||
fb4d2ffa | Moritz Bunkus | $form->{javascript} .=
|
||
7a7f33b5 | Moritz Bunkus | qq|<script type="text/javascript" src="js/show_vc_details.js"></script>| .
|
||
qq|<script type="text/javascript" src="js/follow_up.js"></script>|;
|
||||
fb4d2ffa | Moritz Bunkus | |||
cf5fe23a | Sven Schöling | # $amount = $locale->text('Amount');
|
||
# $project = $locale->text('Project');
|
||||
d319704a | Moritz Bunkus | |||
cf5fe23a | Sven Schöling | my @transactions;
|
||
for my $i (1 .. $form->{rowcount}) {
|
||||
my $transaction = {
|
||||
amount => $form->{"amount_$i"},
|
||||
0ba3b647 | Geoffrey Richardson | tax => $form->{"tax_$i"},
|
||
155f106a | Niclas Zimmermann | project_id => ($i==$form->{rowcount}) ? $form->{globalproject_id} : $form->{"project_id_$i"},
|
||
cf5fe23a | Sven Schöling | };
|
||
3253777d | Moritz Bunkus | |||
6aefd19d | Moritz Bunkus | my $selected_accno_full;
|
||
my ($accno_row) = split(/--/, $form->{"AR_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_AR_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}";
|
||||
}
|
||||
8f8ad003 | Moritz Bunkus | if (!$form->{"taxchart_$i"}) {
|
||
if ($form->{"AR_amount_$i"} =~ m/.--./) {
|
||||
$selected_taxchart = join '--', map { ($_->{id}, $_->{rate}) } first { $_->{id} == $item->{tax_id} } @{ $form->{ALL_TAXCHARTS} };
|
||||
} else {
|
||||
$selected_taxchart = $taxchart_init;
|
||||
}
|
||||
}
|
||||
6aefd19d | Moritz Bunkus | |||
cf5fe23a | Sven Schöling | $transaction->{selectAR_amount} =
|
||
3253777d | Moritz Bunkus | NTI($cgi->popup_menu('-name' => "AR_amount_$i",
|
||
'-id' => "AR_amount_$i",
|
||||
'-style' => 'width:400px',
|
||||
'-onChange' => "setTaxkey(this, $i)",
|
||||
'-values' => \@AR_amount_values,
|
||||
cf5fe23a | Sven Schöling | '-labels' => \%chart_labels,
|
||
6aefd19d | Moritz Bunkus | '-default' => $selected_accno_full))
|
||
. $cgi->hidden('-name' => "previous_AR_amount_$i",
|
||||
'-default' => $selected_accno_full);
|
||||
289ea7d7 | Moritz Bunkus | |||
0ba3b647 | Geoffrey Richardson | $transaction->{taxchart} =
|
||
3253777d | Moritz Bunkus | NTI($cgi->popup_menu('-name' => "taxchart_$i",
|
||
'-id' => "taxchart_$i",
|
||||
'-style' => 'width:200px',
|
||||
'-values' => \@taxchart_values,
|
||||
'-labels' => \%taxchart_labels,
|
||||
cf5fe23a | Sven Schöling | '-default' => $selected_taxchart));
|
||
push @transactions, $transaction;
|
||||
d319704a | Moritz Bunkus | }
|
||
4d20c181 | Moritz Bunkus | $form->{invtotal_unformatted} = $form->{invtotal};
|
||
d319704a | Moritz Bunkus | |||
3253777d | Moritz Bunkus | $ARselected =
|
||
NTI($cgi->popup_menu('-name' => "ARselected", '-id' => "ARselected",
|
||||
'-style' => 'width:400px',
|
||||
cf5fe23a | Sven Schöling | '-values' => \@AR_values, '-labels' => \%chart_labels,
|
||
3253777d | Moritz Bunkus | '-default' => $form->{ARselected}));
|
||
4d20c181 | Moritz Bunkus | |||
d319704a | Moritz Bunkus | $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"});
|
||
cf5fe23a | Sven Schöling | my $now = $form->current_date(\%myconfig);
|
||
my @payments;
|
||||
for my $i (1 .. $form->{paidaccounts}) {
|
||||
my $payment = {
|
||||
paid => $form->{"paid_$i"},
|
||||
exchangerate => $form->{"exchangerate_$i"} || '',
|
||||
gldate => $form->{"gldate_$i"},
|
||||
acc_trans_id => $form->{"acc_trans_id_$i"},
|
||||
source => $form->{"source_$i"},
|
||||
memo => $form->{"memo_$i"},
|
||||
AR_paid => $form->{"AR_paid_$i"},
|
||||
forex => $form->{"forex_$i"},
|
||||
datepaid => $form->{"datepaid_$i"},
|
||||
paid_project_id => $form->{"paid_project_id_$i"},
|
||||
gldate => $form->{"gldate_$i"},
|
||||
};
|
||||
c08b6d21 | Jan Büren | # default account for current assets (i.e. 1801 - SKR04) if no account is selected
|
||
5be8f312 | Jan Büren | $form->{accno_arap} = IS->get_standard_accno_current_assets(\%myconfig, \%$form);
|
||
cf5fe23a | Sven Schöling | $payment->{selectAR_paid} =
|
||
3253777d | Moritz Bunkus | NTI($cgi->popup_menu('-name' => "AR_paid_$i",
|
||
'-id' => "AR_paid_$i",
|
||||
'-values' => \@AR_paid_values,
|
||||
cf5fe23a | Sven Schöling | '-labels' => \%chart_labels,
|
||
c08b6d21 | Jan Büren | '-default' => $payment->{AR_paid} || $form->{accno_arap}));
|
||
d319704a | Moritz Bunkus | |||
4d20c181 | Moritz Bunkus | |||
fb37acdc | Moritz Bunkus | |||
cf5fe23a | Sven Schöling | $payment->{changeable} =
|
||
97954312 | Bernd Bleßmann | SL::DB::Default->get->payments_changeable == 0 ? !$payment->{acc_trans_id} # never
|
||
: SL::DB::Default->get->payments_changeable == 2 ? $payment->{gldate} eq '' || $payment->{gldate} eq $now
|
||||
cf5fe23a | Sven Schöling | : 1;
|
||
4aa81611 | Bernd Bleßmann | |||
cf5fe23a | Sven Schöling | push @payments, $payment;
|
||
d319704a | Moritz Bunkus | }
|
||
a14a3ff5 | Moritz Bunkus | |||
cf5fe23a | Sven Schöling | $form->{totalpaid} = sum map { $_->{paid} } @payments;
|
||
$form->header;
|
||||
print $::form->parse_html_template('ar/form_header', {
|
||||
paid_missing => $::form->{invtotal} - $::form->{totalpaid},
|
||||
show_exch => ($::form->{defaultcurrency} && ($::form->{currency} ne $::form->{defaultcurrency})),
|
||||
payments => \@payments,
|
||||
transactions => \@transactions,
|
||||
project_labels => \%project_labels,
|
||||
rows => $rows,
|
||||
ARselected => $ARselected,
|
||||
title_str => $title,
|
||||
follow_up_trans_info => $follow_up_trans_info,
|
||||
});
|
||||
d319704a | Moritz Bunkus | |||
ebdc6e13 | Sven Schöling | $main::lxdebug->leave_sub();
|
||
d319704a | Moritz Bunkus | }
|
||
sub form_footer {
|
||||
ebdc6e13 | Sven Schöling | $main::lxdebug->enter_sub();
|
||
$main::auth->assert('general_ledger');
|
||||
d319704a | Moritz Bunkus | |||
ebdc6e13 | 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 | |||
d440aa09 | Thomas Heck | if ( $form->{id} ) {
|
||
7a7f33b5 | Moritz Bunkus | my $follow_ups = FU->follow_ups('trans_id' => $form->{id});
|
||
d440aa09 | Thomas Heck | if ( @{ $follow_ups} ) {
|
||
$form->{follow_up_length} = scalar(@{$follow_ups});
|
||||
$form->{follow_up_due_length} = sum(map({ $_->{due} * 1 } @{ $follow_ups }));
|
||||
7a7f33b5 | Moritz Bunkus | }
|
||
}
|
||||
d440aa09 | Thomas Heck | my $transdate = $form->datetonum($form->{transdate}, \%myconfig);
|
||
my $closedto = $form->datetonum($form->{closedto}, \%myconfig);
|
||||
29e31d6b | Moritz Bunkus | |||
d440aa09 | Thomas Heck | $form->{is_closed} = $transdate <= $closedto;
|
||
a4518c4d | Sven Schöling | |||
2f23933d | Sven Schöling | # ToDO: - insert a global check for stornos, so that a storno is only possible a limited time after saving it
|
||
d440aa09 | Thomas Heck | $form->{show_storno_button} =
|
||
$form->{id} &&
|
||||
!IS->has_storno(\%myconfig, $form, 'ar') &&
|
||||
!IS->is_storno(\%myconfig, $form, 'ar') &&
|
||||
($form->{totalpaid} == 0 || $form->{totalpaid} eq "");
|
||||
d319704a | Moritz Bunkus | |||
d440aa09 | Thomas Heck | $form->{show_mark_as_paid_button} = $form->{id} && $::instance_conf->get_ar_show_mark_as_paid();
|
||
ce47a234 | Thomas Kasulke | |||
d440aa09 | Thomas Heck | print $::form->parse_html_template('ar/form_footer');
|
||
d319704a | Moritz Bunkus | |||
ebdc6e13 | Sven Schöling | $main::lxdebug->leave_sub();
|
||
d319704a | Moritz Bunkus | }
|
||
ce47a234 | Thomas Kasulke | sub mark_as_paid {
|
||
ebdc6e13 | Sven Schöling | $main::lxdebug->enter_sub();
|
||
$main::auth->assert('general_ledger');
|
||||
8c7e4493 | Moritz Bunkus | |||
ebdc6e13 | Sven Schöling | my $form = $main::form;
|
||
my %myconfig = %main::myconfig;
|
||||
8c7e4493 | Moritz Bunkus | |||
3b3ef5ba | Sven Schöling | &mark_as_paid_common(\%myconfig,"ar");
|
||
8c7e4493 | Moritz Bunkus | |||
ebdc6e13 | Sven Schöling | $main::lxdebug->leave_sub();
|
||
ce47a234 | Thomas Kasulke | }
|
||
d319704a | Moritz Bunkus | sub update {
|
||
ebdc6e13 | Sven Schöling | $main::lxdebug->enter_sub();
|
||
d319704a | Moritz Bunkus | |||
ebdc6e13 | Sven Schöling | $main::auth->assert('general_ledger');
|
||
my $form = $main::form;
|
||||
my %myconfig = %main::myconfig;
|
||||
8c7e4493 | Moritz Bunkus | |||
d319704a | Moritz Bunkus | my $display = shift;
|
||
ebdc6e13 | Sven Schöling | my ($totaltax, $exchangerate);
|
||
1ae70a98 | Sven Schöling | |||
d319704a | Moritz Bunkus | $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);
|
||||
1ae70a98 | Sven Schöling | my @flds = qw(amount AR_amount projectnumber oldprojectnumber project_id);
|
||
my $count = 0;
|
||||
my @a = ();
|
||||
de651621 | Stephan Köhler | |||
1ae70a98 | Sven Schöling | for my $i (1 .. $form->{rowcount}) {
|
||
$form->{"amount_$i"} = $form->parse_amount(\%myconfig, $form->{"amount_$i"});
|
||||
d319704a | Moritz Bunkus | if ($form->{"amount_$i"}) {
|
||
push @a, {};
|
||||
1ae70a98 | Sven Schöling | my $j = $#a;
|
||
5d44361c | Moritz Bunkus | my ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
|
||
0e68056c | Geoffrey Richardson | |||
my $tmpnetamount;
|
||||
($tmpnetamount,$form->{"tax_$i"}) = $form->calculate_tax($form->{"amount_$i"},$rate,$form->{taxincluded},2);
|
||||
d319704a | Moritz Bunkus | |||
de651621 | Stephan Köhler | $totaltax += $form->{"tax_$i"};
|
||
d319704a | Moritz Bunkus | map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
|
||
$count++;
|
||||
}
|
||||
}
|
||||
$form->redo_rows(\@flds, \@a, $count, $form->{rowcount});
|
||||
de651621 | Stephan Köhler | $form->{rowcount} = $count + 1;
|
||
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}, 'buy');
|
||
$form->{exchangerate} = $form->{forex} if $form->{forex};
|
||||
d319704a | Moritz Bunkus | |||
$form->{invdate} = $form->{transdate};
|
||||
8f8ad003 | Moritz Bunkus | |||
$form->{invdate} = $form->{transdate};
|
||||
f612f63e | Moritz Bunkus | my %saved_variables = map +( $_ => $form->{$_} ), qw(AR AR_amount_1 taxchart_1 customer_id notes);
|
||
595799f4 | Moritz Bunkus | |||
8f8ad003 | Moritz Bunkus | &check_name("customer");
|
||
595799f4 | Moritz Bunkus | |||
8f8ad003 | Moritz Bunkus | $form->{AR} = $saved_variables{AR};
|
||
if ($saved_variables{AR_amount_1} =~ m/.--./) {
|
||||
map { $form->{$_} = $saved_variables{$_} } qw(AR_amount_1 taxchart_1);
|
||||
} else {
|
||||
delete $form->{taxchart_1};
|
||||
}
|
||||
d319704a | Moritz Bunkus | |||
$form->{invtotal} =
|
||||
($form->{taxincluded}) ? $form->{invtotal} : $form->{invtotal} + $totaltax;
|
||||
1ae70a98 | Sven Schöling | 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);
|
||||
abfe327e | Moritz Bunkus | $form->{totalpaid} += $form->{"paid_$i"};
|
||
d319704a | Moritz Bunkus | |||
a53233e5 | Sven Schöling | $form->{"forex_$i"} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy');
|
||
$form->{"exchangerate_$i"} = $form->{"forex_$i"} if $form->{"forex_$i"};
|
||||
d319704a | Moritz Bunkus | }
|
||
}
|
||||
$form->{creditremaining} -=
|
||||
abfe327e | Moritz Bunkus | ($form->{invtotal} - $form->{totalpaid} + $form->{oldtotalpaid} -
|
||
d319704a | Moritz Bunkus | $form->{oldinvtotal});
|
||
$form->{oldinvtotal} = $form->{invtotal};
|
||||
abfe327e | Moritz Bunkus | $form->{oldtotalpaid} = $form->{totalpaid};
|
||
d319704a | Moritz Bunkus | |||
&display_form;
|
||||
ebdc6e13 | Sven Schöling | $main::lxdebug->leave_sub();
|
||
d319704a | Moritz Bunkus | }
|
||
1ae70a98 | Sven Schöling | #
|
||
# ToDO: fix $closedto and $invdate
|
||||
#
|
||||
bdaa8c2f | Philip Reetz | sub post_payment {
|
||
ebdc6e13 | Sven Schöling | $main::lxdebug->enter_sub();
|
||
$main::auth->assert('general_ledger');
|
||||
a326f385 | Moritz Bunkus | |||
ebdc6e13 | Sven Schöling | my $form = $main::form;
|
||
my %myconfig = %main::myconfig;
|
||||
my $locale = $main::locale;
|
||||
8c7e4493 | Moritz Bunkus | |||
a326f385 | Moritz Bunkus | $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
|
||
662ded38 | Sven Schöling | my $invdate = $form->datetonum($form->{transdate}, \%myconfig);
|
||
1ae70a98 | Sven Schöling | for my $i (1 .. $form->{paidaccounts}) {
|
||
eb8bed3f | Moritz Bunkus | if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
|
||
1ae70a98 | Sven Schöling | my $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
|
||
bdaa8c2f | Philip Reetz | |||
$form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
|
||||
9e06d0e4 | Philip Reetz | $form->error($locale->text('Cannot post payment for a closed period!')) if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig));
|
||
bdaa8c2f | Philip Reetz | |||
bea3f989 | Moritz Bunkus | if ($form->{defaultcurrency} && ($form->{currency} ne $form->{defaultcurrency})) {
|
||
1ae70a98 | Sven Schöling | # $form->{"exchangerate_$i"} = $form->{exchangerate} if ($invdate == $datepaid);
|
||
$form->isblank("exchangerate_$i", $locale->text('Exchangerate for payment missing!'));
|
||||
bdaa8c2f | Philip Reetz | }
|
||
}
|
||||
}
|
||||
($form->{AR}) = split /--/, $form->{AR};
|
||||
($form->{AR_paid}) = split /--/, $form->{AR_paid};
|
||||
7a98647b | Geoffrey Richardson | if (AR->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 {
|
||||
$form->error($locale->text('Cannot post payment!'));
|
||||
};
|
||||
bdaa8c2f | Philip Reetz | |||
ebdc6e13 | Sven Schöling | $main::lxdebug->leave_sub();
|
||
bdaa8c2f | Philip Reetz | }
|
||
1ae70a98 | Sven Schöling | sub _post {
|
||
8c7e4493 | Moritz Bunkus | |||
ebdc6e13 | Sven Schöling | $main::auth->assert('general_ledger');
|
||
my $form = $main::form;
|
||||
8c7e4493 | Moritz Bunkus | |||
1ae70a98 | Sven Schöling | # inline post
|
||
post(1);
|
||||
}
|
||||
d319704a | Moritz Bunkus | sub post {
|
||
ebdc6e13 | Sven Schöling | $main::lxdebug->enter_sub();
|
||
d319704a | Moritz Bunkus | |||
ebdc6e13 | Sven Schöling | $main::auth->assert('general_ledger');
|
||
my $form = $main::form;
|
||||
my %myconfig = %main::myconfig;
|
||||
my $locale = $main::locale;
|
||||
8c7e4493 | Moritz Bunkus | |||
1ae70a98 | Sven Schöling | my ($inline) = @_;
|
||
my ($datepaid);
|
||||
d319704a | Moritz Bunkus | # check if there is an invoice number, invoice and due date
|
||
$form->isblank("transdate", $locale->text('Invoice Date missing!'));
|
||||
$form->isblank("duedate", $locale->text('Due Date missing!'));
|
||||
$form->isblank("customer", $locale->text('Customer missing!'));
|
||||
05174f19 | Sven Schöling | if ($myconfig{mandatory_departments} && !$form->{department}) {
|
||
$form->{saved_message} = $::locale->text('You have to specify a department.');
|
||||
update();
|
||||
exit;
|
||||
}
|
||||
1ae70a98 | 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($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 | |||
3b3ef5ba | Sven Schöling | $form->error($locale->text('Zero amount posting!'))
|
||
102600f0 | Sven Schöling | unless grep $_*1, map $form->parse_amount(\%myconfig, $form->{"amount_$_"}), 1..$form->{rowcount};
|
||
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->{AR});
|
||||
1ae70a98 | Sven Schöling | for my $i (1 .. $form->{paidaccounts}) {
|
||
04a2f2e7 | Moritz Bunkus | if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) {
|
||
d319704a | Moritz Bunkus | $datepaid = $form->datetonum($form->{"datepaid_$i"}, \%myconfig);
|
||
$form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
|
||||
$form->error($locale->text('Cannot post payment for a closed period!'))
|
||||
9e06d0e4 | Philip Reetz | if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig));
|
||
d319704a | Moritz Bunkus | |||
bea3f989 | Moritz Bunkus | if ($form->{defaultcurrency} && ($form->{currency} ne $form->{defaultcurrency})) {
|
||
102600f0 | Sven Schöling | $form->{"exchangerate_$i"} = $form->{exchangerate} if ($transdate == $datepaid);
|
||
$form->isblank("exchangerate_$i", $locale->text('Exchangerate for payment missing!'));
|
||||
d319704a | Moritz Bunkus | }
|
||
}
|
||||
}
|
||||
# if oldcustomer ne customer redo form
|
||||
1ae70a98 | Sven Schöling | my ($customer) = split /--/, $form->{customer};
|
||
d319704a | Moritz Bunkus | if ($form->{oldcustomer} ne "$customer--$form->{customer_id}") {
|
||
1ae70a98 | Sven Schöling | update();
|
||
b2945bf6 | Sven Schöling | ::end_of_request();
|
||
d319704a | Moritz Bunkus | }
|
||
3253777d | Moritz Bunkus | $form->{AR}{receivables} = $form->{ARselected};
|
||
91ea86b4 | Moritz Bunkus | $form->{storno} = 0;
|
||
d319704a | Moritz Bunkus | |||
$form->{id} = 0 if $form->{postasnew};
|
||||
1ae70a98 | Sven Schöling | $form->error($locale->text('Cannot post transaction!')) unless AR->post_transaction(\%myconfig, \%$form);
|
||
91ea86b4 | Moritz Bunkus | |||
1ae70a98 | Sven Schöling | # saving the history
|
||
if(!exists $form->{addition} && $form->{id} ne "") {
|
||||
281696eb | Geoffrey Richardson | $form->{snumbers} = "invnumber_$form->{invnumber}";
|
||
$form->{what_done} = "invoice";
|
||||
$form->{addition} = "POSTED";
|
||||
a590a651 | Sven Schöling | $form->save_history;
|
||
590f737f | Thomas Kasulke | }
|
||
3b3ef5ba | Sven Schöling | # /saving the history
|
||
1ae70a98 | Sven Schöling | remove_draft() if $form->{remove_draft};
|
||
$form->redirect($locale->text('Transaction posted!')) unless $inline;
|
||||
d319704a | Moritz Bunkus | |||
ebdc6e13 | Sven Schöling | $main::lxdebug->leave_sub();
|
||
d319704a | Moritz Bunkus | }
|
||
sub post_as_new {
|
||||
ebdc6e13 | Sven Schöling | $main::lxdebug->enter_sub();
|
||
$main::auth->assert('general_ledger');
|
||||
d319704a | Moritz Bunkus | |||
ebdc6e13 | Sven Schöling | my $form = $main::form;
|
||
my %myconfig = %main::myconfig;
|
||||
8c7e4493 | Moritz Bunkus | |||
d319704a | Moritz Bunkus | $form->{postasnew} = 1;
|
||
590f737f | Thomas Kasulke | # saving the history
|
||
if(!exists $form->{addition} && $form->{id} ne "") {
|
||||
281696eb | Geoffrey Richardson | $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
|
||
$form->{what_done} = "invoice";
|
||||
$form->{addition} = "POSTED AS NEW";
|
||||
a590a651 | Sven Schöling | $form->save_history;
|
||
590f737f | Thomas Kasulke | }
|
||
3b3ef5ba | Sven Schöling | # /saving the history
|
||
d319704a | Moritz Bunkus | &post;
|
||
ebdc6e13 | Sven Schöling | $main::lxdebug->leave_sub();
|
||
d319704a | Moritz Bunkus | }
|
||
3cd3e832 | Moritz Bunkus | sub use_as_new {
|
||
ebdc6e13 | Sven Schöling | $main::lxdebug->enter_sub();
|
||
$main::auth->assert('general_ledger');
|
||||
98764afa | Philip Reetz | |||
ebdc6e13 | Sven Schöling | my $form = $main::form;
|
||
my %myconfig = %main::myconfig;
|
||||
8c7e4493 | Moritz Bunkus | |||
4aa81611 | 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;
|
||||
ebdc6e13 | Sven Schöling | $main::lxdebug->leave_sub();
|
||
98764afa | Philip Reetz | }
|
||
d319704a | Moritz Bunkus | sub delete {
|
||
ebdc6e13 | Sven Schöling | $main::lxdebug->enter_sub();
|
||
d319704a | Moritz Bunkus | |||
ebdc6e13 | Sven Schöling | $main::auth->assert('general_ledger');
|
||
my $form = $main::form;
|
||||
my $locale = $main::locale;
|
||||
8c7e4493 | Moritz Bunkus | |||
d319704a | Moritz Bunkus | $form->{title} = $locale->text('Confirm!');
|
||
$form->header;
|
||||
delete $form->{header};
|
||||
print qq|
|
||||
<form method=post action=$form->{script}>
|
||||
|;
|
||||
1ae70a98 | 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>
|
||||
|;
|
||||
ebdc6e13 | Sven Schöling | $main::lxdebug->leave_sub();
|
||
d319704a | Moritz Bunkus | }
|
||
sub yes {
|
||||
ebdc6e13 | Sven Schöling | $main::lxdebug->enter_sub();
|
||
$main::auth->assert('general_ledger');
|
||||
8c7e4493 | Moritz Bunkus | |||
ebdc6e13 | Sven Schöling | my $form = $main::form;
|
||
my %myconfig = %main::myconfig;
|
||||
my $locale = $main::locale;
|
||||
8c7e4493 | Moritz Bunkus | |||
1ae70a98 | Sven Schöling | if (AR->delete_transaction(\%myconfig, \%$form)) {
|
||
590f737f | Thomas Kasulke | # saving the history
|
||
if(!exists $form->{addition}) {
|
||||
281696eb | Geoffrey Richardson | $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
|
||
$form->{what_done} = "invoice";
|
||||
$form->{addition} = "DELETED";
|
||||
a590a651 | Sven Schöling | $form->save_history;
|
||
590f737f | Thomas Kasulke | }
|
||
3b3ef5ba | Sven Schöling | # /saving the history
|
||
590f737f | Thomas Kasulke | $form->redirect($locale->text('Transaction deleted!'));
|
||
}
|
||||
d319704a | Moritz Bunkus | $form->error($locale->text('Cannot delete transaction!'));
|
||
ebdc6e13 | Sven Schöling | $main::lxdebug->leave_sub();
|
||
d319704a | Moritz Bunkus | }
|
||
sub search {
|
||||
ebdc6e13 | Sven Schöling | $main::lxdebug->enter_sub();
|
||
916aae37 | Niclas Zimmermann | $main::auth->assert('invoice_edit');
|
||
d319704a | Moritz Bunkus | |||
ebdc6e13 | 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 | |||
d319704a | Moritz Bunkus | # setup customer selection
|
||
$form->all_vc(\%myconfig, "customer", "AR");
|
||||
3a33f5d3 | Sven Schöling | $form->{title} = $locale->text('AR Transactions');
|
||
d319704a | Moritz Bunkus | |||
044d18ff | Jan Büren | # Auch in Rechnungsübersicht nach Kundentyp filtern - jan
|
||
$form->get_lists("projects" => { "key" => "ALL_PROJECTS", "all" => 1 },
|
||||
"departments" => "ALL_DEPARTMENTS",
|
||||
"customers" => "ALL_VC",
|
||||
"business_types" => "ALL_BUSINESS_TYPES");
|
||||
d139dd31 | Moritz Bunkus | $form->{ALL_EMPLOYEES} = SL::DB::Manager::Employee->get_all_sorted(query => [ deleted => 0 ]);
|
||
044d18ff | Jan Büren | $form->{SHOW_BUSINESS_TYPES} = scalar @{ $form->{ALL_BUSINESS_TYPES} } > 0;
|
||
d319704a | Moritz Bunkus | |||
0e4da157 | Bernd Bleßmann | $form->{CT_CUSTOM_VARIABLES} = CVar->get_configs('module' => 'CT');
|
||
($form->{CT_CUSTOM_VARIABLES_FILTER_CODE},
|
||||
$form->{CT_CUSTOM_VARIABLES_INCLUSION_CODE}) = CVar->render_search_options('variables' => $form->{CT_CUSTOM_VARIABLES},
|
||||
'include_prefix' => 'l_',
|
||||
'include_value' => 'Y');
|
||||
3a33f5d3 | Sven Schöling | # constants and subs for template
|
||
$form->{vc_keys} = sub { "$_[0]->{name}--$_[0]->{id}" };
|
||||
d319704a | Moritz Bunkus | |||
$form->header;
|
||||
3a33f5d3 | Sven Schöling | print $form->parse_html_template('ar/search', { %myconfig });
|
||
d319704a | Moritz Bunkus | |||
ebdc6e13 | Sven Schöling | $main::lxdebug->leave_sub();
|
||
d319704a | Moritz Bunkus | }
|
||
971c9727 | Moritz Bunkus | sub create_subtotal_row {
|
||
ebdc6e13 | Sven Schöling | $main::lxdebug->enter_sub();
|
||
971c9727 | Moritz Bunkus | |||
my ($totals, $columns, $column_alignment, $subtotal_columns, $class) = @_;
|
||||
ebdc6e13 | Sven Schöling | my $form = $main::form;
|
||
my %myconfig = %main::myconfig;
|
||||
971c9727 | 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 };
|
||||
ebdc6e13 | Sven Schöling | $main::lxdebug->leave_sub();
|
||
971c9727 | Moritz Bunkus | |||
return $row;
|
||||
}
|
||||
d319704a | Moritz Bunkus | sub ar_transactions {
|
||
ebdc6e13 | Sven Schöling | $main::lxdebug->enter_sub();
|
||
916aae37 | Niclas Zimmermann | $main::auth->assert('invoice_edit');
|
||
d319704a | Moritz Bunkus | |||
ebdc6e13 | Sven Schöling | my $form = $main::form;
|
||
my %myconfig = %main::myconfig;
|
||||
my $locale = $main::locale;
|
||||
8c7e4493 | Moritz Bunkus | |||
1ae70a98 | Sven Schöling | my ($callback, $href, @columns);
|
||
d319704a | Moritz Bunkus | ($form->{customer}, $form->{customer_id}) = split(/--/, $form->{customer});
|
||
679db39f | Moritz Bunkus | report_generator_set_default_sort('transdate', 1);
|
||
971c9727 | Moritz Bunkus | |||
d319704a | Moritz Bunkus | AR->ar_transactions(\%myconfig, \%$form);
|
||
971c9727 | Moritz Bunkus | $form->{title} = $locale->text('AR Transactions');
|
||
my $report = SL::ReportGenerator->new(\%myconfig, $form);
|
||||
1ae70a98 | Sven Schöling | @columns =
|
||
85b0c4ab | Moritz Bunkus | qw(transdate id type invnumber ordnumber cusordnumber name netamount tax amount paid
|
||
5e984449 | Sven Schöling | datepaid due duedate transaction_description notes salesman employee shippingpoint shipvia
|
||
d504954f | Moritz Bunkus | marge_total marge_percent globalprojectnumber customernumber country ustid taxzone payment_terms charts customertype direct_debit);
|
||
971c9727 | Moritz Bunkus | |||
0e4da157 | Bernd Bleßmann | my $ct_cvar_configs = CVar->get_configs('module' => 'CT');
|
||
my @ct_includeable_custom_variables = grep { $_->{includeable} } @{ $ct_cvar_configs };
|
||||
my @ct_searchable_custom_variables = grep { $_->{searchable} } @{ $ct_cvar_configs };
|
||||
my %column_defs_cvars = map { +"cvar_$_->{name}" => { 'text' => $_->{description} } } @ct_includeable_custom_variables;
|
||||
push @columns, map { "cvar_$_->{name}" } @ct_includeable_custom_variables;
|
||||
971c9727 | Moritz Bunkus | my @hidden_variables = map { "l_${_}" } @columns;
|
||
e24e6570 | Sven Schöling | push @hidden_variables, "l_subtotal", qw(open closed customer invnumber ordnumber cusordnumber transaction_description notes project_id transdatefrom transdateto duedatefrom duedateto employee_id salesman_id business_id);
|
||
0e4da157 | Bernd Bleßmann | push @hidden_variables, map { "cvar_$_->{name}" } @ct_searchable_custom_variables;
|
||
971c9727 | Moritz Bunkus | |||
1ae70a98 | Sven Schöling | $href = build_std_url('action=ar_transactions', grep { $form->{$_} } @hidden_variables);
|
||
971c9727 | Moritz Bunkus | |||
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'), },
|
||||
85b0c4ab | Moritz Bunkus | 'cusordnumber' => { 'text' => $locale->text('Customer Order Number'), },
|
||
971c9727 | Moritz Bunkus | 'name' => { 'text' => $locale->text('Customer'), },
|
||
'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'), },
|
||||
5e984449 | Sven Schöling | 'salesman' => { 'text' => $locale->text('Salesperson'), },
|
||
'employee' => { 'text' => $locale->text('Employee'), },
|
||||
971c9727 | Moritz Bunkus | 'shippingpoint' => { 'text' => $locale->text('Shipping Point'), },
|
||
'shipvia' => { 'text' => $locale->text('Ship via'), },
|
||||
d8e0c6d8 | Bernd Bleßmann | 'globalprojectnumber' => { 'text' => $locale->text('Document Project Number'), },
|
||
4d8a6515 | Philip Reetz | 'marge_total' => { 'text' => $locale->text('Ertrag'), },
|
||
'marge_percent' => { 'text' => $locale->text('Ertrag prozentual'), },
|
||||
3b3ef5ba | Sven Schöling | 'customernumber' => { 'text' => $locale->text('Customer Number'), },
|
||
'country' => { 'text' => $locale->text('Country'), },
|
||||
'ustid' => { 'text' => $locale->text('USt-IdNr.'), },
|
||||
'taxzone' => { 'text' => $locale->text('Steuersatz'), },
|
||||
'payment_terms' => { 'text' => $locale->text('Payment Terms'), },
|
||||
96d60de4 | Sven Schöling | 'charts' => { 'text' => $locale->text('Buchungskonto'), },
|
||
9263b0fa | Jan Büren | 'customertype' => { 'text' => $locale->text('Customer type'), },
|
||
d504954f | Moritz Bunkus | 'direct_debit' => { 'text' => $locale->text('direct debit'), },
|
||
0e4da157 | Bernd Bleßmann | %column_defs_cvars,
|
||
971c9727 | Moritz Bunkus | );
|
||
d504954f | Moritz Bunkus | foreach my $name (qw(id transdate duedate invnumber ordnumber cusordnumber name datepaid employee shippingpoint shipvia transaction_description direct_debit)) {
|
||
679db39f | Moritz Bunkus | my $sortdir = $form->{sort} eq $name ? 1 - $form->{sortdir} : $form->{sortdir};
|
||
$column_defs{$name}->{link} = $href . "&sort=$name&sortdir=$sortdir";
|
||||
971c9727 | 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;
|
||||
d319704a | Moritz Bunkus | |||
971c9727 | Moritz Bunkus | $report->set_columns(%column_defs);
|
||
$report->set_column_order(@columns);
|
||||
ff71dc3f | Moritz Bunkus | $report->set_export_options('ar_transactions', @hidden_variables, qw(sort sortdir));
|
||
971c9727 | Moritz Bunkus | |||
679db39f | Moritz Bunkus | $report->set_sort_indicator($form->{sort}, $form->{sortdir});
|
||
f5e4c22b | Moritz Bunkus | |||
0e4da157 | Bernd Bleßmann | CVar->add_custom_variables_to_report('module' => 'CT',
|
||
'trans_id_field' => 'customer_id',
|
||||
'configs' => $ct_cvar_configs,
|
||||
'column_defs' => \%column_defs,
|
||||
'data' => $form->{AR});
|
||||
971c9727 | Moritz Bunkus | my @options;
|
||
d319704a | Moritz Bunkus | if ($form->{customer}) {
|
||
971c9727 | Moritz Bunkus | push @options, $locale->text('Customer') . " : $form->{customer}";
|
||
d319704a | Moritz Bunkus | }
|
||
b98b8e3f | Sven Schöling | if ($form->{cp_name}) {
|
||
push @options, $locale->text('Contact Person') . " : $form->{cp_name}";
|
||||
}
|
||||
d319704a | Moritz Bunkus | if ($form->{department}) {
|
||
1ae70a98 | Sven Schöling | my ($department) = split /--/, $form->{department};
|
||
971c9727 | Moritz Bunkus | push @options, $locale->text('Department') . " : $department";
|
||
d319704a | Moritz Bunkus | }
|
||
ee9f9f9a | Sven Schöling | if ($form->{department_id}) {
|
||
push @options, $locale->text('Department Id') . " : $form->{department_id}";
|
||||
}
|
||||
d319704a | Moritz Bunkus | if ($form->{invnumber}) {
|
||
971c9727 | Moritz Bunkus | push @options, $locale->text('Invoice Number') . " : $form->{invnumber}";
|
||
d319704a | Moritz Bunkus | }
|
||
if ($form->{ordnumber}) {
|
||||
971c9727 | Moritz Bunkus | push @options, $locale->text('Order Number') . " : $form->{ordnumber}";
|
||
d319704a | Moritz Bunkus | }
|
||
85b0c4ab | Moritz Bunkus | if ($form->{cusordnumber}) {
|
||
push @options, $locale->text('Customer Order Number') . " : $form->{cusordnumber}";
|
||||
}
|
||||
d319704a | Moritz Bunkus | if ($form->{notes}) {
|
||
971c9727 | Moritz Bunkus | push @options, $locale->text('Notes') . " : $form->{notes}";
|
||
d319704a | Moritz Bunkus | }
|
||
c63316e6 | Moritz Bunkus | if ($form->{transaction_description}) {
|
||
971c9727 | Moritz Bunkus | push @options, $locale->text('Transaction description') . " : $form->{transaction_description}";
|
||
c63316e6 | Moritz Bunkus | }
|
||
d319704a | Moritz Bunkus | if ($form->{transdatefrom}) {
|
||
64c4e3c6 | Moritz Bunkus | push @options, $locale->text('From') . " " . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
|
||
d319704a | Moritz Bunkus | }
|
||
if ($form->{transdateto}) {
|
||||
64c4e3c6 | Moritz Bunkus | push @options, $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{transdateto}, 1);
|
||
d319704a | Moritz Bunkus | }
|
||
if ($form->{open}) {
|
||||
971c9727 | Moritz Bunkus | push @options, $locale->text('Open');
|
||
d319704a | Moritz Bunkus | }
|
||
5ee9796f | Geoffrey Richardson | if ($form->{employee_id}) {
|
||
my $employee = SL::DB::Employee->new(id => $form->{employee_id})->load;
|
||||
push @options, $locale->text('Employee') . ' : ' . $employee->name;
|
||||
}
|
||||
if ($form->{salesman_id}) {
|
||||
my $salesman = SL::DB::Employee->new(id => $form->{salesman_id})->load;
|
||||
push @options, $locale->text('Salesman') . ' : ' . $salesman->name;
|
||||
}
|
||||
d319704a | Moritz Bunkus | if ($form->{closed}) {
|
||
971c9727 | Moritz Bunkus | push @options, $locale->text('Closed');
|
||
a4b22a8f | Moritz Bunkus | }
|
||
d319704a | Moritz Bunkus | |||
971c9727 | Moritz Bunkus | $report->set_options('top_info_text' => join("\n", @options),
|
||
9aaca433 | Moritz Bunkus | 'raw_bottom_info_text' => $form->parse_html_template('ar/ar_transactions_bottom'),
|
||
971c9727 | Moritz Bunkus | 'output_format' => 'HTML',
|
||
'title' => $form->{title},
|
||||
'attachment_basename' => $locale->text('invoice_list') . strftime('_%Y%m%d', localtime time),
|
||||
);
|
||||
$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 | |||
# add sort and escape callback, this one we use for the add sub
|
||||
971c9727 | Moritz Bunkus | $form->{callback} = $href .= "&sort=$form->{sort}";
|
||
d319704a | Moritz Bunkus | |||
# escape callback for href
|
||||
971c9727 | Moritz Bunkus | $callback = $form->escape($href);
|
||
d319704a | Moritz Bunkus | |||
5a9d765f | Philip Reetz | my @subtotal_columns = qw(netamount amount paid due marge_total marge_percent);
|
||
d319704a | Moritz Bunkus | |||
971c9727 | Moritz Bunkus | my %totals = map { $_ => 0 } @subtotal_columns;
|
||
my %subtotals = map { $_ => 0 } @subtotal_columns;
|
||||
d319704a | Moritz Bunkus | |||
971c9727 | Moritz Bunkus | my $idx = 0;
|
||
d319704a | Moritz Bunkus | |||
1ae70a98 | Sven Schöling | foreach my $ar (@{ $form->{AR} }) {
|
||
971c9727 | Moritz Bunkus | $ar->{tax} = $ar->{amount} - $ar->{netamount};
|
||
$ar->{due} = $ar->{amount} - $ar->{paid};
|
||||
d319704a | Moritz Bunkus | |||
971c9727 | Moritz Bunkus | map { $subtotals{$_} += $ar->{$_};
|
||
$totals{$_} += $ar->{$_} } @subtotal_columns;
|
||||
d319704a | Moritz Bunkus | |||
3505ff1b | Moritz Bunkus | $subtotals{marge_percent} = $subtotals{netamount} ? ($subtotals{marge_total} * 100 / $subtotals{netamount}) : 0;
|
||
$totals{marge_percent} = $totals{netamount} ? ($totals{marge_total} * 100 / $totals{netamount} ) : 0;
|
||||
5a9d765f | Philip Reetz | |||
4d8a6515 | Philip Reetz | map { $ar->{$_} = $form->format_amount(\%myconfig, $ar->{$_}, 2) } qw(netamount tax amount paid due marge_total marge_percent);
|
||
54740168 | Moritz Bunkus | |||
2654e8ee | Moritz Bunkus | my $is_storno = $ar->{storno} && $ar->{storno_id};
|
||
my $has_storno = $ar->{storno} && !$ar->{storno_id};
|
||||
54740168 | Moritz Bunkus | |||
971c9727 | Moritz Bunkus | $ar->{type} =
|
||
$has_storno ? $locale->text("Invoice with Storno (abbreviation)") :
|
||||
$is_storno ? $locale->text("Storno (one letter abbreviation)") :
|
||||
$ar->{amount} < 0 ? $locale->text("Credit note (one letter abbreviation)") :
|
||||
$ar->{invoice} ? $locale->text("Invoice (one letter abbreviation)") :
|
||||
$locale->text("AR Transaction (abbreviation)");
|
||||
d319704a | Moritz Bunkus | |||
d504954f | Moritz Bunkus | $ar->{direct_debit} = $ar->{direct_debit} ? $::locale->text('yes') : $::locale->text('no');
|
||
971c9727 | Moritz Bunkus | my $row = { };
|
||
d319704a | Moritz Bunkus | |||
971c9727 | Moritz Bunkus | foreach my $column (@columns) {
|
||
$row->{$column} = {
|
||||
'data' => $ar->{$column},
|
||||
'align' => $column_alignment{$column},
|
||||
};
|
||||
}
|
||||
d319704a | Moritz Bunkus | |||
971c9727 | Moritz Bunkus | $row->{invnumber}->{link} = build_std_url("script=" . ($ar->{invoice} ? 'is.pl' : 'ar.pl'), 'action=edit')
|
||
. "&id=" . E($ar->{id}) . "&callback=${callback}";
|
||||
d319704a | Moritz Bunkus | |||
971c9727 | Moritz Bunkus | my $row_set = [ $row ];
|
||
d319704a | Moritz Bunkus | |||
971c9727 | Moritz Bunkus | if (($form->{l_subtotal} eq 'Y')
|
||
&& (($idx == (scalar @{ $form->{AR} } - 1))
|
||||
|| ($ar->{ $form->{sort} } ne $form->{AR}->[$idx + 1]->{ $form->{sort} }))) {
|
||||
push @{ $row_set }, create_subtotal_row(\%subtotals, \@columns, \%column_alignment, \@subtotal_columns, 'listsubtotal');
|
||||
}
|
||||
d319704a | Moritz Bunkus | |||
971c9727 | Moritz Bunkus | $report->add_data($row_set);
|
||
d319704a | Moritz Bunkus | |||
971c9727 | Moritz Bunkus | $idx++;
|
||
}
|
||||
d319704a | Moritz Bunkus | |||
971c9727 | Moritz Bunkus | $report->add_separator();
|
||
$report->add_data(create_subtotal_row(\%totals, \@columns, \%column_alignment, \@subtotal_columns, 'listtotal'));
|
||||
d319704a | Moritz Bunkus | |||
971c9727 | Moritz Bunkus | $report->generate_with_headers();
|
||
d319704a | Moritz Bunkus | |||
ebdc6e13 | Sven Schöling | $main::lxdebug->leave_sub();
|
||
d319704a | Moritz Bunkus | }
|
||
102600f0 | Sven Schöling | |||
sub storno {
|
||||
ebdc6e13 | Sven Schöling | $main::lxdebug->enter_sub();
|
||
$main::auth->assert('general_ledger');
|
||||
102600f0 | Sven Schöling | |||
ebdc6e13 | Sven Schöling | my $form = $main::form;
|
||
my %myconfig = %main::myconfig;
|
||||
my $locale = $main::locale;
|
||||
8c7e4493 | Moritz Bunkus | |||
1ae70a98 | Sven Schöling | # don't cancel cancelled transactions
|
||
102600f0 | Sven Schöling | if (IS->has_storno(\%myconfig, $form, 'ar')) {
|
||
$form->{title} = $locale->text("Cancel Accounts Receivables Transaction");
|
||||
$form->error($locale->text("Transaction has already been cancelled!"));
|
||||
}
|
||||
1ae70a98 | Sven Schöling | AR->storno($form, \%myconfig, $form->{id});
|
||
102600f0 | 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;
|
||
102600f0 | Sven Schöling | }
|
||
3b3ef5ba | Sven Schöling | # /saving the history
|
||
102600f0 | Sven Schöling | |||
3b3ef5ba | Sven Schöling | $form->redirect(sprintf $locale->text("Transaction %d cancelled."), $form->{storno_id});
|
||
1ae70a98 | Sven Schöling | |||
ebdc6e13 | Sven Schöling | $main::lxdebug->leave_sub();
|
||
102600f0 | Sven Schöling | }
|
||
2dacd279 | Sven Schöling | |||
1;
|