From 08e1b04d20e4f328638fbde9f7a2ae54a3dca966 Mon Sep 17 00:00:00 2001 From: einhverfr Date: Thu, 22 Nov 2007 06:19:05 +0000 Subject: 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 --- LedgerSMB/DBObject/Customer.pm | 23 +++++++++++++------- LedgerSMB/Template.pm | 33 ++++++++++++++++++++++++++++- UI/Customer/customer.html | 17 +++++++++------ scripts/customer.pl | 48 ++++++++++++++++++++++++++++++------------ sql/modules/Customer.sql | 29 +++++++++++++++++++++++++ 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 @@
+ +
+
@@ -107,9 +110,8 @@
- + + @@ -199,7 +201,7 @@
@@ -229,7 +231,7 @@
@@ -270,7 +272,7 @@
@@ -282,6 +284,7 @@
+
@@ -307,7 +310,7 @@ -
+ 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 -- cgit v1.2.3