[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
SF.net SVN: ledger-smb: [2163] trunk
- Subject: SF.net SVN: ledger-smb: [2163] trunk
- From: ..hidden..
- Date: Tue, 10 Jun 2008 10:34:41 -0700
Revision: 2163
http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=2163&view=rev
Author: einhverfr
Date: 2008-06-10 10:33:58 -0700 (Tue, 10 Jun 2008)
Log Message:
-----------
Adding UI support for multiple vendor/customer accounts per company.
Modified Paths:
--------------
trunk/LedgerSMB/DBObject/Company.pm
trunk/UI/Contact/contact.html
trunk/scripts/customer.pl
trunk/scripts/vendor.pl
trunk/scripts/vouchers.pl
trunk/sql/modules/Company.sql
Modified: trunk/LedgerSMB/DBObject/Company.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Company.pm 2008-06-08 20:53:41 UTC (rev 2162)
+++ trunk/LedgerSMB/DBObject/Company.pm 2008-06-10 17:33:58 UTC (rev 2163)
@@ -50,9 +50,26 @@
sub save {
my $self = shift @_;
$self->set_entity_class();
+ my ($ref) = $self->exec_method(funcname => 'company_save');
+ $self->{id} = $ref->{company_save};
+ $self->{dbh}->commit;
+}
+
+=over
+
+=item save_credit
+
+This method saves the credit account for the company.
+
+=back
+
+=cut
+
+sub save_credit {
+ my $self = shift @_;
+ $self->set_entity_class();
$self->{threshold} = $self->parse_amount(amount => $self->{threshold});
- my ($ref) = $self->exec_method(funcname => 'entity_credit_save');
- $self->{entity_id} = $ref->{entity_credit_save};
+ $self->exec_method(funcname => 'entity_credit_save');
$self->{threshold} = $self->format_amount(amount => $self->{threshold});
$self->{dbh}->commit;
}
@@ -77,6 +94,24 @@
=over
+=item get_credit_id
+
+This method returns the current credit id from the screen.
+
+=back
+
+=cut
+
+sub get_credit_id {
+ my $self = shift @_;
+ my ($ref) = $self->exec_method(
+ funcname => 'entity_credit_get_id'
+ );
+ $self->{credit_id} = $ref->{'entity_credit_get_id'};
+}
+
+=over
+
=item get_metadata()
This retrieves various information vor building the user interface. Among other
@@ -116,6 +151,9 @@
@{$self->{contact_class_list}} =
$self->exec_method(funcname => 'entity_list_contact_class');
+
+ @{$self->{credit_list}} =
+ $self->exec_method(funcname => 'entity__list_credit');
}
sub save_contact {
Modified: trunk/UI/Contact/contact.html
===================================================================
--- trunk/UI/Contact/contact.html 2008-06-08 20:53:41 UTC (rev 2162)
+++ trunk/UI/Contact/contact.html 2008-06-10 17:33:58 UTC (rev 2163)
@@ -24,7 +24,8 @@
<?lsmb IF entity_class == 3 ?>
<li><a href="#hr_div"><?lsmb text('HR') ?></a></li>
<?lsmb ELSE ?>
- <li><a href="#customer_div"><?lsmb text('Account') ?></a></li>
+ <li><a href="#company_div"><?lsmb text('Company') ?></a></li>
+ <li><a href="#credit_div"><?lsmb text('Accounts') ?></a></li>
<?lsmb END ?>
<?lsmb IF entity_id ?>
<li><a href="#location_div"><?lsmb text('Addresses') ?></a></li>
@@ -136,7 +137,7 @@
</div>
</form>
<?lsmb ELSE ?>
-<div class="container" id="customer_div">
+<div class="container" id="company_div">
<?lsmb SWITCH entity_class
?><?lsmb CASE 1 ?><?lsmb entity_classname = "Vendor"
?><?lsmb CASE 2 ?><?lsmb entity_classname = "Customer"
@@ -153,6 +154,11 @@
} ?>
<?lsmb PROCESS input element_data = {
type = "hidden"
+ name = "id"
+ value = id
+ } ?>
+ <?lsmb PROCESS input element_data = {
+ type = "hidden"
name = "account_class"
value = account_class
} ?>
@@ -163,7 +169,84 @@
value = name,
size = "20"
} ?><br/>
+ <table>
+ <tr>
+
+ <td>
+ <?lsmb INCLUDE input element_data = {
+ label = text('Tax Number/SSN:'),
+ name = "tax_id",
+ value = tax_id,
+ type = "text",
+ size = "19"
+ } #' ?>
+ </td>
+ <td>
+ <?lsmb INCLUDE input element_data = {
+ label = text('SIC:'),
+ name = "sic_code",
+ value = sic_code,
+ type = "text",
+ size = "19",
+ class = 'sic'
+ } ?>
+ </td>
+ </tr>
+ </table>
+
+ <hr/>
+ <?lsmb INCLUDE button element_data = {
+ text = text('Save'),
+ class="submit"
+ type="submit"
+ name="action"
+ value="save"
+ accesskey="S"
+ title="Save [Alt-S]"
+ } ?>
+ </form>
+</div>
+<div id="credit_div">
+<div class="listtop"><strong>Accounts</strong</div>
+ <table width="100%">
+ <tr class="listheading">
+ <th class="account_class"><?lsmb text('Type') ?></th>
+ <th class="number"><?lsmb text("Number") ?></th>
+ <th class="credit_limit"><?lsmb text('Credit Limit') ?></th>
+ <th class="start_date"><?lsmb text('Start Date') ?></th>
+ <th class="end_date"><?lsmb text('End Date') ?></th>
+ </tr>
+ <?lsmb FOREACH cl_item = credit_list ?>
+ <tr>
+ <td><?lsmb IF cl_item.entity_class == 1 ?><?lsmb text('Vendor') ?>
+ <?lsmb ELSIF cl_item.entity_class == 2 ?><?lsmb text('Customer') ?>
+ <?lsmb END ?>
+ </td>
+ <td><?lsmb cl_item.meta_number ?></td>
+ <td><?lsmb cl_item.credit_limit ?></td>
+ <td><?lsmb cl_item.start_date ?></td>
+ <td><?lsmb cl_item.end_date ?></td>
+ </tr>
+ <?lsmb END ?>
+ </table>
+ <form id="credit_form" name="credit_form" method="post"
+ action="<?lsmb script ?>">
<?lsmb PROCESS input element_data = {
+ type = "hidden"
+ name = "entity_id"
+ value = entity_id
+ } ?>
+ <?lsmb PROCESS input element_data = {
+ type = "hidden"
+ name = "credit_id"
+ value = credit_id
+ } ?>
+ <?lsmb PROCESS input element_data = {
+ type = "hidden"
+ name = "account_class"
+ value = account_class
+ } ?>
+ <?lsmb PROCESS input element_data = {
label = text("$entity_classname Number:"),
type= "text",
name = "meta_number",
@@ -214,28 +297,7 @@
size = "5"
} ?> <?lsmb text('days') ?>
</td>
- </tr>
- <tr>
-
- <td>
- <?lsmb INCLUDE input element_data = {
- label = text('Tax Number/SSN:'),
- name = "tax_id",
- value = tax_id,
- type = "text",
- size = "19"
- } #' ?>
- </td>
- <td>
- <?lsmb INCLUDE input element_data = {
- label = text('Subcontract GIFI:'),
- name = "gifi_accno",
- value = gifi_accno,
- type = "text",
- size = "19"
- } #' ?>
- </td>
- </tr>
+ </tr>
<tr>
<td>
<?lsmb INCLUDE input element_data = {
@@ -256,13 +318,12 @@
</td>
<td>
<?lsmb INCLUDE input element_data = {
- label = text('SIC:'),
- name = "sic_code",
- value = sic_code,
+ label = text('Subcontract GIFI:'),
+ name = "gifi_accno",
+ value = gifi_accno,
type = "text",
- size = "19",
- class = 'sic'
- } ?>
+ size = "19"
+ } #' ?>
</td>
</tr>
<tr>
@@ -284,6 +345,7 @@
value_attr = "id"
} ?>
</td>
+ </tr>
<tr>
<td> <?lsmb INCLUDE select element_data = {
name = "business_id"
@@ -303,19 +365,25 @@
class = "numeric"
} ?>
</tr>
- </table>
-
- <hr/>
+ </table>
<?lsmb INCLUDE button element_data = {
text = text('Save'),
class="submit"
type="submit"
name="action"
- value="save"
- accesskey="S"
- title="Save [Alt-S]"
+ value="save_credit"
+ accesskey="C"
+ title="Save Credit Account[Alt-C]"
} ?>
<?lsmb INCLUDE button element_data = {
+ text = text('Save New'),
+ class="submit"
+ type="submit"
+ name="action"
+ value="save_credit_new"
+ title="Save Credit Account as New" #'
+ } ?>
+ <?lsmb INCLUDE button element_data = {
class="submit"
type="submit"
name="action"
@@ -360,6 +428,7 @@
title="Pricelist [Alt-P]"
text = text('Pricelist')
} ?>
+
</form>
</div>
<?lsmb END ?>
Modified: trunk/scripts/customer.pl
===================================================================
--- trunk/scripts/customer.pl 2008-06-08 20:53:41 UTC (rev 2162)
+++ trunk/scripts/customer.pl 2008-06-10 17:33:58 UTC (rev 2163)
@@ -49,6 +49,7 @@
$customer->set( entity_class=> '2' );
my $result = $customer->get();
+ $customer->get_credit_id();
my $template = LedgerSMB::Template->new( user => $user,
template => 'contact', language => $user->{language},
@@ -161,10 +162,26 @@
_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);
}
Modified: trunk/scripts/vendor.pl
===================================================================
--- trunk/scripts/vendor.pl 2008-06-08 20:53:41 UTC (rev 2162)
+++ trunk/scripts/vendor.pl 2008-06-10 17:33:58 UTC (rev 2163)
@@ -49,6 +49,7 @@
$vendor->set( entity_class=> '1' );
$vendor->get();
+ $vendor->get_credit_id();
$vendor->get_metadata();
_render_main_screen($vendor);
}
@@ -219,10 +220,27 @@
_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();
+ $vendor->get_credit_id();
_render_main_screen($vendor);
}
Modified: trunk/scripts/vouchers.pl
===================================================================
--- trunk/scripts/vouchers.pl 2008-06-08 20:53:41 UTC (rev 2162)
+++ trunk/scripts/vouchers.pl 2008-06-10 17:33:58 UTC (rev 2163)
@@ -4,6 +4,8 @@
# the GNU General Public License. For more information please see the included
# LICENSE and COPYRIGHT files
+# THIS FILE NEEDS POD
+
package LedgerSMB::Scripts::vouchers;
our $VERSION = '0.1';
@@ -36,7 +38,9 @@
add_vouchers($batch);
}
+sub search_transactions {
+
sub add_vouchers {
# This function is not safe for caching as long as the scripts are in bin.
# This is because these scripts import all functions into the *current*
Modified: trunk/sql/modules/Company.sql
===================================================================
--- trunk/sql/modules/Company.sql 2008-06-08 20:53:41 UTC (rev 2162)
+++ trunk/sql/modules/Company.sql 2008-06-10 17:33:58 UTC (rev 2163)
@@ -153,43 +153,122 @@
threshold numeric
);
+CREATE TYPE entity_credit_retrieve AS (
+ id int,
+ entity_id int,
+ entity_class int,
+ discount numeric,
+ taxincluded bool,
+ creditlimit numeric,
+ terms int2,
+ meta_number text,
+ business_id int,
+ language_code text,
+ pricegroup_id int,
+ curr text,
+ startdate date,
+ enddate date,
+ ar_ap_account_id int,
+ cash_account_id int,
+ threshold numeric
+);
+
COMMENT ON TYPE entity_credit_search_return IS
$$ This may change in 1.4 and should not be relied upon too much $$;
-CREATE OR REPLACE FUNCTION entity__retrieve_credit
+CREATE OR REPLACE FUNCTION entity_credit_get_id
+(in_entity_id int, in_entity_class int, in_meta_number text)
+RETURNS int AS $$
+DECLARE out_var int;
+BEGIN
+ SELECT id INTO out_var FROM entity_credit_account
+ WHERE entity_id = in_entity_id
+ AND in_entity_class = entity_class
+ AND in_meta_number = meta_number;
+
+ RETURN out_var;
+END;
+$$ language plpgsql;
+
+CREATE OR REPLACE FUNCTION entity__list_credit
(in_entity_id int, in_entity_class int)
-RETURNS entity_credit_search_return AS
+RETURNS SETOF entity_credit_retrieve AS
$$
-DECLARE out_row entity_credit_search_return;
+DECLARE out_row entity_credit_retrieve;
BEGIN
- SELECT c.legal_name, c.id, e.id, ec.entity_class, ec.discount,
- ec.taxincluded, ec.creditlimit, ec.terms, ec.meta_number,
- ec.business_id, ec.language_code, ec.pricegroup_id,
- ec.curr::char(3), ec.startdate, ec.enddate, ec.ar_ap_account_id,
- ec.cash_account_id, c.tax_id, ec.threshold
- INTO out_row
- FROM company c
- JOIN entity e ON (c.entity_id = e.id)
- JOIN entity_credit_account ec ON (c.entity_id = ec.entity_id)
- WHERE e.id = in_entity_id
- AND ec.entity_class = CASE WHEN in_entity_class = 3 THEN 2
- ELSE in_entity_class END;
+ FOR out_row IN
+ SELECT c.id, e.id, ec.entity_class, ec.discount,
+ ec.taxincluded, ec.creditlimit, ec.terms,
+ ec.meta_number, ec.business_id, ec.language_code,
+ ec.pricegroup_id, ec.curr, ec.startdate,
+ ec.enddate, ec.ar_ap_account_id, ec.cash_account_id,
+ c.tax_id, ec.threshold
+ FROM company c
+ JOIN entity e ON (c.entity_id = e.id)
+ JOIN entity_credit_account ec ON (c.entity_id = ec.entity_id)
+ WHERE e.id = in_entity_id
+ AND ec.entity_class =
+ CASE WHEN in_entity_class = 3 THEN 2
+ WHEN in_entity_class IS NULL
+ THEN ec.entity_class
+ ELSE in_entity_class END
+ LOOP
- RETURN out_row;
+ RETURN NEXT out_row;
+ END LOOP;
END;
$$ LANGUAGE PLPGSQL;
+CREATE OR REPLACE FUNCTION company_retrieve (in_id int) RETURNS company AS
+$$
+DECLARE t_company company;
+BEGIN
+ SELECT * INTO t_company FROM company WHERE id = in_id;
+ RETURN t_company;
+END;
+$$ language plpgsql;
+CREATE OR REPLACE FUNCTION company_save (
+ in_id int, in_entity_class int,
+ in_name text, in_tax_id TEXT,
+ in_entity_id int, in_sic_code text
+) RETURNS INT AS $$
+DECLARE t_entity_id INT;
+BEGIN
+ IF in_entity_id IS NULL THEN
+ INSERT INTO entity (name, entity_class)
+ VALUES (in_name, in_entity_class);
+ t_entity_id := currval('entity_id_seq');
+ ELSE
+ t_entity_id := in_entity_id;
+ END IF;
+
+ UPDATE company
+ SET legal_name = in_name,
+ tax_id = in_tax_id,
+ sic_code = in_sic_code
+ WHERE id = in_id;
+
+ IF FOUND THEN
+ RETURN in_id;
+ ELSE
+ INSERT INTO company(entity_id, legal_name, tax_id, sic_code)
+ VALUES (t_entity_id, in_name, in_tax_id, in_sic_code);
+
+ RETURN currval('company_id_seq');
+ END IF;
+END;
+$$ LANGUAGE PLPGSQL;
+
CREATE OR REPLACE FUNCTION entity_credit_save (
- in_id int, in_entity_class int,
-
+ in_credit_id int, in_entity_class int,
+ in_entity_id int,
in_discount numeric, in_taxincluded bool, in_creditlimit numeric,
in_discount_terms int,
in_terms int, in_meta_number varchar(32), in_business_id int,
in_language varchar(6), in_pricegroup_id int,
in_curr char, in_startdate date, in_enddate date,
- in_name text, in_tax_id TEXT,
in_threshold NUMERIC,
in_ar_ap_account_id int,
in_cash_account_id int
@@ -198,28 +277,29 @@
DECLARE
t_entity_class int;
- new_entity_id int;
- v_row company;
l_id int;
BEGIN
+ update entity_credit_account SET
+ discount = in_discount,
+ taxincluded = in_taxincluded,
+ creditlimit = in_creditlimit,
+ terms = in_terms,
+ ar_ap_account_id = in_ar_ap_account_id,
+ cash_account_id = in_cash_account_id,
+ meta_number = in_meta_number,
+ business_id = in_business_id,
+ language_code = in_language,
+ pricegroup_id = in_pricegroup_id,
+ curr = in_curr,
+ startdate = in_startdate,
+ enddate = in_enddate,
+ threshold = in_threshold,
+ discount_terms = in_discount_terms
+ where id = in_credit_id;
- -- TODO: Move every table to an upsert mode independantly.
- SELECT INTO v_row * FROM company WHERE legal_name = in_name;
-
- IF NOT FOUND THEN
- -- do some inserts
-
- select nextval('entity_id_seq') into new_entity_id;
-
- insert into entity (id, name, entity_class)
- VALUES (new_entity_id, in_name, in_entity_class);
-
- INSERT INTO company ( entity_id, legal_name, tax_id )
- VALUES ( new_entity_id, in_name, in_tax_id );
- IF in_entity_class NOT IN (1, 2) THEN
- RETURN new_entity_id;
- END IF;
-
+ IF FOUND THEN
+ RETURN in_credit_id;
+ ELSE
INSERT INTO entity_credit_account (
entity_id,
entity_class,
@@ -240,7 +320,7 @@
cash_account_id
)
VALUES (
- new_entity_id,
+ in_entity_id,
in_entity_class,
in_discount / 100,
in_taxincluded,
@@ -259,32 +339,9 @@
in_cash_account_id
);
-- entity note class
+ RETURN currval('entity_credit_account_id_seq');
+ END IF;
- return new_entity_id;
-
- ELSIF FOUND THEN
-
- update company set tax_id = in_tax_id where id = v_row.id;
- update entity_credit_account SET
- discount = in_discount,
- taxincluded = in_taxincluded,
- creditlimit = in_creditlimit,
- terms = in_terms,
- ar_ap_account_id = in_ar_ap_account_id,
- cash_account_id = in_cash_account_id,
- meta_number = in_meta_number,
- business_id = in_business_id,
- language_code = in_language,
- pricegroup_id = in_pricegroup_id,
- curr = in_curr,
- startdate = in_startdate,
- enddate = in_enddate,
- threshold = in_threshold,
- discount_terms = in_discount_terms
- where entity_id = v_row.entity_id;
-
- return v_row.entity_id;
- END IF;
END;
$$ language 'plpgsql';
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.