# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
-# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA 02110-1335, USA.
#======================================================================
#
# Accounts Receivables
use POSIX qw(strftime);
use List::Util qw(sum first max);
+use List::UtilsBy qw(sort_by);
use SL::AR;
use SL::FU;
use SL::IS;
use SL::PE;
+use SL::DB::Default;
+use SL::DB::Invoice;
use SL::ReportGenerator;
require "bin/mozilla/arap.pl";
require "bin/mozilla/common.pl";
-require "bin/mozilla/drafts.pl";
require "bin/mozilla/reportgenerator.pl";
use strict;
sub add {
$main::lxdebug->enter_sub();
- $main::auth->assert('general_ledger');
+ $main::auth->assert('ar_transactions');
my $form = $main::form;
my %myconfig = %main::myconfig;
- return $main::lxdebug->leave_sub() if (load_draft_maybe());
-
# saving the history
if(!exists $form->{addition} && ($form->{id} ne "")) {
$form->{snumbers} = qq|invnumber_| . $form->{invnumber};
# /saving the history
$form->{title} = "Add";
- $form->{callback} = "ar.pl?action=add&DONT_LOAD_DRAFT=1" unless $form->{callback};
+ $form->{callback} = "ar.pl?action=add" unless $form->{callback};
AR->get_transdate(\%myconfig, $form);
$form->{initial_transdate} = $form->{transdate};
- &create_links;
+ create_links(dont_save => 1);
$form->{transdate} = $form->{initial_transdate};
&display_form;
$main::lxdebug->leave_sub();
sub edit {
$main::lxdebug->enter_sub();
- $main::auth->assert('general_ledger');
+ $main::auth->assert('ar_transactions');
my $form = $main::form;
$form->{javascript} .= qq|<script type="text/javascript" src="js/common.js"></script>|;
$form->{title} = "Edit";
- &create_links;
+ create_links();
&display_form;
$main::lxdebug->leave_sub();
sub display_form {
$main::lxdebug->enter_sub();
- $main::auth->assert('general_ledger');
+ $main::auth->assert('ar_transactions');
my $form = $main::form;
$main::lxdebug->leave_sub();
}
+sub _retrieve_invoice_object {
+ return undef if !$::form->{id};
+ return $::form->{invoice_obj} if $::form->{invoice_obj} && $::form->{invoice_obj}->id == $::form->{id};
+ return SL::DB::Invoice->new(id => $::form->{id})->load;
+}
+
sub create_links {
$main::lxdebug->enter_sub();
- $main::auth->assert('general_ledger');
+ $main::auth->assert('ar_transactions');
+ my %params = @_;
my $form = $main::form;
my %myconfig = %main::myconfig;
- my ($duedate, $taxincluded);
-
$form->create_links("AR", \%myconfig, "customer");
- $duedate = $form->{duedate};
+ $form->{invoice_obj} = _retrieve_invoice_object();
+
+ my %saved;
+ if (!$params{dont_save}) {
+ %saved = map { ($_ => $form->{$_}) } qw(direct_debit id taxincluded);
+ $saved{duedate} = $form->{duedate} if $form->{duedate};
+ $saved{currency} = $form->{currency} if $form->{currency};
+ }
- $taxincluded = $form->{taxincluded};
- my $id = $form->{id};
IS->get_customer(\%myconfig, \%$form);
- $form->{taxincluded} = $taxincluded;
- $form->{id} = $id;
- $form->{duedate} = $duedate if $duedate;
+ $form->{$_} = $saved{$_} for keys %saved;
$form->{oldcustomer} = "$form->{customer}--$form->{customer_id}";
$form->{rowcount} = 1;
- # notes
- $form->{notes} = $form->{intnotes} unless $form->{notes};
-
# currencies
$form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
+ $form->{selectcurrency} = "";
map { $form->{selectcurrency} .= "<option>$_\n" } $form->get_all_currencies(\%myconfig);
# customers
sub form_header {
$main::lxdebug->enter_sub();
- $main::auth->assert('general_ledger');
+ $main::auth->assert('ar_transactions');
my $form = $main::form;
my %myconfig = %main::myconfig;
my $locale = $main::locale;
my $cgi = $::request->{cgi};
+ $form->{invoice_obj} = _retrieve_invoice_object();
+
my ($title, $readonly, $exchangerate, $rows);
my ($notes, $department, $customer, $employee, $amount, $project);
- my ($onload);
my ($ARselected);
#/show history button js
$readonly = ($form->{id}) ? "readonly" : "";
- $form->{radier} = ($form->current_date(\%myconfig) eq $form->{gldate}) ? 1 : 0;
+ $form->{radier} = ($::instance_conf->get_ar_changeable == 2)
+ ? ($form->current_date(\%myconfig) eq $form->{gldate})
+ : ($::instance_conf->get_ar_changeable == 1);
$readonly = ($form->{radier}) ? "" : $readonly;
# set option selected
$form->{forex} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{transdate}, 'buy');
$form->{exchangerate} = $form->{forex} if $form->{forex};
+ # format exchangerate
+ $form->{exchangerate} = $form->{exchangerate} ? $form->format_amount(\%myconfig, $form->{exchangerate}) : '';
+
$rows = max 2, $form->numtextrows($form->{notes}, 50);
my @old_project_ids = grep { $_ } map { $form->{"project_id_$_"} } 1..$form->{rowcount};
$taxcharts{$item->{id}} = $item;
}
- $form->{fokus} = "arledger.customer";
-
my $follow_up_vc = $form->{customer};
$follow_up_vc =~ s/--.*?//;
my $follow_up_trans_info = "$form->{invnumber} ($follow_up_vc)";
$form->{javascript} .=
qq|<script type="text/javascript" src="js/show_vc_details.js"></script>| .
- qq|<script type="text/javascript" src="js/follow_up.js"></script>|;
-
- $onload = qq|focus()|;
- $onload .= qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|;
+ qq|<script type="text/javascript" src="js/follow_up.js"></script>| .
+ qq|<script type="text/javascript" src="js/kivi.Draft.js"></script>|;
# $amount = $locale->text('Amount');
# $project = $locale->text('Project');
for my $i (1 .. $form->{rowcount}) {
my $transaction = {
amount => $form->{"amount_$i"},
- tax => $form->{"tax$i"},
- project_id => $form->{"project_id_$i"},
+ tax => $form->{"tax_$i"},
+ project_id => ($i==$form->{rowcount}) ? $form->{globalproject_id} : $form->{"project_id_$i"},
};
my $selected_accno_full;
. $cgi->hidden('-name' => "previous_AR_amount_$i",
'-default' => $selected_accno_full);
- $transaction->{tax} =
+ $transaction->{taxchart} =
NTI($cgi->popup_menu('-name' => "taxchart_$i",
'-id' => "taxchart_$i",
'-style' => 'width:200px',
gldate => $form->{"gldate_$i"},
};
+ # default account for current assets (i.e. 1801 - SKR04) if no account is selected
+ $form->{accno_arap} = IS->get_standard_accno_current_assets(\%myconfig, \%$form);
+
$payment->{selectAR_paid} =
NTI($cgi->popup_menu('-name' => "AR_paid_$i",
'-id' => "AR_paid_$i",
'-values' => \@AR_paid_values,
'-labels' => \%chart_labels,
- '-default' => $payment->{AR_paid}));
+ '-default' => $payment->{AR_paid} || $form->{accno_arap}));
$payment->{changeable} =
- $::lx_office_conf{features}->{payments_changeable} == 0 ? !$payment->{acc_trans_id} # never
- : $::lx_office_conf{features}->{payments_changeable} == 2 ? $payment->{gldate} eq '' || $payment->{gldate} eq $now
+ 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
: 1;
+ #deaktivieren von gebuchten Zahlungen ausserhalb der Bücherkontrolle, vorher prüfen ob heute eingegeben
+ if ($form->date_closed($payment->{"gldate_$i"})) {
+ $payment->{changeable} = 0;
+ }
+
push @payments, $payment;
}
+ my @empty = grep { $_->{paid} eq '' } @payments;
+ @payments = (
+ (sort_by { DateTime->from_kivitendo($_->{datepaid}) } grep { $_->{paid} ne '' } @payments),
+ @empty,
+ );
+
$form->{totalpaid} = sum map { $_->{paid} } @payments;
$form->header;
project_labels => \%project_labels,
rows => $rows,
ARselected => $ARselected,
- onload => $onload,
title_str => $title,
follow_up_trans_info => $follow_up_trans_info,
+ today => DateTime->today,
});
$main::lxdebug->leave_sub();
sub form_footer {
$main::lxdebug->enter_sub();
- $main::auth->assert('general_ledger');
+ $main::auth->assert('ar_transactions');
my $form = $main::form;
my %myconfig = %main::myconfig;
my $locale = $main::locale;
my $cgi = $::request->{cgi};
- my ($transdate, $closedto);
-
- my $follow_ups_block;
- if ($form->{id}) {
- my $follow_ups = FU->follow_ups('trans_id' => $form->{id});
-
- if (@{ $follow_ups} ) {
- my $num_due = sum map { $_->{due} * 1 } @{ $follow_ups };
- $follow_ups_block = qq|<p>| . $locale->text("There are #1 unfinished follow-ups of which #2 are due.", scalar @{ $follow_ups }, $num_due) . qq|</p>|;
+ if ( $form->{id} ) {
+ my $follow_ups = FU->follow_ups('trans_id' => $form->{id}, 'not_done' => 1);
+ if ( @{ $follow_ups} ) {
+ $form->{follow_up_length} = scalar(@{$follow_ups});
+ $form->{follow_up_due_length} = sum(map({ $_->{due} * 1 } @{ $follow_ups }));
}
}
- print qq|
-
-$follow_ups_block
-
-<input name=gldate type=hidden value="| . Q($form->{gldate}) . qq|">
-
-<input name=callback type=hidden value="$form->{callback}">
-|
-. $cgi->hidden('-name' => 'draft_id', '-default' => [$form->{draft_id}])
-. $cgi->hidden('-name' => 'draft_description', '-default' => [$form->{draft_description}])
-. qq|
-
-<br>
-|;
-
- if (!$form->{id} && $form->{draft_id}) {
- print(NTI($cgi->checkbox('-name' => 'remove_draft', '-id' => 'remove_draft',
- '-value' => 1, '-checked' => $form->{remove_draft},
- '-label' => '')) .
- qq| <label for="remove_draft">| .
- $locale->text("Remove draft when posting") .
- qq|</label><br>|);
- }
-
- $transdate = $form->datetonum($form->{transdate}, \%myconfig);
- $closedto = $form->datetonum($form->{closedto}, \%myconfig);
+ my $transdate = $form->datetonum($form->{transdate}, \%myconfig);
+ my $closedto = $form->datetonum($form->{closedto}, \%myconfig);
- print qq|<input class="submit" type="submit" name="action" id="update_button" value="| . $locale->text('Update') . qq|">\n|;
+ $form->{is_closed} = $transdate <= $closedto;
# ToDO: - insert a global check for stornos, so that a storno is only possible a limited time after saving it
- print qq| <input class=submit type=submit name=action value="| . $locale->text('Storno') . qq|"> |
- if ($form->{id} && !IS->has_storno(\%myconfig, $form, 'ar') && !IS->is_storno(\%myconfig, $form, 'ar') && (($form->{totalpaid} == 0) || ($form->{totalpaid} eq "")));
-
- if ($form->{id}) {
- if ($form->{radier}) {
- print qq|
- <input class=submit type=submit name=action value="| . $locale->text('Post') . qq|">
- <input class=submit type=submit name=action value="| . $locale->text('Delete') . qq|"> |;
- }
- if ($transdate > $closedto) {
- print qq|
- <input class=submit type=submit name=action value="| . $locale->text('Use As Template') . qq|"> |;
- }
- print qq|
- <input class=submit type=submit name=action value="| . $locale->text('Post Payment') . qq|">
- <input type="button" class="submit" onclick="follow_up_window()" value="|
- . $locale->text('Follow-Up')
- . qq|"> |;
-
- } else {
- if ($transdate > $closedto) {
- print qq| <input class=submit type=submit name=action value="| . $locale->text('Post') . qq|"> | .
- NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'), '-class' => 'submit'));
- }
- }
-
- if ($form->{menubar}) {
- require "bin/mozilla/menu.pl";
- &menubar;
- }
- # button for saving history
- if($form->{id} ne "") {
- print qq| <input type=button class=submit onclick=set_history_window($form->{id}); name=history id=history value=| . $locale->text('history') . qq|> |;
- }
- # /button for saving history
- # mark_as_paid button
- if($form->{id} ne "") {
- print qq|<input type="submit" class="submit" name="action" value="|
- . $locale->text('mark as paid') . qq|">|;
- }
- # /mark_as_paid button
+ $form->{show_storno_button} =
+ $form->{id} &&
+ !IS->has_storno(\%myconfig, $form, 'ar') &&
+ !IS->is_storno(\%myconfig, $form, 'ar') &&
+ ($form->{totalpaid} == 0 || $form->{totalpaid} eq "");
- print "
-</form>
+ $form->{show_mark_as_paid_button} = $form->{id} && $::instance_conf->get_ar_show_mark_as_paid();
-</body>
-</html>
-";
+ print $::form->parse_html_template('ar/form_footer');
$main::lxdebug->leave_sub();
}
sub mark_as_paid {
$main::lxdebug->enter_sub();
- $main::auth->assert('general_ledger');
+ $main::auth->assert('ar_transactions');
my $form = $main::form;
my %myconfig = %main::myconfig;
sub update {
$main::lxdebug->enter_sub();
- $main::auth->assert('general_ledger');
+ $main::auth->assert('ar_transactions');
my $form = $main::form;
my %myconfig = %main::myconfig;
for my $i (1 .. $form->{rowcount}) {
$form->{"amount_$i"} = $form->parse_amount(\%myconfig, $form->{"amount_$i"});
- $form->{"tax_$i"} = $form->parse_amount(\%myconfig, $form->{"tax_$i"});
if ($form->{"amount_$i"}) {
push @a, {};
my $j = $#a;
my ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"});
- if ($taxkey > 1) {
- if ($form->{taxincluded}) {
- $form->{"tax_$i"} = $form->{"amount_$i"} / ($rate + 1) * $rate;
- } else {
- $form->{"tax_$i"} = $form->{"amount_$i"} * $rate;
- }
- } else {
- $form->{"tax_$i"} = 0;
- }
- $form->{"tax_$i"} = $form->round_amount($form->{"tax_$i"}, 2);
+
+ my $tmpnetamount;
+ ($tmpnetamount,$form->{"tax_$i"}) = $form->calculate_tax($form->{"amount_$i"},$rate,$form->{taxincluded},2);
$totaltax += $form->{"tax_$i"};
map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds;
$form->{invdate} = $form->{transdate};
- $form->{invdate} = $form->{transdate};
-
- my %saved_variables = map +( $_ => $form->{$_} ), qw(AR AR_amount_1 taxchart_1 customer_id);
+ my %saved_variables = map +( $_ => $form->{$_} ), qw(AR AR_amount_1 taxchart_1 customer_id notes);
&check_name("customer");
- # check_name loads customer notes into notes, but ar only knows intnotes, so copy them
- $form->{notes} = $form->{intnotes} if $saved_variables{customer_id} != $form->{customer_id};
-
$form->{AR} = $saved_variables{AR};
if ($saved_variables{AR_amount_1} =~ m/.--./) {
map { $form->{$_} = $saved_variables{$_} } qw(AR_amount_1 taxchart_1);
sub post_payment {
$main::lxdebug->enter_sub();
- $main::auth->assert('general_ledger');
+ $main::auth->assert('ar_transactions');
my $form = $main::form;
my %myconfig = %main::myconfig;
my $locale = $main::locale;
+ $form->mtime_ischanged('ar');
$form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
my $invdate = $form->datetonum($form->{transdate}, \%myconfig);
$form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
- $form->error($locale->text('Cannot post payment for a closed period!')) if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig));
+ $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)
+ $form->error($locale->text('Cannot post payment for a closed period!'))
+ if ($form->date_closed($form->{"datepaid_$i"}) && !$form->date_closed($form->{"gldate_$i"}, \%myconfig));
if ($form->{defaultcurrency} && ($form->{currency} ne $form->{defaultcurrency})) {
# $form->{"exchangerate_$i"} = $form->{exchangerate} if ($invdate == $datepaid);
($form->{AR}) = split /--/, $form->{AR};
($form->{AR_paid}) = split /--/, $form->{AR_paid};
- $form->redirect($locale->text('Payment posted!')) if (AR->post_payment(\%myconfig, \%$form));
- $form->error($locale->text('Cannot post payment!'));
+ 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!'));
+ };
$main::lxdebug->leave_sub();
}
sub _post {
- $main::auth->assert('general_ledger');
+ $main::auth->assert('ar_transactions');
my $form = $main::form;
sub post {
$main::lxdebug->enter_sub();
- $main::auth->assert('general_ledger');
+ $main::auth->assert('ar_transactions');
my $form = $main::form;
my %myconfig = %main::myconfig;
my ($inline) = @_;
+ $form->mtime_ischanged('ar');
+
my ($datepaid);
# check if there is an invoice number, invoice and due date
my $closedto = $form->datetonum($form->{closedto}, \%myconfig);
my $transdate = $form->datetonum($form->{transdate}, \%myconfig);
+
+ $form->error($locale->text('Cannot post transaction above the maximum future booking date!'))
+ if ($form->date_max_future($transdate, \%myconfig));
+
$form->error($locale->text('Cannot post transaction for a closed period!')) if ($form->date_closed($form->{"transdate"}, \%myconfig));
$form->error($locale->text('Zero amount posting!'))
$form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
+ $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)
$form->error($locale->text('Cannot post payment for a closed period!'))
- if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig));
+ if ($form->date_closed($form->{"datepaid_$i"}) && !$form->date_closed($form->{"gldate_$i"}, \%myconfig));
if ($form->{defaultcurrency} && ($form->{currency} ne $form->{defaultcurrency})) {
$form->{"exchangerate_$i"} = $form->{exchangerate} if ($transdate == $datepaid);
my ($customer) = split /--/, $form->{customer};
if ($form->{oldcustomer} ne "$customer--$form->{customer_id}") {
update();
- ::end_of_request();
+ $::dispatcher->end_request;
}
$form->{AR}{receivables} = $form->{ARselected};
# saving the history
if(!exists $form->{addition} && $form->{id} ne "") {
- $form->{snumbers} = "invnumber_$form->{invnumber}";
- $form->{addition} = "POSTED";
+ $form->{snumbers} = "invnumber_$form->{invnumber}";
+ $form->{what_done} = "invoice";
+ $form->{addition} = "POSTED";
$form->save_history;
}
# /saving the history
- remove_draft() if $form->{remove_draft};
$form->redirect($locale->text('Transaction posted!')) unless $inline;
sub post_as_new {
$main::lxdebug->enter_sub();
- $main::auth->assert('general_ledger');
+ $main::auth->assert('ar_transactions');
my $form = $main::form;
my %myconfig = %main::myconfig;
$form->{postasnew} = 1;
# saving the history
if(!exists $form->{addition} && $form->{id} ne "") {
- $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
- $form->{addition} = "POSTED AS NEW";
+ $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
+ $form->{what_done} = "invoice";
+ $form->{addition} = "POSTED AS NEW";
$form->save_history;
}
# /saving the history
$main::lxdebug->leave_sub();
}
-sub use_as_template {
+sub use_as_new {
$main::lxdebug->enter_sub();
- $main::auth->assert('general_ledger');
+ $main::auth->assert('ar_transactions');
my $form = $main::form;
my %myconfig = %main::myconfig;
sub delete {
$main::lxdebug->enter_sub();
- $main::auth->assert('general_ledger');
+ $main::auth->assert('ar_transactions');
my $form = $main::form;
my $locale = $main::locale;
delete $form->{header};
print qq|
-<body>
-
<form method=post action=$form->{script}>
|;
<input name=action class=submit type=submit value="|
. $locale->text('Yes') . qq|">
</form>
-
-</body>
-</html>
|;
$main::lxdebug->leave_sub();
sub yes {
$main::lxdebug->enter_sub();
- $main::auth->assert('general_ledger');
+ $main::auth->assert('ar_transactions');
my $form = $main::form;
my %myconfig = %main::myconfig;
if (AR->delete_transaction(\%myconfig, \%$form)) {
# saving the history
if(!exists $form->{addition}) {
- $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
- $form->{addition} = "DELETED";
+ $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
+ $form->{what_done} = "invoice";
+ $form->{addition} = "DELETED";
$form->save_history;
}
# /saving the history
sub search {
$main::lxdebug->enter_sub();
- $main::auth->assert('general_ledger | invoice_edit');
+ $main::auth->assert('invoice_edit');
my $form = $main::form;
my %myconfig = %main::myconfig;
my $locale = $main::locale;
my $cgi = $::request->{cgi};
- my ($customer, $department);
- my ($jsscript, $button1, $button2, $onload);
-
# setup customer selection
$form->all_vc(\%myconfig, "customer", "AR");
$form->{title} = $locale->text('AR Transactions');
- $form->{jsscript} = 1;
# 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");
- $form->{ALL_EMPLOYEES} = SL::DB::Manager::Employee->get_all(query => [ deleted => 0 ]);
+ $form->{ALL_EMPLOYEES} = SL::DB::Manager::Employee->get_all_sorted(query => [ deleted => 0 ]);
$form->{SHOW_BUSINESS_TYPES} = scalar @{ $form->{ALL_BUSINESS_TYPES} } > 0;
+ $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');
+
# constants and subs for template
- $form->{jsscript} = 1;
$form->{vc_keys} = sub { "$_[0]->{name}--$_[0]->{id}" };
$form->header;
sub ar_transactions {
$main::lxdebug->enter_sub();
- $main::auth->assert('general_ledger | invoice_edit');
+ $main::auth->assert('invoice_edit');
my $form = $main::form;
my %myconfig = %main::myconfig;
my $report = SL::ReportGenerator->new(\%myconfig, $form);
@columns =
- qw(transdate id type invnumber ordnumber name netamount tax amount paid
+ qw(ids transdate id type invnumber ordnumber cusordnumber name netamount tax amount paid
datepaid due duedate transaction_description notes salesman employee shippingpoint shipvia
- marge_total marge_percent globalprojectnumber customernumber country ustid taxzone payment_terms charts customertype);
+ marge_total marge_percent globalprojectnumber customernumber country ustid taxzone
+ payment_terms charts customertype direct_debit dunning_description department);
+
+ 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;
my @hidden_variables = map { "l_${_}" } @columns;
- push @hidden_variables, "l_subtotal", qw(open closed customer invnumber ordnumber transaction_description notes project_id transdatefrom transdateto employee_id salesman_id business_id);
+ 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 parts_partnumber parts_description department_id);
+ push @hidden_variables, map { "cvar_$_->{name}" } @ct_searchable_custom_variables;
$href = build_std_url('action=ar_transactions', grep { $form->{$_} } @hidden_variables);
my %column_defs = (
+ 'ids' => { raw_header_data => $::request->presenter->checkbox_tag("", id => "check_all", checkall => "[data-checkall=1]"), align => 'center' },
'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'), },
+ 'cusordnumber' => { 'text' => $locale->text('Customer Order Number'), },
'name' => { 'text' => $locale->text('Customer'), },
'netamount' => { 'text' => $locale->text('Amount'), },
'tax' => { 'text' => $locale->text('Tax'), },
'payment_terms' => { 'text' => $locale->text('Payment Terms'), },
'charts' => { 'text' => $locale->text('Buchungskonto'), },
'customertype' => { 'text' => $locale->text('Customer type'), },
+ 'direct_debit' => { 'text' => $locale->text('direct debit'), },
+ 'department' => { 'text' => $locale->text('Department'), },
+ dunning_description => { 'text' => $locale->text('Dunning level'), },
+ %column_defs_cvars,
);
- foreach my $name (qw(id transdate duedate invnumber ordnumber name datepaid employee shippingpoint shipvia transaction_description)) {
+ foreach my $name (qw(id transdate duedate invnumber ordnumber cusordnumber name datepaid employee shippingpoint shipvia transaction_description direct_debit)) {
my $sortdir = $form->{sort} eq $name ? 1 - $form->{sortdir} : $form->{sortdir};
$column_defs{$name}->{link} = $href . "&sort=$name&sortdir=$sortdir";
}
$form->{"l_type"} = "Y";
map { $column_defs{$_}->{visible} = $form->{"l_${_}"} ? 1 : 0 } @columns;
+ $column_defs{ids}->{visible} = 'HTML';
+
$report->set_columns(%column_defs);
$report->set_column_order(@columns);
$report->set_sort_indicator($form->{sort}, $form->{sortdir});
+ CVar->add_custom_variables_to_report('module' => 'CT',
+ 'trans_id_field' => 'customer_id',
+ 'configs' => $ct_cvar_configs,
+ 'column_defs' => \%column_defs,
+ 'data' => $form->{AR});
+
my @options;
if ($form->{customer}) {
push @options, $locale->text('Customer') . " : $form->{customer}";
}
+ if ($form->{cp_name}) {
+ push @options, $locale->text('Contact Person') . " : $form->{cp_name}";
+ }
+
+ # $form->{department} seems to never be filled, and showing the department_id
+ # at the top of the report doesn't make much sense.
+ # So determine the department name from the id whenever we have a filter for
+ # department
if ($form->{department}) {
my ($department) = split /--/, $form->{department};
push @options, $locale->text('Department') . " : $department";
}
if ($form->{department_id}) {
- push @options, $locale->text('Department Id') . " : $form->{department_id}";
+ # push @options, $locale->text('Department Id') . " : $form->{department_id}";
+ unless ($form->{department}) {
+ require SL::DB::Department;
+ my $department = SL::DB::Manager::Department->find_by(id => $::form->{department_id});
+ push @options, $locale->text('Department') . " : " . $department->description if $department;
+ }
}
if ($form->{invnumber}) {
push @options, $locale->text('Invoice Number') . " : $form->{invnumber}";
if ($form->{ordnumber}) {
push @options, $locale->text('Order Number') . " : $form->{ordnumber}";
}
+ if ($form->{cusordnumber}) {
+ push @options, $locale->text('Customer Order Number') . " : $form->{cusordnumber}";
+ }
if ($form->{notes}) {
push @options, $locale->text('Notes') . " : $form->{notes}";
}
if ($form->{transaction_description}) {
push @options, $locale->text('Transaction description') . " : $form->{transaction_description}";
}
+ if ($form->{parts_partnumber}) {
+ push @options, $locale->text('Part Number') . " : $form->{parts_partnumber}";
+ }
+ if ($form->{parts_description}) {
+ push @options, $locale->text('Part Description') . " : $form->{parts_description}";
+ }
if ($form->{transdatefrom}) {
push @options, $locale->text('From') . " " . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
}
push @options, $locale->text('Closed');
}
+ $form->{ALL_PRINTERS} = SL::DB::Manager::Printer->get_all_sorted;
+
$report->set_options('top_info_text' => join("\n", @options),
+ 'raw_top_info_text' => $form->parse_html_template('ar/ar_transactions_header'),
'raw_bottom_info_text' => $form->parse_html_template('ar/ar_transactions_bottom'),
'output_format' => 'HTML',
'title' => $form->{title},
$subtotals{marge_percent} = $subtotals{netamount} ? ($subtotals{marge_total} * 100 / $subtotals{netamount}) : 0;
$totals{marge_percent} = $totals{netamount} ? ($totals{marge_total} * 100 / $totals{netamount} ) : 0;
- map { $ar->{$_} = $form->format_amount(\%myconfig, $ar->{$_}, 2) } qw(netamount tax amount paid due marge_total marge_percent);
-
my $is_storno = $ar->{storno} && $ar->{storno_id};
my $has_storno = $ar->{storno} && !$ar->{storno_id};
$ar->{invoice} ? $locale->text("Invoice (one letter abbreviation)") :
$locale->text("AR Transaction (abbreviation)");
+ map { $ar->{$_} = $form->format_amount(\%myconfig, $ar->{$_}, 2) } qw(netamount tax amount paid due marge_total marge_percent);
+
+ $ar->{direct_debit} = $ar->{direct_debit} ? $::locale->text('yes') : $::locale->text('no');
+
my $row = { };
foreach my $column (@columns) {
$row->{invnumber}->{link} = build_std_url("script=" . ($ar->{invoice} ? 'is.pl' : 'ar.pl'), 'action=edit')
. "&id=" . E($ar->{id}) . "&callback=${callback}";
+ $row->{ids} = {
+ raw_data => $::request->presenter->checkbox_tag("id[]", value => $ar->{id}, "data-checkall" => 1),
+ valign => 'center',
+ align => 'center',
+ };
+
my $row_set = [ $row ];
if (($form->{l_subtotal} eq 'Y')
sub storno {
$main::lxdebug->enter_sub();
- $main::auth->assert('general_ledger');
+ $main::auth->assert('ar_transactions');
my $form = $main::form;
my %myconfig = %main::myconfig;
# saving the history
if(!exists $form->{addition} && $form->{id} ne "") {
- $form->{snumbers} = "ordnumber_$form->{ordnumber}";
- $form->{addition} = "STORNO";
+ $form->{snumbers} = qq|invnumber_| . $form->{invnumber};
+ $form->{addition} = "STORNO";
+ $form->{what_done} = "invoice";
$form->save_history;
}
# /saving the history