#===================================================================== # LedgerSMB # Small Medium Business Accounting software # http://www.ledgersmb.org/ # # # Copyright (C) 2006 # This work contains copyrighted information from a number of sources all used # with permission. # # This file contains source code included with or based on SQL-Ledger which # is Copyright Dieter Simader and DWS Systems Inc. 2000-2005 and licensed # under the GNU General Public License version 2 or, at your option, any later # version. For a full list including contact information of contributors, # maintainers, and copyright holders, see the CONTRIBUTORS file. # # Original Copyright Notice from SQL-Ledger 2.6.17 (before the fork): # Copyright (c) 2001 # # Author: DWS Systems Inc. # Web: http://www.sql-ledger.org # # Contributors: # #====================================================================== # # This file has NOT undergone whitespace cleanup. # #====================================================================== # # administration # #====================================================================== use LedgerSMB::AM; use LedgerSMB::CA; use LedgerSMB::Form; use LedgerSMB::User; use LedgerSMB::RP; use LedgerSMB::GL; use LedgerSMB::Template; 1; # end of main sub add { &{"add_$form->{type}"} } sub edit { &{"edit_$form->{type}"} } sub save { &{"save_$form->{type}"} } sub delete { &{"delete_$form->{type}"} } sub save_as_new { delete $form->{id}; &save; } sub add_account { $form->{title} = "Add"; $form->{charttype} = "A"; $form->{callback} = "$form->{script}?action=list_account&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}" unless $form->{callback}; &account_header; &form_footer; } sub edit_account { $form->{title} = "Edit"; $form->{accno} =~ s/\\'/'/g; $form->{accno} =~ s/\\\\/\\/g; AM->get_account( \%myconfig, \%$form ); foreach my $item ( split( /:/, $form->{link} ) ) { $form->{$item} = "checked"; } &account_header; &form_footer; } sub account_header { $form->{title} = $locale->text("$form->{title} Account"); $checked{ $form->{charttype} } = "checked"; $checked{contra} = "checked" if $form->{contra}; $checked{"$form->{category}_"} = "checked"; for (qw(accno description)) { $form->{$_} = $form->quote( $form->{$_} ) } # this is for our parser only! # type=submit $locale->text('Add Account') # type=submit $locale->text('Edit Account') $form->header; print qq|
{script}> {id}> {inventory_accno_id}> {income_accno_id}> {expense_accno_id}> {fxgain_accno_id}> {fxloss_accno_id}>
$form->{title}
|; if ( $form->{charttype} eq "A" ) { print qq| |; } print qq|
| . $locale->text('Account Number') . qq|
| . $locale->text('Description') . qq|
| . $locale->text('Account Type') . qq|
 | . $locale->text('Asset') . qq|\n
 | . $locale->text('Liability') . qq|\n
 | . $locale->text('Equity') . qq|\n
 | . $locale->text('Income') . qq|\n
 | . $locale->text('Expense') . qq|
 | . $locale->text('Contra') . qq|  | . $locale->text('Heading') . qq|
 | . $locale->text('Account') . qq|
| . $locale->text('Is this a summary account to record') . qq| {AR}> | . $locale->text('AR') . qq| {AP}> | . $locale->text('AP') . qq| {IC}> | . $locale->text('Inventory') . qq|
| . $locale->text('Include in drop-down menus') . qq|
| . $locale->text('Receivables') . qq| | . $locale->text('Payables') . qq| | . $locale->text('Tracking Items') . qq| | . $locale->text('Non-tracking Items') . qq|
{AR_amount}> | . $locale->text('Income') . qq|\n
{AR_paid}> | . $locale->text('Payment') . qq|\n
{AR_tax}> | . $locale->text('Tax') . qq|
{AP_amount}> | . $locale->text('Expense/Asset') . qq|\n
{AP_paid}> | . $locale->text('Payment') . qq|\n
{AP_tax}> | . $locale->text('Tax') . qq|
{IC_sale}> | . $locale->text('Income') . qq|\n
{IC_cogs}> | . $locale->text('COGS') . qq|\n
{IC_taxpart}> | . $locale->text('Tax') . qq|
{IC_income}> | . $locale->text('Income') . qq|\n
{IC_expense}> | . $locale->text('Expense') . qq|\n
{IC_taxservice}> | . $locale->text('Tax') . qq|
| . $locale->text('GIFI') . qq|

