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

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



Revision: 1350
          http://svn.sourceforge.net/ledger-smb/?rev=1350&view=rev
Author:   aurynn_cmd
Date:     2007-07-05 11:44:24 -0700 (Thu, 05 Jul 2007)

Log Message:
-----------
Modifications to support toggling of the On-Hold field in the ar and ap tables;

An On-Hold toggle button was added to the Invoice Edit page, as well as a selector for All Invoices (default), Active Invoices, and Held Invoices to the AR and AP search pages.

Modifications as needed to bring the code in line with linuxpoet's entity patches.

Modified Paths:
--------------
    trunk/LedgerSMB/AA.pm
    trunk/LedgerSMB/CT.pm
    trunk/LedgerSMB/Form.pm
    trunk/LedgerSMB/IR.pm
    trunk/LedgerSMB/IS.pm
    trunk/bin/aa.pl
    trunk/bin/ir.pl
    trunk/bin/is.pl

Modified: trunk/LedgerSMB/AA.pm
===================================================================
--- trunk/LedgerSMB/AA.pm	2007-07-05 18:35:37 UTC (rev 1349)
+++ trunk/LedgerSMB/AA.pm	2007-07-05 18:44:24 UTC (rev 1350)
@@ -886,6 +886,25 @@
 			                                WHERE lower(description)
 			                                      LIKE '$var'))|;
     }
+    
+    if ($form->{invoice_type}) {
+        
+        if ( $form->{invoice_type} == 2 ) {
+        
+            $where .= qq|
+                AND a.on_hold = 'f'        
+            |;
+        }
+    
+        if ($form->{invoice_type} == 3) {
+        
+            $where .= qq|
+                AND a.on_hold = 't'
+            |;
+        }
+    }
+    
+    # the third state, all invoices, sets no explicit toggles. It just selects them all, as normal. 
 
     $query .= "WHERE $where
 			ORDER BY $sortorder";
@@ -972,7 +991,7 @@
 		     FROM $form->{vc} c
 		     JOIN entity ON (entity.id = c.entity_id)
 		LEFT JOIN business b ON (b.id = c.business_id)
-		    WHERE c.id = ?|;
+		    WHERE c.entity_id = ?|;
     # TODO:  Add location join
 
     @queryargs = ( $form->{"$form->{vc}_id"} );

Modified: trunk/LedgerSMB/CT.pm
===================================================================
--- trunk/LedgerSMB/CT.pm	2007-07-05 18:35:37 UTC (rev 1349)
+++ trunk/LedgerSMB/CT.pm	2007-07-05 18:44:24 UTC (rev 1350)
@@ -264,42 +264,46 @@
     }
     if (!$updated){
             # Creating Entity
-            $query = qq|INSERT INTO entity (name, entity_class) VALUES (?, ?)|;
+            ($form->{entity_id}) = $dbh->selectrow_array("SELECT nextval('entity_id_seq')");
+            $query = qq|INSERT INTO entity (id, name, entity_class) VALUES (?, ?)|;
             $sth = $dbh->prepare($query);
-            $sth->execute($form->{name}, $form->{entity_class});
+            $sth->execute($form->{entity_id}, $form->{name}, $form->{entity_class});
             $sth->finish;
-            ($form->{entity_id}) = 
-		$dbh->selectrow_array("SELECT currval('entity_id_seq')");
+		
             # Creating LOCATION
+            ($form->{location_id}) = 
+		$dbh->selectrow_array("SELECT nextval('location_id_seq')");
             $query = qq|
 		INSERT INTO location
-			(line_one, line_two, city_province, mail_code, 
-			country_id)
+			(id, line_one, line_two, city_province, mail_code, 
+			country_id, location_class,created)
 		VALUES
 			(?, ?, ?, ?, 
 				(SELECT id FROM country
-				WHERE short_name = ? OR name = ?))
-            |;
+				WHERE short_name = ? OR name = ?),
+			 1, current_date)
+            |; # location class 1 is Billing. This is a sensible default.
             $sth = $dbh->prepare($query);
