[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
SF.net SVN: ledger-smb:[3589] trunk
- Subject: SF.net SVN: ledger-smb:[3589] trunk
- From: ..hidden..
- Date: Fri, 29 Jul 2011 19:05:12 +0000
Revision: 3589
http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=3589&view=rev
Author: einhverfr
Date: 2011-07-29 19:05:12 +0000 (Fri, 29 Jul 2011)
Log Message:
-----------
Docstrings for payment routines.
Moving some generally unused (and not exposed by default) sql routines into an
addon module.
Modified Paths:
--------------
trunk/LedgerSMB/DBObject/Payment.pm
trunk/scripts/payment.pl
trunk/sql/modules/Payment.sql
trunk/t/98-pod-coverage.t
Modified: trunk/LedgerSMB/DBObject/Payment.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Payment.pm 2011-07-29 07:08:55 UTC (rev 3588)
+++ trunk/LedgerSMB/DBObject/Payment.pm 2011-07-29 19:05:12 UTC (rev 3589)
@@ -415,6 +415,7 @@
WARNING THIS IS NOT BEEING USED BY THE SINGLE PAYMENT SYSTEM....
=back
+
=cut
sub get_open_currencies {
@@ -426,7 +427,6 @@
=over
-
=item list_accounting
This method lists all accounts that match the role specified in account_class property and
@@ -590,6 +590,65 @@
$self->{dbh}->commit; # Commit locks
}
+=item post_bulk
+
+This function posts the payments in bulk. Note that queue_payments is not a
+common setting and rather this provides a hook for an add-on.
+
+This API was developed early in 1.3 and is likely to change for better
+encapsulation. Currenty it uses the following structure:
+
+Within the main hashref:
+
+=over
+
+=item contact_count
+
+The number of payments. One per contact.
+
+=item contact_$row
+
+for (1 .. contact_count), contact_$_ is the entity credit account's id
+associated with the current contact. We will call this $contact_id below.
+
+For each contact id, we have the following, suffixed with _$contact_id:
+
+=over
+
+=item source
+
+=item invoice_count
+
+Number of invoices to loop through
+
+=item invoice_${contact_id}_$row
+
+for $row in (1 .. invoice_count), each this provides the transaction id of the
+invoice.
+
+=back
+
+Each invoice has the following attributes, suffxed with
+${invoice_id}
+
+=over
+
+=item amount
+
+=item paid
+
+=item net
+
+=back
+
+=back
+
+In the future the payment posting API will become more standardized and the
+conversion between flat and hierarchical representation will be moved to the
+workflow scripts.
+
+=cut
+
sub post_bulk {
my ($self) = @_;
my $total_count = 0;
@@ -647,6 +706,12 @@
return $self->{dbh}->commit;
}
+=item check_job
+
+To be moved into payment_queue addon.
+
+=cut
+
sub check_job {
my ($self) = @_;
($self->{job}) = $self->exec_method(funcname => 'job__status');
@@ -715,16 +780,38 @@
return @{$self->{open_overpayment_entities}};
}
+=item get_unused_overpayments
+
+This is a simple wrapper around payment_get_unused_overpayments sql function.
+
+=cut
+
sub get_unused_overpayments {
my ($self) = @_;
@{$self->{unused_overpayment}} = $self->exec_method(funcname => 'payment_get_unused_overpayment');
return @{$self->{unused_overpayment}};
}
+=item get_available_overpayment_amount
+
+Simple wrapper around payment_get_available_overpayment_amount sql function.
+
+=cut
+
sub get_available_overpayment_amount {
my ($self) = @_;
@{$self->{available_overpayment_amount}} = $self->exec_method(funcname => 'payment_get_available_overpayment_amount');
return @{$self->{available_overpayment_amount}};
}
+=item init
+
+Initializes the num2text system
+
+=item num2text
+
+Translates numbers into words.
+
+=cut
+
1;
Modified: trunk/scripts/payment.pl
===================================================================
--- trunk/scripts/payment.pl 2011-07-29 07:08:55 UTC (rev 3588)
+++ trunk/scripts/payment.pl 2011-07-29 19:05:12 UTC (rev 3589)
@@ -60,7 +60,14 @@
# 1: I don't think it is a good idea to make the UI too dependant on internal
# code structures but I don't see a good alternative at the moment.
# 2: CamelCasing: -1
+# 3: Not good to have this much duplication of code all the way down the stack.# At the moment this is helpful because it gives us an opportunity to look
+# at various sets of requirements and workflows, but for future versions
+# if we don't refactor, this will turn into a bug factory.
+# 4: Both current interfaces have issues regarding separating layers of logic
+# and concern properly.
+# CT: Plans are to completely rewrite all payment logic for 1.4 anyway.
+
=pod
=item payment
@@ -89,6 +96,20 @@
$template->render($payment);
}
+=item get_search_criteria
+
+Displays the payment criteria screen. Optional inputs are
+
+=over
+
+=item batch_id
+
+=item batch_date
+
+=back
+
+=cut
+
sub get_search_criteria {
my ($request) = @_;
my $payment = LedgerSMB::DBObject::Payment->new({'base' => $request});
@@ -106,6 +127,13 @@
$template->render($payment);
}
+=item pre_bulk_post_report
+
+This displays a report of the expected GL activity of a payment batch before it
+is saved. For receipts, this just redirects to bulk_post currently.
+
+=cut
+
sub pre_bulk_post_report {
my ($request) = @_;
if ($request->{account_class} == 2){ # Not so helpful for receipts --CT
@@ -211,14 +239,45 @@
});
}
+# Is this even used? It would just redirect back to the report which is not
+# helpful. --CT
+
sub p_payments_bulk_post {
my ($request) = @_;
pre_bulk_post_report(@_);
}
+# wrapper around post_payments_bulk munged for dynatable.
+
sub p_post_payments_bulk {
post_payments_bulk(@_);
}
+
+=item get_search_results
+
+Displays the payment search results.
+
+inputs currently expected include
+
+=over
+
+=item credit_id
+
+=item date_from
+
+=item date_to
+
+=item source
+
+=item cash_accno
+
+=item account_class
+
+=back
+
+=cut
+
+
sub get_search_results {
my ($request) = @_;
my $rows = [];
@@ -327,6 +386,12 @@
});
}
+=item get_search_results_reverse_payments
+
+This reverses payments selected in the search results.
+
+=cut
+
sub get_search_results_reverse_payments {
my ($request) = @_;
my $payment = LedgerSMB::DBObject::Payment->new({base => $request});
@@ -342,7 +407,18 @@
get_search_criteria($payment);
}
+=item post_payments_bulk
+This is a light-weight wrapper around LedgerSMB::DBObject::Payment->post_bulk.
+
+Please see the documentation of that function as to expected inouts.
+
+Additionally, this checks against the XSRF framework and reloads the screen
+with a notice to try again if the attempt to close out the form key is not
+successful.
+
+=cut
+
sub post_payments_bulk {
my ($request) = @_;
my $payment = LedgerSMB::DBObject::Payment->new({'base' => $request});
@@ -357,6 +433,13 @@
payments($request);
}
+=item print
+
+Prints a stack of checks. Currently the logic from the single payment interface
+is not merged in, meaning that $request->{multiple} must be set to a true value.
+
+=cut
+
sub print {
use LedgerSMB::DBObject::Company;
use LedgerSMB::Batch;
@@ -452,10 +535,22 @@
}
+=item update_payments
+
+Displays the bulk payment screen with current data
+
+=cut
+
sub update_payments {
display_payments(@_);
}
+=item display_payments
+
+This displays the bulk payment screen with current data.
+
+=cut
+
sub display_payments {
my ($request) = @_;
my $payment = LedgerSMB::DBObject::Payment->new({'base' => $request});
@@ -537,8 +632,7 @@
format => 'HTML',
);
$template->render($payment);
-}
-
+}
=item payment
Modified: trunk/sql/modules/Payment.sql
===================================================================
--- trunk/sql/modules/Payment.sql 2011-07-29 07:08:55 UTC (rev 3588)
+++ trunk/sql/modules/Payment.sql 2011-07-29 19:05:12 UTC (rev 3589)
@@ -27,7 +27,11 @@
END;
$$ LANGUAGE PLPGSQL;
+COMMENT ON FUNCTION payment_type__get_label(in_payment_type_id int) IS
+$$ Returns all information on a payment type by the id. This should be renamed
+to account for its behavior in future versions.$$;
+
CREATE OR REPLACE FUNCTION payment_get_entity_accounts
(in_account_class int,
in_vc_name text,
@@ -53,6 +57,13 @@
END;
$$ LANGUAGE PLPGSQL;
+COMMENT ON FUNCTION payment_get_entity_accounts
+(in_account_class int,
+ in_vc_name text,
+ in_vc_idn text) IS
+$$ Returns a minimal set of information about customer or vendor accounts
+as needed for discount calculations and the like.$$;
+
-- payment_get_open_accounts and the option to get all accounts need to be
-- refactored and redesigned. -- CT
CREATE OR REPLACE FUNCTION payment_get_open_accounts(in_account_class int)
@@ -422,57 +433,7 @@
username of the individual who has the lock.
$$;
-CREATE OR REPLACE FUNCTION payment_bulk_queue
-(in_transactions numeric[], in_batch_id int, in_source text, in_total numeric,
- in_ar_ap_accno text, in_cash_accno text,
- in_payment_date date, in_account_class int)
-returns int as
-$$
-BEGIN
- INSERT INTO payments_queue
- (transactions, batch_id, source, total, ar_ap_accno, cash_accno,
- payment_date, account_class)
- VALUES
- (in_transactions, in_batch_id, in_source, in_total, in_ar_ap_accno,
- in_cash_accno, in_payment_date, in_account_class);
- RETURN array_upper(in_transactions, 1) -
- array_lower(in_transactions, 1);
-END;
-$$ LANGUAGE PLPGSQL;
-
-CREATE OR REPLACE FUNCTION job__create(in_batch_class int, in_batch_id int)
-RETURNS int AS
-$$
-BEGIN
- INSERT INTO pending_job (batch_class, batch_id)
- VALUES (coalesce(in_batch_class, 3), in_batch_id);
-
- RETURN currval('pending_job_id_seq');
-END;
-$$ LANGUAGE PLPGSQL;
-
-CREATE TYPE job__status AS (
- completed int, -- 1 for completed, 0 for no
- success int, -- 1 for success, 0 for no
- completed_at timestamp,
- error_condition text -- error if not successful
-);
-
-CREATE OR REPLACE FUNCTION job__status(in_job_id int) RETURNS job__status AS
-$$
-DECLARE out_row job__status;
-BEGIN
- SELECT (completed_at IS NULL)::INT, success::int, completed_at,
- error_condition
- INTO out_row
- FROM pending_job
- WHERE id = in_job_id;
-
- RETURN out_row;
-END;
-$$ language plpgsql;
-
CREATE OR REPLACE FUNCTION payment_bulk_post
(in_transactions numeric[], in_batch_id int, in_source text, in_total numeric,
in_ar_ap_accno text, in_cash_accno text,
@@ -591,7 +552,9 @@
in_payment_date date, in_account_class int, int,
in_exchangerate numeric, in_curr text)
IS
-$$ Note that in_transactions is a two-dimensional numeric array. Of each
+$$ This posts the payments for large batch workflows.
+
+Note that in_transactions is a two-dimensional numeric array. Of each
sub-array, the first element is the (integer) transaction id, and the second
is the amount for that transaction. $$;
@@ -856,7 +819,34 @@
END;
$$ LANGUAGE PLPGSQL;
-- I HAVE TO MAKE A COMMENT ON THIS FUNCTION
+COMMENT ON FUNCTION payment_post
+(in_datepaid date,
+ in_account_class int,
+ in_entity_credit_id int,
+ in_curr char(3),
+ in_notes text,
+ in_department_id int,
+ in_gl_description text,
+ in_cash_account_id int[],
+ in_amount numeric[],
+ in_cash_approved bool[],
+ in_source text[],
+ in_memo text[],
+ in_transaction_id int[],
+ in_op_amount numeric[],
+ in_op_cash_account_id int[],
+ in_op_source text[],
+ in_op_memo text[],
+ in_op_account_id int[],
+ in_ovp_payment_id int[],
+ in_approved bool) IS
+$$ Posts a payment. in_op_* arrays are cross-indexed with eachother.
+Other arrays are cross-indexed with eachother.
+This API will probably change in 1.4 as we start looking at using more custom
+complex types and arrays of those (requires Pg 8.4 or higher).
+$$;
+
-- Move this to the projects module when we start on that. CT
CREATE OR REPLACE FUNCTION project_list_open(in_date date)
RETURNS SETOF project AS
@@ -923,6 +913,13 @@
END;
$$ language plpgsql;
+COMMENT ON FUNCTION payments_get_open_currencies(in_account_class int) IS
+$$ This does a sparse scan to find currencies attached to open invoices.
+
+It should scale per the number of currencies used rather than the size of the
+ar or ap tables.
+$$;
+
CREATE OR REPLACE FUNCTION currency_get_exchangerate(in_currency char(3), in_date date, in_account_class int)
RETURNS NUMERIC AS
$$
@@ -1052,6 +1049,16 @@
END;
$$ language plpgsql;
+COMMENT ON FUNCTION payment__search
+(in_source text, in_date_from date, in_date_to date, in_credit_id int,
+ in_cash_accno text, in_account_class int) IS
+$$This searches for payments. in_date_to and _date_from specify the acceptable
+date range. All other matches are exact except that null matches all values.
+
+Currently (and to support earlier data) we define a payment as a collection of
+acc_trans records against the same credit account and cash account, on the same
+day with the same source number, and optionally the same voucher id.$$;
+
CREATE OR REPLACE FUNCTION payment__reverse
(in_source text, in_date_paid date, in_credit_id int, in_cash_accno text,
in_date_reversed date, in_account_class int, in_batch_id int,
@@ -1145,6 +1152,13 @@
END;
$$ LANGUAGE PLPGSQL;
+COMMENT ON FUNCTION payment__reverse
+(in_source text, in_date_paid date, in_credit_id int, in_cash_accno text,
+ in_date_reversed date, in_account_class int, in_batch_id int,
+ in_voucher_id int) IS $$
+Reverses a payment. All fields are mandatory except batch_id and voucher_id
+because they determine the identity of the payment to be reversed.
+$$;
CREATE OR REPLACE FUNCTION payments_set_exchangerate(in_account_class int,
in_exchangerate numeric, in_curr char(3), in_datepaid date )
@@ -1173,7 +1187,13 @@
END;
$$ language plpgsql;
+COMMENT ON FUNCTION payments_set_exchangerate(in_account_class int,
+ in_exchangerate numeric, in_curr char(3), in_datepaid date ) IS
+$$ 1.3 only. This will be replaced by a more generic function in 1.4.
+This sets the exchange rate for a class of transactions (payable, receivable)
+to a certain rate for a specific date.$$;
+
CREATE TYPE payment_header_item AS (
payment_id int,
payment_reference int,
@@ -1331,6 +1351,9 @@
END;
$$ LANGUAGE PLPGSQL;
+COMMENT ON FUNCTION payment_get_unused_overpayment(
+in_account_class int, in_entity_credit_id int, in_chart_id int) IS
+$$ Returns a list of available overpayments$$;
CREATE TYPE payment_overpayments_available_amount AS (
chart_id int,
@@ -1358,3 +1381,7 @@
END;
$$ LANGUAGE PLPGSQL;
+COMMENT ON FUNCTION payment_get_unused_overpayment(
+in_account_class int, in_entity_credit_id int, in_chart_id int) IS
+$$ Returns a list of available overpayments$$;
+
Modified: trunk/t/98-pod-coverage.t
===================================================================
--- trunk/t/98-pod-coverage.t 2011-07-29 07:08:55 UTC (rev 3588)
+++ trunk/t/98-pod-coverage.t 2011-07-29 19:05:12 UTC (rev 3589)
@@ -13,7 +13,7 @@
if ($@){
plan skip_all => "Test::Pod::Coverage required for testing POD coverage";
} else {
- plan tests => 24;
+ plan tests => 25;
}
pod_coverage_ok("LedgerSMB");
pod_coverage_ok("LedgerSMB::Form");
@@ -39,3 +39,7 @@
pod_coverage_ok("LedgerSMB::DBObject::Employee");
pod_coverage_ok("LedgerSMB::File");
pod_coverage_ok("LedgerSMB::DBObject");
+pod_coverage_ok("LedgerSMB::DBObject::Payment",
+ {also_private => [qr/^(format_ten_|num2text_)/]}
+);
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.