summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreinhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46>2007-11-22 06:19:05 +0000
committereinhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46>2007-11-22 06:19:05 +0000
commit08e1b04d20e4f328638fbde9f7a2ae54a3dca966 (patch)
tree1191bd1b7d8bad8873a95b864e108e8358ae2345
parenta7badcbfb8db7f379590d66031137efb9f65717c (diff)
First (unsuccessful) attempt to automatically handle number formatting in the template engine..
Customer screen enhancements as well. git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@1890 4979c152-3d1c-0410-bac9-87ea11338e46
-rw-r--r--LedgerSMB/DBObject/Customer.pm23
-rwxr-xr-xLedgerSMB/Template.pm33
-rw-r--r--UI/Customer/customer.html17
-rw-r--r--scripts/customer.pl48
-rw-r--r--sql/modules/Customer.sql29
5 files changed, 120 insertions, 30 deletions
diff --git a/LedgerSMB/DBObject/Customer.pm b/LedgerSMB/DBObject/Customer.pm
index 7bae0a9c..3805762f 100644
--- a/LedgerSMB/DBObject/Customer.pm
+++ b/LedgerSMB/DBObject/Customer.pm
@@ -3,6 +3,7 @@ package LedgerSMB::DBObject::Customer;
use base qw(LedgerSMB::DBObject);
use LedgerSMB::DBObject;
use LedgerSMB::Entity;
+use strict;
my $CUSTOMER_ENTITY_CLASS = 2;
@@ -12,7 +13,7 @@ sub save {
# 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 save {
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_location {
}
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 @@ sub get {
@{$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(
diff --git a/LedgerSMB/Template.pm b/LedgerSMB/Template.pm
index 28c1f40e..aff967a0 100755
--- a/LedgerSMB/Template.pm
+++ b/LedgerSMB/Template.pm
@@ -198,6 +198,35 @@ sub _valid_language {
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 @@ sub render {
throw Error::Simple "Invalid format";
}
my $format = "LedgerSMB::Template::$self->{format}";
-
+# if ($self->{myconfig}){
+# $self->_preprocess($vars);
+# }
eval "require $format";
if ($@) {
throw Error::Simple $@;
diff --git a/UI/Customer/customer.html b/UI/Customer/customer.html
index 5fb8a1be..e39bfdcc 100644
--- a/UI/Customer/customer.html
+++ b/UI/Customer/customer.html
@@ -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 ?>">
diff --git a/scripts/customer.pl b/scripts/customer.pl
index bef642ec..c1cee521 100644
--- a/scripts/customer.pl
+++ b/scripts/customer.pl
@@ -93,18 +93,7 @@ This method creates a blank screen for entering a customer's information.
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 @@ sub save {
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;
diff --git a/sql/modules/Customer.sql b/sql/modules/Customer.sql
index 500556f5..3ce11f30 100644
--- a/sql/modules/Customer.sql
+++ b/sql/modules/Customer.sql
@@ -227,6 +227,35 @@ BEGIN
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