#======================================================================
use POSIX qw(strftime);
+use List::Util qw(sum);
use SL::AR;
+use SL::FU;
use SL::IS;
use SL::PE;
use SL::ReportGenerator;
sub add {
$lxdebug->enter_sub();
+ $auth->assert('general_ledger');
+
return $lxdebug->leave_sub() if (load_draft_maybe());
# saving the history
# /saving the history
$form->{title} = "Add";
- $form->{callback} =
- "$form->{script}?action=add&login=$form->{login}&password=$form->{password}"
- unless $form->{callback};
+ $form->{callback} = "ar.pl?action=add" unless $form->{callback};
AR->get_transdate(\%myconfig, $form);
$form->{initial_transdate} = $form->{transdate};
sub edit {
$lxdebug->enter_sub();
+
+ $auth->assert('general_ledger');
+
# show history button
$form->{javascript} = qq|<script type="text/javascript" src="js/show_history.js"></script>|;
#/show hhistory button
sub display_form {
$lxdebug->enter_sub();
+ $auth->assert('general_ledger');
+
&form_header;
&form_footer;
sub create_links {
$lxdebug->enter_sub();
+ $auth->assert('general_ledger');
+
my ($duedate, $taxincluded, @curr);
$form->create_links("AR", \%myconfig, "customer");
sub form_header {
$lxdebug->enter_sub();
+ $auth->assert('general_ledger');
+
my ($title, $readonly, $exchangerate, $rows);
my ($taxincluded, $notes, $department, $customer, $employee, $amount, $project);
my ($jsscript, $button1, $button2, $onload);
- my ($selectAR_amount, $selectAR_paid, $korrektur_checked, $ARselected, $tax);
+ my ($selectAR_amount, $selectAR_paid, $ARselected, $tax);
my (@column_index, %column_data);
s/option>\Q$form->{$item}\E/option selected>$form->{$item}/;
}
- $form->{exchangerate} = $exchangerate
- if (
- $form->{forex} = (
- $exchangerate =
- $form->check_exchangerate(
- \%myconfig, $form->{currency}, $form->{transdate}, 'buy'
- )));
+ $form->{forex} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{transdate}, 'buy');
+ $form->{exchangerate} = $form->{forex} if $form->{forex};
# format amounts
$form->{exchangerate} =
map({ push(@old_project_ids, $form->{"project_id_$_"})
if ($form->{"project_id_$_"}); } (1..$form->{"rowcount"}));
- $form->get_lists("projects" => { "key" => "ALL_PROJECTS",
- "all" => 0,
- "old_id" => \@old_project_ids },
- "charts" => { "key" => "ALL_CHARTS",
- "transdate" => $form->{transdate} },
- "taxcharts" => "ALL_TAXCHARTS");
+ $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" },);
map({ $_->{link_split} = [ split(/:/, $_->{link}) ]; }
@{ $form->{ALL_CHARTS} });
qq|<td><input name=duedate id=duedate size=11 title="$myconfig{dateformat}" value="$form->{duedate}" onBlur=\"check_right_date_format(this)\"></td>|;
}
+ 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/common.js"></script>| .
- qq|<script type="text/javascript" src="js/show_vc_details.js"></script>|;
+ qq|<script type="text/javascript" src="js/show_vc_details.js"></script>| .
+ qq|<script type="text/javascript" src="js/follow_up.js"></script>|;
$form->header;
$onload = qq|focus()|;
<input type=hidden name=closedto value=$form->{closedto}>
<input type=hidden name=locked value=$form->{locked}>
<input type=hidden name=title value="$title">
+<input type="hidden" name="follow_up_trans_id_1" value="| . H($form->{id}) . qq|">
+<input type="hidden" name="follow_up_trans_type_1" value="ar_transaction">
+<input type="hidden" name="follow_up_trans_info_1" value="| . H($follow_up_trans_info) . qq|">
+<input type="hidden" name="follow_up_rowcount" value="1">
| . ($form->{saved_message} ? qq|<p>$form->{saved_message}</p>| : "") . qq|
<th class=listheading style="width:10%">|
. $locale->text('Tax') . qq|</th>
<th class=listheading style="width:5%">|
- . $locale->text('Korrektur') . qq|</th>
- <th class=listheading style="width:10%">|
. $locale->text('Taxkey') . qq|</th>
<th class=listheading style="width:10%">|
. $locale->text('Project') . qq|</th>
'-default' => $selected_taxchart))
. qq|</td>|;
- $korrektur_checked = ($form->{"korrektur_$i"} ? 'checked' : '');
-
my $projectnumber =
NTI($cgi->popup_menu('-name' => "project_id_$i",
'-values' => \@project_values,
<tr>
<td>$selectAR_amount</td>
<td><input name="amount_$i" size=10 value=$form->{"amount_$i"}></td>
- <td><input name="tax_$i" size=10 value=$form->{"tax_$i"}></td>
- <td><input type="checkbox" name="korrektur_$i" value="1" $korrektur_checked></td>
+ <td><input type="hidden" name="tax_$i" value="$form->{"tax_$i"}">$form->{"tax_$i"}</td>
$tax
<td>$projectnumber</td>
</tr>
sub form_footer {
$lxdebug->enter_sub();
+ $auth->assert('general_ledger');
+
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>|;
+ }
+ }
+
print qq|
+$follow_ups_block
+
<input name=gldate type=hidden value="| . Q($form->{gldate}) . qq|">
<input name=callback type=hidden value="$form->{callback}">
-
-<input type=hidden name=login value=$form->{login}>
-<input type=hidden name=password value=$form->{password}>
|
. $cgi->hidden('-name' => 'draft_id', '-default' => [$form->{draft_id}])
. $cgi->hidden('-name' => 'draft_description', '-default' => [$form->{draft_description}])
<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 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) {
sub mark_as_paid {
$lxdebug->enter_sub();
+
+ $auth->assert('general_ledger');
+
&mark_as_paid_common(\%myconfig,"ar");
+
$lxdebug->leave_sub();
}
sub update {
$lxdebug->enter_sub();
+ $auth->assert('general_ledger');
+
my $display = shift;
my ($totaltax, $exchangerate, $totalpaid);
if ($form->{"amount_$i"}) {
push @a, {};
my $j = $#a;
- if (!$form->{"korrektur_$i"}) {
- 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;
- }
+ 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"} = 0;
+ $form->{"tax_$i"} = $form->{"amount_$i"} * $rate;
}
+ } else {
+ $form->{"tax_$i"} = 0;
}
$form->{"tax_$i"} = $form->round_amount($form->{"tax_$i"}, 2);
$form->{rowcount} = $count + 1;
map { $form->{invtotal} += $form->{"amount_$_"} } (1 .. $form->{rowcount});
- $form->{exchangerate} = $exchangerate
- if (
- $form->{forex} = (
- $exchangerate =
- $form->check_exchangerate(
- \%myconfig, $form->{currency}, $form->{transdate}, 'buy'
- )));
+ $form->{forex} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{transdate}, 'buy');
+ $form->{exchangerate} = $form->{forex} if $form->{forex};
$form->{invdate} = $form->{transdate};
my $save_AR = $form->{AR};
$totalpaid += $form->{"paid_$i"};
- $form->{"exchangerate_$i"} = $exchangerate
- if (
- $form->{"forex_$i"} = (
- $exchangerate =
- $form->check_exchangerate(
- \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy'
- )));
+ $form->{"forex_$i"} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy');
+ $form->{"exchangerate_$i"} = $form->{"forex_$i"} if $form->{"forex_$i"};
}
}
sub post_payment {
$lxdebug->enter_sub();
+ $auth->assert('general_ledger');
+
$form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
for my $i (1 .. $form->{paidaccounts}) {
$form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
-# $form->error($locale->text('Cannot post payment for a closed period!')) if ($datepaid <= $closedto);
+ $form->error($locale->text('Cannot post payment for a closed period!')) if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig));
if ($form->{currency} ne $form->{defaultcurrency}) {
# $form->{"exchangerate_$i"} = $form->{exchangerate} if ($invdate == $datepaid);
}
sub _post {
+
+ $auth->assert('general_ledger');
+
# inline post
post(1);
}
sub post {
$lxdebug->enter_sub();
+ $auth->assert('general_ledger');
+
my ($inline) = @_;
my ($datepaid);
my $closedto = $form->datetonum($form->{closedto}, \%myconfig);
my $transdate = $form->datetonum($form->{transdate}, \%myconfig);
- $form->error($locale->text('Cannot post transaction for a closed period!')) if ($transdate <= $closedto);
+ $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!'))
unless grep $_*1, map $form->parse_amount(\%myconfig, $form->{"amount_$_"}), 1..$form->{rowcount};
$form->isblank("datepaid_$i", $locale->text('Payment date missing!'));
$form->error($locale->text('Cannot post payment for a closed period!'))
- if ($datepaid <= $closedto);
+ if ($form->date_closed($form->{"datepaid_$i"}, \%myconfig));
if ($form->{currency} ne $form->{defaultcurrency}) {
$form->{"exchangerate_$i"} = $form->{exchangerate} if ($transdate == $datepaid);
sub post_as_new {
$lxdebug->enter_sub();
+ $auth->assert('general_ledger');
+
$form->{postasnew} = 1;
# saving the history
if(!exists $form->{addition} && $form->{id} ne "") {
sub use_as_template {
$lxdebug->enter_sub();
+ $auth->assert('general_ledger');
+
map { delete $form->{$_} } qw(printed emailed queued invnumber invdate deliverydate id datepaid_1 source_1 memo_1 paid_1 exchangerate_1 AP_paid_1 storno);
$form->{paidaccounts} = 1;
$form->{rowcount}--;
sub delete {
$lxdebug->enter_sub();
+ $auth->assert('general_ledger');
+
$form->{title} = $locale->text('Confirm!');
$form->header;
|;
foreach my $key (keys %$form) {
+ next if (($key eq 'login') || ($key eq 'password') || ('' ne ref $form->{$key}));
$form->{$key} =~ s/\"/"/g;
print qq|<input type=hidden name=$key value="$form->{$key}">\n|;
}
sub yes {
$lxdebug->enter_sub();
+
+ $auth->assert('general_ledger');
+
if (AR->delete_transaction(\%myconfig, \%$form)) {
# saving the history
if(!exists $form->{addition}) {
sub search {
$lxdebug->enter_sub();
+ $auth->assert('general_ledger | invoice_edit');
+
my ($customer, $department);
my ($jsscript, $button1, $button2, $onload);
<tr>
<td align=right><input name="l_notes" class=checkbox type=checkbox value=Y></td>
<td nowrap>| . $locale->text('Notes') . qq|</td>
- <td align=right><input name="l_employee" class=checkbox type=checkbox value=Y></td>
+ <td align=right><input name="l_salesman" class=checkbox type=checkbox value=Y></td>
<td nowrap>| . $locale->text('Salesperson') . qq|</td>
<td align=right><input name="l_shippingpoint" class=checkbox type=checkbox value=Y></td>
<td nowrap>| . $locale->text('Shipping Point') . qq|</td>
<td nowrap>| . $locale->text('Ship via') . qq|</td>
</tr>
<tr>
- <td align=right><input name="l_marge_total" class=checkbox type=checkbox value=Y></td><td> |
- . $locale->text('Ertrag') . qq|</td>
- <td align=right><input name="l_marge_percent" class=checkbox type=checkbox value=Y></td><td> |
- . $locale->text('Ertrag prozentual') . qq|</td>
+ <td align=right><input name="l_marge_total" class=checkbox type=checkbox value=Y></td>
+ <td nowrap> | . $locale->text('Ertrag') . qq|</td>
+ <td align=right><input name="l_marge_percent" class=checkbox type=checkbox value=Y></td>
+ <td nowrap> | . $locale->text('Ertrag prozentual') . qq|</td>
+ <td align=right><input name="l_employee" class=checkbox type=checkbox value=Y></td>
+ <td nowrap>| . $locale->text('Employee') . qq|</td>
</tr>
<tr>
<td align=right><input name="l_subtotal" class=checkbox type=checkbox value=Y></td>
<input type=hidden name=nextsub value=$form->{nextsub}>
-<input type=hidden name=login value=$form->{login}>
-<input type=hidden name=password value=$form->{password}>
-
<br>
<input class=submit type=submit name=action value="|
. $locale->text('Continue') . qq|">
sub ar_transactions {
$lxdebug->enter_sub();
+ $auth->assert('general_ledger | invoice_edit');
+
my ($callback, $href, @columns);
$form->{customer} = $form->unescape($form->{customer});
($form->{customer}, $form->{customer_id}) = split(/--/, $form->{customer});
- $form->{sort} ||= 'transdate';
+ report_generator_set_default_sort('transdate', 1);
AR->ar_transactions(\%myconfig, \%$form);
@columns =
qw(transdate id type invnumber ordnumber name netamount tax amount paid
- datepaid due duedate transaction_description notes employee shippingpoint shipvia
+ datepaid due duedate transaction_description notes salesman employee shippingpoint shipvia
marge_total marge_percent globalprojectnumber);
my @hidden_variables = map { "l_${_}" } @columns;
'duedate' => { 'text' => $locale->text('Due Date'), },
'transaction_description' => { 'text' => $locale->text('Transaction description'), },
'notes' => { 'text' => $locale->text('Notes'), },
- 'employee' => { 'text' => $locale->text('Salesperson'), },
+ 'salesman' => { 'text' => $locale->text('Salesperson'), },
+ 'employee' => { 'text' => $locale->text('Employee'), },
'shippingpoint' => { 'text' => $locale->text('Shipping Point'), },
'shipvia' => { 'text' => $locale->text('Ship via'), },
'globalprojectnumber' => { 'text' => $locale->text('Project Number'), },
'marge_percent' => { 'text' => $locale->text('Ertrag prozentual'), },
);
- foreach my $name (qw(id transdate duedate invnumber ordnumber name datepaid
- employee shippingpoint shipvia)) {
- $column_defs{$name}->{link} = $href . "&sort=$name";
+ foreach my $name (qw(id transdate duedate invnumber ordnumber name datepaid employee shippingpoint shipvia transaction_description)) {
+ my $sortdir = $form->{sort} eq $name ? 1 - $form->{sortdir} : $form->{sortdir};
+ $column_defs{$name}->{link} = $href . "&sort=$name&sortdir=$sortdir";
}
my %column_alignment = map { $_ => 'right' } qw(netamount tax amount paid due);
$report->set_export_options('ar_transactions', @hidden_variables);
- $report->set_sort_indicator($form->{sort}, 1);
+ $report->set_sort_indicator($form->{sort}, $form->{sortdir});
my @options;
if ($form->{customer}) {
push @options, $locale->text('Transaction description') . " : $form->{transaction_description}";
}
if ($form->{transdatefrom}) {
- push @options, $locale->text('From') . " " . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
+ push @options, $locale->text('From') . " " . $locale->date(\%myconfig, $form->{transdatefrom}, 1);
}
if ($form->{transdateto}) {
- push @options, $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{transdateto}, 1);
+ push @options, $locale->text('Bis') . " " . $locale->date(\%myconfig, $form->{transdateto}, 1);
}
if ($form->{open}) {
push @options, $locale->text('Open');
# escape callback for href
$callback = $form->escape($href);
- my @subtotal_columns = qw(netamount amount paid due marge_total);
+ my @subtotal_columns = qw(netamount amount paid due marge_total marge_percent);
my %totals = map { $_ => 0 } @subtotal_columns;
my %subtotals = map { $_ => 0 } @subtotal_columns;
map { $subtotals{$_} += $ar->{$_};
$totals{$_} += $ar->{$_} } @subtotal_columns;
+ $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};
+ my $is_storno = $ar->{storno} && $ar->{storno_id};
+ my $has_storno = $ar->{storno} && !$ar->{storno_id};
$ar->{type} =
$has_storno ? $locale->text("Invoice with Storno (abbreviation)") :
sub storno {
$lxdebug->enter_sub();
+ $auth->assert('general_ledger');
+
# don't cancel cancelled transactions
if (IS->has_storno(\%myconfig, $form, 'ar')) {
$form->{title} = $locale->text("Cancel Accounts Receivables Transaction");