[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
SF.net SVN: ledger-smb: [1890] trunk
- Subject: SF.net SVN: ledger-smb: [1890] trunk
- From: ..hidden..
- Date: Wed, 21 Nov 2007 22:19:06 -0800
Revision: 1890
http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=1890&view=rev
Author: einhverfr
Date: 2007-11-21 22:19:05 -0800 (Wed, 21 Nov 2007)
Log Message:
-----------
First (unsuccessful) attempt to automatically handle number formatting in the template engine..
Customer screen enhancements as well.
Modified Paths:
--------------
trunk/LedgerSMB/DBObject/Customer.pm
trunk/LedgerSMB/Template.pm
trunk/UI/Customer/customer.html
trunk/scripts/customer.pl
trunk/sql/modules/Customer.sql
Modified: trunk/LedgerSMB/DBObject/Customer.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Customer.pm 2007-11-22 03:59:09 UTC (rev 1889)
+++ trunk/LedgerSMB/DBObject/Customer.pm 2007-11-22 06:19:05 UTC (rev 1890)
@@ -3,6 +3,7 @@
use base qw(LedgerSMB::DBObject);
use LedgerSMB::DBObject;
use LedgerSMB::Entity;
+use strict;
my $CUSTOMER_ENTITY_CLASS = 2;
@@ -12,7 +13,7 @@
# This saves both the entity and the credit account. -- CT
$self->{entity_class} = $CUSTOMER_ENTITY_CLASS;
- ($ref) = $self->exec_method(funcname => 'entity_credit_save');
+ my ($ref) = $self->exec_method(funcname => 'entity_credit_save');
$self->{entity_id} = $ref->{entity_credit_save};
$self->{dbh}->commit;
}
@@ -20,18 +21,18 @@
sub get_metadata {
my $self = shift @_;
- @{$self->{location_class}} =
+ @{$self->{location_class_list}} =
$self->exec_method(funcname => 'location_list_class');
- @{$self->{country}} =
+ @{$self->{country_list}} =
$self->exec_method(funcname => 'location_list_country');
- @{$self->{contact_class}} =
+ @{$self->{contact_class_list}} =
$self->exec_method(funcname => 'entity_list_contact_class');
}
sub save_location {
- $self = shift @_;
+ my $self = shift @_;
$self->{entity_class} = $CUSTOMER_ENTITY_CLASS;
$self->{country_id} = $self->{country};
$self->exec_method(funcname => 'customer_location_save');
@@ -40,14 +41,20 @@
}
sub save_contact {
+ my ($self) = @_;
+ $self->exec_method(funcname => 'company__save_contact');
+ $self->{dbh}->commit;
}
-sub save_bank_acct {
+sub save_bank_account {
+ my $self = shift @_;
+ $self->exec_method(funcname => 'entity__save_bank_account');
+ $self->{dbh}->commit;
}
sub get {
my $self = shift @_;
- ($ref) = $self->exec_method(funcname => 'customer__retrieve');
+ my ($ref) = $self->exec_method(funcname => 'customer__retrieve');
$self->merge($ref);
$self->{name} = $self->{legal_name};
@@ -58,7 +65,7 @@
@{$self->{contacts}} = $self->exec_method(
funcname => 'company__list_contacts');
- @{$self->{contacts}} = $self->exec_method(
+ @{$self->{bank_account}} = $self->exec_method(
funcname => 'company__list_bank_account');
@{$self->{notes}} = $self->exec_method(
Modified: trunk/LedgerSMB/Template.pm
===================================================================
--- trunk/LedgerSMB/Template.pm 2007-11-22 03:59:09 UTC (rev 1889)
+++ trunk/LedgerSMB/Template.pm 2007-11-22 06:19:05 UTC (rev 1890)
@@ -198,6 +198,35 @@
return 1;
}
+sub _preprocess {
+ my ($self, $vars) = @_;
+ return unless $self->{myconfig};
+ use LedgerSMB;
+ if (UNIVERSAL::isa($vars, 'Math::BigFloat')){
+ $vars =
+ LedgerSMB::format_amount('LedgerSMB',
+ {amount => $vars.
+ user => $self->{myconfig} });
+ }
+ my $type = ref($vars);
+
+ if ($type eq 'SCALAR' || !$type){
+ return;
+ }
+ if ($type eq 'ARRAY'){
+ for (@$vars){
+ if (ref($_)){
+ $self->_preprocess($_);
+ }
+ }
+ }
+ else {
+ for my $key (keys %$vars){
+ $self->_preprocess($vars->{$key});
+ }
+ }
+}
+
sub render {
my $self = shift;
my $vars = shift;
@@ -205,7 +234,9 @@
throw Error::Simple "Invalid format";
}
my $format = "LedgerSMB::Template::$self->{format}";
-
+# if ($self->{myconfig}){
+# $self->_preprocess($vars);
+# }
eval "require $format";
if ($@) {
throw Error::Simple $@;
Modified: trunk/UI/Customer/customer.html
===================================================================
--- trunk/UI/Customer/customer.html 2007-11-22 03:59:09 UTC (rev 1889)
+++ trunk/UI/Customer/customer.html 2007-11-22 06:19:05 UTC (rev 1890)
@@ -16,6 +16,9 @@
</div>
<div class="container" id="customer_div">
<div class="listtop"><strong><?lsmb text('Add/Edit Customer') ?></strong></div>
+<?lsmb FOREACH n = notes ?>
+<div class="entity_note"><?lsmb n.note ?></div>
+<?lsmb END ?>
<form name="customer" method="POST" action="customer.pl">
<input type="hidden" name="entity_id" value="<?lsmb entity_id ?>">
<label for="name"><?lsmb text('Name:') ?></label>
@@ -107,9 +110,8 @@
<tr>
<td>
<label for="notes"><?lsmb text('Notes:') ?></label><br/>
- <textarea name="notes" rows="3" cols="40" id="notes"><?lsmb
- notes
- ?></textarea>
+
+ <textarea name="notes" rows="3" cols="40" id="notes"></textarea>
<!-- CT: The prior funny whitespace may look funny but it
prevents additional whitespace from being added to the data
every time it is saved. -->
@@ -199,7 +201,7 @@
<div>
<label for="loc_type"><?lsmb text('Type:') ?></label>
<select id='loc_type' name="location_class">
- <?lsmb FOREACH lc = location_class ?>
+ <?lsmb FOREACH lc = location_class_list ?>
<option value="<?lsmb lc.id ?>"><?lsmb lc.class ?></option>
<?lsmb END ?>
</select>
@@ -229,7 +231,7 @@
<div>
<label for="country"><?lsmb text('Country:') ?></label>
<select name="country" id="country">
- <?lsmb FOREACH c = country ?>
+ <?lsmb FOREACH c = country_list ?>
<option value="<?lsmb c.id ?>"><?lsmb c.name ?></option>
<?lsmb END ?>
</select>
@@ -270,7 +272,7 @@
<input type="hidden" name="contact_id" value="<?lsmb contact_id ?>">
<div><label for="contact_type"><?lsmb text('Type:') ?></label>
<select name="contact_class" id="contact_type">
- <?lsmb FOREACH cc = contact_class ?>
+ <?lsmb FOREACH cc = contact_class_list ?>
<option value="<?lsmb cc.id ?>"><?lsmb cc.class ?></option>
<?lsmb END ?>
</select>
@@ -282,6 +284,7 @@
<div><button name="action" id="contact_action_save"
value="save_contact"><?lsmb text('Save Contact') ?></button>
</div>
+</form>
</div>
<div class="container" id="bank_div">
@@ -307,7 +310,7 @@
</tr>
<?lsmb END ?>
</table>
-<form action="customer.pl">
+<form name="bank_acct" action="customer.pl">
<input type="hidden" name="entity_id" value="<?lsmb entity_id ?>">
<input type="hidden" name="bank_account_id"
value="<?lsmb bank_account_id ?>">
Modified: trunk/scripts/customer.pl
===================================================================
--- trunk/scripts/customer.pl 2007-11-22 03:59:09 UTC (rev 1889)
+++ trunk/scripts/customer.pl 2007-11-22 06:19:05 UTC (rev 1890)
@@ -93,18 +93,7 @@
sub add {
my ($request) = @_;
my $customer = LedgerSMB::DBObject::Customer->new(base => $request, copy => 'all');
- $customer->set(entity_class=>2);
-
- $customer->get_metadata();
-
- my $template = LedgerSMB::Template->new(
- user => $user,
- template => 'customer',
- path => 'UI/Customer',
- locale => $request->{_locale},
- format => 'HTML');
- $request->{script} = 'Customer/customer';
- $template->render($customer);
+ _render_main_screen($customer);
}
=pod
@@ -173,16 +162,47 @@
my $customer = LedgerSMB::DBObject::Customer->new({base => $request});
$customer->save();
+ _render_main_screen($customer);
+}
+
+sub edit{
+ my $request = shift @_;
+ my $customer = LedgerSMB::DBObject::Customer->new({base => $request});
+ $customer->get();
+ _render_main_screen($customer);
+}
+
+sub _render_main_screen{
+ my $customer = shift @_;
$customer->get_metadata();
+ $customer->{creditlimit} = "$customer->{creditlimit}";
+ $customer->{discount} = "$customer->{discount}";
+
my $template = LedgerSMB::Template->new(
- user => $request->{_user},
+ user => $customer->{_user},
template => 'customer',
- locale => $request->{_locale},
+ locale => $customer->{_locale},
path => 'UI/Customer',
format => 'HTML'
);
$template->render($customer);
}
+sub save_contact {
+ my ($request) = @_;
+ my $customer = LedgerSMB::DBObject::Customer->new({base => $request});
+ $customer->save_contact();
+ $customer->get;
+ _render_main_screen($customer);
+}
+
+sub save_bank_account {
+ my ($request) = @_;
+ my $customer = LedgerSMB::DBObject::Customer->new({base => $request});
+ $customer->save_bank_account();
+ $customer->get;
+ _render_main_screen($customer);
+}
+
1;
Modified: trunk/sql/modules/Customer.sql
===================================================================
--- trunk/sql/modules/Customer.sql 2007-11-22 03:59:09 UTC (rev 1889)
+++ trunk/sql/modules/Customer.sql 2007-11-22 06:19:05 UTC (rev 1890)
@@ -227,6 +227,35 @@
END;
$$ LANGUAGE PLPGSQL;
+CREATE OR REPLACE FUNCTION entity__save_bank_account
+(in_entity_id int, in_bic text, in_iban text)
+RETURNS int AS
+$$
+DECLARE out_id int;
+BEGIN
+ INSERT INTO entity_bank_account(entity_id, bic, iban)
+ VALUES(in_entity_id, in_bic, in_iban);
+
+ SELECT CURRVAL('entity_bank_account_id_seq') INTO out_id ;
+
+ RETURN out_id;
+END;
+$$ LANGUAGE PLPGSQL;
+
+CREATE OR REPLACE FUNCTION company__save_contact
+(in_entity_id int, in_contact_class int, in_contact text)
+RETURNS INT AS
+$$
+DECLARE out_id int;
+BEGIN
+ INSERT INTO company_to_contact(company_id, contact_class_id, contact)
+ SELECT id, in_contact_class, in_contact FROM company
+ WHERE entity_id = in_entity_id;
+
+ RETURN 1;
+END;
+$$ LANGUAGE PLPGSQL;
+
CREATE TYPE entity_note_list AS (
id int,
note text
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.