-            $sth->execute($form->{address1}, $form->{address2}, 
+            $sth->execute($form->{location_id}, $form->{address1}, $form->{address2}, 
                   "$form->{city}, $form->{state}", $form->{zipcode},
                   $form->{country}, $form->{country}
             ) || $form->dberror($query);
             
-            ($form->{location_id}) = 
-		$dbh->selectrow_array("SELECT currval('location_id_seq')");
+            
             #Creating company
+            # Removed entity_class_id ~Aurynn
+            # removed primary_location_id ~Aurynn
             $query = qq|
 		INSERT INTO company
-			(entity_id, entity_class_id, legal_name, 
-			primary_location_id, tax_id)
+			(entity_id, legal_name, tax_id)
 		VALUES
-			(?, ?, ?, ?, ?)
+			(?, ?, ?)
             |;
             $sth = $dbh->prepare($query) || $form->dberror($query);
-            $sth->execute($form->{entity_id}, $form->{entity_class}, 
+            $sth->execute($form->{entity_id}, # $form->{entity_class}, # removed entity_class_id ~Aurynn
                   $form->{name}, 
-                  $form->{location_id}, $form->{taxnumber});
+                  # $form->{location_id}, # removed by ~aurynn
+                  $form->{taxnumber});
             #Creating customer record
             $query = qq|
 		INSERT INTO customer 
@@ -331,7 +335,7 @@
 
     my ( $self, $myconfig, $form ) = @_;
 
-    # connect to database
+    # connect to databaseÂ
     my $dbh = $form->{dbh};
     my $query;
     my $sth;

Modified: trunk/LedgerSMB/Form.pm
===================================================================
--- trunk/LedgerSMB/Form.pm	2007-07-05 18:35:37 UTC (rev 1349)
+++ trunk/LedgerSMB/Form.pm	2007-07-05 18:44:24 UTC (rev 1350)
@@ -1201,10 +1201,11 @@
     my $name = $self->like( lc $self->{$table} );
 
     my $query = qq|
-		SELECT * FROM $table
-		WHERE (lower(name) LIKE ? OR ${table}number LIKE ?)
+		SELECT * FROM $table t
+		JOIN entity e ON t.entity_id = e.id
+		WHERE (lower(e.name) LIKE ? OR t.${table}number LIKE ?)
 		$where
-		ORDER BY name|;
+		ORDER BY e.name|;
 
     unshift( @queryargs, $name, $name );
     my $sth = $self->{dbh}->prepare($query);
@@ -1726,7 +1727,7 @@
     $where = "AND $where " if $where;
     $inv_notes = "ct.invoice_notes," if $vc eq 'customer';
     my $query = qq|
-		SELECT entity.name, ct.curr AS currency, ct.id AS ${vc}_id,
+		SELECT entity.name, ct.curr AS currency, entity_id AS ${vc}_id,
 			current_date + ct.terms AS duedate, 
 			$inv_notes 
 			ct.curr AS currency

Modified: trunk/LedgerSMB/IR.pm
===================================================================
--- trunk/LedgerSMB/IR.pm	2007-07-05 18:35:37 UTC (rev 1349)
+++ trunk/LedgerSMB/IR.pm	2007-07-05 18:44:24 UTC (rev 1350)
@@ -1044,7 +1044,8 @@
 			SELECT a.invnumber, a.transdate, a.duedate,
 			       a.ordnumber, a.quonumber, a.paid, a.taxincluded,
 			       a.notes, a.intnotes, a.curr AS currency, 
-			       a.vendor_id, a.language_code, a.ponumber
+			       a.vendor_id, a.language_code, a.ponumber,
+			       a.on_hold
 			  FROM ap a
 			 WHERE id = ?|;
         $sth = $dbh->prepare($query);
@@ -1375,5 +1376,39 @@
     $sth->finish;
 }
 
