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

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



Revision: 3566
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=3566&view=rev
Author:   einhverfr
Date:     2011-07-26 00:27:30 +0000 (Tue, 26 Jul 2011)

Log Message:
-----------
file retrieval api added to GL, working without errors.

Modified Paths:
--------------
    trunk/LedgerSMB/DBObject.pm
    trunk/LedgerSMB/File.pm
    trunk/LedgerSMB/GL.pm
    trunk/bin/gl.pl
    trunk/sql/modules/Files.sql
    trunk/sql/modules/Report.sql
    trunk/sql/modules/Roles.sql
    trunk/t/98-pod-coverage.t

Modified: trunk/LedgerSMB/DBObject.pm
===================================================================
--- trunk/LedgerSMB/DBObject.pm	2011-07-25 20:16:16 UTC (rev 3565)
+++ trunk/LedgerSMB/DBObject.pm	2011-07-26 00:27:30 UTC (rev 3566)
@@ -109,7 +109,7 @@
 
 sub exec_method {
     my $self   = shift @_;
-    my %args     = @_;
+    my %args  = (ref($_[0]) eq 'HASH')? %{$_[0]}: @_;
     my $funcname = $args{funcname};
     
     my $schema   = $args{schema} || $LedgerSMB::Sysconfig::db_namespace;

Modified: trunk/LedgerSMB/File.pm
===================================================================
--- trunk/LedgerSMB/File.pm	2011-07-25 20:16:16 UTC (rev 3565)
+++ trunk/LedgerSMB/File.pm	2011-07-26 00:27:30 UTC (rev 3566)
@@ -131,19 +131,19 @@
     my ($self, $args)  = @_;
     my $dbobject;
     my $rc = 0; # Success
-    if (LedgerSMB::Form->isa($args->{base})){
+    if (ref $args->{base} eq 'Form'){
          use LedgerSMB::Locale;
          my $lsmb = LedgerSMB->new();
          $lsmb->merge($args->{base});
-         if (LedgerSMB::Locale->isa($args->{locale})){
+         if ((ref $args->{locale}) =~ /^LedgerSMB::Locale/){
              $lsmb->{_locale} = $args->{locale};
-             my $dbobject = LedgerSMB::DBObject({base => $lsmb});
+             $dbobject = LedgerSMB::DBObject->new({base => $lsmb});
          } else {
              $rc | 2; # No locale
          }
     }
     elsif (LedgerSMB->isa($args->{base})){
-         my $dbobject = LedgerSMB::DBObject({base => $args->{base}});
+         $dbobject = LedgerSMB::DBObject->new({base => $args->{base}});
     }
     else {
         $rc | 4; # Incorrect base type
@@ -154,6 +154,7 @@
     if ($rc){
         return $rc;  # Return error.
     } else {
+        
         $self->dbobject($dbobject);
         return 0;
     }
@@ -180,6 +181,12 @@
     }
 }
 
+=item set_mime_type
+
+Sets the mipe_type_id from the mime_type_text
+
+=cut
+
 sub set_mime_type {
     my ($self, $mime_type) = @_;
     $self->mime_type_text($mime_type);
@@ -189,6 +196,17 @@
 
 }
 
+=item detect_type
+
+Auto-detects the type of the file.  Not yet implemented
+
+=cut
+
+sub detect_type {
+    my ($self) = @_;
+    print STDERR "WARNING:  Stub LedgerSMB::File::detect_type\n";
+};
+
 =item get
 
 Retrives a file.  ID and file_class properties must be set.
@@ -210,7 +228,7 @@
 sub list{
     my ($self, $args) = @_;
     my @results = $self->exec_method(
-                 {funcname => 'file__list', 
+                 {funcname => 'file__list_by', 
                       args => [$args->{ref_key}, $args->{file_class}]
                  }
      );

Modified: trunk/LedgerSMB/GL.pm
===================================================================
--- trunk/LedgerSMB/GL.pm	2011-07-25 20:16:16 UTC (rev 3565)
+++ trunk/LedgerSMB/GL.pm	2011-07-26 00:27:30 UTC (rev 3566)
@@ -33,6 +33,30 @@
 
 package GL;
 
+use LedgerSMB::File;
+
+=over
+
+=item get_files
+
+Returns a list of files associated with the existing transaction.  This is 
+provisional, and wil change for 1.4 as the GL transaction functionality is 
+                  {ref_key => $self->{id}, file_class => 1}
+rewritten
+
+=cut
+
+sub get_files {
+     my ($self, $form, $locale) = @_;
+     my $file = LedgerSMB::File->new();
+     $file->new_dbobject({base => $form, locale => $locale});
+     @{$self->{files}} = $file->list({ref_key => $self->{id}, file_class => 1});
+     @{$self->{file_links}} = $file->list_links(
+                  {ref_key => $self->{id}, file_class => 1}
+     );
+
+}
+
 sub delete_transaction {
 
     my ( $self, $myconfig, $form ) = @_;

Modified: trunk/bin/gl.pl
===================================================================
--- trunk/bin/gl.pl	2011-07-25 20:16:16 UTC (rev 3565)
+++ trunk/bin/gl.pl	2011-07-26 00:27:30 UTC (rev 3566)
@@ -921,7 +921,9 @@
 
         $i++;
     }
-
+   if ($form->{id}){
+       GL->get_files($form, $locale);
+   }
    $form->{rowcount} = $i;
    $form->{focus}    = "debit_$i";
    &display_form;

Modified: trunk/sql/modules/Files.sql
===================================================================
--- trunk/sql/modules/Files.sql	2011-07-25 20:16:16 UTC (rev 3565)
+++ trunk/sql/modules/Files.sql	2011-07-26 00:27:30 UTC (rev 3566)
@@ -6,7 +6,7 @@
  where ($1 IS NULL OR id = $1) AND ($2 IS NULL OR mime_type = $2);
 $$ language sql;
 
-COMMENT ON FUNCTION file__get_mime_type(in_mime_type_id int) IS
+COMMENT ON FUNCTION file__get_mime_type(in_mime_type_id int, in_mime_type text) IS
 $$Retrieves mime type information associated with a file object.$$;
 
 CREATE OR REPLACE FUNCTION file__attach_to_tx
@@ -19,7 +19,7 @@
 BEGIN
    IF in_id IS NOT NULL THEN
        IF in_content THEN
-          RAISE EXCEPTION $e$Can't specify id and content in attachment$$;--'
+          RAISE EXCEPTION $e$Can't specify id and content in attachment$e$;--'
        END IF;
        INSERT INTO file_order_to_tx        
               (file_id, source_class, ref_key, dest_class, attached_by,
@@ -52,7 +52,7 @@
 
 CREATE OR REPLACE FUNCTION file__attach_to_order
 (in_content bytea, in_mime_type_id int, in_file_name text,
-in_description text, in_id int, ref_key int, file_class int)
+in_description text, in_id int, in_ref_key int, in_file_class int)
 RETURNS file_base
 AS
 $$
@@ -62,18 +62,18 @@
        IF in_content THEN
           RAISE EXCEPTION $e$Conflicting options file_id and content$e$;
        END IF;
-       IF file_class = 1 THEN
+       IF in_file_class = 1 THEN
            INSERT INTO file_tx_to_order        
                   (file_id, source_class, ref_key, dest_class, attached_by,
                   attached_at)
            VALUES (in_id, 1, in_ref_key, 2, person__get_my_entity_id(), now());
-       ELSIF file_class = 2 THEN
+       ELSIF in_file_class = 2 THEN
            INSERT INTO file_order_to_order
                   (file_id, source_class, ref_key, dest_class, attached_by,
                   attached_at)
            VALUES (in_id, 2, in_ref_key, 2, person__get_my_entity_id(), now());
        ELSE 
-           RAISE EXCEPTION $E$Invalid file class$e$;
+           RAISE EXCEPTION $E$Invalid file class$E$;
        END IF;
        SELECT * INTO retval FROM file_base where id = in_id;
        RETURN retval;
@@ -99,7 +99,7 @@
 Setting both raises an exception.$$;
 
 
-CREATE TYPE file_list_item AS
+CREATE TYPE file_list_item AS (
        mime_type text,
        file_name text,
        description text,
@@ -112,7 +112,7 @@
 );
 
 CREATE OR REPLACE FUNCTION file__list_by(in_ref_key int, in_file_class int)
-RETURNS SETOF file_base AS
+RETURNS SETOF file_list_item AS
 $$
 
 SELECT m.mime_type, f.file_name, f.description, f.uploaded_by, e.name, 
@@ -143,8 +143,8 @@
 DELETE FROM file_view_catalog WHERE file_class in (1, 2);
 
 CREATE OR REPLACE view file_tx_links AS
-SELECT file_id, ref_key, gl.reference, gl.type, dest_class, src_class
-       sl.refkey as dest_ref
+SELECT file_id, ref_key, gl.reference, gl.type, dest_class, source_class,
+       sl.ref_key as dest_ref
   FROM file_secondary_attachment sl
   JOIN (select id, reference, 'gl' as type
           FROM gl
@@ -153,19 +153,19 @@
           FROM ar
          UNION
         SELECT id, invnumber, case when invoice then 'ir' else 'ap' end as type
-          FROM ap) gl ON sl.ref_key = gl.id and sl.src_class = 1;
+          FROM ap) gl ON sl.ref_key = gl.id and sl.source_class = 1;
 -- view of links FROM transactions
 
 INSERT INTO file_view_catalog (file_class, view_name) 
      VALUES (1, 'file_tx_links');
 
 CREATE OR REPLACE view file_order_links AS
-SELECT file_id, ref_key, oe.ornumber as reference, oc.oe_class, dest_class, 
-       src_class, sl.refkey as dest_ref
+SELECT file_id, ref_key, oe.ordnumber as reference, oc.oe_class, dest_class, 
+       source_class, sl.ref_key as dest_ref
   FROM file_secondary_attachment sl   
   JOIN oe ON sl.ref_key = oe.id
-  JOIN order_class oc ON oe.oe_class_id = oc.id
- WHERE sl.src_class = 2;
+  JOIN oe_class oc ON oe.oe_class_id = oc.id
+ WHERE sl.source_class = 2;
        
 
 -- view of links FROM orders
@@ -178,18 +178,18 @@
 RETURNS bool AS
 $$
 DECLARE 
-   viewline file_catalog%rowtype;
+   viewline file_view_catalog%rowtype;
    stmt text;
 BEGIN
    stmt := '';
    FOR viewline IN
-       select * from view_catalog
+       select * from file_view_catalog
    LOOP
        IF stmt = '' THEN
            stmt := 'SELECT * FROM ' || quote_ident(viewline.view_name) || '
 ';
        ELSE
-           stmt := 'UNION
+           stmt := stmt || ' UNION
 SELECT * FROM '|| quote_ident(viewline.view_name) || '
 ';
        END IF; 
@@ -205,7 +205,7 @@
 
 CREATE OR REPLACE FUNCTION file__list_links(in_ref_key int, in_file_class int)
 RETURNS setof file_links AS
-$$ select * from file_links where ref_key = $1 and file_class = $2;
+$$ select * from file_links where ref_key = $1 and dest_class = $2;
 $$ language sql;
 
 COMMENT ON FUNCTION file__list_links(in_ref_key int, in_file_class int) IS

Modified: trunk/sql/modules/Report.sql
===================================================================
--- trunk/sql/modules/Report.sql	2011-07-25 20:16:16 UTC (rev 3565)
+++ trunk/sql/modules/Report.sql	2011-07-26 00:27:30 UTC (rev 3566)
@@ -1,3 +1,7 @@
+-- Unused currently and untested.  This is expected to be a basis for 1.4 work
+-- not recommended for current usage.  Not documenting yet.  --CT
+
+
 CREATE TYPE report_aging_item AS (
 	entity_id int,
 	account_number varchar(24),
@@ -153,3 +157,4 @@
 END;
 $$ language plpgsql;
 
+

Modified: trunk/sql/modules/Roles.sql
===================================================================
--- trunk/sql/modules/Roles.sql	2011-07-25 20:16:16 UTC (rev 3565)
+++ trunk/sql/modules/Roles.sql	2011-07-26 00:27:30 UTC (rev 3566)
@@ -5,7 +5,8 @@
 CREATE ROLE "lsmb_<?lsmb dbname ?>__file_read"
 WITH INHERIT NOLOGIN;
 
-GRANT SELECT ON file_base, file_secondary_attachment 
+GRANT SELECT ON file_base, file_secondary_attachment, file_transaction,
+file_order, file_links
       TO "lsmb_<?lsmb dbname ?>__file_read";
 
 CREATE ROLE "lsmb_<?lsmb dbname ?>__file_attach_tx"
@@ -1686,6 +1687,7 @@
                 asset_disposal_method TO PUBLIC;
 GRANT SELECT ON mime_type, file_class TO PUBLIC;
 
+
 GRANT EXECUTE ON FUNCTION user__get_all_users() TO public;
 
 --TODO, lock recurring, pending_job, payment_queue down more

Modified: trunk/t/98-pod-coverage.t
===================================================================
--- trunk/t/98-pod-coverage.t	2011-07-25 20:16:16 UTC (rev 3565)
+++ trunk/t/98-pod-coverage.t	2011-07-26 00:27:30 UTC (rev 3566)
@@ -13,7 +13,7 @@
 if ($@){
     plan skip_all => "Test::Pod::Coverage required for testing POD coverage";
 } else {
-    plan tests => 22;
+    plan tests => 24;
 }
 pod_coverage_ok("LedgerSMB");
 pod_coverage_ok("LedgerSMB::Form");
@@ -37,3 +37,5 @@
 pod_coverage_ok("LedgerSMB::DBObject::Admin");
 pod_coverage_ok("LedgerSMB::ScriptLib::Company");
 pod_coverage_ok("LedgerSMB::DBObject::Employee");
+pod_coverage_ok("LedgerSMB::File");
+pod_coverage_ok("LedgerSMB::DBObject");


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