|; } sub form_footer { $form->hide_form(qw(callback path login sessionid)); # type=submit $locale->text('Save') # type=submit $locale->text('Save as new') # type=submit $locale->text('Delete') %button = (); if ( $form->{id} ) { $button{'save'} = { ndx => 3, key => 'S', value => $locale->text('Save') }; $button{'save_as_new'} = { ndx => 7, key => 'N', value => $locale->text('Save as new') }; if ( $form->{orphaned} ) { $button{'delete'} = { ndx => 16, key => 'D', value => $locale->text('Delete') }; } } else { $button{'save'} = { ndx => 3, key => 'S', value => $locale->text('Save') }; } for ( sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button ) { $form->print_button( \%button, $_ ); } if ( $form->{lynx} ) { require "bin/menu.pl"; &menubar; } print qq|
|; } sub save_account { $form->isblank( "accno", $locale->text('Account Number missing!') ); $form->isblank( "category", $locale->text('Account Type missing!') ); # check for conflicting accounts if ( $form->{AR} || $form->{AP} || $form->{IC} ) { $a = ""; for (qw(AR AP IC)) { $a .= $form->{$_} } $form->error( $locale->text( 'Cannot set account for more than one of AR, AP or IC') ) if length $a > 2; for ( qw(AR_amount AR_tax AR_paid AP_amount AP_tax AP_paid IC_taxpart IC_taxservice IC_sale IC_cogs IC_income IC_expense) ) { $form->error( "$form->{AR}$form->{AP}$form->{IC} " . $locale->text( 'account cannot be set to any other type of account') ) if $form->{$_}; } } foreach $item ( "AR", "AP" ) { $i = 0; for ( "${item}_amount", "${item}_paid", "${item}_tax" ) { $i++ if $form->{$_}; } $form->error( $locale->text( 'Cannot set multiple options for [_1]', $item ) ) if $i > 1; } if ( AM->save_account( \%myconfig, \%$form ) ) { $form->redirect( $locale->text('Account saved!') ); } else { $form->error( $locale->text('Cannot save account!') ); } } sub list_account { CA->all_accounts( \%myconfig, \%$form ); $form->{title} = $locale->text('Chart of Accounts'); # construct callback $callback = "$form->{script}?action=list_account&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"; $form->{callback} = $callback; @column_index = qw(accno gifi_accno description debit credit link); $column_header{accno} = $locale->text('Account'); $column_header{gifi_accno} = $locale->text('GIFI'); $column_header{description} = $locale->text('Description'); $column_header{debit} = $locale->text('Debit'); $column_header{credit} = $locale->text('Credit'); $column_header{link} = $locale->text('Link'); # escape callback $callback = $form->escape($callback); my @rows; foreach my $ca ( @{ $form->{CA} } ) { my %column_data; $ca->{debit} = " "; $ca->{credit} = " "; if ( $ca->{amount} > 0 ) { $ca->{credit} = $form->format_amount( \%myconfig, $ca->{amount}, 2, " " ); } if ( $ca->{amount} < 0 ) { $ca->{debit} = $form->format_amount( \%myconfig, -$ca->{amount}, 2, " " ); } #$ca->{link} =~ s/:/
/og; $gifi_accno = $form->escape( $ca->{gifi_accno} ); if ( $ca->{charttype} eq "H" ) { $column_data{class} = 'heading'; $column_data{accno} = { text => $ca->{accno}, href => "$form->{script}?action=edit_account&id=$ca->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback"}; $column_data{gifi_accno} = { text => $ca->{gifi_accno}, href => "$form->{script}?action=edit_gifi&accno=$gifi_accno&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback"}; $column_data{description} = $ca->{description}; $column_data{debit} = " "; $column_data{credit} = " "; $column_data{link} = " "; } else { $i++; $i %= 2; $column_data{i} = $i; $column_data{accno} = { text => $ca->{accno}, href => "$form->{script}?action=edit_account&id=$ca->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback"}; $column_data{gifi_accno} = { text => $ca->{gifi_accno}, href => "$form->{script}?action=edit_gifi&accno=$gifi_accno&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback"}; $column_data{description} = $ca->{description}; $column_data{debit} = $ca->{debit}; $column_data{credit} = $ca->{credit}; $column_data{link} = {text => $ca->{link}, delimiter => ':'}; } push @rows, \%column_data; } my @buttons; for my $type (qw(CSV XLS ODS)) { push @buttons, { name => 'action', value => lc "${type}_list_account", text => $locale->text("$type Report"), type => 'submit', class => 'submit', }; } my %hiddens = ( callback => $callback, action => 'list_account', path => $form->{path}, login => $form->{login}, sessionid => $form->{sessionid}, ); my %row_alignment = ('credit' => 'right', 'debit' => 'right'); my $format = uc substr($form->{action}, 0, 3); my $template = LedgerSMB::Template->new( user => \%myconfig, locale => $locale, path => 'UI', template => 'form-dynatable', format => ($format ne 'LIS')? $format: 'HTML'); $template->render({ form => $form, buttons => \@buttons, hiddens => \%hiddens, columns => \@column_index, heading => \%column_header, rows => \@rows, row_alignment => \%row_alignment, }); } sub csv_list_account { &list_account } sub xls_list_account { &list_account } sub ods_list_account { &list_account } sub delete_account { $form->{title} = $locale->text('Delete Account'); foreach $id ( qw(inventory_accno_id income_accno_id expense_accno_id fxgain_accno_id fxloss_accno_id) ) { if ( $form->{id} == $form->{$id} ) { $form->error( $locale->text('Cannot delete default account!') ); } } if ( AM->delete_account( \%myconfig, \%$form ) ) { $form->redirect( $locale->text('Account deleted!') ); } else { $form->error( $locale->text('Cannot delete account!') ); } } sub list_gifi { @{ $form->{fields} } = qw(accno description); $form->{table} = "gifi"; AM->gifi_accounts( \%myconfig, \%$form ); $form->{title} = $locale->text('GIFI'); my %hiddens; # construct callback my $callback = "$form->{script}?action=list_gifi&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"; $form->{callback} = $callback; $hiddens{callback} = $callback; $hiddens{action} = 'list_gifi'; $hiddens{path} = $form->{path}; $hiddens{login} = $form->{login}; $hiddens{sessionid} = $form->{sessionid}; my @column_index = qw(accno description); my %column_header; my @rows; $column_header{accno} = $locale->text('GIFI'); $column_header{description} = $locale->text('Description'); my $i = 0; foreach $ca ( @{ $form->{ALL} } ) { my %column_data; $i++; $i %= 2; $column_data{i} = $i; $accno = $form->escape( $ca->{accno} ); $column_data{accno} = {text => $ca->{accno}, href => qq|$form->{script}?action=edit_gifi&coa=1&accno=$accno&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback|}; $column_data{description} = $ca->{description}; push @rows, \%column_data; } my @buttons; push @buttons, { name => 'action', value => 'csv_list_gifi', text => $locale->text('CSV Report'), type => 'submit', class => 'submit', }; my $template = LedgerSMB::Template->new( user => \%myconfig, locale => $locale, path => 'UI', template => 'form-dynatable', format => ($form->{action} =~ /^csv/)? 'CSV': 'HTML'); $template->render({ form => \%$form, hiddens => \%hiddens, buttons => \@buttons, columns => \@column_index, heading => \%column_header, rows => \@rows, }); } sub csv_list_gifi { &list_gifi } sub add_gifi { $form->{title} = "Add"; # construct callback $form->{callback} = "$form->{script}?action=list_gifi&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"; $form->{coa} = 1; &gifi_header; &gifi_footer; } sub edit_gifi { $form->{title} = "Edit"; AM->get_gifi( \%myconfig, \%$form ); $form->error( $locale->text('Account does not exist!') ) unless $form->{accno}; &gifi_header; &gifi_footer; } sub gifi_header { $form->{title} = $locale->text("$form->{title} GIFI"); # $locale->text('Add GIFI') # $locale->text('Edit GIFI') for (qw(accno description)) { $form->{$_} = $form->quote( $form->{$_} ) } $form->header; print qq|
{script}>
$form->{title}
| . $locale->text('GIFI') . qq|
| . $locale->text('Description') . qq|

|; } sub gifi_footer { $form->hide_form(qw(callback path login sessionid)); # type=submit $locale->text('Save') # type=submit $locale->text('Copy to COA') # type=submit $locale->text('Delete') %button = (); $button{'save'} = { ndx => 3, key => 'S', value => $locale->text('Save') }; if ( $form->{accno} ) { if ( $form->{orphaned} ) { $button{'delete'} = { ndx => 16, key => 'D', value => $locale->text('Delete') }; } } if ( $form->{coa} ) { $button{'copy_to_coa'} = { ndx => 7, key => 'C', value => $locale->text('Copy to COA') }; } for ( sort { $button{$a}->{ndx} <=> $button{$b}->{ndx} } keys %button ) { $form->print_button( \%button, $_ ); } if ( $form->{lynx} ) { require "bin/menu.pl"; &menubar; } print qq|
|; } sub save_gifi { $form->isblank( "accno", $locale->text('GIFI missing!') ); AM->save_gifi( \%myconfig, \%$form ); $form->redirect( $locale->text('GIFI saved!') ); } sub copy_to_coa { $form->isblank( "accno", $locale->text('GIFI missing!') ); AM->save_gifi( \%myconfig, \%$form ); delete $form->{id}; $form->{gifi_accno} = $form->{accno}; $form->{title} = "Add"; $form->{charttype} = "A"; &account_header; &form_footer; } sub delete_gifi { AM->delete_gifi( \%myconfig, \%$form ); $form->redirect( $locale->text('GIFI deleted!') ); } sub add_department { $form->{title} = "Add"; $form->{role} = "P"; $form->{callback} = "$form->{script}?action=add_department&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}" unless $form->{callback}; &department_header; &form_footer; } sub edit_department { $form->{title} = "Edit"; AM->get_department( \%myconfig, \%$form ); &department_header; &form_footer; } sub list_department { AM->departments( \%myconfig, \%$form ); my $href = "$form->{script}?action=list_department&direction=$form->{direction}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"; $form->sort_order(); $form->{callback} = "$form->{script}?action=list_department&direction=$form->{direction}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"; my $callback = $form->escape( $form->{callback} ); $form->{title} = $locale->text('Departments'); my @column_index = qw(description cost profit); my %column_header; $column_header{description} = { text => $locale->text('Description'), href => $href}; $column_header{cost} = $locale->text('Cost Center'); $column_header{profit} = $locale->text('Profit Center'); my @rows; my $i = 0; foreach my $ref ( @{ $form->{ALL} } ) { my %column_data; $i++; $i %= 2; $column_data{i} = $i; $column_data{cost} = ( $ref->{role} eq "C" ) ? "*" : " "; $column_data{profit} = ( $ref->{role} eq "P" ) ? "*" : " "; $column_data{description} = { text => $ref->{description}, href => qq|$form->{script}?action=edit_department&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback|,}; push @rows, \%column_data; } $form->{type} = "department"; my @hiddens = qw(type callback path login sessionid); ## SC: removing this for now #if ( $form->{lynx} ) { # require "bin/menu.pl"; # &menubar; #} my @buttons; push @buttons, { name => 'action', value => 'add_department', text => $locale->text('Add Department'), type => 'submit', class => 'submit', }; my $template = LedgerSMB::Template->new_UI( user => \%myconfig, locale => $locale, template => 'am-list-departments'); $template->render({ form => $form, buttons => \@buttons, columns => \@column_index, heading => \%column_header, rows => \@rows, hiddens => \@hiddens, }); } sub department_header { $form->{title} = $locale->text("$form->{title} Department"); # $locale->text('Add Department') # $locale->text('Edit Department') $form->{description} = $form->quote( $form->{description} ); if ( ( $rows = $form->numtextrows( $form->{description}, 60 ) ) > 1 ) { $description = qq||; } else { $description = qq||; } $costcenter = "checked" if $form->{role} eq "C"; $profitcenter = "checked" if $form->{role} eq "P"; $form->header; print qq|
{script}> {id}>
$form->{title}
| . $locale->text('Description') . qq| $description
| . $locale->text('Cost Center') . qq| | . $locale->text('Profit Center') . qq|

|; } sub save_department { $form->isblank( "description", $locale->text('Description missing!') ); AM->save_department( \%myconfig, \%$form ); $form->redirect( $locale->text('Department saved!') ); } sub delete_department { AM->delete_department( \%myconfig, \%$form ); $form->redirect( $locale->text('Department deleted!') ); } sub add_business { $form->{title} = "Add"; $form->{callback} = "$form->{script}?action=add_business&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}" unless $form->{callback}; &business_header; &form_footer; } sub edit_business { $form->{title} = "Edit"; AM->get_business( \%myconfig, \%$form ); &business_header; $form->{orphaned} = 1; &form_footer; } sub list_business { AM->business( \%myconfig, \%$form ); my $href = "$form->{script}?action=list_business&direction=$form->{direction}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"; $form->sort_order(); $form->{callback} = "$form->{script}?action=list_business&direction=$form->{direction}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"; my $callback = $form->escape( $form->{callback} ); $form->{title} = $locale->text('Type of Business'); my @column_index = qw(description discount); my %column_header; $column_header{description} = { text => $locale->text('Description'), href => $href }; $column_header{discount} = $locale->text('Discount %'); my @rows; $i = 0; foreach my $ref ( @{ $form->{ALL} } ) { my %column_data; $i++; $i %= 2; $column_data{i} = $i; $column_data{discount} = $form->format_amount( \%myconfig, $ref->{discount} * 100, 2, " " ); $column_data{description} = { text => $ref->{description}, href => qq|$form->{script}?action=edit_business&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback|}; push @rows, \%column_data; } $form->{type} = "business"; my @hiddens = qw(type callback path login sessionid); ## SC: Temporary removal ## if ( $form->{lynx} ) { ## require "bin/menu.pl"; ## &menubar; ## } my @buttons; push @buttons, { name => 'action', value => 'add_business', text => $locale->text('Add Business'), type => 'submit', class => 'submit', }; my $template = LedgerSMB::Template->new_UI( user => \%myconfig, locale => $locale, template => 'am-list-departments'); $template->render({ form => $form, buttons => \@buttons, columns => \@column_index, heading => \%column_header, rows => \@rows, hiddens => \@hiddens, }); } sub business_header { $form->{title} = $locale->text("$form->{title} Business"); # $locale->text('Add Business') # $locale->text('Edit Business') $form->{description} = $form->quote( $form->{description} ); $form->{discount} = $form->format_amount( \%myconfig, $form->{discount} * 100 ); $form->header; print qq| {script}> {id}>
$form->{title}
| . $locale->text('Type of Business') . qq|
| . $locale->text('Discount') . qq| % {discount}>

|; } sub save_business { $form->isblank( "description", $locale->text('Description missing!') ); AM->save_business( \%myconfig, \%$form ); $form->redirect( $locale->text('Business saved!') ); } sub delete_business { AM->delete_business( \%myconfig, \%$form ); $form->redirect( $locale->text('Business deleted!') ); } sub add_sic { $form->{title} = "Add"; $form->{callback} = "$form->{script}?action=add_sic&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}" unless $form->{callback}; &sic_header; &form_footer; } sub edit_sic { $form->{title} = "Edit"; $form->{code} =~ s/\\'/'/g; $form->{code} =~ s/\\\\/\\/g; AM->get_sic( \%myconfig, \%$form ); $form->{id} = $form->{code}; &sic_header; $form->{orphaned} = 1; &form_footer; } sub list_sic { AM->sic( \%myconfig, \%$form ); $href = "$form->{script}?action=list_sic&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"; $form->sort_order(); $form->{callback} = "$form->{script}?action=list_sic&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"; $callback = $form->escape( $form->{callback} ); $form->{title} = $locale->text('Standard Industrial Codes'); @column_index = $form->sort_columns(qw(code description)); $column_header{code} = qq|| . $locale->text('Code') . qq||; $column_header{description} = qq|| . $locale->text('Description') . qq||; $form->header; print qq|
$form->{title}
|; for (@column_index) { print "$column_header{$_}\n" } print qq| |; foreach $ref ( @{ $form->{ALL} } ) { $i++; $i %= 2; if ( $ref->{sictype} eq 'H' ) { print qq| |; $column_data{code} = qq||; $column_data{description} = qq||; } else { print qq| |; $column_data{code} = qq||; $column_data{description} = qq||; } for (@column_index) { print "$column_data{$_}\n" } print qq| |; } print qq|
{script}?action=edit_sic&code=$ref->{code}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{code}$ref->{description}
{script}?action=edit_sic&code=$ref->{code}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{code}$ref->{description}


{script}> |; $form->{type} = "sic"; $form->hide_form(qw(type callback path login sessionid)); print qq| |; if ( $form->{lynx} ) { require "bin/menu.pl"; &menubar; } print qq|
|; } sub sic_header { $form->{title} = $locale->text("$form->{title} SIC"); # $locale->text('Add SIC') # $locale->text('Edit SIC') for (qw(code description)) { $form->{$_} = $form->quote( $form->{$_} ) } $checked = ( $form->{sictype} eq 'H' ) ? "checked" : ""; $form->header; print qq|
{script}>
$form->{title}
| . $locale->text('Code') . qq|
| . $locale->text('Heading') . qq|
| . $locale->text('Description') . qq|

|; } sub save_sic { $form->isblank( "code", $locale->text('Code missing!') ); $form->isblank( "description", $locale->text('Description missing!') ); AM->save_sic( \%myconfig, \%$form ); $form->redirect( $locale->text('SIC saved!') ); } sub delete_sic { AM->delete_sic( \%myconfig, \%$form ); $form->redirect( $locale->text('SIC deleted!') ); } sub add_language { $form->{title} = "Add"; $form->{callback} = "$form->{script}?action=add_language&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}" unless $form->{callback}; &language_header; &form_footer; } sub edit_language { $form->{title} = "Edit"; $form->{code} =~ s/\\'/'/g; $form->{code} =~ s/\\\\/\\/g; AM->get_language( \%myconfig, \%$form ); $form->{id} = $form->{code}; &language_header; $form->{orphaned} = 1; &form_footer; } sub list_language { AM->language( \%myconfig, \%$form ); $href = "$form->{script}?action=list_language&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"; $form->sort_order(); $form->{callback} = "$form->{script}?action=list_language&direction=$form->{direction}&oldsort=$form->{oldsort}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"; my $callback = $form->escape( $form->{callback} ); $form->{title} = $locale->text('Languages'); my @column_index = $form->sort_columns(qw(code description)); my %column_header; $column_header{code} = { text => $locale->text('Code'), href => "$href&sort=code" }; $column_header{description} = { text => $locale->text('Description'), href => "$href&sort=description" }; my @rows; my $i = 0; foreach my $ref ( @{ $form->{ALL} } ) { my %column_data; $i++; $i %= 2; $column_data{i} = $i; $column_data{code} = {text => $ref->{code}, href => qq|$form->{script}?action=edit_language&code=$ref->{code}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback|}; $column_data{description} = $ref->{description}; push @rows, \%column_data; } $form->{type} = "language"; my @hiddens = qw(type callback path login sessionid); ## SC: Temporary removal ## if ( $form->{lynx} ) { ## require "bin/menu.pl"; ## &menubar; ## } my @buttons; push @buttons, { name => 'action', value => 'add_language', text => $locale->text('Add Lanugage'), type => 'submit', class => 'submit', }; # SC: I'm not concerned about the wider description as code is 6 chars max my $template = LedgerSMB::Template->new_UI( user => \%myconfig, locale => $locale, template => 'am-list-departments'); $template->render({ form => $form, buttons => \@buttons, columns => \@column_index, heading => \%column_header, rows => \@rows, hiddens => \@hiddens, }); } sub language_header { $form->{title} = $locale->text("$form->{title} Language"); # $locale->text('Add Language') # $locale->text('Edit Language') for (qw(code description)) { $form->{$_} = $form->quote( $form->{$_} ) } $form->header; print qq| {script}>
$form->{title}
| . $locale->text('Code') . qq|
| . $locale->text('Description') . qq|

|; } sub save_language { $form->isblank( "code", $locale->text('Code missing!') ); $form->isblank( "description", $locale->text('Description missing!') ); $form->{code} =~ s/(\.\.|\*)//g; AM->save_language( \%myconfig, \%$form ); if ( !-d "$myconfig{templates}/$form->{code}" ) { umask(002); if ( mkdir "$myconfig{templates}/$form->{code}", oct("771") ) { umask(007); opendir TEMPLATEDIR, "$myconfig{templates}" or $form->error("$myconfig{templates} : $!"); @templates = grep !/^(\.|\.\.)/, readdir TEMPLATEDIR; closedir TEMPLATEDIR; foreach $file (@templates) { if ( -f "$myconfig{templates}/$file" ) { open( TEMP, '<', "$myconfig{templates}/$file" ) or $form->error("$myconfig{templates}/$file : $!"); open( NEW, '>', "$myconfig{templates}/$form->{code}/$file" ) or $form->error( "$myconfig{templates}/$form->{code}/$file : $!"); while ( $line = ) { print NEW $line; } close(TEMP); close(NEW); } } } else { $form->error("${templates}/$form->{code} : $!"); } } $form->redirect( $locale->text('Language saved!') ); } sub delete_language { $form->{title} = $locale->text('Confirm!'); $form->header; print qq| {script}> |; for (qw(action nextsub)) { delete $form->{$_} } $form->hide_form; print qq|

$form->{title}

| . $locale->text( 'Deleting a language will also delete the templates for the language [_1]', $form->{invnumber} ) . qq|

|; } sub yes_delete_language { AM->delete_language( \%myconfig, \%$form ); # delete templates $dir = "$myconfig{templates}/$form->{code}"; if ( -d $dir ) { unlink <$dir/*>; rmdir "$myconfig{templates}/$form->{code}"; } $form->redirect( $locale->text('Language deleted!') ); } sub display_stylesheet { $form->{file} = "css/$myconfig{stylesheet}"; &display_form; } sub list_templates { AM->language( \%myconfig, \%$form ); if ( !@{ $form->{ALL} } ) { &display_form; exit; } unshift @{ $form->{ALL} }, { code => '.', description => $locale->text('Default Template') }; my $href = "$form->{script}?action=list_templates&direction=$form->{direction}&oldsort=$form->{oldsort}&file=$form->{file}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"; $form->sort_order(); $form->{callback} = "$form->{script}?action=list_templates&direction=$form->{direction}&oldsort=$form->{oldsort}&file=$form->{file}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}"; my $callback = $form->escape( $form->{callback} ); chomp $myconfig{templates}; $form->{file} =~ s/$myconfig{templates}//; $form->{file} =~ s/\///; $form->{title} = "$form->{format}: $form->{template}"; my @column_index = $form->sort_columns(qw(code description)); $column_header{code} = { text => $locale->text('Code'), href => "$href&sort=code" }; $column_header{description} = { text => $locale->text('Description'), href => "$href&sort=description" }; my @rows; my $i = 0; foreach my $ref ( @{ $form->{ALL} } ) { my %column_data; $i++; $i %= 2; $column_data{i} = $i; $column_data{code} = { text => $ref->{code}, href => qq|$form->{script}?action=display_form&file=$myconfig{templates}/$ref->{code}/$form->{file}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&code=$ref->{code}&callback=$callback|}; $column_data{description} = $ref->{description}; push @rows, \%column_data; } $form->{type} = 'language'; my @hiddens = qw(sessionid login path calllback type); ## SC: Temporary removal ## if ( $form->{lynx} ) { ## require "bin/menu.pl"; ## &menubar; ## } # SC: I'm not concerned about the wider description as code is 6 chars max my $template = LedgerSMB::Template->new_UI( user => \%myconfig, locale => $locale, template => 'am-list-departments'); $template->render({ form => $form, columns => \@column_index, heading => \%column_header, rows => \@rows, hiddens => \@hiddens, }); } sub display_form { AM->load_template( \%myconfig, \%$form ); $form->{title} = $form->{file}; $form->{body} =~ s/<%include (.*?)%>/{script}\?action=display_form&file=$myconfig{templates}\/$form->{code}\/$1&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}>$1<\/a>/g; # if it is anything but html if ( $form->{file} !~ /\.html$/ ) { $form->{body} = "
\n$form->{body}\n
"; } $form->header; print qq| $form->{body}
{script}> |; $form->{type} = "template"; $form->hide_form(qw(file type path login sessionid)); print qq| |; if ( $form->{lynx} ) { require "bin/menu.pl"; &menubar; } print qq|
|; } sub edit_template { AM->load_template( \%myconfig, \%$form ); $form->{title} = $locale->text('Edit Template'); # convert   to &nbsp; $form->{body} =~ s/ /&nbsp;/gi; $form->header; print qq|
{script}> {file}> {path}> {login}> {sessionid}>
|; if ( $form->{lynx} ) { require "bin/menu.pl"; &menubar; } print q|
|; } sub save_template { AM->save_template( \%myconfig, \%$form ); $form->redirect( $locale->text('Template saved!') ); } sub defaults { # get defaults for account numbers and last numbers AM->get_all_defaults( \%$form ); my %selects = ( 'FX_loss' => {name => 'FX_loss', options => []}, 'FX_gain' => {name => 'FX_gain', options => []}, 'IC_expense' => {name => 'IC_expense', options => []}, 'IC_income' => {name => 'IC_income', options => []}, 'IC_inventory' => {name => 'IC_inventory', options => []}, 'IC' => {name => 'IC', options => []}, ); foreach $key ( keys %{ $form->{accno} } ) { foreach $accno ( sort keys %{ $form->{accno}{$key} } ) { push @{$selects{$key}{options}}, { text => "$accno--$form->{accno}{$key}{$accno}{description}", value => "$accno--$form->{accno}{$key}{$accno}{description}", }; $selects{$key}{default_values} = "$accno--$form->{accno}{$key}{$accno}{description}" if ($form->{defaults}{$key} == $form->{accno}{$key}{$accno}{id}); } } for (qw(accno defaults)) { delete $form->{$_} } ##SC: temporary commenting out ## if ( $form->{lynx} ) { ## require "bin/menu.pl"; ## &menubar; ## } my %hiddens = ( path => $form->{path}, login => $form->{login}, sessionid => $form->{sessionid}, type => 'defaults', ); my $template = LedgerSMB::Template->new_UI( user => \%myconfig, locale => $locale, template => 'am-defaults'); $template->render({ form => $form, hiddens => \%hiddens, selects => \%selects, }); } sub taxes { # get tax account numbers AM->taxes( \%myconfig, \%$form ); $i = 0; foreach $ref ( @{ $form->{taxrates} } ) { $i++; $form->{"taxrate_$i"} = $form->format_amount( \%myconfig, $ref->{rate} ); $form->{"taxdescription_$i"} = $ref->{description}; for (qw(taxnumber validto pass taxmodulename)) { $form->{"${_}_$i"} = $ref->{$_}; } $form->{taxaccounts} .= "$ref->{id}_$i "; } chop $form->{taxaccounts}; &display_taxes; } sub display_taxes { $form->{title} = $locale->text('Taxes'); my %hiddens = ( path => $form->{path}, login => $form->{login}, sessionid => $form->{sessionid}, type => 'taxes', ); my @rows; for ( split( / /, $form->{taxaccounts} ) ) { ( $null, $i ) = split /_/, $_; $form->{"taxrate_$i"} = $form->format_amount( \%myconfig, $form->{"taxrate_$i"} ); $hiddens{"taxdescription_$i"} = $form->{"taxdescription_$i"}; my %select = (name => "taxmodule_id_$i", options => []); foreach my $taxmodule ( sort keys %$form ) { next if ( $taxmodule !~ /^taxmodule_/ ); next if ( $taxmodule =~ /^taxmodule_id_/ ); my $modulenum = $taxmodule; $modulenum =~ s/^taxmodule_//; push @{$select{options}}, {text => $form->{$taxmodule}, value => $modulenum}; $select{default_values} = $modulenum if $form->{$taxmodule} eq $form->{"taxmodulename_$i"}; } if ( $form->{"taxdescription_$i"} eq $sametax ) { push @rows, ["", \%select]; } else { push @rows, [$form->{"taxdescription_$i"}, \%select]; } $sametax = $form->{"taxdescription_$i"}; } $hiddens{taxaccounts} = $form->{taxaccounts}; foreach my $taxmodule ( sort keys %$form ) { next if ( $taxmodule !~ /^taxmodule_/ ); next if ( $taxmodule =~ /^taxmodule_id_/ ); $hiddens{$taxmodule}; } ##SC: Temporary removal ## if ( $form->{lynx} ) { ## require "bin/menu.pl"; ## &menubar; ## } my $template = LedgerSMB::Template->new_UI( user => \%myconfig, locale => $locale, template => 'am-taxes'); $template->render({ form => $form, hiddens => \%hiddens, selects => \%selects, rows => \@rows, }); } sub update { @a = split / /, $form->{taxaccounts}; $ndx = $#a + 1; foreach $item (@a) { ( $accno, $i ) = split /_/, $item; push @t, $accno; $form->{"taxmodulename_$i"} = $form->{ "taxmodule_" . $form->{"taxmodule_id_$i"} }; if ( $form->{"validto_$i"} ) { $j = $i + 1; if ( $form->{"taxdescription_$i"} ne $form->{"taxdescription_$j"} ) { #insert line for ( $j = $ndx + 1 ; $j > $i ; $j-- ) { $k = $j - 1; for (qw(taxrate taxdescription taxnumber validto)) { $form->{"${_}_$j"} = $form->{"${_}_$k"}; } } $ndx++; $k = $i + 1; for (qw(taxdescription taxnumber)) { $form->{"${_}_$k"} = $form->{"${_}_$i"}; } for (qw(taxrate validto)) { $form->{"${_}_$k"} = "" } push @t, $accno; } } else { # remove line $j = $i + 1; if ( $form->{"taxdescription_$i"} eq $form->{"taxdescription_$j"} ) { for ( $j = $i + 1 ; $j <= $ndx ; $j++ ) { $k = $j + 1; for (qw(taxrate taxdescription taxnumber validto)) { $form->{"${_}_$j"} = $form->{"${_}_$k"}; } } $ndx--; splice @t, $i - 1, 1; } } } $i = 1; $form->{taxaccounts} = ""; for (@t) { $form->{taxaccounts} .= "${_}_$i "; $i++; } chop $form->{taxaccounts}; &display_taxes; } sub config { my %selects; $selects{dateformat} = { name => 'dateformat', default_values => $myconfig{dateformat}, options => [], }; foreach $item (qw(mm-dd-yy mm/dd/yy dd-mm-yy dd/mm/yy dd.mm.yy yyyy-mm-dd)) { push @{$selects{dateformat}{options}}, {text => $item, value => $item}; } $selects{numberformat} = { name => 'numberformat', default_values => $myconfig{numberformat}, options => [], }; my @formats = qw(1,000.00 1000.00 1.000,00 1000,00 1'000.00); push @formats, '1 000.00'; foreach $item (@formats) { push @{$selects{numberformat}{options}}, {text => $item, value => $item}; } ## for (qw(name company address signature)) { ## $myconfig{$_} = $form->quote( $myconfig{$_} ); ## } for (qw(address signature)) { $myconfig{$_} =~ s/\\n/\n/g } $selects{countrycode} = { name => 'countrycode', default_values => ($myconfig{countrycode})? $myconfig{countrycode}: 'en', options => [], }; %countrycodes = LedgerSMB::User->country_codes; foreach $key ( sort { $countrycodes{$a} cmp $countrycodes{$b} } keys %countrycodes ) { push @{$selects{countrycode}{options}}, { text => $countrycodes{$key}, value => $key }; } opendir CSS, "css/."; @all = grep /.*\.css$/, readdir CSS; closedir CSS; $selects{stylesheet} = { name => 'usestylesheet', default_values => $myconfig{stylesheet}, options => [], }; foreach $item (@all) { push @{$selects{stylesheet}{options}}, {text => $item, value => $item}; } push @{$selects{stylesheet}{options}}, {text => 'none', value => '0'}; if ( %{LedgerSMB::Sysconfig::printer} && ${LedgerSMB::Sysconfig::latex} ) { $selects{printer} = { name => 'printer', default_values => $myconfig{printer}, options => [], }; foreach $item ( sort keys %{LedgerSMB::Sysconfig::printer} ) { push @{$selects{printer}{options}}, {text => $item, value => $item}; } } $form->{title} = $locale->text( 'Edit Preferences for [_1]', $form->{login} ); ##SC: Temporary commenting out ## if ( $form->{lynx} ) { ## require "bin/menu.pl"; ## &menubar; ## } my %hiddens = ( path => $form->{path}, login => $form->{login}, sessionid => $form->{sessionid}, type => 'preferences', role => $myconfig{role}, old_password => $myconfig{password}, ); my $template = LedgerSMB::Template->new_UI( user => \%myconfig, locale => $locale, template => 'am-userconfig'); $template->render({ form => $form, user => \%myconfig, hiddens => \%hiddens, selects => \%selects, }); } sub save_defaults { if ( AM->save_defaults( \%myconfig, \%$form ) ) { $form->redirect( $locale->text('Defaults saved!') ); } else { $form->error( $locale->text('Cannot save defaults!') ); } } sub save_taxes { if ( AM->save_taxes( \%myconfig, \%$form ) ) { $form->redirect( $locale->text('Taxes saved!') ); } else { $form->error( $locale->text('Cannot save taxes!') ); } } sub save_preferences { $form->{stylesheet} = $form->{usestylesheet}; if ( $form->{new_password} ne $form->{old_password} ) { $form->error( $locale->text('Password does not match!') ) if $form->{new_password} ne $form->{confirm_password}; } if ( AM->save_preferences( \%myconfig, \%$form ) ) { $form->info( $locale->text('Preferences saved!') ); } else { $form->error( $locale->text('Cannot save preferences!') ); } } sub backup { if ( $form->{media} eq 'email' ) { $form->error( $locale->text( 'No email address for [_1]', $myconfig{name} ) ) unless ( $myconfig{email} ); } $SIG{INT} = 'IGNORE'; AM->backup( \%myconfig, \%$form, ${LedgerSMB::Sysconfig::userspath}, ${LedgerSMB::Sysconfig::gzip} ); if ( $form->{media} eq 'email' ) { $form->redirect( $locale->text( 'Backup sent to [_1]', $myconfig{email} ) ); } } sub audit_control { $form->{title} = $locale->text('Audit Control'); AM->closedto( \%myconfig, \%$form ); my %checked; if ( $form->{revtrans} ) { $checked{revtransY} = 'checked'; } else { $checked{revtransN} = 'checked'; } if ( $form->{audittrail} ) { $checked{audittrailY} = 'checked'; } else { $checked{audittrailN} = 'checked'; } my %hiddens = ( path => $form->{path}, login => $form->{login}, sessionid => $form->{sessionid}, ); my $template = LedgerSMB::Template->new_UI( user => \%myconfig, locale => $locale, template => 'am-audit-control'); $template->render({ user => \%myconfig, form => $form, checked => \%checked, hiddens => \%hiddens, }); } sub doclose { AM->closebooks( \%myconfig, \%$form ); if ( $form->{revtrans} ) { $msg = $locale->text('Transaction reversal enforced for all dates'); } else { if ( $form->{closedto} ) { $msg = $locale->text('Transaction reversal enforced up to [_1]', $locale->date( \%myconfig, $form->{closedto}, 1 )); } else { $msg = $locale->text('Books are open'); } } $msg .= "

"; 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}; &warehouse_header; &form_footer; } sub edit_warehouse { $form->{title} = "Edit"; AM->get_warehouse( \%myconfig, \%$form ); &warehouse_header; &form_footer; } sub list_warehouse { AM->warehouses( \%myconfig, \%$form ); $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}"; $callback = $form->escape( $form->{callback} ); $form->{title} = $locale->text('Warehouses'); @column_index = qw(description); $column_header{description} = qq|| . $locale->text('Description') . qq||; $form->header; print qq|
$form->{title}
|; for (@column_index) { print "$column_header{$_}\n" } print qq| |; foreach $ref ( @{ $form->{ALL} } ) { $i++; $i %= 2; print qq| |; $column_data{description} = qq||; for (@column_index) { print "$column_data{$_}\n" } print qq| |; } print qq|
{script}?action=edit_warehouse&id=$ref->{id}&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}&callback=$callback>$ref->{description}


{script}> |; $form->{type} = "warehouse"; $form->hide_form(qw(type callback path login sessionid)); print qq| |; if ( $form->{lynx} ) { require "bin/menu.pl"; &menubar; } print qq|
|; } sub warehouse_header { $form->{title} = $locale->text("$form->{title} Warehouse"); # $locale->text('Add Warehouse') # $locale->text('Edit Warehouse') $form->{description} = $form->quote( $form->{description} ); if ( ( $rows = $form->numtextrows( $form->{description}, 60 ) ) > 1 ) { $description = qq||; } else { $description = qq||; } $form->header; print qq|
{script}> {id}>
$form->{title}
| . $locale->text('Description') . qq| $description

|; } 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 ); $chart = ""; for ( @{ $form->{chart} } ) { $chart .= "
|; } 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|