-1;
+sub toggle_on_hold {
+    
+    my $self = shift @_;
+    my $form = shift @_;
+    
+    if ($form->{id}) { # it's an existing (.. probably) invoice.
+        
+        my $dbh = $form->{dbh};
+        my $sth = $dbh->prepare("SELECT on_hold from ar where ar.id = ?");
+        $sth->execute($form->{id});
+        my $state = $sth->fetchrow_array;
+        my $sth;
+        my $n_s; # new state
+        if ($state[0] == 't') {
+            
+            # Turn it off
+            $n_s = 'f';
+            
+        } else {
+            $n_s = 't';
+        }
+        
+        my $sth = $dbh->prepare("update ar set on_hold = ?::boolean where ar.id = ?");
+        my $code = $dbh->execute($ns, $form->{id});
+        
+        return 1;
+        
+    } else { # This shouldn't even be possible, but check for it anyway.
+        
+        # Definitely, DEFINITELY check it.        
+        # happily return 0. Find out about proper error states.
+        return 0;
+    }
+}
 
+1;
\ No newline at end of file

Modified: trunk/LedgerSMB/IS.pm
===================================================================
--- trunk/LedgerSMB/IS.pm	2007-07-05 18:35:37 UTC (rev 1349)
+++ trunk/LedgerSMB/IS.pm	2007-07-05 18:44:24 UTC (rev 1350)
@@ -1759,7 +1759,8 @@
 			          a.duedate, a.taxincluded, a.curr AS currency,
 			          a.employee_id, e.name AS employee, a.till, 
 			          a.entity_id,
-			          a.language_code, a.ponumber
+			          a.language_code, a.ponumber,
+			          a.on_hold
 			     FROM ar a
 			LEFT JOIN employee e ON (e.entity_id = a.employee_id)
 			    WHERE a.id = ?|;
@@ -2039,5 +2040,44 @@
 
 }
 
+=pod
+
+=cut
+
+sub toggle_on_hold {
+    
+    my $self = shift @_;
+    my $form = shift @_;
+    
+    if ($form->{id}) { # it's an existing (.. probably) invoice.
+        
+        my $dbh = $form->{dbh};
+        my $sth = $dbh->prepare("SELECT on_hold from ar where ar.id = ?");
+        $sth->execute($form->{id});
+        my $state = $sth->fetchrow_array;
+        my $sth;
+        my $n_s; # new state
+        if ($state[0] == 't') {
+            
+            # Turn it off
+            $n_s = 'f';
+            
+        } else {
+            $n_s = 't';
+        }
+        
+        my $sth = $dbh->prepare("update ar set on_hold = ?::boolean where ar.id = ?");
+        my $code = $dbh->execute($ns, $form->{id});
+        
+        return 1;
+        
+    } else { # This shouldn't even be possible, but check for it anyway.
+        
+        # Definitely, DEFINITELY check it.        
+        # happily return 0. Find out about proper error states.
+        return 0;
+    }
+}
+
 1;
 

Modified: trunk/bin/aa.pl
===================================================================
--- trunk/bin/aa.pl	2007-07-05 18:35:37 UTC (rev 1349)
+++ trunk/bin/aa.pl	2007-07-05 18:44:24 UTC (rev 1350)
@@ -1424,7 +1424,17 @@
       </table>
     </td>
   </tr>
+  
   <tr>
+    <td>        
+        |.$locale->text('All Invoices').qq|: <input type="radio" name="invoice_type" checked value="1"> 
+        |.$locale->text('Active').qq|: <input type="radio" name="invoice_type" value="2">  
+        |.$locale->text('On Hold').qq|: <input type="radio" name="invoice_type" value="3"> 
+        <br/>    
+    </td>
+  </tr>
+  
+  <tr>
     <td>
       <table>
 	<tr>

