[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SF.net SVN: ledger-smb:[2318] trunk



Revision: 2318
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=2318&view=rev
Author:   einhverfr
Date:     2008-09-09 22:17:46 +0000 (Tue, 09 Sep 2008)

Log Message:
-----------
Refactored code for customers and vendors for better maintenance and customizability

Modified Paths:
--------------
    trunk/UI/Contact/contact.html
    trunk/lsmb-request.pl
    trunk/scripts/customer.pl
    trunk/scripts/vendor.pl

Added Paths:
-----------
    trunk/LedgerSMB/ScriptLib/
    trunk/LedgerSMB/ScriptLib/Company.pm

Added: trunk/LedgerSMB/ScriptLib/Company.pm
===================================================================
--- trunk/LedgerSMB/ScriptLib/Company.pm	                        (rev 0)
+++ trunk/LedgerSMB/ScriptLib/Company.pm	2008-09-09 22:17:46 UTC (rev 2318)
@@ -0,0 +1,483 @@
+package LedgerSMB::ScriptLib::Company;
+use LedgerSMB::Template;
+
+my $ec_labels = {
+      1 => 'Vendor',
+      2 => 'Customer',
+};
+
+=pod
+
+=head1 NAME
+
+LedgerSMB::ScriptLib::Company - LedgerSMB class defining the Controller
+functions, template instantiation and rendering for vendor and customer editing 
+and display.  This would also form the basis for other forms of company
+contacts.
+
+=head1 SYOPSIS
+
+This module is the UI controller for the vendor DB access; it provides the 
+View interface, as well as defines the Save vendor. 
+Save vendor/customer will update or create as needed.
+
+
+=head1 METHODS
+
+=over
+
+=item set_entity_class($request) returns int entity class
+
+Errors if not inherited.  Inheriting classes MUST define this to set
+$entity_class appropriately.
+
+=back
+
+=cut
+
+sub set_entity_class {
+    my ($request) = @_;
+    $request->{_script_handle}->set_entity_class(@_) || $request->error(
+       "Error:  Cannot call LedgerSMB::ScriptLib::Company::set_entity_class " .
+       "directly!");
+}
+
+=pod
+
+=over
+
+=item new_company($request) 
+
+returns object inheriting LedgerSMB::DBObject::Company
+
+This too must be defined in classes that inherit this class.
+
+=back
+
+=cut
+
+sub new_company {
+    my ($request) = @_;
+    $request->{_script_handle}->new_company(@_) || $request->error(
+       "Error:  Cannot call LedgerSMB::ScriptLib::Company::new_company " .
+       "directly!");
+}
+
+=pod
+
+=over
+
+=item get($self, $request, $user)
+
+Requires form var: id
+
+Extracts a single company from the database, using its company ID as the primary
+point of uniqueness. Shows (appropriate to user privileges) and allows editing
+of the company informations.
+
+=back
+
+=cut
+
+sub get {
+    
+    my ($request) = @_;
+    my $company = new_company($request);
+    
+    set_entity_class($company);
+    $company->get();
+    $company->get_credit_id();
+    $company->get_metadata();
+    _render_main_screen($company);
+}
+
+=pod
+
+=over
+
+=item add_location 
+
+Adds a location to the company as defined in the inherited object
+
+=back
+
+=cut
+
+sub add_location {
+    my ($request) = @_;
+    my $company = new_company($request);
+    set_entity_class($company);
+    $company->save_location();
+    $company->get();
+
+    
+    $company->get_metadata();
+
+    _render_main_screen($company);
+	
+}
+
+=pod
+
+=over
+
+=item generate_control_code 
+
+Sets $company->{control_code} equal to the next in the series of entity_control 
+values
+
+=back
+
+=cut
+
+sub generate_control_code {
+    my ($request) = @_;
+    my $company = new_company($request);
+    
+    my ($ref) = $company->call_procedure(
+                             procname => 'setting_increment', 
+                             args     => ['entity_control']
+                           );
+    ($company->{control_code}) = values %$ref;
+    $company->{dbh}->commit;
+    if ($company->{meta_number}){
+        edit($company);
+    } else {
+       _render_main_screen($company);
+    }
+    
+}
+
+=pod
+
+=over
+
+=item add
+
+This method creates a blank screen for entering a company's information.
+
+=back
+
+=cut 
+
+sub add {
+    my ($request) = @_;
+    my $company = new_company($request);
+    set_entity_class($company);
+    _render_main_screen($company);
+}
+
+=pod
+
+=over
+
+=item get_result($self, $request, $user)
+
+Requires form var: search_pattern
+
+Directly calls the database function search, and returns a set of all vendors
+found that match the search parameters. Search parameters search over address 
+as well as vendor/Company name.
+
+=back
+
+=cut
+
+sub get_results {
+    my ($request) = @_;
+        
+    my $company = new_company($request);
+    set_entity_class($company);
+    $company->{contact_info} = 
+             qq|{"%$request->{email}%","%$request->{phone}%"}|;
+    my $results = $company->search();
+    if ($company->{order_by}){
+       # TODO:  Set ordering logic
+    };
+
+    # URL Setup
+    my $baseurl = "$request->{script}";
+    my $search_url = "$base_url?action=get_results";
+    my $get_url = "$base_url?action=get&account_class=$request->{account_class}";
+    for (keys %$vendor){
+        next if $_ eq 'order_by';
+        $search_url .= "&$_=$form->{$_}";
+    }
+
+    # Column definitions for dynatable
+    @columns = qw(legal_name meta_number business_type curr);
+    my %column_heading;
+    $column_heading{legal_name} = {
+        text => $request->{_locale}->text('Name'),
+	href => "$search_url&order_by=legal_name",
+    };
+    $column_heading{meta_number} = {
+        text => $request->{_locale}->text('Vendor Number'),
+	href => "$search_url&order_by=meta_number",
+    };
+    $column_heading{business_type} = {
+        text => $request->{_locale}->text('Business Type'),
+	href => "$search_url&order_by=business_type",
+    };
+    $column_heading{curr} = {
+        text => $request->{_locale}->text('Currency'),
+	href => "$search_url&order_by=curr",
+    };
+
+    my @rows;
+    for $ref (@{$company->{search_results}}){
+	push @rows, 
+                {legal_name   => $ref->{legal_name},
+                meta_number   => {text => $ref->{meta_number},
+                                  href => "$get_url&entity_id=$ref->{entity_id}"		                           . "&meta_number=$ref->{meta_number}"
+		                 },
+		business_type => $ref->{business_type},
+                curr          => $ref->{curr},
+                };
+    }
+# CT:  The CSV Report is broken.  I get:
+# Not an ARRAY reference at 
+# /usr/lib/perl5/site_perl/5.8.8/CGI/Simple.pm line 423
+# Disabling the button for now.
+    my @buttons = (
+#	{name => 'action',
+#        value => 'csv_company_list',
+#        text => $company->{_locale}->text('CSV Report'),
+#        type => 'submit',
+#        class => 'submit',
+#        },
+	{name => 'action',
+        value => 'add',
+        text => $company->{_locale}->text('Add Vendor'),
+        type => 'submit',
+        class => 'submit',
+	}
+    );
+
+    my $template = LedgerSMB::Template->new( 
+		user => $user,
+		path => 'UI' ,
+    		template => 'form-dynatable', 
+		locale => $company->{_locale}, 
+		format => ($request->{FORMAT}) ? $request->{FORMAT}  : 'HTML',
+    );
+            
+    $template->render({
+	form    => $company,
+	columns => ..hidden..,
+        hiddens => $company,
+	buttons => ..hidden..,
+	heading => \%column_heading,
+	rows    => ..hidden..,
+    });
+}
+
+=pod
+
+=over
+
+=item csv_company_list($request)
+
+Generates CSV report (not working at present)
+
+=back
+
+=cut
+
+sub csv_company_list {
+    my ($request) = @_;
+    $request->{FORMAT} = 'CSV';
+    get_results($request); 
+}
+
+=pod
+
+=over
+
+=item save($self, $request, $user)
+
+Saves a company to the database. The function will update or insert a new 
+company as needed, and will generate a new Company ID for the company if needed.
+
+=back
+
+=cut
+
+sub save {
+    
+    my ($request) = @_;
+
+    my $company = new_company($request);
+    $company->save();
+    _render_main_screen($company);
+}
+
+=pod
+
+=over
+
+=item save_credit($request)
+
+This inserts or updates a credit account of the sort listed here.
+
+=back
+
+=cut
+
+sub save_credit {
+    
+    my ($request) = @_;
+
+    my $company = new_company($request);
+    $company->save_credit();
+    $company->get();
+    _render_main_screen($company);
+}
+
+=pod
+
+=over
+
+=item save_credit_new($request)
+
+This inserts a new credit account.
+
+=back
+
+=cut
+
+
+sub save_credit_new {
+    my ($request) = @_;
+    $request->{credit_id} = undef;
+    save_credit($request);
+}
+
+=pod
+
+=over
+
+=item edit($request)
+
+Displays a company for editing.  Needs the following to be set:
+entity_id, account_class, and meta_number.
+
+=back
+
+=cut
+
+sub edit{
+    my $request = shift @_;
+    my $company = LedgerSMB::DBObject::Vendor->new({base => $request});
+    $company->get();
+    _render_main_screen($company);
+}
+
+=pod
+
+=over
+
+=item PRIVATE _render_main_screen($company)
+
+Pulls relevant data from db and renders the data entry screen for it.
+
+=back
+
+=cut
+
+sub _render_main_screen{
+    my $company = shift @_;
+    $company->get_metadata();
+
+    $company->{creditlimit} = "$company->{creditlimit}"; 
+    $company->{discount} = "$company->{discount}"; 
+    $company->{note_class_options} = [
+        {label => 'Entity', value => 1},
+        {label => $ec_labels->{"$company->{entity_class}"} . ' Account', 
+         value => 3},
+    ];
+    $company->{threshold} = $company->format_amount(amount => $company->{threshold});
+
+    my $template = LedgerSMB::Template->new( 
+	user => $company->{_user}, 
+    	template => 'contact', 
+	locale => $company->{_locale},
+	path => 'UI/Contact',
+        format => 'HTML'
+    );
+    $template->render($company);
+}
+
+=pod
+
+=over
+
+=item search($request)
+
+Renders the search criteria screen.
+
+=back
+
+=cut
+
+sub search {
+    my ($request) = @_;
+    set_entity_class($request);
+    my $template = LedgerSMB::Template->new( 
+	user => $request->{_user}, 
+    	template => 'search', 
+	locale => $request->{_locale},
+	path => 'UI/Contact',
+        format => 'HTML'
+    );
+    $template->render($request);
+}    
+
+=pod
+
+=over
+
+=item save_contact($request)
+
+Saves contact info as per LedgerSMB::DBObject::Company::save_contact.
+
+=back
+
+=cut
+
+sub save_contact {
+    my ($request) = @_;
+    my $company = new_company($request);
+    $company->save_contact();
+    $company->get;
+    _render_main_screen($company );
+}
+
+=pod
+
+=over
+
+=item save_bank_account($request)
+
+Adds a bank account to a company and, if defined, an entity credit account.
+
+=back
+
+=cut
+
+sub save_bank_account {
+    my ($request) = @_;
+    my $company = new_company($request);
+    $company->save_bank_account();
+    $company->get;
+    _render_main_screen($company );
+}
+
+sub save_notes {
+    my ($request) = @_;
+    my $company = new_company($company);
+    $company->save_notes();
+    $company->get();
+    _render_main_screen($company );
+}
+1;

Modified: trunk/UI/Contact/contact.html
===================================================================
--- trunk/UI/Contact/contact.html	2008-09-08 18:14:38 UTC (rev 2317)
+++ trunk/UI/Contact/contact.html	2008-09-09 22:17:46 UTC (rev 2318)
@@ -6,7 +6,7 @@
 <?lsmb PROCESS 'elements.html' ?>
 <body>
     <?lsmb IF name ?> 
-    <div class="pageheading"><?lsmb name?></font>
+    <div class="pageheading"><?lsmb name?></div>
     <?lsmb END ?>
 <div class="navigation" id="nav_div">
 <?lsmb IF entity_id ?><?lsmb operation = "Edit" ?><?lsmb ELSE
@@ -144,7 +144,7 @@
 	?><?lsmb CASE 2 ?><?lsmb entity_classname = "Customer" 
 	?><?lsmb END ?>
 	<div class="listtop"><strong><?lsmb text("$operation $entity_classname") ?></strong></div>
-<form name="customer" method="POST" action="<?lsmb script ?>">
+<form name="customer" method="post" action="<?lsmb script ?>">
 	<?lsmb PROCESS input element_data = {
 		type = "hidden"
 		name = "entity_id"

Modified: trunk/lsmb-request.pl
===================================================================
--- trunk/lsmb-request.pl	2008-09-08 18:14:38 UTC (rev 2317)
+++ trunk/lsmb-request.pl	2008-09-09 22:17:46 UTC (rev 2318)
@@ -52,13 +52,14 @@
         
     my $script = shift @_;
     my $request = shift @_;
+    $request->{script} = $script;
     eval { require "scripts/$script" } 
       || $request->error($locale->text('Unable to open script') . ": scripts/$script : $!");
     $script =~ s/\.pl$//;
     $script = "LedgerSMB::Scripts::$script";
+    $request->{_script_handle} = $script;
     $script->can($request->{action}) 
       || $request->error($locale->text("Action Not Defined: ") . $request->{action});
-
     $script->can( $request->{action} )->($request);
 }
 1;

Modified: trunk/scripts/customer.pl
===================================================================
--- trunk/scripts/customer.pl	2008-09-08 18:14:38 UTC (rev 2317)
+++ trunk/scripts/customer.pl	2008-09-09 22:17:46 UTC (rev 2318)
@@ -20,299 +20,18 @@
 
 package LedgerSMB::Scripts::customer;
 
-use LedgerSMB::Template;
 use LedgerSMB::DBObject::Customer;
+use base qw(LedgerSMB::ScriptLib::Company);
 
 require 'lsmb-request.pl';
 
-=pod
-
-=over
-
-=item get($self, $request, $user)
-
-Requires form var: id
-
-Extracts a single customer from the database, using its company ID as the primary
-point of uniqueness. Shows (appropriate to user privileges) and allows editing
-of the customer informations.
-
-=back
-
-=cut
-
-
-sub get {
-    
+sub set_entity_class {
     my ($request) = @_;
-    my $customer = LedgerSMB::DBObject::Customer->new(base => $request, copy => 'all');
-    
-    $customer->set( entity_class=> '2' );
-    my $result = $customer->get();
-    $customer->get_credit_id();
-    my $template = LedgerSMB::Template->new( 
-	template => 'contact', 
-	user => $request->{_user},
-	locale => $request->{_locale},
-	path => 'UI/Contact',
-        format => 'HTML');
-    $template->render($results);
-        
+    $request->{entity_class} = 2;
+    return 1;
 }
 
-
-sub add_location {
-    my ($request) = @_;
-    my $customer = LedgerSMB::DBObject::Customer->new({base => $request, copy => 'all'});
-    $customer->set( entity_class=> '2' );
-    $customer->save_location();
-    $customer->get();
-
-    
-    $customer->get_metadata();
-
-    _render_main_screen($customer);
-	
+sub new_company {
+    my ($null, $request) = @_;
+    return LedgerSMB::DBObject::Customer->new(base=> $request, copy => 'all');
 }
-
-=pod
-
-=over
-
-=item add
-
-This method creates a blank screen for entering a customer's information.
-
-=back
-
-=cut 
-
-sub add {
-    my ($request) = @_;
-    my $customer = LedgerSMB::DBObject::Customer->new(base => $request, copy => 'all');
-    $customer->set( entity_class=> '2' );
-    _render_main_screen($customer);
-}
-
-=pod
-
-=over
-
-=item search($self, $request, $user)
-
-Requires form var: search_pattern
-
-Directly calls the database function search, and returns a set of all customers
-found that match the search parameters. Search parameters search over address 
-as well as customer/Company name.
-
-=back
-
-=cut
-
-sub search {
-    my ($request) = @_;
-    
-        
-    $request->{script} = "customer.pl";
-    $request->{account_class} = 2; 
-    my $template = LedgerSMB::Template->new( 
-		user => $request->{_user},
-		path => 'UI/Contact' ,
-    		template => 'search', 
-		locale => $request->{_locale}, 
-		format => 'HTML');
-            
-    $template->render($request);
-}
-
-=pod
-
-=item get_result($self, $request, $user)
-
-Requires form var: search_pattern
-
-Directly calls the database function search, and returns a set of all vendors
-found that match the search parameters. Search parameters search over address 
-as well as vendor/Company name.
-
-=back
-
-=cut
-
-sub get_results {
-    my ($request) = @_;
-        
-    my $customer = LedgerSMB::DBObject::Customer->new(base => $request, copy => 'all');
-    $customer->set(entity_class=>2);
-    $customer->{contact_info} = qq|{"%$request->{email}%","%$request->{phone}%"}|;
-    my $results = $customer->search();
-    if ($customer->{order_by}){
-       # TODO:  Set ordering logic
-    };
-
-    # URL Setup
-    my $baseurl = "$request->{script}";
-    my $search_url = "$base_url?action=get_results";
-    my $get_url = "$base_url?action=get&account_class=$request->{account_class}";
-    for (keys %$vendor){
-        next if $_ eq 'order_by';
-        $search_url .= "&$_=$form->{$_}";
-    }
-
-    # Column definitions for dynatable
-    @columns = qw(legal_name meta_number business_type curr);
-    my %column_heading;
-    $column_heading{legal_name} = {
-        text => $request->{_locale}->text('Name'),
-	href => "$search_url&order_by=legal_name",
-    };
-    $column_heading{meta_number} = {
-        text => $request->{_locale}->text('Customer Number'),
-	href => "$search_url&order_by=meta_number",
-    };
-    $column_heading{business_type} = {
-        text => $request->{_locale}->text('Business Type'),
-	href => "$search_url&order_by=business_type",
-    };
-    $column_heading{curr} = {
-        text => $request->{_locale}->text('Currency'),
-	href => "$search_url&order_by=curr",
-    };
-
-    my @rows;
-    for $ref (@{$customer->{search_results}}){
-	push @rows, 
-                {legal_name   => $ref->{legal_name},
-                meta_number   => {text => $ref->{meta_number},
-                                  href => "$get_url&entity_id=$ref->{entity_id}"		                           . "&meta_number=$ref->{meta_number}"
-		                 },
-		business_type => $ref->{business_type},
-                curr          => $ref->{curr},
-                };
-    }
-# CT:  The CSV Report is broken.  I get:
-# Not an ARRAY reference at 
-# /usr/lib/perl5/site_perl/5.8.8/CGI/Simple.pm line 423
-# Disabling the button for now.
-    my @buttons = (
-#	{name => 'action',
-#        value => 'csv_vendor_list',
-#        text => $vendor->{_locale}->text('CSV Report'),
-#        type => 'submit',
-#        class => 'submit',
-#        },
-	{name => 'action',
-        value => 'add',
-        text => $customer->{_locale}->text('Add Customer'),
-        type => 'submit',
-        class => 'submit',
-	}
-    );
-
-    my $template = LedgerSMB::Template->new( 
-		user => $user,
-		path => 'UI' ,
-    		template => 'form-dynatable', 
-		locale => $customer->{_locale}, 
-		format => ($request->{FORMAT}) ? $request->{FORMAT}  : 'HTML',
-    );
-            
-    $template->render({
-	form    => $customer,
-	columns => ..hidden..,
-        hiddens => $vendor,
-	buttons => ..hidden..,
-	heading => \%column_heading,
-	rows    => ..hidden..,
-    });
-}
-=pod
-
-=over
-
-=item save($self, $request, $user)
-
-Saves a customer to the database. The function will update or insert a new 
-customer as needed, and will generate a new Company ID for the customer if needed.
-
-=back
-
-=cut
-
-sub save {
-    
-    my ($request) = @_;
-
-    my $customer = LedgerSMB::DBObject::Customer->new({base => $request});
-    $customer->save();
-    _render_main_screen($customer);
-}
-
-sub save_credit {
-    my ($request) = @_;
-    my $customer = LedgerSMB::DBObject::Customer->new({base => $request});
-    $customer->save_credit();
-    $customer->get();
-    _render_main_screen($customer);
-}
-
-sub save_credit_new {
-    my ($request) = @_;
-    $request->{credit_id} = undef;
-    save_credit($request);
-}
-
-
-sub edit{
-    my $request = shift @_;
-    my $customer = LedgerSMB::DBObject::Customer->new({base => $request});
-    $customer->get();
-    $customer->get_credit_id();
-    _render_main_screen($customer);
-}
-
-sub _render_main_screen{
-    my $customer = shift @_;
-    $customer->get_metadata();
-
-    $customer->{creditlimit} = "$customer->{creditlimit}"; 
-    $customer->{discount} = "$customer->{discount}"; 
-    $customer->{script} = "customer.pl";
-
-    my $template = LedgerSMB::Template->new( 
-	user => $customer->{_user}, 
-    	template => 'contact', 
-	locale => $customer->{_locale},
-	path => 'UI/Contact',
-        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);
-}
-
-sub save_notes {
-    my ($request) = @_;
-    my $customer = LedgerSMB::DBObject::Customer->new({base => $request});
-    $customer->save_notes();
-    $customer->get();
-    _render_main_screen($customer);
-}
-    
-eval { do "scripts/custom/customer.pl"};
-1;

Modified: trunk/scripts/vendor.pl
===================================================================
--- trunk/scripts/vendor.pl	2008-09-08 18:14:38 UTC (rev 2317)
+++ trunk/scripts/vendor.pl	2008-09-09 22:17:46 UTC (rev 2318)
@@ -20,308 +20,22 @@
 
 package LedgerSMB::Scripts::vendor;
 
-use LedgerSMB::Template;
 use LedgerSMB::DBObject::Vendor;
+use base qw(LedgerSMB::ScriptLib::Company);
 
 require 'lsmb-request.pl';
 
-=pod
-
-=over
-
-=item get($self, $request, $user)
-
-Requires form var: id
-
-Extracts a single vendor from the database, using its company ID as the primary
-point of uniqueness. Shows (appropriate to user privileges) and allows editing
-of the vendor informations.
-
-=back
-
-=cut
-
-sub get {
-    
+sub set_entity_class {
     my ($request) = @_;
-    my $vendor = LedgerSMB::DBObject::Vendor->new(base => $request, copy => 'all');
-    
-    $vendor->set( entity_class=> '1' );
-    $vendor->get();
-    $vendor->get_credit_id();
-    $vendor->get_metadata();
-    _render_main_screen($vendor);
+    $request->{entity_class} = 1;
+    return 1;
 }
 
-
-sub add_location {
-    my ($request) = @_;
-    my $vendor= LedgerSMB::DBObject::Vendor->new({base => $request, copy => 'all'});
-    $vendor->set( entity_class=> '1' );
-    $vendor->save_location();
-    $vendor->get();
-
-    
-    $vendor->get_metadata();
-
-    _render_main_screen($vendor);
-	
+sub new_company {
+    my ($null, $request) = @_;
+    return LedgerSMB::DBObject::Vendor->new(base=> $request, copy => 'all');
 }
 
-sub generate_control_code {
-    my ($request) = @_;
-    my $vendor= LedgerSMB::DBObject::Vendor->new({base => $request, copy => 'all'});
-    
-    my ($ref) = $vendor->call_procedure(
-                             procname => 'setting_increment', 
-                             args     => ['entity_control']
-                           );
-    ($vendor->{control_code}) = values %$ref;
-    $vendor->{dbh}->commit;
-    if ($vendor->{meta_number}){
-        edit($vendor);
-    } else {
-       _render_main_screen($vendor);
-    }
-    
-}
-
-=pod
-
-=over
-
-=item add
-
-This method creates a blank screen for entering a vendor's information.
-
-=back
-
-=cut 
-
-sub add {
-    my ($request) = @_;
-    my $vendor= LedgerSMB::DBObject::Vendor->new(base => $request, copy => 'all');
-    $vendor->set( entity_class=> '1' );
-    _render_main_screen($vendor);
-}
-
-=pod
-
-=over
-
-=item get_result($self, $request, $user)
-
-Requires form var: search_pattern
-
-Directly calls the database function search, and returns a set of all vendors
-found that match the search parameters. Search parameters search over address 
-as well as vendor/Company name.
-
-=back
-
-=cut
-
-sub get_results {
-    my ($request) = @_;
-        
-    my $vendor = LedgerSMB::DBObject::Vendor->new(base => $request, copy => 'all');
-    $vendor->set(entity_class=>1);
-    $vendor->{contact_info} = qq|{"%$request->{email}%","%$request->{phone}%"}|;
-    my $results = $vendor->search();
-    if ($vendor->{order_by}){
-       # TODO:  Set ordering logic
-    };
-
-    # URL Setup
-    my $baseurl = "$request->{script}";
-    my $search_url = "$base_url?action=get_results";
-    my $get_url = "$base_url?action=get&account_class=$request->{account_class}";
-    for (keys %$vendor){
-        next if $_ eq 'order_by';
-        $search_url .= "&$_=$form->{$_}";
-    }
-
-    # Column definitions for dynatable
-    @columns = qw(legal_name meta_number business_type curr);
-    my %column_heading;
-    $column_heading{legal_name} = {
-        text => $request->{_locale}->text('Name'),
-	href => "$search_url&order_by=legal_name",
-    };
-    $column_heading{meta_number} = {
-        text => $request->{_locale}->text('Vendor Number'),
-	href => "$search_url&order_by=meta_number",
-    };
-    $column_heading{business_type} = {
-        text => $request->{_locale}->text('Business Type'),
-	href => "$search_url&order_by=business_type",
-    };
-    $column_heading{curr} = {
-        text => $request->{_locale}->text('Currency'),
-	href => "$search_url&order_by=curr",
-    };
-
-    my @rows;
-    for $ref (@{$vendor->{search_results}}){
-	push @rows, 
-                {legal_name   => $ref->{legal_name},
-                meta_number   => {text => $ref->{meta_number},
-                                  href => "$get_url&entity_id=$ref->{entity_id}"		                           . "&meta_number=$ref->{meta_number}"
-		                 },
-		business_type => $ref->{business_type},
-                curr          => $ref->{curr},
-                };
-    }
-# CT:  The CSV Report is broken.  I get:
-# Not an ARRAY reference at 
-# /usr/lib/perl5/site_perl/5.8.8/CGI/Simple.pm line 423
-# Disabling the button for now.
-    my @buttons = (
-#	{name => 'action',
-#        value => 'csv_vendor_list',
-#        text => $vendor->{_locale}->text('CSV Report'),
-#        type => 'submit',
-#        class => 'submit',
-#        },
-	{name => 'action',
-        value => 'add',
-        text => $vendor->{_locale}->text('Add Vendor'),
-        type => 'submit',
-        class => 'submit',
-	}
-    );
-
-    my $template = LedgerSMB::Template->new( 
-		user => $user,
-		path => 'UI' ,
-    		template => 'form-dynatable', 
-		locale => $vendor->{_locale}, 
-		format => ($request->{FORMAT}) ? $request->{FORMAT}  : 'HTML',
-    );
-            
-    $template->render({
-	form    => $vendor,
-	columns => ..hidden..,
-        hiddens => $vendor,
-	buttons => ..hidden..,
-	heading => \%column_heading,
-	rows    => ..hidden..,
-    });
-}
-
-sub csv_vendor_list {
-    my ($request) = @_;
-    $request->{FORMAT} = 'CSV';
-    get_results($request); 
-}
-
-=pod
-
-=over
-
-=item save($self, $request, $user)
-
-Saves a vendor to the database. The function will update or insert a new 
-vendor as needed, and will generate a new Company ID for the vendor if needed.
-
-=back
-
-=cut
-
-
-sub save {
-    
-    my ($request) = @_;
-
-    my $vendor = LedgerSMB::DBObject::Vendor->new({base => $request});
-    $vendor->save();
-    _render_main_screen($vendor);
-}
-
-sub save_credit {
-    
-    my ($request) = @_;
-
-    my $vendor = LedgerSMB::DBObject::Vendor->new({base => $request});
-    $vendor->save_credit();
-    $vendor->get();
-    _render_main_screen($vendor);
-}
-
-sub save_credit_new {
-    my ($request) = @_;
-    $request->{credit_id} = undef;
-    save_credit($request);
-}
-
-sub edit{
-    my $request = shift @_;
-    my $vendor = LedgerSMB::DBObject::Vendor->new({base => $request});
-    $vendor->get();
-    _render_main_screen($vendor);
-}
-
-sub _render_main_screen{
-    my $vendor = shift @_;
-    $vendor->get_metadata();
-
-    $vendor->{creditlimit} = "$vendor->{creditlimit}"; 
-    $vendor->{discount} = "$vendor->{discount}"; 
-    $vendor->{script} = "vendor.pl";
-    $vendor->{note_class_options} = [
-        {label => 'Entity', value => 1},
-        {label => 'Vendor Account', value => 3},
-    ];
-    $vendor->{threshold} = $vendor->format_amount(amount => $vendor->{threshold});
-
-    my $template = LedgerSMB::Template->new( 
-	user => $vendor->{_user}, 
-    	template => 'contact', 
-	locale => $vendor->{_locale},
-	path => 'UI/Contact',
-        format => 'HTML'
-    );
-    $template->render($vendor);
-}
-
-sub search {
-    my ($request) = @_;
-    $request->{account_class} = 1;
-    $request->{script} = 'vendor.pl';
-    my $template = LedgerSMB::Template->new( 
-	user => $request->{_user}, 
-    	template => 'search', 
-	locale => $request->{_locale},
-	path => 'UI/Contact',
-        format => 'HTML'
-    );
-    $template->render($request);
-}    
-
-sub save_contact {
-    my ($request) = @_;
-    my $vendor = LedgerSMB::DBObject::Vendor->new({base => $request});
-    $vendor->save_contact();
-    $vendor->get;
-    _render_main_screen($vendor );
-}
-
-
-sub save_bank_account {
-    my ($request) = @_;
-    my $vendor = LedgerSMB::DBObject::Vendor->new({base => $request});
-    $vendor->save_bank_account();
-    $vendor->get;
-    _render_main_screen($vendor );
-}
-
-sub save_notes {
-    my ($request) = @_;
-    my $vendor = LedgerSMB::DBObject::Vendor->new({base => $request});
-    $vendor->save_notes();
-    $vendor->get();
-    _render_main_screen($vendor );
-}
 eval { do "scripts/custom/vendor.pl"};
     
 1;


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.