"; if ( $form->{audittrail} ) { $msg .= $locale->text('Audit trail enabled'); } else { $msg .= $locale->text('Audit trail disabled'); } ##SC: Disabling audit trail deletion ## $msg .= "
";
## if ( $form->{removeaudittrail} ) {
## $msg .=
## $locale->text('Audit trail removed up to') . " "
## . $locale->date( \%myconfig, $form->{removeaudittrail}, 1 );
## }
$form->redirect($msg);
}
sub add_warehouse {
$form->{title} = "Add";
$form->{callback} =
"$form->{script}?action=add_warehouse&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"
unless $form->{callback};
my %hiddens;
my @buttons;
my $rows = &warehouse_header(\%hiddens);
&form_footer_buttons(\%hiddens, \@buttons);
my $template = LedgerSMB::Template->new_UI(
user => \%myconfig,
locale => $locale,
template => 'am-warehouse-form');
$template->render({
form => $form,
row_count => $rows,
buttons => \@buttons,
hiddens => \%hiddens,
});
}
sub edit_warehouse {
$form->{title} = "Edit";
AM->get_warehouse( \%myconfig, \%$form );
my %hiddens;
my @buttons;
my $rows = &warehouse_header(\%hiddens);
&form_footer_buttons(\%hiddens, \@buttons);
my $template = LedgerSMB::Template->new_UI(
user => \%myconfig,
locale => $locale,
template => 'am-warehouse-form');
$template->render({
form => $form,
row_count => $rows,
buttons => \@buttons,
hiddens => \%hiddens,
});
}
sub list_warehouse {
AM->warehouses( \%myconfig, \%$form );
my %hiddens;
my $href =
"$form->{script}?action=list_warehouse&direction=$form->{direction}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
$form->sort_order();
$form->{callback} =
"$form->{script}?action=list_warehouse&direction=$form->{direction}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
my $callback = $form->escape( $form->{callback} );
$form->{title} = $locale->text('Warehouses');
my @column_index = qw(description);
my %column_header;
$column_header{description} = {
href => $href,
text => $locale->text('Description'),
};
my @rows;
my $i;
foreach my $ref ( @{ $form->{ALL} } ) {
my %column_data;
$i++;
$i %= 2;
$column_data{i} = $i;
$column_data{description} = {
href => "$form->{script}?action=edit_warehouse&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback",
text => $ref->{description},
};
push @rows, \%column_data;
}
$form->{type} = "warehouse";
$hiddens{$_} = $form->{$_} foreach qw(type callback path login sessionid);
##SC: Temporary commenting
## if ( $form->{lynx} ) {
## require "bin/menu.pl";
## &menubar;
## }
my @buttons = ({
name => 'action',
value => 'add_warehouse',
text => $locale->text('Add Warehouse'),
});
my $template = LedgerSMB::Template->new_UI(
user => \%myconfig,
locale => $locale,
template => 'form-dynatable');
$template->render({
form => $form,
buttons => \@buttons,
hiddens => \%hiddens,
columns => \@column_index,
heading => \%column_header,
rows => \@rows,
});
}
sub warehouse_header {
my $hiddens = shift;
$form->{title} = $locale->text("$form->{title} Warehouse");
# $locale->text('Add Warehouse')
# $locale->text('Edit Warehouse')
$form->{description} = $form->quote( $form->{description} );
$hiddens->{id} = $form->{id};
$hiddens->{type} = 'warehouse';
my $rows = $form->numtextrows( $form->{description}, 60 );
$rows;
}
sub save_warehouse {
$form->isblank( "description", $locale->text('Description missing!') );
AM->save_warehouse( \%myconfig, \%$form );
$form->redirect( $locale->text('Warehouse saved!') );
}
sub delete_warehouse {
AM->delete_warehouse( \%myconfig, \%$form );
$form->redirect( $locale->text('Warehouse deleted!') );
}
sub yearend {
AM->earningsaccounts( \%myconfig, \%$form );
my %hiddens;
my $chart = "";
my %accounts = (
name => 'accno',
options => [],
);
for ( @{ $form->{chart} } ) {
push @{$accounts{options}}, {
text => "$_->{accno}--$_->{description}",
value => "$_->{accno}--$_->{description}",
};
}
$form->{title} = $locale->text('Yearend');
$hiddens{decimalplaces} = 2;
$hiddens{l_accno} = 'Y';
$hiddens{$_} = $form->{$_} foreach qw(path login sessionid);
my @buttons = ({
name => 'action',
value => 'generate_yearend',
text => $locale->text('Continue'),
});
my $template = LedgerSMB::Template->new_UI(
user => \%myconfig,
locale => $locale,
template => 'am-yearend');
$template->render({
user => \%myconfig,
form => $form,
buttons => \@buttons,
hiddens => \%hiddens,
accounts => \%accounts,
});
}
sub generate_yearend {
$form->isblank( "todate", $locale->text('Yearend date missing!') );
RP->yearend_statement( \%myconfig, \%$form );
$form->{transdate} = $form->{todate};
$earnings = 0;
$form->{rowcount} = 1;
foreach $key ( keys %{ $form->{I} } ) {
if ( $form->{I}{$key}{charttype} eq "A" ) {
$form->{"debit_$form->{rowcount}"} = $form->{I}{$key}{this};
$earnings += $form->{I}{$key}{this};
$form->{"accno_$form->{rowcount}"} = $key;
$form->{rowcount}++;
$ok = 1;
}
}
foreach $key ( keys %{ $form->{E} } ) {
if ( $form->{E}{$key}{charttype} eq "A" ) {
$form->{"credit_$form->{rowcount}"} = $form->{E}{$key}{this} * -1;
$earnings += $form->{E}{$key}{this};
$form->{"accno_$form->{rowcount}"} = $key;
$form->{rowcount}++;
$ok = 1;
}
}
if ( $earnings > 0 ) {
$form->{"credit_$form->{rowcount}"} = $earnings;
$form->{"accno_$form->{rowcount}"} = $form->{accno};
}
else {
$form->{"debit_$form->{rowcount}"} = $earnings * -1;
$form->{"accno_$form->{rowcount}"} = $form->{accno};
}
if ($ok) {
if ( AM->post_yearend( \%myconfig, \%$form ) ) {
$form->redirect( $locale->text('Yearend posted!') );
}
else {
$form->error( $locale->text('Yearend posting failed!') );
}
}
else {
$form->error('Nothing to do!');
}
}
sub company_logo {
$myconfig{address} =~ s/\\n/
/g; # Template cleans this up
$myconfig{dbhost} = $locale->text('localhost') unless $myconfig{dbhost};
$form->{stylesheet} = $myconfig{stylesheet};
$form->{title} = $locale->text('About');
# create the logo screen
my $template = LedgerSMB::Template->new_UI(
user => \%myconfig,
locale => $locale,
template => 'am-company-logo');
$template->render({
form => $form,
user => \%myconfig,
});
}
sub recurring_transactions {
# $locale->text('Day')
# $locale->text('Days')
# $locale->text('Month')
# $locale->text('Months')
# $locale->text('Week')
# $locale->text('Weeks')
# $locale->text('Year')
# $locale->text('Years')
my %hiddens;
my %column_header;
$form->{stylesheet} = $myconfig{stylesheet};
$form->{title} = $locale->text('Recurring Transactions');
$column_header{id} = "";
AM->recurring_transactions( \%myconfig, \%$form );
$href = "$form->{script}?action=recurring_transactions";
for (qw(direction oldsort path login sessionid)) {
$href .= qq|&$_=$form->{$_}|;
}
$form->sort_order();
my @column_index = qw(ndx reference description);
push @column_index,
qw(nextdate enddate id amount curr repeat howmany recurringemail recurringprint);
$column_header{reference} = {
text => $locale->text('Reference'),
href => "$href&sort=reference",
};
$column_header{ndx} = ' ';
$column_header{id} = $locale->text('ID');
$column_header{description} = $locale->text('Description');
$column_header{nextdate} = {
text => $locale->text('Next'),
href => "$href&sort=nextdate",
};
$column_header{enddate} = {
text => $locale->text('Ends'),
href => "$href&sort=enddate",
};
$column_header{amount} = $locale->text('Amount');
$column_header{curr} = ' ';
$column_header{repeat} = $locale->text('Every');
$column_header{howmany} = $locale->text('Times');
$column_header{recurringemail} = $locale->text('E-mail');
$column_header{recurringprint} = $locale->text('Print');
my $i = 1;
my %tr = (
ar => $locale->text('AR'),
ap => $locale->text('AP'),
gl => $locale->text('GL'),
so => $locale->text('Sales Orders'),
po => $locale->text('Purchase Orders'),
);
my %f = &formnames;
my @transactions;
my $j;
my $k;
foreach my $transaction ( sort keys %{ $form->{transactions} } ) {
my $transaction_count = scalar( @{ $form->{transactions}{$transaction} } );
push @transactions, {type => $transaction,
title => "$tr{$transaction} ($transaction_count)",
transactions => [],
};
foreach my $ref ( @{ $form->{transactions}{$transaction} } ) {
my %column_data;
for (@column_index) {
$column_data{$_} = "$ref->{$_}";
}
my $unit;
my $repeat;
if ( $ref->{repeat} > 1 ) {
$unit = $locale->text( ucfirst $ref->{unit} );
$repeat = "$ref->{repeat} $unit";
}
else {
chop $ref->{unit};
$unit = $locale->text( ucfirst $ref->{unit} );
$repeat = $unit;
}
$column_data{ndx} = '';
if ( !$ref->{expired} ) {
if ( $ref->{overdue} <= 0 ) {
$k++;
$column_data{ndx} = {
name => "ndx_$k",
type => 'checkbox',
value => $ref->{id},
checked => 'checked',
};
}
}
my $reference =
( $ref->{reference} )
? $ref->{reference}
: $locale->text('Next Number');
$column_data{reference} = {
text => $reference,
href => qq|$form->{script}?action=edit_recurring&id=$ref->{id}&vc=$ref->{vc}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&module=$ref->{module}&invoice=$ref->{invoice}&transaction=$ref->{transaction}&recurringnextdate=$ref->{nextdate}|,
};
my $module = "$ref->{module}.pl";
my $type = "";
if ( $ref->{module} eq 'ar' ) {
$module = "is.pl" if $ref->{invoice};
$ref->{amount} /= $ref->{exchangerate};
}
if ( $ref->{module} eq 'ap' ) {
$module = "ir.pl" if $ref->{invoice};
$ref->{amount} /= $ref->{exchangerate};
}
if ( $ref->{module} eq 'oe' ) {
$type =
( $ref->{vc} eq 'customer' )
? "sales_order"
: "purchase_order";
}
$column_data{id} = {
text => $ref->{id},
href => qq|$module?action=edit&id=$ref->{id}&vc=$ref->{vc}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&type=$type&readonly=1|,
};
$column_data{repeat} = $repeat;
$column_data{howmany} =
$form->format_amount( \%myconfig, $ref->{howmany} );
$column_data{amount} =
$form->format_amount( \%myconfig, $ref->{amount}, 2 );
my @temp_split;
my @f = split /:/, $ref->{recurringemail};
for ( 0 .. $#f ) {
push @temp_split, $f{$f[$_]};
}
$column_data{recurringemail} = {
text => join ':', @temp_split,
delimeter => ':',
};
@temp_split = ();
@f = split /:/, $ref->{recurringprint};
for ( 0 .. $#f ) {
push @temp_split, $f{$f[$_]};
}
$column_data{recurringprint} = {
text => join ':', @temp_split,
delimeter => ':',
};
$j++;
$j %= 2;
$column_data{i} = $j;
push @{$transactions[$#transactions]{transactions}}, \%column_data;
}
}
##SC: Temporary removal
## if ( $form->{lynx} ) {
## require "bin/menu.pl";
## &menubar;
## }
$hiddens{path} = $form->{path};
$hiddens{login} = $form->{login};
$hiddens{sessionid} = $form->{sessionid};
$hiddens{lastndx} = $k;
my @buttons;
push @buttons, {
name => 'action',
value => 'process_transactions',
text => $locale->text('Process Transactions'),
type => 'submit',
class => 'submit',
};
my $template = LedgerSMB::Template->new_UI(
user => \%myconfig,
locale => $locale,
template => 'am-list-recurring');
$template->render({
form => $form,
buttons => \@buttons,
columns => \@column_index,
heading => \%column_header,
transactions => \@transactions,
hiddens => \%hiddens,
});
}
sub edit_recurring {
%links = (
ar => 'create_links',
ap => 'create_links',
gl => 'create_links',
is => 'invoice_links',
ir => 'invoice_links',
oe => 'order_links',
);
%prepare = (
is => 'prepare_invoice',
ir => 'prepare_invoice',
oe => 'prepare_order',
);
$form->{callback} =
"$form->{script}?action=recurring_transactions&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
$form->{type} = "transaction";
if ( $form->{module} eq 'ar' ) {
if ( $form->{invoice} ) {
$form->{type} = "invoice";
$form->{module} = "is";
}
}
if ( $form->{module} eq 'ap' ) {
if ( $form->{invoice} ) {
$form->{type} = "invoice";
$form->{module} = "ir";
}
}
if ( $form->{module} eq 'oe' ) {
%tr = (
so => sales_order,
po => purchase_order,
);
$form->{type} = $tr{ $form->{transaction} };
}
$form->{script} = "$form->{module}.pl";
do "bin/$form->{script}";
&{ $links{ $form->{module} } };
# return if transaction doesn't exist
$form->redirect unless $form->{recurring};
if ( $prepare{ $form->{module} } ) {
&{ $prepare{ $form->{module} } };
}
$form->{selectformat} = qq|