[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SF.net SVN: ledger-smb: [1955] trunk



Revision: 1955
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=1955&view=rev
Author:   einhverfr
Date:     2007-12-06 14:08:49 -0800 (Thu, 06 Dec 2007)

Log Message:
-----------
Misc fixes

Modified Paths:
--------------
    trunk/LedgerSMB/Batch.pm
    trunk/LedgerSMB/DBObject/Payment.pm
    trunk/LedgerSMB/GL.pm
    trunk/UI/create_batch.html
    trunk/UI/payments/payments_detail.html
    trunk/UI/payments/payments_filter.html
    trunk/lsmb-request.pl
    trunk/sql/modules/Payment.sql
    trunk/sql/modules/Session.sql

Modified: trunk/LedgerSMB/Batch.pm
===================================================================
--- trunk/LedgerSMB/Batch.pm	2007-12-06 20:08:57 UTC (rev 1954)
+++ trunk/LedgerSMB/Batch.pm	2007-12-06 22:08:49 UTC (rev 1955)
@@ -8,6 +8,7 @@
     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};
 }
 

Modified: trunk/LedgerSMB/DBObject/Payment.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Payment.pm	2007-12-06 20:08:57 UTC (rev 1954)
+++ trunk/LedgerSMB/DBObject/Payment.pm	2007-12-06 22:08:49 UTC (rev 1955)
@@ -381,4 +381,36 @@
     }
 }    
 
+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;

Modified: trunk/LedgerSMB/GL.pm
===================================================================
--- trunk/LedgerSMB/GL.pm	2007-12-06 20:08:57 UTC (rev 1954)
+++ trunk/LedgerSMB/GL.pm	2007-12-06 22:08:49 UTC (rev 1955)
@@ -67,7 +67,6 @@
     my ( $self, $myconfig, $form ) = @_;
     $form->{reference} = $form->update_defaults( $myconfig, 'glnumber', $dbh )
       unless $form->{reference};
-
     my $null;
     my $project_id;
     my $department_id;

Modified: trunk/UI/create_batch.html
===================================================================
--- trunk/UI/create_batch.html	2007-12-06 20:08:57 UTC (rev 1954)
+++ trunk/UI/create_batch.html	2007-12-06 22:08:49 UTC (rev 1955)
@@ -1,8 +1,8 @@
-<?lsmb INCLUDE ui-header.html
+<?lsmb INCLUDE "ui-header.html"
 	titlebar = text('Create Batch') # '
 	include_stylesheet = [
+		"css/scripts/create_batch.css"
 		stylesheet
-		"css/scripts/create_batch.css"
         ]
 ?>
 <body>

Modified: trunk/UI/payments/payments_detail.html
===================================================================
--- trunk/UI/payments/payments_detail.html	2007-12-06 20:08:57 UTC (rev 1954)
+++ trunk/UI/payments/payments_detail.html	2007-12-06 22:08:49 UTC (rev 1955)
@@ -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'

Modified: trunk/UI/payments/payments_filter.html
===================================================================
--- trunk/UI/payments/payments_filter.html	2007-12-06 20:08:57 UTC (rev 1954)
+++ trunk/UI/payments/payments_filter.html	2007-12-06 22:08:49 UTC (rev 1955)
@@ -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">

Modified: trunk/lsmb-request.pl
===================================================================
--- trunk/lsmb-request.pl	2007-12-06 20:08:57 UTC (rev 1954)
+++ trunk/lsmb-request.pl	2007-12-06 22:08:49 UTC (rev 1955)
@@ -37,7 +37,6 @@
 $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 @@
 
     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}) 

Modified: trunk/sql/modules/Payment.sql
===================================================================
--- trunk/sql/modules/Payment.sql	2007-12-06 20:08:57 UTC (rev 1954)
+++ trunk/sql/modules/Payment.sql	2007-12-06 22:08:49 UTC (rev 1955)
@@ -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 @@
 		              (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 @@
 		         ) 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 

Modified: trunk/sql/modules/Session.sql
===================================================================
--- trunk/sql/modules/Session.sql	2007-12-06 20:08:57 UTC (rev 1954)
+++ trunk/sql/modules/Session.sql	2007-12-06 22:08:49 UTC (rev 1955)
@@ -21,7 +21,7 @@
                 -- 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;


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.