[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
SF.net SVN: ledger-smb:[2656] trunk/scripts/account.pl
- Subject: SF.net SVN: ledger-smb:[2656] trunk/scripts/account.pl
- From: ..hidden..
- Date: Fri, 12 Jun 2009 16:14:23 +0000
Revision: 2656
http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=2656&view=rev
Author: einhverfr
Date: 2009-06-12 16:14:23 +0000 (Fri, 12 Jun 2009)
Log Message:
-----------
Adding missing workflow script
Added Paths:
-----------
trunk/scripts/account.pl
Added: trunk/scripts/account.pl
===================================================================
--- trunk/scripts/account.pl (rev 0)
+++ trunk/scripts/account.pl 2009-06-12 16:14:23 UTC (rev 2656)
@@ -0,0 +1,103 @@
+use Template;
+use LedgerSMB::DBObject::Account;
+package LedgerSMB::Scripts::account;
+use strict;
+
+sub new {
+ my ($request) = @_;
+ $request->{title} = $request->{_locale}->text('Add Account');
+ $request->{charttype} = 'A';
+ _display_account_screen($request);
+}
+
+sub edit {
+ my ($request) = @_;
+ $request->{chart_id} = $request->{id};
+ my $account = LedgerSMB::DBObject::Account->new(base => $request);
+ my @accounts = $account->get();
+ my $a = shift @accounts;
+ $a->debug({file => '/tmp/account'});
+ $a->{title} = $request->{_locale}->text('Edit Account');
+ _display_account_screen($a);
+}
+
+sub save {
+ my ($request) = @_;
+ my $account = LedgerSMB::DBObject::Account->new(base => $request);
+ $account->save;
+ edit($request);
+}
+
+sub save_new {
+ my ($request) = @_;
+ delete $request->{id};
+ save($request);
+}
+
+# copied from AM.pm. To be refactored.
+sub _display_account_screen {
+ my ($form) = @_;
+ my $locale = $form->{_locale};
+ my $buttons = [];
+ my $checked;
+ my $hiddens;
+
+ foreach my $item ( split( /:/, $form->{link} ) ) {
+ $form->{$item} = "checked";
+ }
+
+ $hiddens->{type} = 'account';
+ $hiddens->{$_} = $form->{$_} foreach qw(id inventory_accno_id income_accno_id expense_accno_id fxgain_accno_id fxloss_accno_id);
+ $checked->{ $form->{charttype} } = "checked";
+
+ for my $ct (qw(A E I Q L)){
+ $checked->{"${ct}_"} = "checked" if $form->{category} eq $ct;
+ }
+
+ for my $cb (qw(contra)){
+ $checked->{$cb} = "checked" if $form->{$cb};
+ }
+ my %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 ) {
+ push @{$buttons}, {
+ name => 'action',
+ value => $_,
+ accesskey => $button{$_}{key},
+ title => "$button{$_}{value} [Alt-$button{$_}{key}]",
+ text => $button{$_}{value},
+ };
+ }
+ my $template = LedgerSMB::Template->new_UI(
+ user => $form->{_user},
+ locale => $locale,
+ template => 'am-account-form');
+ $template->render({
+ form => $form,
+ checked => $checked,
+ buttons => $buttons,
+ hiddens => $hiddens,
+ });
+
+}
+
+
+# From AM.pm, modified for better API.
+
+1;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.