Modified: trunk/bin/ir.pl
===================================================================
--- trunk/bin/ir.pl	2007-07-05 18:35:37 UTC (rev 1349)
+++ trunk/bin/ir.pl	2007-07-05 18:44:24 UTC (rev 1350)
@@ -519,13 +519,22 @@
 
     $form->{oldinvtotal} = $form->{invtotal};
     $form->{invtotal} =
-      $form->format_amount( \%myconfig, $form->{invtotal}, 2, 0 );
+    $form->format_amount( \%myconfig, $form->{invtotal}, 2, 0 );
+    
+    my $hold;
+    
+    if ($form->{on_hold}) {
+        
+        $hold = qq| <font size="17"><b> This invoice is On Hold </b></font> |;
+    }
 
     print qq|
   <tr>
     <td>
       <table width=100%>
 	<tr valign=bottom>
+	    | . $hold . qq|
+	
 	  <td>
 	    <table>
 	      <tr>
@@ -681,12 +690,14 @@
               { ndx => 7, key => 'H', value => $locale->text('Schedule') },
             'delete' =>
               { ndx => 8, key => 'D', value => $locale->text('Delete') },
+            'on_hold' =>
+              { ndx => 9, key=> 'O', value => $locale->text('On Hold') },
         );
 
         if ( $form->{id} ) {
 
             if ( $form->{locked} ) {
-                for ( "post", "delete" ) { delete $button{$_} }
+                for ( "post", "delete", 'on_hold' ) { delete $button{$_} }
             }
 
         }
@@ -1119,3 +1130,13 @@
 
 }
 
+sub on_hold {
+    
+    if ($form->{id}) {
+        
+        my $toggled = IS->toggle_on_old($form);
+    
+        #&invoice_links(); # is that it?
+        &edit(); # it was already IN edit for this to be reached.
+    }    
+}
\ No newline at end of file

Modified: trunk/bin/is.pl
===================================================================
--- trunk/bin/is.pl	2007-07-05 18:35:37 UTC (rev 1349)
+++ trunk/bin/is.pl	2007-07-05 18:44:24 UTC (rev 1350)
@@ -568,13 +568,21 @@
 
     $form->{oldinvtotal} = $form->{invtotal};
     $form->{invtotal} =
-      $form->format_amount( \%myconfig, $form->{invtotal}, 2, 0 );
+    $form->format_amount( \%myconfig, $form->{invtotal}, 2, 0 );
+    
+    my $hold;
+    
+    if ($form->{on_hold}) {
+        
+        $hold = qq| <font size="17"><b> This invoice is On Hold </b></font> |;
+    }
 
     print qq|
   <tr>
     <td>
       <table width=100%>
 	<tr valign=bottom>
+	    | . $hold . qq|
 	  <td>
 	    <table>
 	      <tr>
@@ -723,6 +731,8 @@
     # type=submit $locale->text('Sales Order')
 
     if ( !$form->{readonly} ) {
+        
+        # changes by Aurynn to add an On Hold button
 
         %button = (
             'update' =>
@@ -752,6 +762,8 @@
               { ndx => 10, key => 'H', value => $locale->text('Schedule') },
             'delete' =>
               { ndx => 11, key => 'D', value => $locale->text('Delete') },
+            'on_hold' =>
+              { ndx => 12, key => 'O', value => $locale->text('On Hold') },
         );
 
         if ( $form->{id} ) {
@@ -772,9 +784,9 @@
         else {
 
             if ( $transdate > $closedto ) {
-
+                # Added on_hold, by Aurynn.
                 for ( "update", "ship_to", "print", "e_mail", "post",
-                    "schedule" )
+                    "schedule", "on_hold" )
                 {
                     $allowed{$_} = 1;
                 }
@@ -1177,3 +1189,13 @@
 
 }
 
+sub on_hold {
+    
+    if ($form->{id}) {
+        
+        my $toggled = IS->toggle_on_old($form);
+    
+        #&invoice_links(); # is that it?
+        &edit(); # it was already IN edit for this to be reached.
+    }    
+}
\ No newline at end of file


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