diff options
-rw-r--r-- | LedgerSMB/DBObject/Company.pm | 42 | ||||
-rw-r--r-- | UI/Contact/contact.html | 141 | ||||
-rw-r--r-- | scripts/customer.pl | 17 | ||||
-rw-r--r-- | scripts/vendor.pl | 18 | ||||
-rw-r--r-- | scripts/vouchers.pl | 4 | ||||
-rw-r--r-- | sql/modules/Company.sql | 187 |
6 files changed, 306 insertions, 103 deletions
diff --git a/LedgerSMB/DBObject/Company.pm b/LedgerSMB/DBObject/Company.pm index b2584aa0..2d538582 100644 --- a/LedgerSMB/DBObject/Company.pm +++ b/LedgerSMB/DBObject/Company.pm @@ -50,9 +50,26 @@ TODO: Separate company from credit account storage. 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 @@ sub save_location { =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 @@ sub get_metadata { @{$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 { diff --git a/UI/Contact/contact.html b/UI/Contact/contact.html index 2f1e7d09..75851e2b 100644 --- a/UI/Contact/contact.html +++ b/UI/Contact/contact.html @@ -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 @@ problems with multi-word single-quoted constructs in PI tags. -CT --> </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 @@ problems with multi-word single-quoted constructs in PI tags. -CT --> } ?> <?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,6 +169,83 @@ problems with multi-word single-quoted constructs in PI tags. -CT --> 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", @@ -214,28 +297,7 @@ problems with multi-word single-quoted constructs in PI tags. -CT --> 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 @@ problems with multi-word single-quoted constructs in PI tags. -CT --> </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 @@ problems with multi-word single-quoted constructs in PI tags. -CT --> value_attr = "id" } ?> </td> + </tr> <tr> <td> <?lsmb INCLUDE select element_data = { name = "business_id" @@ -303,17 +365,23 @@ problems with multi-word single-quoted constructs in PI tags. -CT --> 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" @@ -360,6 +428,7 @@ problems with multi-word single-quoted constructs in PI tags. -CT --> title="Pricelist [Alt-P]" text = text('Pricelist') } ?> + </form> </div> <?lsmb END ?> diff --git a/scripts/customer.pl b/scripts/customer.pl index 1834da7a..2828c377 100644 --- a/scripts/customer.pl +++ b/scripts/customer.pl @@ -49,6 +49,7 @@ sub get { $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 @@ sub 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); } diff --git a/scripts/vendor.pl b/scripts/vendor.pl index f84cee1d..321f76d4 100644 --- a/scripts/vendor.pl +++ b/scripts/vendor.pl @@ -49,6 +49,7 @@ sub get { $vendor->set( entity_class=> '1' ); $vendor->get(); + $vendor->get_credit_id(); $vendor->get_metadata(); _render_main_screen($vendor); } @@ -219,10 +220,27 @@ sub 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(); + $vendor->get_credit_id(); _render_main_screen($vendor); } diff --git a/scripts/vouchers.pl b/scripts/vouchers.pl index da3901d6..5f4d8401 100644 --- a/scripts/vouchers.pl +++ b/scripts/vouchers.pl @@ -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,6 +38,8 @@ sub create_vouchers { add_vouchers($batch); } +sub search_transactions { + sub add_vouchers { # This function is not safe for caching as long as the scripts are in bin. diff --git a/sql/modules/Company.sql b/sql/modules/Company.sql index 63714c31..f493586f 100644 --- a/sql/modules/Company.sql +++ b/sql/modules/Company.sql @@ -153,43 +153,122 @@ CREATE TYPE entity_credit_search_return AS ( 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; - - RETURN out_row; + 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 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 entity_credit_save ( +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_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 @@ CREATE OR REPLACE FUNCTION entity_credit_save ( 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 @@ CREATE OR REPLACE FUNCTION entity_credit_save ( cash_account_id ) VALUES ( - new_entity_id, + in_entity_id, in_entity_class, in_discount / 100, in_taxincluded, @@ -259,32 +339,9 @@ CREATE OR REPLACE FUNCTION entity_credit_save ( 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'; |