[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
SF.net SVN: ledger-smb:[3640] trunk
- Subject: SF.net SVN: ledger-smb:[3640] trunk
- From: ..hidden..
- Date: Fri, 05 Aug 2011 23:37:33 +0000
Revision: 3640
http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=3640&view=rev
Author: einhverfr
Date: 2011-08-05 23:37:32 +0000 (Fri, 05 Aug 2011)
Log Message:
-----------
File attachments for parts
Modified Paths:
--------------
trunk/LedgerSMB/IC.pm
trunk/bin/ic.pl
trunk/scripts/file.pl
trunk/sql/Pg-database.sql
trunk/sql/modules/Files.sql
Added Paths:
-----------
trunk/setup.pl
trunk/sql/upgrade/3640-new-file-type.sql
Modified: trunk/LedgerSMB/IC.pm
===================================================================
--- trunk/LedgerSMB/IC.pm 2011-08-05 00:42:37 UTC (rev 3639)
+++ trunk/LedgerSMB/IC.pm 2011-08-05 23:37:32 UTC (rev 3640)
@@ -34,9 +34,32 @@
package IC;
use LedgerSMB::Log;
+use LedgerSMB::File;
my $logger = Log::Log4perl->get_logger('IC');
+=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});
+ @{$form->{files}} = $file->list({ref_key => $form->{id}, file_class => 3});
+ @{$form->{file_links}} = $file->list_links(
+ {ref_key => $form->{id}, file_class => 3}
+ );
+
+}
+
sub get_part {
my ( $self, $myconfig, $form ) = @_;
Modified: trunk/bin/ic.pl
===================================================================
--- trunk/bin/ic.pl 2011-08-05 00:42:37 UTC (rev 3639)
+++ trunk/bin/ic.pl 2011-08-05 23:37:32 UTC (rev 3640)
@@ -825,7 +825,11 @@
}
sub form_footer {
+ if ($form->{id}){
+ IC->get_files($form, $locale);
+ }
+
print qq|
<tr>
<td><hr size=3 noshade></td>
@@ -879,6 +883,64 @@
}
}
+ if ($form->{id}){
+ print qq|
+<table width="100%">
+<tr class="listtop">
+<th colspan="4">| . $locale->text('Attached and Linked Files') . qq|</th>
+<tr class="listheading">
+<th>| . $locale->text('File name') . qq|</th>
+<th>| . $locale->text('File type') . qq|</th>
+<th>| . $locale->text('Attached at') . qq|</th>
+<th>| . $locale->text('Attached by') . qq|</th>
+</tr> |;
+ foreach my $file (@{$form->{files}}){
+ print qq|
+<tr>
+<td><a href="file.pl?action=get&file_class=3&ref_key=$form->{id}&id=$file->{id}"
+ >$file->{file_name}</a></td>
+<td>$file->{mime_type}</td>
+<td>$file->{uploaded_at}</td>
+<td>$file->{uploaded_by_name}</td>
+</tr>
+ |;
+ }
+ print qq|
+<table width="100%">
+<tr class="listheading">
+<th>| . $locale->text('File name') . qq|</th>
+<th>| . $locale->text('File type') . qq|</th>
+<th>| . $locale->text('Attached To Type') . qq|</th>
+<th>| . $locale->text('Attached To') . qq|</th>
+<th>| . $locale->text('Attached at') . qq|</th>
+<th>| . $locale->text('Attached by') . qq|</th>
+</tr>|;
+ foreach my $link (@{$form->{file_links}}){
+ $aclass=" ";
+ if ($link.src_class == 1){
+ $aclass="Transaction";
+ } elsif ($link.src_class == 2){
+ $aclass="Order";
+ }
+ print qq|
+<tr>
+<td> $file->{file_name} </td>
+<td> $file->{mime_type} </td>
+<td> $aclass </td>
+<td> $file->{reference} </td>
+<td> $file->{attached_at} </td>
+<td> $file->{attached_by} </td>
+</tr>|;
+ }
+ print qq|
+</table>|;
+ $callback = $form->escape(
+ lc($form->{ARAP}) . ".pl?action=edit&id=".$form->{id}
+ );
+ print qq|
+<a href="file.pl?action=show_attachment_screen&ref_key=$form->{id}&file_class=3&callback=$callback"
+ >[| . $locale->text('Attach') . qq|]</a>|;
+ }
if ( $form->{lynx} ) {
require "bin/menu.pl";
Modified: trunk/scripts/file.pl
===================================================================
--- trunk/scripts/file.pl 2011-08-05 00:42:37 UTC (rev 3639)
+++ trunk/scripts/file.pl 2011-08-05 23:37:32 UTC (rev 3640)
@@ -24,12 +24,14 @@
use LedgerSMB::File;
use LedgerSMB::File::Transaction;
use LedgerSMB::File::Order;
+use LedgerSMB::File::Part;
use strict;
use CGI::Simple;
our $fileclassmap = {
1 => 'LedgerSMB::File::Transaction',
2 => 'LedgerSMB::File::Order',
+ 3 => 'LedgerSMB::File::Part',
};
sub get {
Copied: trunk/setup.pl (from rev 3637, trunk/drafts.pl)
===================================================================
--- trunk/setup.pl (rev 0)
+++ trunk/setup.pl 2011-08-05 23:37:32 UTC (rev 3640)
@@ -0,0 +1,3 @@
+#!/usr/bin/perl
+
+require 'lsmb-request.pl';
Modified: trunk/sql/Pg-database.sql
===================================================================
--- trunk/sql/Pg-database.sql 2011-08-05 00:42:37 UTC (rev 3639)
+++ trunk/sql/Pg-database.sql 2011-08-05 23:37:32 UTC (rev 3640)
@@ -4399,6 +4399,7 @@
insert into file_class values (1, 'transaction');
insert into file_class values (2, 'order');
+insert into file_class values (3, 'part');
COMMENT ON TABLE file_class IS
$$ File classes are collections of files attached against rows in specific
@@ -4448,9 +4449,19 @@
foreign key (ref_key) references oe(id)
) inherits (file_base);
-COMMENT ON TABLE file_transaction IS
-$$ File attachments primarily attached to orders and quotatoins.$$;
+COMMENT ON TABLE file_order IS
+$$ File attachments primarily attached to orders and quotations.$$;
+CREATE TABLE file_part (
+ check (file_class=3),
+ unique(id),
+ primary key (ref_key, file_name, file_class),
+ foreign key (ref_key) references parts(id)
+) inherits (file_base);
+
+COMMENT ON TABLE file_part IS
+$$ File attachments primarily attached to orders and quotations.$$;
+
CREATE TABLE file_secondary_attachment (
file_id int not null,
source_class int references file_class(id),
Modified: trunk/sql/modules/Files.sql
===================================================================
--- trunk/sql/modules/Files.sql 2011-08-05 00:42:37 UTC (rev 3639)
+++ trunk/sql/modules/Files.sql 2011-08-05 23:37:32 UTC (rev 3640)
@@ -50,6 +50,44 @@
Setting both raises an exception.$$;
+CREATE OR REPLACE FUNCTION file__attach_to_part
+(in_content bytea, in_mime_type_id int, in_file_name text,
+in_description text, in_id int, in_ref_key int, in_file_class int)
+RETURNS file_base
+AS
+$$
+DECLARE retval file_base;
+BEGIN
+ IF in_id IS NOT NULL THEN
+ IF in_content THEN
+ RAISE EXCEPTION $e$Can't specify id and content in attachment$e$;--'
+ END IF;
+ RAISE EXCEPTION 'links not implemented';
+ RETURN retval;
+ ELSE
+ INSERT INTO file_part
+ (content, mime_type_id, file_name, description, ref_key,
+ file_class, uploaded_by, uploaded_at)
+ VALUES (in_content, in_mime_type_id, in_file_name, in_description,
+ in_ref_key, in_file_class, person__get_my_entity_id(),
+ now());
+ SELECT * INTO retval FROM file_base
+ where id = currval('file_base_id_seq');
+
+ RETURN retval;
+ END IF;
+END;
+$$ LANGUAGE PLPGSQL;
+
+COMMENT ON FUNCTION file__attach_to_part
+(in_content bytea, in_mime_type_id int, in_file_name text,
+in_description text, in_id int, in_ref_key int, in_file_class int) IS
+$$ Attaches or links a file to a good or service. in_content OR id can be set.
+Setting both raises an exception.
+
+Note that currently links (setting id) is NOT supported because we dont have a
+use case of linking files to parts$$;
+
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, in_ref_key int, in_file_class int)
Added: trunk/sql/upgrade/3640-new-file-type.sql
===================================================================
--- trunk/sql/upgrade/3640-new-file-type.sql (rev 0)
+++ trunk/sql/upgrade/3640-new-file-type.sql 2011-08-05 23:37:32 UTC (rev 3640)
@@ -0,0 +1,12 @@
+insert into file_class values (3, 'part');
+
+CREATE TABLE file_part (
+ check (file_class=3),
+ unique(id),
+ primary key (ref_key, file_name, file_class),
+ foreign key (ref_key) references parts(id)
+) inherits (file_base);
+
+COMMENT ON TABLE file_part IS
+$$ File attachments primarily attached to orders and quotations.$$;
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.