summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--LedgerSMB/Batch.pm1
-rw-r--r--LedgerSMB/DBObject/Payment.pm32
-rw-r--r--LedgerSMB/GL.pm1
-rw-r--r--UI/create_batch.html4
-rw-r--r--UI/payments/payments_detail.html61
-rw-r--r--UI/payments/payments_filter.html5
-rw-r--r--lsmb-request.pl2
-rw-r--r--sql/modules/Payment.sql82
-rw-r--r--sql/modules/Session.sql2
9 files changed, 168 insertions, 22 deletions
diff --git a/LedgerSMB/Batch.pm b/LedgerSMB/Batch.pm
index 19cb656e..5c948f79 100644
--- a/LedgerSMB/Batch.pm
+++ b/LedgerSMB/Batch.pm
@@ -8,6 +8,7 @@ sub create {
my ($ref) = $self->exec_method(funcname => 'batch_create');
print STDERR "$ref, $ref->{batch_create}, " . join (':', keys %$ref);
$self->{id} = $ref->{batch_create};
+ $self->{dbh}->commit;
return $ref->{id};
}
diff --git a/LedgerSMB/DBObject/Payment.pm b/LedgerSMB/DBObject/Payment.pm
index d8af8a9f..2c523717 100644
--- a/LedgerSMB/DBObject/Payment.pm
+++ b/LedgerSMB/DBObject/Payment.pm
@@ -381,4 +381,36 @@ sub get_payment_detail_data {
}
}
+sub post_bulk {
+ my ($self) = @_;
+ my $total_count = 0;
+ $self->{payment_date} = $self->{datepaid};
+ for my $contact_row (1 .. $self->{contact_count}){
+ my $contact_id = $self->{"contact_$contact_row"};
+ next if (!$self->{"id_$contact_id"});
+ my $invoice_array = "{}"; # Pg Array
+ for my $invoice_row (1 .. $self->{"invoice_count_$contact_id"}){
+ my $invoice_id = $self->{"invoice_${contact_id}_${invoice_row}"};
+ print STDERR "invoice_${contact_id}_${invoice_row}: $invoice_id\n";
+ my $pay_amount = ($self->{"paid_$contact_id"} eq 'all' )
+ ? $self->{"net_$invoice_id"}
+ : $self->{"payment_$invoice_id"};
+ if (!$pay_amount){
+ $pay_amount = 0;
+ }
+ my $invoice_subarray = "{$invoice_id,$pay_amount}";
+ if ($invoice_array eq '{}'){ # Omit comma
+ $invoice_array = "{$invoice_subarray}";
+ } else {
+ $invoice_array =~ s/}$/,$invoice_subarray}/;
+ }
+ }
+ $self->{transactions} = $invoice_array;
+ $self->{source} = $self->{"source_$contact_id"};
+ $self->exec_method(funcname => 'payment_bulk_post');
+
+ }
+ $self->{dbh}->commit;
+}
+
1;
diff --git a/LedgerSMB/GL.pm b/LedgerSMB/GL.pm
index 7e4f8cc8..1c5cd97c 100644
--- a/LedgerSMB/GL.pm
+++ b/LedgerSMB/GL.pm
@@ -67,7 +67,6 @@ sub post_transaction {
my ( $self, $myconfig, $form ) = @_;
$form->{reference} = $form->update_defaults( $myconfig, 'glnumber', $dbh )
unless $form->{reference};
-
my $null;
my $project_id;
my $department_id;
diff --git a/UI/create_batch.html b/UI/create_batch.html
index 26500b7c..df50cdbd 100644
--- a/UI/create_batch.html
+++ b/UI/create_batch.html
@@ -1,8 +1,8 @@
-<?lsmb INCLUDE ui-header.html
+<?lsmb INCLUDE "ui-header.html"
titlebar = text('Create Batch') # '
include_stylesheet = [
- stylesheet
"css/scripts/create_batch.css"
+ stylesheet
]
?>
<body>
diff --git a/UI/payments/payments_detail.html b/UI/payments/payments_detail.html
index d46cfe64..be3facb2 100644
--- a/UI/payments/payments_detail.html
+++ b/UI/payments/payments_detail.html
@@ -23,6 +23,12 @@
} ?>
<?lsmb INCLUDE input element_data = {
type = "hidden"
+ name = "account_class"
+ value = account_class
+
+ } ?>
+ <?lsmb INCLUDE input element_data = {
+ type = "hidden"
name = "department_id"
value = department_id
} ?>
@@ -70,7 +76,9 @@
<div id="date_row">
<label for="date_paid"><?lsmb text('Posting Date:') ?></label>
<?lsmb IF batch_id ?>
- <span id="date_paid"><?lsmb date_paid ?></span>
+ <?lsmb IF ! datepaid ?><?lsmb datepaid = batch_date
+ ?><?lsmb END ?>
+ <span id="date_paid"><?lsmb datepaid ?></span>
<?lsmb END ?>
<?lsmb INCLUDE input element_data= {
value = datepaid
@@ -129,6 +137,15 @@
<?lsmb END # foreach b ?></span>
</div>
<?lsmb END # if business ?>
+ <div class="input" id="cash_account_div">
+ <select name="cash_accno" id="cash_account">
+ <?lsmb FOREACH a = cash_accounts ?>
+ <option value="<?lsmb a.accno ?>">
+ <?lsmb a.accno ?>--<?lsmb a.description ?>
+ </option>
+ <?lsmb END # foreach a ?>
+ </select>
+ </div>
<table id="payments_table">
<tr class="listheading">
<th class="account_number"><?lsmb text('Account_number') ?></th>
@@ -137,11 +154,25 @@
<th class="payment"><?lsmb text('Payment') ?></th>
<th class="payment"><?lsmb text('Details') ?></th>
</tr>
- <?lsmb rc = 1 ?>
+ <?lsmb rc = 1 ?><?lsmb count = 0 ?>
<?lsmb FOREACH r = contact_invoices ?>
- <?lsmb rc = rc + 1; rc = rc % 2 ?>
+ <?lsmb rc = (rc + 1) % 2; count = count + 1 ?>
<tr class="listrow<?lsmb rc ?>">
- <td class="account_number" rowspan="2" ><?lsmb r.account_number ?></td>
+ <td class="account_number" rowspan="2" >
+ <?lsmb INCLUDE input element_data = {
+ type = "hidden"
+ name = "contact_$count"
+ value = r.contact_id
+ } ?>
+ <?lsmb INCLUDE input element_data = {
+ type = "checkbox"
+ name = "id_$r.contact_id"
+ value = r.contact_id
+ checked = (r.unselected) ? "" : "checked"
+
+ } ?>
+ <?lsmb r.account_number ?>
+ </td>
<td class="entity_name"><?lsmb r.contact_name ?></td>
<td class="invoice"><?lsmb r.total_due ?> <?lsmb currency ?></td>
<td class="payment">
@@ -182,7 +213,9 @@
<th class="net_due_list"><?lsmb text('Net Due') ?> </th>
<th class="to_pay_list"><?lsmb text('To Pay') ?></th>
</tr>
+ <?lsmb icount = 0 ?>
<?lsmb FOREACH i = r.invoices ?>
+ <?lsmb icount = icount + 1 ?>
<tr>
<td class="invoice_date_list">&nbsp;<?lsmb i.2 ?></td>
<td class="invoice_list">&nbsp;<?lsmb i.1 ?></td>
@@ -204,13 +237,33 @@
type = "text"
class = "monetary"
} ?>
+ <?lsmb INCLUDE input element_data = {
+ type = "hidden"
+ name = "invoice_${r.contact_id}_$icount"
+ value = i.0
+ } ?>
+ <?lsmb INCLUDE input element_data = {
+ type = "hidden"
+ name = "net_$i.0"
+ value = i.6
+ } ?>
</td>
</tr>
<?lsmb END # foreach i ?>
+ <?lsmb INCLUDE input element_data = {
+ type = "hidden"
+ name = "invoice_count_${r.contact_id}"
+ value = icount
+ } ?>
</table>
</tr>
<?lsmb END # foreach r ?>
</table>
+ <?lsmb INCLUDE input element_data = {
+ type = "hidden"
+ name = "contact_count"
+ value = count
+ } ?>
<?lsmb INCLUDE button element_data = {
text = text('Post'),
value = 'post_payments_bulk'
diff --git a/UI/payments/payments_filter.html b/UI/payments/payments_filter.html
index e8cbd6b0..f3ff8e3d 100644
--- a/UI/payments/payments_filter.html
+++ b/UI/payments/payments_filter.html
@@ -29,6 +29,11 @@
type = "hidden"
name = "batch_id"
} ?>
+<?lsmb INCLUDE input element_data={
+ value = batch_date
+ type = "hidden"
+ name = "batch_date"
+} ?>
<div id = "payments-filter-categories" class="inputgroup">
<?lsmb IF projects ?>
<div id = "payments-filter-projects" class="input">
diff --git a/lsmb-request.pl b/lsmb-request.pl
index 3a33d278..a0de6115 100644
--- a/lsmb-request.pl
+++ b/lsmb-request.pl
@@ -37,7 +37,6 @@ eval { require "custom.pl"; };
$request = new LedgerSMB;
$request->{action} = '__default' if (!$request->{action});
-
$ENV{SCRIPT_NAME} =~ m/([^\/\\]*.pl)\?*.*$/;
$script = $1;
$locale = LedgerSMB::Locale->get_handle( ${LedgerSMB::Sysconfig::language} )
@@ -56,7 +55,6 @@ sub call_script {
eval { require "scripts/$script" }
|| $request->error($locale->text('Unable to open script') . ": scripts/$script : $!");
-
$script =~ s/\.pl$//;
$script = "LedgerSMB::Scripts::$script";
$script->can($request->{action})
diff --git a/sql/modules/Payment.sql b/sql/modules/Payment.sql
index d19a821b..d3026420 100644
--- a/sql/modules/Payment.sql
+++ b/sql/modules/Payment.sql
@@ -125,7 +125,7 @@ $$
DECLARE payment_item payment_contact_invoice;
BEGIN
FOR payment_item IN
- SELECT e.id AS contact_id, e.name AS contact_name,
+ SELECT c.id AS contact_id, e.name AS contact_name,
c.meta_number AS account_number,
sum(a.amount - a.paid) AS total_due,
compound_array(ARRAY[[
@@ -134,13 +134,13 @@ BEGIN
(CASE WHEN c.discount_terms
> extract('days' FROM age(a.transdate))
THEN 0
- ELSE (a.amount - a.paid) * c.discount / 100
+ ELSE (a.amount - coalesce(a.paid, 0)) * coalesce(c.discount, 0) / 100
END)::text,
- (a.amount - a.paid -
+ (a.amount - coalesce(a.paid, 0) -
(CASE WHEN c.discount_terms
> extract('days' FROM age(a.transdate))
THEN 0
- ELSE (a.amount - a.paid) * c.discount / 100
+ ELSE (a.amount - coalesce(a.paid, 0)) * coalesce(c.discount, 0) / 100
END))::text]]),
bool_and(lock_record(a.id, (select max(session_id) FROM "session" where users_id = (
select id from users WHERE username =
@@ -160,26 +160,28 @@ BEGIN
) a USING (entity_id)
JOIN transactions t ON (a.id = t.id)
WHERE a.invoice_class = in_account_class
- AND ((a.transdate >= in_date_from
- AND a.transdate <= in_date_to)
+ AND c.business_id =
+ coalesce(in_business_type, c.business_id)
+ AND ((a.transdate >= COALESCE(in_date_from, a.transdate)
+ AND a.transdate <= COALESCE(in_date_to, a.transdate))
OR a.id IN (select voucher.trans_id FROM voucher
WHERE batch_id = in_batch_id))
AND c.entity_class = in_account_class
AND a.curr = in_currency
AND a.entity_credit_account = c.id
AND a.amount - a.paid <> 0
- AND t.locked_by NOT IN
+ AND NOT (t.locked_by IS NOT NULL AND t.locked_by IN
(select "session_id" FROM "session"
WHERE users_id IN
(select id from users
- where username <> SESSION_USER))
+ where username <> SESSION_USER)))
AND EXISTS (select trans_id FROM acc_trans
WHERE trans_id = a.id AND
chart_id = (SELECT id frOM chart
WHERE accno
= in_ar_ap_accno)
)
- GROUP BY e.id, e.name, c.meta_number, c.threshold
+ GROUP BY c.id, e.name, c.meta_number, c.threshold
HAVING sum(a.amount - a.paid) > c.threshold
LOOP
RETURN NEXT payment_item;
@@ -206,18 +208,74 @@ $$;
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, in_approved bool,
+ in_ar_ap_accno text, in_cash_accno text,
in_payment_date date, in_account_class int)
RETURNS int AS
$$
-DECLARE payment_trans numeric[];
+DECLARE
+ payment_trans numeric[];
+ out_count int;
+ t_voucher_id int;
+ t_trans_id int;
+ t_amount numeric;
BEGIN
+ IF in_batch_id IS NULL THEN
+ t_voucher_id := NULL;
+ ELSE
+ INSERT INTO voucher (batch_id, trans_id)
+ values (in_batch_id, in_transactions[1][1]);
+
+ t_voucher_id := currval('voucher_id_seq');
+ END IF;
+ FOR out_count IN
+ array_lower(in_transactions, 1) ..
+ array_upper(in_transactions, 1)
+ LOOP
+ INSERT INTO acc_trans
+ (trans_id, chart_id, amount, approved, voucher_id,
+ transdate)
+ VALUES
+ (in_transactions[out_count][1],
+ case when in_account_class = 1 THEN
+ (SELECT id FROM chart
+ WHERE accno = in_cash_accno)
+ WHEN in_account_class = 2 THEN
+ (SELECT id FROM chart
+ WHERE accno = in_ar_ap_accno)
+ ELSE -1 END,
+
+ in_transactions[out_count][2],
+
+ CASE WHEN t_voucher_id IS NULL THEN true
+ ELSE false END,
+ t_voucher_id, in_payment_date),
+
+ (in_transactions[out_count][1],
+ case when in_account_class = 1 THEN
+ (SELECT id FROM chart
+ WHERE accno = in_ar_ap_accno)
+ WHEN in_account_class = 2 THEN
+ (SELECT id FROM chart
+ WHERE accno = in_cash_accno)
+ ELSE -1 END,
+
+ in_transactions[out_count][2]* -1,
+
+ CASE WHEN t_voucher_id IS NULL THEN true
+ ELSE false END,
+ t_voucher_id, in_payment_date);
+ insert into test_pay(id, amount) values (in_transactions[out_count][1],in_transactions[out_count][2]);
+ UPDATE ap
+ set paid = paid +in_transactions[out_count][2]
+ where id =in_transactions[out_count][1];
+ END LOOP;
+ return out_count;
END;
$$ language plpgsql;
COMMENT ON 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, in_approved bool,
+ in_ar_ap_accno text, in_cash_accno text,
in_payment_date date, in_account_class int)
IS
$$ Note that in_transactions is a two-dimensional numeric array. Of each
diff --git a/sql/modules/Session.sql b/sql/modules/Session.sql
index a44ed924..58de0f2e 100644
--- a/sql/modules/Session.sql
+++ b/sql/modules/Session.sql
@@ -21,7 +21,7 @@ BEGIN
-- session
IF NOT FOUND THEN
- SELECT id FROM users WHERE username = SESSION_USER;
+ PERFORM id FROM users WHERE username = SESSION_USER;
IF NOT FOUND THEN
RAISE EXCEPTION 'User Not Known';
END IF;