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

SF.net SVN: ledger-smb: [1902] trunk/scripts/vendor.pl



Revision: 1902
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=1902&view=rev
Author:   einhverfr
Date:     2007-11-25 12:31:25 -0800 (Sun, 25 Nov 2007)

Log Message:
-----------
Moving vendor workflow script to refactored code.  TODO:  Refactor customer/vendor/employee workflow scripts to move common functionality to standard file.

Modified Paths:
--------------
    trunk/scripts/vendor.pl

Modified: trunk/scripts/vendor.pl
===================================================================
--- trunk/scripts/vendor.pl	2007-11-25 19:59:02 UTC (rev 1901)
+++ trunk/scripts/vendor.pl	2007-11-25 20:31:25 UTC (rev 1902)
@@ -1,3 +1,4 @@
+#!/usr/bin/perl
 
 =pod
 
@@ -3,11 +4,11 @@
 =head1 NAME
 
-LedgerSMB::Scripts::Vendor - LedgerSMB class defining the Controller
-functions, template instantiation and rendering for Vendor editing and display.
+LedgerSMB::Scripts::vendor - LedgerSMB class defining the Controller
+functions, template instantiation and rendering for vendor editing and display.
 
 =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. 
+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 will update or create as needed.
 
@@ -17,11 +18,13 @@
 
 =cut
 
-package LedgerSMB::Scripts::Vendor;
+package LedgerSMB::Scripts::vendor;
 
 use LedgerSMB::Template;
 use LedgerSMB::DBObject::Vendor;
 
+require 'lsmb-request.pl';
+
 =pod
 
 =over
@@ -30,7 +33,7 @@
 
 Requires form var: id
 
-Extracts a single Vendor from the database, using its company ID as the primary
+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.
 
@@ -38,142 +41,165 @@
 
 =cut
 
+
 sub get {
     
-    my ($class, $request) = @_;
+    my ($request) = @_;
     my $vendor = LedgerSMB::DBObject::Vendor->new(base => $request, copy => 'all');
-    my $result = $vendor->get($vendor->{id});
     
+    $vendor->set( entity_class=> '2' );
+    my $result = $vendor->get();
+    
     my $template = LedgerSMB::Template->new( user => $user, 
-	template => 'vendor.html', language => $user->{language}, 
-        format => 'html');
+	template => 'contact', language => $user->{language}, 
+	path => 'UI/Contact',
+        format => 'HTML');
     $template->render($results);
         
 }
 
-=pod
 
-=over
+sub add_location {
+    my ($request) = @_;
+    my $vendor= LedgerSMB::DBObject::Vendor->new({base => $request, copy => 'all'});
+    $vendor->set( entity_class=> '2' );
+    $vendor->save_location();
+    $vendor->get();
 
-=item search($self, $request, $user)
+    
+    $vendor->get_metadata();
 
-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 search {
-    my ($class, $request) = @_;
-    my $vendor = LedgerSMB::DBObject::Vendor->new(base => $request, copy => 'all');
-    my $results = $vendor->search($vendor->{search_pattern});
-    
-    my $template = LedgerSMB::Template->new( user => $user, 
-	template => 'vendor_search.html', language => $user->{language}, 
-        format => 'html');
-    $template->render($results);
+    _render_main_screen($vendor);
+	
 }
 
 =pod
 
 =over
 
-=item save($self, $request, $user)
+=item add
 
-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.
+This method creates a blank screen for entering a vendor's information.
 
 =back
 
-=cut
+=cut 
 
-sub save {
-    
-    my ($class, $request) = @_;
-    my $vendor = LedgerSMB::DBObject::Vendor->new(base => $request, copy => 'all');
-    my $result = $vendor->save_to_db();
-    
-    my $template = LedgerSMB::Template->new( user => $user, 
-	template => 'vendor.html', language => $user->{language}, 
-        format => 'html');
-    $template->render($result);    
+sub add {
+    my ($request) = @_;
+    my $vendor= LedgerSMB::DBObject::Vendor->new(base => $request, copy => 'all');
+    $vendor->set( entity_class=> '2' );
+    _render_main_screen($vendor);
 }
 
 =pod
 
 =over
 
-=item vendor_invoice($self, $request, $user)
+=item search($self, $request, $user)
 
-Added based on existing New Vendor screen.
+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 search {
+    my ($request) = @_;
+    
+    if ($request->type() eq 'POST') {
+        # assume it's asking us to do the search, now
+        
+        my $vendor = LedgerSMB::DBObject::Vendor->new(base => $request, copy => 'all');
+        $vendor->set(entity_class=>2);
+        my $results = $vendor->search($vendor->{search_pattern});
 
-sub vendor_invoice {
-    
-    
+        my $template = LedgerSMB::Template->new( user => $user, 
+    	template => 'Contact/vendor', language => $user->{language}, 
+            format => 'HTML');
+        $template->render($results);
+        
+    }
+    else {
+        
+        # grab the happy search page out.
+        
+        my $template = LedgerSMB::Template->new( 
+		user => $user,
+		path => 'UI/Contact' ,
+    		template => 'vendor_search', 
+		locale => $request->{_locale}, 
+		format => 'HTML');
+            
+        $template->render();
+    }
 }
 
 =pod
 
 =over
 
-=item purchase_order($self, $request, $user)
+=item save($self, $request, $user)
 
-Added based on existing New Vendor screen.
+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 purchase_order {
+sub save {
     
-    
+    my ($request) = @_;
+
+    my $vendor = LedgerSMB::DBObject::Vendor->new({base => $request});
+    $vendor->save();
+    _render_main_screen($vendor);
 }
 
-=pod
+sub edit{
+    my $request = shift @_;
+    my $vendor = LedgerSMB::DBObject::Vendor->new({base => $request});
+    $vendor->get();
+    _render_main_screen($vendor);
+}
 
-=over
+sub _render_main_screen{
+    my $vendor = shift @_;
+    $vendor->get_metadata();
 
-=item rfq($self, $request, $user)
+    $vendor->{creditlimit} = "$vendor->{creditlimit}"; 
+    $vendor->{discount} = "$vendor->{discount}"; 
+    $vendor->{script} = "vendor.pl";
 
-Added based on existing New Vendor screen.
+    my $template = LedgerSMB::Template->new( 
+	user => $vendor->{_user}, 
+    	template => 'contact', 
+	locale => $vendor->{_locale},
+	path => 'UI/Contact',
+        format => 'HTML'
+    );
+    $template->render($vendor);
+}
 
-=back
-
-=cut
-
-sub rfq {
-    
-    $self->save(@_);
-    my ($class, $request) = @_;
-    # saves a new vendor, then generates something.
-    
+sub save_contact {
+    my ($request) = @_;
+    my $vendor = LedgerSMB::DBObject::Vendor->new({base => $request});
+    $vendor ->save_contact();
+    $vendor ->get;
+    _render_main_screen($vendor );
 }
 
-=pod
-
-=over
-
-=item pricelist($self, $request, $user)
-
-Added based on existing New Vendor screen.
-
-=back
-
-=cut
-
-sub pricelist {
-    
-    
-    
+sub save_bank_account {
+    my ($request) = @_;
+    my $vendor = LedgerSMB::DBObject::Vendor->new({base => $request});
+    $vendor ->save_bank_account();
+    $vendor ->get;
+    _render_main_screen($vendor );
 }
 
 1;


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