[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
SF.net SVN: ledger-smb:[4425] trunk
- Subject: SF.net SVN: ledger-smb:[4425] trunk
- From: ..hidden..
- Date: Fri, 09 Mar 2012 13:43:26 +0000
Revision: 4425
http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=4425&view=rev
Author: einhverfr
Date: 2012-03-09 13:43:25 +0000 (Fri, 09 Mar 2012)
Log Message:
-----------
Credit accounts now save using new Moose-based framework
Modified Paths:
--------------
trunk/LedgerSMB/DBObject/Company.pm
trunk/LedgerSMB/DBObject/Entity/Credit_Account.pm
trunk/LedgerSMB/ScriptLib/Company.pm
trunk/UI/Contact/contact.html
trunk/sql/modules/Company.sql
Modified: trunk/LedgerSMB/DBObject/Company.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Company.pm 2012-03-09 10:18:43 UTC (rev 4424)
+++ trunk/LedgerSMB/DBObject/Company.pm 2012-03-09 13:43:25 UTC (rev 4425)
@@ -227,67 +227,8 @@
return @results;
}
-=pod
-
=over
-=item save_credit
-
-This method saves the credit account for the company.
-
-Expected inputs:
-credit_id (int): (Optional) Id for the account
-entity_class (int): Class of the account, required (1 = vendor, 2 = customer)
-entity_id (int): ID of entity to attach to.
-description (text): Description of account
-discount (numeric): Early payment discount
-taxincluded (bool): Whether prices include tax.
-creditlimit (numeric): Credit limit
-discount_terms (int): How many days can elapse before the discount lapses too.
-terms (int): How many days can lapse before the invoice is overdue.
-meta_number (varchar): Account string identifier for the account.
-business_id (int): ID for business type.
-language (varchar): Language code for invoices.
-pricegroup_id (int): Price group
-curr (char): Currency identifier, three characters long.
-startdate (date): Date of the start of the relationship.
-enddate (date): Date of the end of the relationship.
-threshold (NUMERIC): How much must be owed before the invoices can be paid.
-ar_ap_account_id (int): ID of ar/ap account. REQUIRED
-cash_account_id (int): ID of cash account (Optional)
-pay_to_name (text): Name to pay to or receive from.
-taxform_id (int); ID of tax form
-
-=back
-
-=cut
-
-sub save_credit {
-
- my $self = shift @_;
- $self->set_entity_class();
- $self->{threshold} = $self->parse_amount(amount => $self->{threshold});
- $self->{tax_ids} = $self->_db_array_scalars(@{$self->{tax_ids}});
- my ($ref) = $self->exec_method(funcname => 'entity_credit_save');
- $self->{credit_id} = (values %$ref)[0];
- my $dbh=$self->{dbh};
- if ($self->{taxform1_id}) {
- my $sth = $dbh->prepare(
- "update entity_credit_account
- set country_taxform_id=?
- where id=?"
- );
- $sth->execute($self->{taxform1_id}, $self->{credit_id});
- }
- if ($self->{tax_ids} ne '{}'){
- $self->exec_method(funcname => 'eca__set_taxes');
- }
- $self->{threshold} = $self->format_amount(amount => $self->{threshold});
- $self->{dbh}->commit;
-}
-
-=over
-
=item save_location
This method saves an address for a company.
Modified: trunk/LedgerSMB/DBObject/Entity/Credit_Account.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Entity/Credit_Account.pm 2012-03-09 10:18:43 UTC (rev 4424)
+++ trunk/LedgerSMB/DBObject/Entity/Credit_Account.pm 2012-03-09 13:43:25 UTC (rev 4425)
@@ -232,8 +232,16 @@
be linked to an entity, but only one can be primary, for things like payments by
wire or ACH.
+=item tax_ids
+
+This is an arrayref of ints for the tax accounts linked to the customer.
+
=cut
+has 'tax_ids' => (is => 'rw', isa => 'Maybe[ArrayRef[Int]]');
+
+=cut
+
has 'bank_account' => (is => 'rw', isa => 'Maybe[Int]');
=item taxform_id
@@ -250,16 +258,83 @@
=over
-=item get_by_id
+=item get_by_id($id int);
-=item get_by_meta_number
+Retrieves and returns the entity credit account corresponding with the id
+mentioned.
-=item list_for_entity
+=cut
-=item get_current_debt
+sub get_by_id {
+ my ($self, $id) = @_;
+ my ($ref) = $self->call_procedure(procname => 'entity_credit__get',
+ args => [$id]);
+ $self->prepare_dbhash($ref);
+ return $self->new(%$ref);
+}
-=item save
+=item get_by_meta_number($meta_number string, $entity_class int)
+Retrieves and returns the entity credit account, of entity class $entity_class,
+identified by $meta_number
+
+=cut
+
+sub get_by_meta_number {
+ my ($self, $meta_number, $entity_class) = @_;
+ my ($ref) = $self->call_procedure(procname => 'eca__get_by_met_number',
+ args => [$meta_number,
+ $entity_class]);
+ $self->prepare_dbhash($ref);
+ return $self->new(%$ref);
+}
+
+=item list_for_entity($entity_id int, [$entity_class int]);
+
+Returns a list of entity credit accounts for the entity (company or person)
+identified by $entity_id
+
+=cut
+
+sub list_for_entity {
+ my ($self, $entity_id, $entity_class) = @_;
+ my @results = $self->call_procedure(procname => 'entity__list_credit',
+ args => [$entity_id, $entity_class]
+ );
+ for my $ref (@results){
+ $self->prepare_dbhash($ref);
+ $ref = $self->new(%$ref);
+ }
+ return @results;
+}
+
+=item get_current_debt()
+
+Sets $self->current_debt and returns the same value.
+
+=cut
+
+sub get_current_debt {
+ my ($self) = @_;
+ my ($ref) = $self->exec_method({funcname => 'eca__get_current_debt'});
+ $self->current_debt($ref->{eca__get_current_debt});
+ return $self->current_debt;
+}
+
+=item save()
+
+Saves the entity credit account. This also sets db defaults if not set.
+
+=cut
+
+sub save {
+ my ($self) = @_;
+ my ($ref) = $self->exec_method({funcname => 'eca__save'});
+ $self->prepare_dbhash($ref);
+ $self = $self->new(%$ref);
+}
+
+
=head1 COPYRIGHT
Copyright (C) 2012 The LedgerSMB Core Team. This file may be reused under the
Modified: trunk/LedgerSMB/ScriptLib/Company.pm
===================================================================
--- trunk/LedgerSMB/ScriptLib/Company.pm 2012-03-09 10:18:43 UTC (rev 4424)
+++ trunk/LedgerSMB/ScriptLib/Company.pm 2012-03-09 13:43:25 UTC (rev 4425)
@@ -2,6 +2,7 @@
use LedgerSMB::Template;
use LedgerSMB::DBObject::Customer;
use LedgerSMB::DBObject::Entity::Company;
+use LedgerSMB::DBObject::Entity::Credit_Account;
use LedgerSMB::DBObject::Vendor;
use Log::Log4perl;
@@ -661,26 +662,28 @@
sub save_credit {
my ($request) = @_;
+ my $company;
+ my @taxes;
+ $request->{entity_class} = $request->{account_class};
+
if (!$request->{ar_ap_account_id}){
$request->error(
$request->{_locale}->text('No AR or AP Account Selected')
);
}
- my $company = new_company($request);
- my @taxes;
- $company->{tax_ids} = [];
- for my $key(keys %$company){
+ $request->{tax_ids} = [];
+ for my $key(keys %$request){
if ($key =~ /^taxact_(\d+)$/){
my $tax = $1;
- push @{$company->{tax_ids}}, $tax;
+ push @{$request->{tax_ids}}, $tax;
}
}
- if (_close_form($company)){
- $company->save_credit();
+ if (_close_form($request)){
+ $credit = LedgerSMB::DBObject::Entity::Credit_Account->new(%$request);
+ $credit->save();
}
- $company->get();
- _render_main_screen($company);
+ _render_main_screen($request);
}
=pod
Modified: trunk/UI/Contact/contact.html
===================================================================
--- trunk/UI/Contact/contact.html 2012-03-09 10:18:43 UTC (rev 4424)
+++ trunk/UI/Contact/contact.html 2012-03-09 13:43:25 UTC (rev 4425)
@@ -389,6 +389,7 @@
} ?>
</div>
</div>
+</form>
<?lsmb FOREACH n = notes ?>
<div class="note">
<div class="note_contents"><?lsmb n.note ?></div>
Modified: trunk/sql/modules/Company.sql
===================================================================
--- trunk/sql/modules/Company.sql 2012-03-09 10:18:43 UTC (rev 4424)
+++ trunk/sql/modules/Company.sql 2012-03-09 13:43:25 UTC (rev 4425)
@@ -66,6 +66,14 @@
salesperson_name text
);
+CREATE OR REPLACE FUNCTION eca__get_by_meta_number
+(in_meta_number text, in_entity_class int)
+RETURNS entity_credit_account AS
+$$
+SELECT * FROM entity_credit_account
+ WHERE entity_class = $2 AND meta_number = $1;
+$$ language sql;
+
CREATE OR REPLACE FUNCTION eca_history
(in_name text, in_meta_number text, in_contact_info text, in_address_line text,
in_city text, in_state text, in_zip text, in_salesperson text, in_notes text,
@@ -713,7 +721,7 @@
in_pay_to_name text,
in_taxform_id int);
-CREATE OR REPLACE FUNCTION entity_credit_save (
+CREATE OR REPLACE FUNCTION eca__save (
in_credit_id int, in_entity_class int,
in_entity_id int, in_description text,
in_discount numeric, in_taxincluded bool, in_creditlimit numeric,
@@ -822,7 +830,7 @@
$$ language 'plpgsql';
-COMMENT ON FUNCTION entity_credit_save (
+COMMENT ON FUNCTION eca__save (
in_credit_id int, in_entity_class int,
in_entity_id int, in_description text,
in_discount numeric, in_taxincluded bool, in_creditlimit numeric,
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.