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

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



Revision: 4264
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=4264&view=rev
Author:   einhverfr
Date:     2012-01-17 01:51:53 +0000 (Tue, 17 Jan 2012)
Log Message:
-----------
Merging from 1.3

Modified Paths:
--------------
    trunk/BUGS
    trunk/Changelog
    trunk/LedgerSMB/AA.pm
    trunk/LedgerSMB/DBObject/Customer.pm
    trunk/LedgerSMB/DBObject/Payment.pm
    trunk/LedgerSMB/DBObject/Vendor.pm
    trunk/LedgerSMB/IR.pm
    trunk/LedgerSMB/IS.pm
    trunk/LedgerSMB/OE.pm
    trunk/LedgerSMB/Scripts/payment.pm
    trunk/Makefile.PL
    trunk/UI/am-defaults.html
    trunk/UI/menu/expanding.html
    trunk/UI/payments/payment2.html
    trunk/UI/rp-aging.csv
    trunk/UPGRADE
    trunk/bin/am.pl
    trunk/bin/ic.pl
    trunk/bin/io.pl
    trunk/bin/ir.pl
    trunk/bin/is.pl
    trunk/bin/oe.pl
    trunk/dists/rpm/ledgersmb.spec
    trunk/sql/Pg-database.sql
    trunk/sql/coa/uk/chart/General.sql
    trunk/sql/modules/Fixes.sql
    trunk/sql/modules/Payment.sql
    trunk/sql/modules/Roles.sql
    trunk/templates/xedemo/balance_sheet.html
    trunk/tools/prepare-company-database.sh

Added Paths:
-----------
    trunk/doc/notes/
    trunk/doc/notes/foreign-currency-handling
    trunk/pos.conf.pl.template

Removed Paths:
-------------
    trunk/doc/notes/foreign-currency-handling

Property Changed:
----------------
    trunk/
    trunk/LedgerSMB/Scripts/admin.pm
    trunk/LedgerSMB/Scripts/employee.pm
    trunk/LedgerSMB/Scripts/file.pm
    trunk/LedgerSMB/Scripts/login.pm
    trunk/LedgerSMB/Scripts/menu.pm
    trunk/LedgerSMB/Scripts/payment.pm
    trunk/LedgerSMB/Scripts/recon.pm
    trunk/LedgerSMB/Scripts/setup.pm
    trunk/LedgerSMB/Scripts/taxform.pm
    trunk/sql/upgrade/1.2-1.3-manual.sql


Property changes on: trunk
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/1.3:3711-4215
   + /branches/1.3:3711-4262

Modified: trunk/BUGS
===================================================================
--- trunk/BUGS	2012-01-16 23:32:37 UTC (rev 4263)
+++ trunk/BUGS	2012-01-17 01:51:53 UTC (rev 4264)
@@ -1,7 +1,5 @@
 CURRENT KNOWN BUGS:
 
-1)  Checks don't print from single check printing interface
+1)  Payment reversals don't properly handle fx gain/loss
+2)  Bulk payment interface doesn't properly handle foreign currencies
 
-BUGS FIXED SINCE LAST BETA:
-
-Not applicable

Modified: trunk/Changelog
===================================================================
--- trunk/Changelog	2012-01-16 23:32:37 UTC (rev 4263)
+++ trunk/Changelog	2012-01-17 01:51:53 UTC (rev 4264)
@@ -15,7 +15,31 @@
 * More Localization Fixes (Herman V)
 * Customer/Vendor Search now shows records without credit accounts (Herman V)
 * Better error handling contrib modules not found (Chris T)
+* pos.conf.pl no longer overwritten on upgrade (Chris T)
+* Fixed multi-currency single payment handling (Erik H / Chris T)
+* Fixed "New Window" not working (Erik H)
+* Fixed Pg 9.1 detection in setup.pl (Chris T and Pongracz I)
+* Fixed SQL error loading Utils.sql (Michael R)
+* Updated docs on foreign exchange settings (Erik H)
+* Fixed forex settings not saving on defaults screen (Chris T)
+* Formatted paid amount for payment screen (Herman V)
+* Fixed help message on prepare-database.sh (Michael R)
+* Fixed links on payment report (Erik H)
+* Added more forex documentation (Erik H)
+* Fixed UK chart of accounts VAT accounts (Erik H)
+* Fixed issues involving employee_id references (Erik H)
+* Fixed shipto menu (Erik H)
+* Fixed wrong orders showing up on ship/receive (Erik H)
+* Fixed Makefile.PL version info (Chris T)
+* Fixed HTML attribute quoting (John L and Erik H)
 
+Chris T is Chris Travers
+Erik H is Erik Huelsmann
+Herman V is Herman Vierendeels
+John L is John Locke
+Michael R is Michael Richardson
+Pongracz I is Pongracz Istvan
+
 Changelog for 1.3.9
 * More logging enhancements (Herman V)
 * Translation fixes in tax form reports (Chris T)

Modified: trunk/LedgerSMB/AA.pm
===================================================================
--- trunk/LedgerSMB/AA.pm	2012-01-16 23:32:37 UTC (rev 4263)
+++ trunk/LedgerSMB/AA.pm	2012-01-17 01:51:53 UTC (rev 4264)
@@ -188,7 +188,12 @@
 
             # multiply by exchangerate
             $amount = $amount{fxamount}{$i} * $form->{exchangerate};
-            $amount{amount}{$i} = $form->round_amount( $amount - $diff, 2 );
+
+	    # The following line used to be
+	    # $amount{amount}{$i} =  $form->round_amount( $amount - $diff, 2 );
+	    # but that causes problems when processing the payments
+	    # due to the fact that the payments are un-rounded
+            $amount{amount}{$i} = $amount;
             $diff = $amount{amount}{$i} - ( $amount - $diff );
 
             ( $null, $project_id ) = split /--/, $form->{"projectnumber_$i"};
@@ -267,9 +272,12 @@
     }
 
     $fxinvamount += $fxtax unless $form->{taxincluded};
-    $fxinvamount = $form->round_amount( $fxinvamount, 2 );
-    $invamount   = $form->round_amount( $invamount,   2 );
-    $paid        = $form->round_amount( $paid,        2 );
+#   These lines are commented out because payments get posted without
+#   rounding. Having rounded amounts on the AR/AP creation side leads
+#   to unmatched payments
+#    $fxinvamount = $form->round_amount( $fxinvamount, 2 );
+#    $invamount   = $form->round_amount( $invamount,   2 );
+#    $paid        = $form->round_amount( $paid,        2 );
 
     $paid =
       ( $fxinvamount == $paid )

Modified: trunk/LedgerSMB/DBObject/Customer.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Customer.pm	2012-01-16 23:32:37 UTC (rev 4263)
+++ trunk/LedgerSMB/DBObject/Customer.pm	2012-01-17 01:51:53 UTC (rev 4264)
@@ -28,7 +28,7 @@
 use base qw(LedgerSMB::DBObject::Company);
 use strict;
 
-my $ENTITY_CLASS = 2;
+our $ENTITY_CLASS = 2;
 
 sub set_entity_class {
     

Modified: trunk/LedgerSMB/DBObject/Payment.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Payment.pm	2012-01-16 23:32:37 UTC (rev 4263)
+++ trunk/LedgerSMB/DBObject/Payment.pm	2012-01-17 01:51:53 UTC (rev 4264)
@@ -735,16 +735,15 @@
    if (!$db_exchangerate) {
    # We have to set the exchangerate
   
+   $self->call_procedure(procname => 'payments_set_exchangerate',  args => ["$self->{account_class}", $self->{exrate} ,"$self->{curr}", "$self->{datepaid}"]);
 
-   $self->call_procedure(procname => 'payments_set_exchangerate',  args => ["$self->{account_class}", "$self->{exchangerate}" ,"$self->{curr}", "$self->{datepaid}"]);
 
 
-
    }
-   elsif ($db_exchangerate != $self->{exchangerate} )
+   elsif ($db_exchangerate != $self->{exrate} )
    {
    # Something went wrong
-   $self->error("Exchange rate inconsistency with database, please try again")
+   $self->error($self->{_locale}->text("Exchange rate inconsistency with database.  Got [_1], expected [_2]", $self->{exrate}, $db_exchangerate));
    }
  }
  my @TMParray = $self->exec_method(funcname => 'payment_post');

Modified: trunk/LedgerSMB/DBObject/Vendor.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Vendor.pm	2012-01-16 23:32:37 UTC (rev 4263)
+++ trunk/LedgerSMB/DBObject/Vendor.pm	2012-01-17 01:51:53 UTC (rev 4264)
@@ -29,7 +29,7 @@
 use base qw(LedgerSMB::DBObject::Company);
 use strict;
 
-my $ENTITY_CLASS = 1;
+our $ENTITY_CLASS = 1;
 
 sub set_entity_class {
     my $self = shift @_;

Modified: trunk/LedgerSMB/IR.pm
===================================================================
--- trunk/LedgerSMB/IR.pm	2012-01-16 23:32:37 UTC (rev 4263)
+++ trunk/LedgerSMB/IR.pm	2012-01-17 01:51:53 UTC (rev 4264)
@@ -331,10 +331,12 @@
                 $invoice_id
             ) || $form->dberror($query);
 
-            my $report=($taxformfound and $form->{"taxformcheck_$i"})?"true":"false";
-            IR->update_invoice_tax_form($form,$dbh,$invoice_id,$report);
+            if($taxformfound)
+            {
+             my $report=$form->{"taxformcheck_$i"}?"true":"false";
+             IR->update_invoice_tax_form($form,$dbh,$invoice_id,$report);
+            }
 
-
             if (defined $form->{approved}) {
 
                 $query = qq| UPDATE ap SET approved = ? WHERE id = ?|;

Modified: trunk/LedgerSMB/IS.pm
===================================================================
--- trunk/LedgerSMB/IS.pm	2012-01-16 23:32:37 UTC (rev 4263)
+++ trunk/LedgerSMB/IS.pm	2012-01-17 01:51:53 UTC (rev 4264)
@@ -2074,6 +2074,7 @@
     if ( $form->{id} ) {
 
         # retrieve invoice
+        #HV TODO drop entity_id from ar
         $query = qq|
 			   SELECT a.invnumber, a.ordnumber, a.quonumber,
 			          a.transdate, a.paid,
@@ -2081,7 +2082,7 @@
 			          a.intnotes,
 			          a.duedate, a.taxincluded, a.curr AS currency,
 			          a.person_id, e.name AS employee, a.till, 
-			          a.entity_id, a.reverse,
+			          a.reverse,
 			          a.language_code, a.ponumber,
 			          a.on_hold
 			     FROM ar a

Modified: trunk/LedgerSMB/OE.pm
===================================================================
--- trunk/LedgerSMB/OE.pm	2012-01-16 23:32:37 UTC (rev 4263)
+++ trunk/LedgerSMB/OE.pm	2012-01-17 01:51:53 UTC (rev 4264)
@@ -199,8 +199,9 @@
 			WHERE o.quotation = '0'
 			AND (p.inventory_accno_id > 0 OR p.assembly = '1')
 			AND oi.qty != oi.ship
+                        AND o.oe_class_id = ?
 			$department|;
-        @queryargs = @dptargs;    #reset @queryargs
+        @queryargs = ( $form->{oe_class_id} );
 
         if ( $warehouse_id && $form->{type} eq 'ship_order' ) {
             $query .= qq| 
@@ -1879,7 +1880,7 @@
 				INSERT INTO inventory 
 					(parts_id, warehouse_id, qty, trans_id, 
 					orderitems_id, shippingdate, 
-					employee_id)
+					entity_id)
 				VALUES 
 					(?, ?, ?, ?, ?, ?, ?)|;
             $sth2 = $dbh->prepare($query);
@@ -2180,7 +2181,7 @@
 
     my $query = qq|
 		INSERT INTO inventory
-			(warehouse_id, parts_id, qty, shippingdate, employee_id)
+			(warehouse_id, parts_id, qty, shippingdate, entity_id)
 		VALUES (?, ?, ?, ?, ?)|;
     $sth = $dbh->prepare($query) || $form->dberror($query);
 
@@ -2486,6 +2487,7 @@
         ( $null, $department_id ) = split /--/, $form->{department};
         $department_id *= 1;
 
+
         $query = qq|
 			UPDATE oe SET
 				ordnumber = ?,
@@ -2495,7 +2497,7 @@
 				netamount = ?,
 				taxincluded = ?,
 				curr = ?,
-				employee_id = ?,
+				person_id = (select id from person where entity_id = ?),
 				department_id = ?,
 				ponumber = ?
 			WHERE id = ?|;


Property changes on: trunk/LedgerSMB/Scripts/admin.pm
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/1.3/LedgerSMB/Scripts/admin.pm:3901-4215
/branches/1.3/scripts/admin.pl:3711-3903
   + /branches/1.3/LedgerSMB/Scripts/admin.pm:3901-4262
/branches/1.3/scripts/admin.pl:3711-3903


Property changes on: trunk/LedgerSMB/Scripts/employee.pm
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/1.3/LedgerSMB/Scripts/employee.pm:3712-4215
/branches/1.3/scripts/employee.pl:3842-3843
   + /branches/1.3/LedgerSMB/Scripts/employee.pm:3712-4262
/branches/1.3/scripts/employee.pl:3842-3843


Property changes on: trunk/LedgerSMB/Scripts/file.pm
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/1.3/LedgerSMB/Scripts/file.pm:3711-4215
/branches/1.3/scripts/file.pl:3711-4138
   + /branches/1.3/LedgerSMB/Scripts/file.pm:3711-4262
/branches/1.3/scripts/file.pl:3711-4138


Property changes on: trunk/LedgerSMB/Scripts/login.pm
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/1.3/LedgerSMB/Scripts/login.pm:4193-4215
/branches/1.3/scripts/login.pl:3711-4192
   + /branches/1.3/LedgerSMB/Scripts/login.pm:4193-4262
/branches/1.3/scripts/login.pl:3711-4192


Property changes on: trunk/LedgerSMB/Scripts/menu.pm
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/1.3/LedgerSMB/Scripts/menu.pm:4155-4215
/branches/1.3/scripts/menu.pl:3711-4192
   + /branches/1.3/LedgerSMB/Scripts/menu.pm:4155-4262
/branches/1.3/scripts/menu.pl:3711-4192

Modified: trunk/LedgerSMB/Scripts/payment.pm
===================================================================
--- trunk/LedgerSMB/Scripts/payment.pm	2012-01-16 23:32:37 UTC (rev 4263)
+++ trunk/LedgerSMB/Scripts/payment.pm	2012-01-17 01:51:53 UTC (rev 4264)
@@ -49,6 +49,8 @@
 use LedgerSMB::Sysconfig;
 use LedgerSMB::DBObject::Payment;
 use LedgerSMB::DBObject::Date;
+use LedgerSMB::DBObject::Customer;
+use LedgerSMB::DBObject::Vendor;
 use LedgerSMB::CancelFurtherProcessing;
 use Error::Simple;
 use Error;
@@ -882,12 +884,22 @@
                            {text => $locale->text('Amount Due').$currency_text};
  # WE SET THEM IN THE RIGHT ORDER FOR THE TABLE INSIDE THE UI   
      @column_headers[7,8] = @column_headers[8,7];
- # DOES THE CURRENCY IN USE HAS AN EXCHANGE RATE?, IF SO 
- # WE MUST SET THE VALUE, OTHERWISE THE UI WILL HANDLE IT
-   $exchangerate = $request->{exrate} ? 
-                   $request->{exrate} :
-                   $Payment->get_exchange_rate($request->{curr}, 
-                   $request->{datepaid} ? $request->{datepaid} : $Payment->{current_date});
+
+     # select the exchange rate for the currency at the payment date
+     # this has preference over what comes from the request, because the payment date
+     # may have changed since the last request and the currency rate in the request
+     # can be associated with the old payment date -- for example when a rate has been
+     # entered for the current date and the user selects a different date after opening
+     # the screen: today's rate would be used with no way for the user to override, if
+     # we would simply take the exrate from the request.
+     $exchangerate = $Payment->get_exchange_rate($request->{curr},
+						 $request->{datepaid} ? $request->{datepaid}
+						 : $Payment->{current_date});
+     $exchangerate = $request->{exrate}
+        if ((! $exchangerate) &&
+	    $request->{datepaid} eq $request->{olddatepaid});
+
+
    if ($exchangerate) {
      @currency_options = {
           name => 'exrate',
@@ -934,7 +946,7 @@
        $topay_fx_value = $due_fx = $due_fx + $request->round_amount($array_options[$ref]->{discount}/$array_options[$ref]->{exchangerate});
         }
    } else {
-       $topay_fx_value = "N/A";
+   #    $topay_fx_value = "N/A";
    }
 
    
@@ -959,11 +971,41 @@
          #$request->{"topay_fx_$array_options[$ref]->{invoice_id}"} = "$due_fx";
          $request_topay_fx_bigfloat=$due_fx;
      } 
-#Now its time to build the link to the invoice :)
+ #print STDERR localtime()." payment.pl array=".Data::Dumper::Dumper($array_options[$ref])."\n";
+ my $paid_formatted=$Payment->format_amount(amount=>($array_options[$ref]->{amount} - $array_options[$ref]->{due} - $array_options[$ref]->{discount}));
+ #Now its time to build the link to the invoice :)
+ my $uri_module;
+ #TODO move following code to sub getModuleForUri() ?
+ if($Payment->{account_class} == $LedgerSMB::DBObject::Vendor::ENTITY_CLASS)
+ {
+  if($array_options[$ref]->{invoice})
+  {
+   $uri_module='ir';
+  }
+  else
+  {
+   $uri_module='ap';
+  }
+ }#account_class 1
+ elsif($Payment->{account_class} == $LedgerSMB::DBObject::Customer::ENTITY_CLASS)
+ {
+  if($array_options[$ref]->{invoice})
+  {
+   $uri_module='is';
+  }
+  else
+  {
+   $uri_module='ar';
+  }
+ }#account_class 2
+ else
+ {
+  #TODO
+  $uri_module='??';
+ }
+#my $uri = $Payment->{account_class} == 1 ? 'ap' : 'ar';
+ my $uri =$uri_module.'.pl?action=edit&id='.$array_options[$ref]->{invoice_id}.'&path=bin/mozilla&login='.$request->{login};
 
-my $uri = $Payment->{account_class} == 1 ? 'ap' : 'ar';
-$uri .= '.pl?action=edit&id='.$array_options[$ref]->{invoice_id}.'&path=bin/mozilla&login='.$request->{login};
-
    push @invoice_data, {       invoice => { number => $array_options[$ref]->{invnumber},
                                             id     =>  $array_options[$ref]->{invoice_id},
                                             href   => $uri
@@ -971,7 +1013,7 @@
                                invoice_date      => "$array_options[$ref]->{invoice_date}",
                                amount            => $Payment->format_amount(amount=>$array_options[$ref]->{amount}),
                                due               => $Payment->format_amount(amount=>$request->{"optional_discount_$array_options[$ref]->{invoice_id}"}?  $array_options[$ref]->{due} : $array_options[$ref]->{due} + $array_options[$ref]->{discount}),
-                               paid              => "$array_options[$ref]->{amount}" - "$array_options[$ref]->{due}"-"$array_options[$ref]->{discount}",
+                               paid              => $paid_formatted,
                                discount          => $request->{"optional_discount_$array_options[$ref]->{invoice_id}"} ? "$array_options[$ref]->{discount}" : 0 ,
                                optional_discount =>  $request->{"optional_discount_$array_options[$ref]->{invoice_id}"},
                                exchange_rate     =>  "$array_options[$ref]->{exchangerate}",


Property changes on: trunk/LedgerSMB/Scripts/payment.pm
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/1.3/LedgerSMB/Scripts/payment.pm:4010-4215
/branches/1.3/scripts/payment.pl:3711-4192
   + /branches/1.3/LedgerSMB/Scripts/payment.pm:4010-4262
/branches/1.3/scripts/payment.pl:3711-4263


Property changes on: trunk/LedgerSMB/Scripts/recon.pm
___________________________________________________________________
Added: svn:mergeinfo
   + /branches/1.3/LedgerSMB/Scripts/recon.pm:3711-4262
/branches/1.3/scripts/recon.pl:4194-4263


Property changes on: trunk/LedgerSMB/Scripts/setup.pm
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/1.3/LedgerSMB/Scripts/setup.pm:3937-4215
/branches/1.3/scripts/setup.pl:3711-4216
   + /branches/1.3/LedgerSMB/Scripts/setup.pm:3937-4262
/branches/1.3/scripts/setup.pl:3711-4216


Property changes on: trunk/LedgerSMB/Scripts/taxform.pm
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/1.3/LedgerSMB/Scripts/taxform.pm:4193-4215
/branches/1.3/scripts/taxform.pl:3711-4192
   + /branches/1.3/LedgerSMB/Scripts/taxform.pm:4193-4262
/branches/1.3/scripts/taxform.pl:3711-4192

Modified: trunk/Makefile.PL
===================================================================
--- trunk/Makefile.PL	2012-01-16 23:32:37 UTC (rev 4263)
+++ trunk/Makefile.PL	2012-01-17 01:51:53 UTC (rev 4264)
@@ -5,7 +5,7 @@
 use inc::Module::Install 0.65;
 
 name 'LedgerSMB';
-version '1.2.99';
+version '1.3.10';
 license 'GPL';
 
 perl_version '5.8.1';

Modified: trunk/UI/am-defaults.html
===================================================================
--- trunk/UI/am-defaults.html	2012-01-16 23:32:37 UTC (rev 4263)
+++ trunk/UI/am-defaults.html	2012-01-17 01:51:53 UTC (rev 4264)
@@ -44,7 +44,7 @@
     </td>
   </tr>
   <tr>
-    <th class="listheading"><?lsmb escape(text('Last Numbers & Default Accounts')) ?></th>
+    <th class="listheading"><?lsmb text('Last Numbers & Default Accounts') ?></th>
   </tr>
   <tr>
     <td>
@@ -52,31 +52,31 @@
 	<tr>
           <th align="right" nowrap="nowrap"><?lsmb text('Inventory') ?></th>
 	  <td>
-<?lsmb PROCESS select element_data=selects.IC ?>
+<?lsmb PROCESS select element_data=selects.inventory_accno_id ?>
           </td>
 	</tr>
 	<tr>
           <th align="right" nowrap="nowrap"><?lsmb text('Income') ?></th>
 	  <td>
-<?lsmb PROCESS select element_data=selects.IC_income ?>
+<?lsmb PROCESS select element_data=selects.income_accno_id ?>
          </td>
 	</tr>
 	<tr>
           <th align="right" nowrap="nowrap"><?lsmb text('Expense') ?></th>
 	  <td>
-<?lsmb PROCESS select element_data=selects.IC_expense ?>
+<?lsmb PROCESS select element_data=selects.expense_accno_id ?>
          </td>
 	</tr>
 	<tr>
           <th align="right" nowrap="nowrap"><?lsmb text('Foreign Exchange Gain') ?></th>
 	  <td>
-<?lsmb PROCESS select element_data=selects.FX_gain ?>
+<?lsmb PROCESS select element_data=selects.fxgain_accno_id ?>
          </td>
 	</tr>
 	<tr>
           <th align="right" nowrap="nowrap"><?lsmb text('Foreign Exchange Loss') ?></th>
 	  <td>
-<?lsmb PROCESS select element_data=selects.FX_loss ?>
+<?lsmb PROCESS select element_data=selects.fxloss_accno_id ?>
          </td>
 	</tr>
 	<tr>
@@ -96,7 +96,7 @@
     </td>
   </tr>
   <tr>
-    <th align="left"><?lsmb escape(text('Enter up to 3 letters separated by a colon (i.e CAD:USD:EUR) for your native and foreign currencies')) ?></th>
+    <th align="left"><?lsmb text('Enter up to 3 letters separated by a colon (i.e CAD:USD:EUR) for your native and foreign currencies') ?></th>
   </tr>
   <tr>
     <td>

Modified: trunk/UI/menu/expanding.html
===================================================================
--- trunk/UI/menu/expanding.html	2012-01-16 23:32:37 UTC (rev 4263)
+++ trunk/UI/menu/expanding.html	2012-01-17 01:51:53 UTC (rev 4264)
@@ -75,7 +75,7 @@
 					target = '_top'
 				<?lsmb END ?>
 				<?lsmb IF item.menu && 
-					('New Menu' != item.label) ?> 
+					('New Window' != item.label) ?> 
 					onclick="return SwitchMenu('<?lsmb item.id ?>')"
 				<?lsmb END ?>
 				id = "a_<?lsmb item.id ?>"

Modified: trunk/UI/payments/payment2.html
===================================================================
--- trunk/UI/payments/payment2.html	2012-01-16 23:32:37 UTC (rev 4263)
+++ trunk/UI/payments/payment2.html	2012-01-17 01:51:53 UTC (rev 4264)
@@ -99,7 +99,7 @@
      </tr>
      <tr id="date_row"><?lsmb # here goes an input where the date can be written, we can also use a java calendar :). We can use an ajax script to call the Exchange rate of the input date wich can be called with the onChange Method	  ?>
       <th align="right" nowrap id="date_label_column"><?lsmb text('Date') ?></th>
-      <td colspan="2" id="date_column"> <?lsmb INCLUDE input element_data=datepaid ?> </td>
+      <td colspan="2" id="date_column"> <?lsmb INCLUDE input element_data=datepaid ?><?lsmb datepaid.id='olddatepaid'; datepaid.name='olddatepaid'; datepaid.type='hidden'; INCLUDE input element_data=datepaid ?> </td>
      </tr>
      <tr id="source_row">
      <?lsmb # here goes all the posible sources wich we can use -?>

Modified: trunk/UI/rp-aging.csv
===================================================================
--- trunk/UI/rp-aging.csv	2012-01-16 23:32:37 UTC (rev 4263)
+++ trunk/UI/rp-aging.csv	2012-01-17 01:51:53 UTC (rev 4264)
@@ -3,7 +3,7 @@
         heading.$column.text;
     ELSE;
         heading.$column;
-    END ?>,<?lsmb END; escape(text('Currency')) ?>
+    END ?>,<?lsmb END; text('Currency') ?>
 <?lsmb FOREACH currency IN currencies;
     FOREACH row IN currency.rows;
         FOREACH column IN columns;

Modified: trunk/UPGRADE
===================================================================
--- trunk/UPGRADE	2012-01-16 23:32:37 UTC (rev 4263)
+++ trunk/UPGRADE	2012-01-17 01:51:53 UTC (rev 4264)
@@ -1,6 +1,6 @@
-Upgrading to LedgerSMB 1.3.3 
+Upgrading to LedgerSMB 1.3
 
-From LedgerSMB 1.3.0-1.3.2:
+From LedgerSMB 1.3:
 
 Untar over the top and then:
 
@@ -15,6 +15,8 @@
 * direct browser to the setup.pl file in the directory you are in.
 * provide PostgreSQL superuser credentials and the name of your data base.
 * Click continue.
+* [Optionally] Click 'Backup DB' and/or 'Backup Roles'.
+* Click 'Yes', answering "LedgerSMB 1.3 found. Rebuild/Upgrade?"
 * Repeat for each database.
 
 From LedgerSMB 1.1 and earlier:

Modified: trunk/bin/am.pl
===================================================================
--- trunk/bin/am.pl	2012-01-16 23:32:37 UTC (rev 4263)
+++ trunk/bin/am.pl	2012-01-17 01:51:53 UTC (rev 4264)
@@ -78,8 +78,9 @@
 );
 
 my @default_others = qw(businessnumber weightunit separate_duties default_language
-                        IC IC_income IC_expense 
-                        FX_gain FX_loss default_country templates curr);
+                        inventory_accno_id income_accno_id expense_accno_id 
+                        fxgain_accno_id fxloss_accno_id default_country 
+                        templates curr);
 
 sub save_as_new {
 
@@ -1431,12 +1432,11 @@
     # get defaults for account numbers and last numbers
     AM->get_all_defaults( \%$form );
     my %selects = (
-        'FX_loss' => {name => 'FX_loss', options => []},
-        'FX_gain' => {name => 'FX_gain', options => []},
-        'IC_expense' => {name => 'IC_expense', options => []},
-        'IC_income' => {name => 'IC_income', options => []},
-        'IC_inventory' => {name => 'IC_inventory', options => []},
-        'IC' => {name => 'IC', options => []},
+        'fxloss_accno_id' => {name => 'fxloss_accno_id', options => []},
+        'fxgain_accno_id' => {name => 'fxgain_accno_id', options => []},
+        'expense_accno_id' => {name => 'expense_accno_id', options => []},
+        'income_accno_id' => {name => 'income_accno_id', options => []},
+        'inventory_accno_id' => {name => 'inventory_accno_id', options => []},
 	'default_country' => {name   => 'default_country', 
 			     options => $form->{countries},
 			     default_values => [$form->{'default_country'}],
@@ -1452,13 +1452,16 @@
 	'templates'       => {name => 'templates', options => []}	
         );
     foreach $key ( keys %{ $form->{accno} } ) {
+	print STDERR "$key\n";
         foreach $accno ( sort keys %{ $form->{accno}{$key} } ) {
             push @{$selects{$key}{options}}, {
                 text => "$accno--$form->{accno}{$key}{$accno}{description}",
                 value => "$accno--$form->{accno}{$key}{$accno}{description}",
                 };
-            $selects{$key}{default_values} = "$accno--$form->{accno}{$key}{$accno}{description}" if
+            $selects{$key}{default_values} = ["$accno--$form->{accno}{$key}{$accno}{description}"] if
                 ($form->{defaults}{$key} == $form->{accno}{$key}{$accno}{id});
+            print STDERR "$key $accno--$form->{accno}{$key}{$accno}{description}\n" if
+                ($form->{defaults}{$key} == $form->{accno}{$key}{$accno}{id});
         }
     }
     for (qw(accno defaults)) { delete $form->{$_} }

Modified: trunk/bin/ic.pl
===================================================================
--- trunk/bin/ic.pl	2012-01-16 23:32:37 UTC (rev 4263)
+++ trunk/bin/ic.pl	2012-01-17 01:51:53 UTC (rev 4264)
@@ -3931,21 +3931,21 @@
           . qq|</td>|;
         $column_data{rop} =
             qq|<td align=right>|
-          . $form->format_amount( \%myconfig, $ref->{rop}, '', "&nbsp;" )
-          . qq|</td>|;
-        $column_data{stock} =
-            qq|<td width=10%><input name="qty_$i" size=10 value=|
-          . $form->format_amount( \%myconfig, $ref->{stock} )
-          . qq|></td>
-    <input type=hidden name="stock_$i" value=$ref->{stock}>|;
-
-        $j++;
-        $j %= 2;
-        print
-qq|<tr class=listrow$j><input name="id_$i" type=hidden value=$ref->{id}>\n|;
-
-        for (@column_index) { print "\n$column_data{$_}" }
-
+          . $form->format_amount( \%myconfig, $ref->{rop}, '', "&nbsp;" )
+          . qq|</td>|;
+        $column_data{stock} =
+            qq|<td width=10%><input name="qty_$i" size="10" value="|
+          . $form->format_amount( \%myconfig, $ref->{stock} )
+          . qq|"></td>
+    <input type=hidden name="stock_$i" value="$ref->{stock}">|;
+
+        $j++;
+        $j %= 2;
+        print
+qq|<tr class=listrow$j><input name="id_$i" type=hidden value="$ref->{id}">\n|;
+
+        for (@column_index) { print "\n$column_data{$_}" }
+
         print qq|
 	</tr>
 |;

Modified: trunk/bin/io.pl
===================================================================
--- trunk/bin/io.pl	2012-01-16 23:32:37 UTC (rev 4263)
+++ trunk/bin/io.pl	2012-01-17 01:51:53 UTC (rev 4264)
@@ -337,30 +337,30 @@
 
 $column_data{runningnumber} =
           qq|<td><input name="runningnumber_$i" size=3 value=$i></td>|;
-        $column_data{partnumber} =
-qq|<td><input name="partnumber_$i" size=15 value="$form->{"partnumber_$i"}" accesskey="$i" title="[Alt-$i]">$skunumber</td>|;
-        $column_data{qty} =
-qq|<td align=right><input name="qty_$i" title="$form->{"onhand_$i"}" size=5 value=|
-          . $form->format_amount( \%myconfig, $form->{"qty_$i"} )
-          . qq|></td>|;
-        $column_data{ship} =
-            qq|<td align=right><input name="ship_$i" size=5 value=|
-          . $form->format_amount( \%myconfig, $form->{"ship_$i"} )
-          . qq|></td>|;
-        $column_data{unit} =
-          qq|<td><input name="unit_$i" size=5 value="$form->{"unit_$i"}"></td>|;
-        $column_data{sellprice} =
-          qq|<td align=right><input name="sellprice_$i" size=9 value=|
-          . $form->format_amount( \%myconfig, $form->{"sellprice_$i"},
-            $form->{"precision_$i"} )
-          . qq|></td>|;
-        $column_data{discount} =
-            qq|<td align=right><input name="discount_$i" size=3 value=|
-          . $form->format_amount( \%myconfig, $form->{"discount_$i"} )
-          . qq|></td>|;
-        $column_data{linetotal} =
-            qq|<td align=right>|
-          . $form->format_amount( \%myconfig, $linetotal, 2 )
+        $column_data{partnumber} =
+qq|<td><input name="partnumber_$i" size=15 value="$form->{"partnumber_$i"}" accesskey="$i" title="[Alt-$i]">$skunumber</td>|;
+        $column_data{qty} =
+qq|<td align=right><input name="qty_$i" title="$form->{"onhand_$i"}" size="5" value="|
+          . $form->format_amount( \%myconfig, $form->{"qty_$i"} )
+          . qq|"></td>|;
+        $column_data{ship} =
+            qq|<td align=right><input name="ship_$i" size="5" value="|
+          . $form->format_amount( \%myconfig, $form->{"ship_$i"} )
+          . qq|"></td>|;
+        $column_data{unit} =
+          qq|<td><input name="unit_$i" size=5 value="$form->{"unit_$i"}"></td>|;
+        $column_data{sellprice} =
+          qq|<td align=right><input name="sellprice_$i" size="9" value="|
+          . $form->format_amount( \%myconfig, $form->{"sellprice_$i"},
+            $form->{"precision_$i"} )
+          . qq|"></td>|;
+        $column_data{discount} =
+            qq|<td align=right><input name="discount_$i" size="3" value="|
+          . $form->format_amount( \%myconfig, $form->{"discount_$i"} )
+          . qq|"></td>|;
+        $column_data{linetotal} =
+            qq|<td align=right>|
+          . $form->format_amount( \%myconfig, $linetotal, 2 )
           . qq|</td>|;
         $column_data{bin}    = qq|<td>$form->{"bin_$i"}</td>|;
         $column_data{onhand} = qq|<td>$form->{"onhand_$i"}</td>|;

Modified: trunk/bin/ir.pl
===================================================================
--- trunk/bin/ir.pl	2012-01-16 23:32:37 UTC (rev 4263)
+++ trunk/bin/ir.pl	2012-01-17 01:51:53 UTC (rev 4264)
@@ -1380,22 +1380,20 @@
 	    {
             #print STDERR qq| taxformcheck_$i = $form->{"taxformcheck_$i"} and taxformfound= $taxformfound ___________|;
 		
-		if($form->{"taxformcheck_$i"} and $taxformfound)
+                if($taxformfound)
+                {
+                if($form->{"taxformcheck_$i"})
 		{
-			
 		  IR->update_invoice_tax_form($form,$form->{dbh},$form->{"invoice_id_$i"},"true") if($form->{"invoice_id_$i"});
           $form->{$dbh}->commit();#highest-level sub should commit
-
 		}
 		else
 		{
-
 		    IR->update_invoice_tax_form($form,$form->{dbh},$form->{"invoice_id_$i"},"false") if($form->{"invoice_id_$i"});
             $form->{$dbh}->commit();#highest-level sub should commit
-
 		}
-		
-	    }    
+                }#taxformfound		
+	    }
 
 	    if ($form->{callback}){
 		print "Location: $form->{callback}\n";

Modified: trunk/bin/is.pl
===================================================================
--- trunk/bin/is.pl	2012-01-16 23:32:37 UTC (rev 4263)
+++ trunk/bin/is.pl	2012-01-17 01:51:53 UTC (rev 4264)
@@ -341,63 +341,63 @@
           s/option>\Q$form->{$_}\E/option selected>$form->{$_}/;
     }
 
-    for (qw(customer department employee)) {
-        $form->{"select$_"} = $form->unescape( $form->{"select$_"} );
-        $form->{"select$_"} =~ s/ selected//;
-        $form->{"select$_"} =~ s/(<option value="\Q$form->{$_}\E")/$1 selected/;
-    }
-
-    $form->{exchangerate} =
+    for (qw(customer department employee)) {
+        $form->{"select$_"} = $form->unescape( $form->{"select$_"} );
+        $form->{"select$_"} =~ s/ selected//;
+        $form->{"select$_"} =~ s/(<option value="\Q$form->{$_}\E")/$1 selected="selected"/;
+    }
+
+    $form->{exchangerate} =
       $form->format_amount( \%myconfig, $form->{exchangerate} );
 
-    $exchangerate = qq|<tr>|;
-    $exchangerate .= qq|
-		<th align=right nowrap>| . $locale->text('Currency') . qq|</th>
-		<td><select name=currency>$form->{selectcurrency}</select></td>
-| if $form->{defaultcurrency};
-    $exchangerate .= qq|
-		<input type=hidden name=selectcurrency value="$form->{selectcurrency}">
-		<input type=hidden name=defaultcurrency value=$form->{defaultcurrency}>
-|;
-
-    if (   $form->{defaultcurrency}
+    $exchangerate = qq|<tr>|;
+    $exchangerate .= qq|
+		<th align=right nowrap>| . $locale->text('Currency') . qq|</th>
+		<td><select name="currency">$form->{selectcurrency}</select></td>
+| if $form->{defaultcurrency};
+    $exchangerate .= qq|
+		<input type=hidden name="selectcurrency" value="$form->{selectcurrency}">
+		<input type=hidden name="defaultcurrency"value="$form->{defaultcurrency}">
+|;
+
+    if (   $form->{defaultcurrency}
         && $form->{currency} ne $form->{defaultcurrency} )
     {
         if ( $form->{forex} ) {
-            $exchangerate .=
-                qq|<th align=right>|
-              . $locale->text('Exchange Rate')
-              . qq|</th><td>$form->{exchangerate}<input type=hidden name=exchangerate value=$form->{exchangerate}></td>|;
-        }
-        else {
-            $exchangerate .=
-                qq|<th align=right>|
-              . $locale->text('Exchange Rate')
-              . qq|</th><td><input name=exchangerate size=10 value=$form->{exchangerate}></td>|;
-        }
-    }
-    $exchangerate .= qq|
-<input type=hidden name=forex value=$form->{forex}>
-</tr>
-|;
-
-    if ( $form->{selectcustomer} ) {
-        $customer = qq|<select name=customer>$form->{selectcustomer}</select>
-                   <input type=hidden name="selectcustomer" value="|
-          . $form->escape( $form->{selectcustomer}, 1 ) . qq|">|;
-    }
-    else {
-        $customer = qq|<input name=customer value="$form->{customer}" size=35>|;
-    }
-
-    $department = qq|
-              <tr>
-	        <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
-		<td colspan=3><select name=department>$form->{selectdepartment}</select>
-		<input type=hidden name=selectdepartment value="|
-      . $form->escape( $form->{selectdepartment}, 1 ) . qq|">
-		</td>
-	      </tr>
+            $exchangerate .=
+                qq|<th align=right>|
+              . $locale->text('Exchange Rate')
+              . qq|</th><td>$form->{exchangerate}<input type="hidden" name="exchangerate" value="$form->{exchangerate}"></td>|;
+        }
+        else {
+            $exchangerate .=
+                qq|<th align=right>|
+              . $locale->text('Exchange Rate')
+              . qq|</th><td><input name="exchangerate size="10" value="$form->{exchangerate}"></td>|;
+        }
+    }
+    $exchangerate .= qq|
+<input type=hidden name="forex" value="$form->{forex}">
+</tr>
+|;
+
+    if ( $form->{selectcustomer} ) {
+        $customer = qq|<select name="customer">$form->{selectcustomer}</select>
+                   <input type="hidden" name="selectcustomer" value="|
+          . $form->escape( $form->{selectcustomer}, 1 ) . qq|">|;
+    }
+    else {
+        $customer = qq|<input name="customer" value="$form->{customer}" size="35">|;
+    }
+
+    $department = qq|
+              <tr>
+	        <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
+		<td colspan="3"><select name="department">$form->{selectdepartment}</select>
+		<input type="hidden" name="selectdepartment" value="|
+      . $form->escape( $form->{selectdepartment}, 1 ) . qq|">
+		</td>
+	      </tr>
 | if $form->{selectdepartment};
 
     $n = ( $form->{creditremaining} < 0 ) ? "0" : "1";
@@ -414,21 +414,21 @@
           . qq| %</td>
 	      </tr>
 |;
-    }
+    }
+
+    $employee = qq|
+                <input type=hidden name="employee" value="$form->{employee}">
+|;
+
+    $employee = qq|
+	      <tr>
+	        <th align=right nowrap>| . $locale->text('Salesperson') . qq|</th>
+		<td><select name="employee">$form->{selectemployee}</select></td>
+		<input type=hidden name="selectemployee" value="|
+      . $form->escape( $form->{selectemployee}, 1 ) . qq|">
+	      </tr>
+| if $form->{selectemployee};
 
-    $employee = qq|
-                <input type=hidden name=employee value="$form->{employee}">
-|;
-
-    $employee = qq|
-	      <tr>
-	        <th align=right nowrap>| . $locale->text('Salesperson') . qq|</th>
-		<td><select name=employee>$form->{selectemployee}</select></td>
-		<input type=hidden name=selectemployee value="|
-      . $form->escape( $form->{selectemployee}, 1 ) . qq|">
-	      </tr>
-| if $form->{selectemployee};
-
     $i     = $form->{rowcount} + 1;
     $focus = "partnumber_$i";
 
@@ -477,14 +477,14 @@
 	<tr valign=top>
 	  <td>
 	    <table>
-	      <tr>
-		<th align=right nowrap>| . $locale->text('Customer') . qq|</th>
-		<td colspan=3>$customer</td>
-		<input type=hidden name=customer_id value=$form->{customer_id}>
-		<input type=hidden name=oldcustomer value="$form->{oldcustomer}"> 
-	      </tr>
-	      <tr>
-		<td></td>
+	      <tr>
+		<th align=right nowrap>| . $locale->text('Customer') . qq|</th>
+		<td colspan=3>$customer</td>
+		<input type=hidden name="customer_id" value="$form->{customer_id}">
+		<input type=hidden name="oldcustomer" value="$form->{oldcustomer}"> 
+	      </tr>
+	      <tr>
+		<td></td>
 		<td colspan=3>
 		  <table>
 		    <tr>
@@ -500,51 +500,51 @@
 		    </tr>
 		    $business
 		  </table>
-		</td>
-	      </tr>
-	      <tr>
-		<th align=right nowrap>| . $locale->text('Record in') . qq|</th>
-		<td colspan=3><select name=AR>$form->{selectAR}</select></td>
-		<input type=hidden name=selectAR value="$form->{selectAR}">
-	      </tr>
-	      $department
-	      $exchangerate
-	      <tr>
-		<th align=right nowrap>| . $locale->text('Shipping Point') . qq|</th>
-		<td colspan=3><input name=shippingpoint size=35 value="$form->{shippingpoint}"></td>
-	      </tr>
-	      <tr>
-		<th align=right nowrap>| . $locale->text('Ship via') . qq|</th>
-		<td colspan=3><input name=shipvia size=35 value="$form->{shipvia}"></td>
-	      </tr>
-	    </table>
-	  </td>
+		</td>
+	      </tr>
+	      <tr>
+		<th align="right" nowrap>| . $locale->text('Record in') . qq|</th>
+		<td colspan="3"><select name="AR">$form->{selectAR}</select></td>
+		<input type="hidden" name="selectAR" value="$form->{selectAR}">
+	      </tr>
+	      $department
+	      $exchangerate
+	      <tr>
+		<th align=right nowrap>| . $locale->text('Shipping Point') . qq|</th>
+		<td colspan=3><input name="shippingpoint" size="35" value="$form->{shippingpoint}"></td>
+	      </tr>
+	      <tr>
+		<th align=right nowrap>| . $locale->text('Ship via') . qq|</th>
+		<td colspan=3><input name="shipvia" size="35" value="$form->{shipvia}"></td>
+	      </tr>
+	    </table>
+	  </td>
 	  <td align=right>
 	    <table>
-	      $employee
-	      <tr>
-		<th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
-		<td><input name=invnumber size=20 value="$form->{invnumber}"></td>
-	      </tr>
-	      <tr>
-		<th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
-		<td><input name=ordnumber size=20 value="$form->{ordnumber}"></td>
-<input type=hidden name=quonumber value="$form->{quonumber}">
-	      </tr>
-	      <tr>
-		<th align=right>| . $locale->text('Invoice Date') . qq|</th>
-		<td><input class="date" name=transdate size=11 title="$myconfig{dateformat}" value=$form->{transdate}></td>
-	      </tr>
-	      <tr>
-		<th align=right>| . $locale->text('Due Date') . qq|</th>
-		<td><input class="date" name=duedate size=11 title="$myconfig{dateformat}" value=$form->{duedate}></td>
-	      </tr>
-	      <tr>
-		<th align=right nowrap>| . $locale->text('PO Number') . qq|</th>
-		<td><input name=ponumber size=20 value="$form->{ponumber}"></td>
-	      </tr>
-	    </table>
-	  </td>
+	      $employee
+	      <tr>
+		<th align=right nowrap>| . $locale->text('Invoice Number') . qq|</th>
+		<td><input name="invnumber" size="20" value="$form->{invnumber}"></td>
+	      </tr>
+	      <tr>
+		<th align=right nowrap>| . $locale->text('Order Number') . qq|</th>
+		<td><input name="ordnumber" size="20" value="$form->{ordnumber}"></td>
+<input type=hidden name="quonumber" value="$form->{quonumber}">
+	      </tr>
+	      <tr>
+		<th align=right>| . $locale->text('Invoice Date') . qq|</th>
+		<td><input class="date" name="transdate" size="11" title="$myconfig{dateformat}" value="$form->{transdate}"></td>
+	      </tr>
+	      <tr>
+		<th align=right>| . $locale->text('Due Date') . qq|</th>
+		<td><input class="date" name="duedate" size="11" title="$myconfig{dateformat}" value="$form->{duedate}"></td>
+	      </tr>
+	      <tr>
+		<th align=right nowrap>| . $locale->text('PO Number') . qq|</th>
+		<td><input name="ponumber" size="20" value="$form->{ponumber}"></td>
+	      </tr>
+	    </table>
+	  </td>
 	</tr>
       </table>
     </td>
@@ -609,25 +609,25 @@
     }
     if ( ( $introws = $form->numtextrows( $form->{intnotes}, 35, 8 ) ) < 2 ) {
         $introws = 5;
-    }
-    $rows = ( $rows > $introws ) ? $rows : $introws;
-    $notes =
-qq|<textarea name=notes rows=$rows cols=40 wrap=soft>$form->{notes}</textarea>|;
-    $intnotes =
-qq|<textarea name=intnotes rows=$rows cols=40 wrap=soft>$form->{intnotes}</textarea>|;
-
-    $form->{taxincluded} = ( $form->{taxincluded} ) ? "checked" : "";
-
+    }
+    $rows = ( $rows > $introws ) ? $rows : $introws;
+    $notes =
+qq|<textarea name="notes" rows="$rows" cols="40" wrap="soft">$form->{notes}</textarea>|;
+    $intnotes =
+qq|<textarea name="intnotes" rows="$rows" cols="40" wrap="soft">$form->{intnotes}</textarea>|;
+
+    $form->{taxincluded} = ( $form->{taxincluded} ) ? "checked" : "";
+
     $taxincluded = "";
     if ($form->{taxaccounts} ) {
         $taxincluded = qq|
-              <tr height="5"></tr>
-              <tr>
-	        <td align=right>
-	        <input name=taxincluded class=checkbox type=checkbox value=1 $form->{taxincluded}></td><th align=left>|
-          . $locale->text('Tax Included')
-          . qq|</th>
-	     </tr>
+              <tr height="5"></tr>
+              <tr>
+	        <td align=right>
+	        <input name="taxincluded" class="checkbox" type="checkbox" value="1" $form->{taxincluded}></td><th align=left>|
+          . $locale->text('Tax Included')
+          . qq|</th>
+	     </tr>
 |;
     }
 
@@ -826,35 +826,35 @@
           $form->format_amount( \%myconfig, $form->{"exchangerate_$i"} );
 
         $exchangerate = qq|&nbsp;|;
-        if ( $form->{currency} ne $form->{defaultcurrency} ) {
-            if ( $form->{"forex_$i"} ) {
-                $exchangerate =
-qq|<input type=hidden name="exchangerate_$i" value=$form->{"exchangerate_$i"}>$form->{"exchangerate_$i"}|;
-            }
-            else {
-                $exchangerate =
-qq|<input name="exchangerate_$i" size=10 value=$form->{"exchangerate_$i"}>|;
-            }
-        }
-
-        $exchangerate .= qq|
-<input type=hidden name="forex_$i" value=$form->{"forex_$i"}>
-|;
-
-        $column_data{paid} =
-qq|<td align=center><input name="paid_$i" size=11 value=$form->{"paid_$i"}></td>|;
-        $column_data{exchangerate} = qq|<td align=center>$exchangerate</td>|;
-        $column_data{AR_paid} =
-qq|<td align=center><select name="AR_paid_$i">$form->{"selectAR_paid_$i"}</select></td>|;
-        $column_data{datepaid} =
-qq|<td align=center><input class="date" name="datepaid_$i" size=11 title="$myconfig{dateformat}" value=$form->{"datepaid_$i"}></td>|;
-        $column_data{source} =
-qq|<td align=center><input name="source_$i" size=11 value="$form->{"source_$i"}"></td>|;
-        $column_data{memo} =
-qq|<td align=center><input name="memo_$i" size=11 value="$form->{"memo_$i"}"></td>|;
-
-        for (@column_index) { print qq|$column_data{$_}\n| }
-        print "
+        if ( $form->{currency} ne $form->{defaultcurrency} ) {
+            if ( $form->{"forex_$i"} ) {
+                $exchangerate =
+qq|<input type="hidden" name="exchangerate_$i" value="$form->{"exchangerate_$i"}">$form->{"exchangerate_$i"}|;
+            }
+            else {
+                $exchangerate =
+qq|<input name="exchangerate_$i" size="10" value="$form->{"exchangerate_$i"}">|;
+            }
+        }
+
+        $exchangerate .= qq|
+<input type="hidden" name="forex_$i" value="$form->{"forex_$i"}">
+|;
+
+        $column_data{paid} =
+qq|<td align="center"><input name="paid_$i" size="11" value="$form->{"paid_$i"}"></td>|;
+        $column_data{exchangerate} = qq|<td align="center">$exchangerate</td>|;
+        $column_data{AR_paid} =
+qq|<td align="center"><select name="AR_paid_$i">$form->{"selectAR_paid_$i"}</select></td>|;
+        $column_data{datepaid} =
+qq|<td align="center"><input class="date" name="datepaid_$i" size="11" title="$myconfig{dateformat}" value="$form->{"datepaid_$i"}"></td>|;
+        $column_data{source} =
+qq|<td align="center"><input name="source_$i" size="11" value="$form->{"source_$i"}"></td>|;
+        $column_data{memo} =
+qq|<td align="center"><input name="memo_$i" size="11" value="$form->{"memo_$i"}"></td>|;
+
+        for (@column_index) { print qq|$column_data{$_}\n| }
+        print "
         </tr>\n";
     }
 

Modified: trunk/bin/oe.pl
===================================================================
--- trunk/bin/oe.pl	2012-01-16 23:32:37 UTC (rev 4263)
+++ trunk/bin/oe.pl	2012-01-17 01:51:53 UTC (rev 4264)
@@ -1199,6 +1199,7 @@
         $ordlabel      = $locale->text('Order Number');
         $ordnumber     = 'ordnumber';
         $employee      = $locale->text('Employee');
+        $form->{oe_class_id} = 2;
     }
 
     if ( $form->{type} eq 'generate_sales_order' ) {
@@ -1244,6 +1245,7 @@
         $ordlabel      = $locale->text('Order Number');
         $ordnumber     = 'ordnumber';
         $employee      = $locale->text('Salesperson');
+        $form->{oe_class_id} = 1;
     }
 
     if ( $form->{type} eq 'sales_quotation' ) {
@@ -2929,15 +2931,15 @@
 qq|<td>$description<input type=hidden name="description_$i" value="$form->{"description_$i"}"></td>|;
         $column_data{qty} =
             qq|<td align=right>|
-          . $form->format_amount( \%myconfig, $form->{"qty_$i"} )
-          . qq|<input type=hidden name="qty_$i" value="$form->{"qty_$i"}"></td>|;
-        $column_data{ship} =
-            qq|<td align=right><input name="ship_$i" size=5 value=|
-          . $form->format_amount( \%myconfig, $form->{"ship_$i"} )
-          . qq|></td>|;
-        $column_data{unit} =
-qq|<td>$form->{"unit_$i"}<input type=hidden name="unit_$i" value="$form->{"unit_$i"}"></td>|;
-        $column_data{bin} =
+          . $form->format_amount( \%myconfig, $form->{"qty_$i"} )
+          . qq|<input type=hidden name="qty_$i" value="$form->{"qty_$i"}"></td>|;
+        $column_data{ship} =
+            qq|<td align=right><input name="ship_$i" size=5 value="|
+          . $form->format_amount( \%myconfig, $form->{"ship_$i"} )
+          . qq|"></td>|;
+        $column_data{unit} =
+qq|<td>$form->{"unit_$i"}<input type=hidden name="unit_$i" value="$form->{"unit_$i"}"></td>|;
+        $column_data{bin} =
 qq|<td>$form->{"bin_$i"}<input type=hidden name="bin_$i" value="$form->{"bin_$i"}"></td>|;
 
         $column_data{serialnumber} =
@@ -2968,7 +2970,10 @@
 
     $form->{copies} = 1;
 
-    &print_options;
+    $printops = &print_options;
+    print_select($form, $printops->{formname});
+    print_select($form, $printops->{format});
+    print_select($form, $printops->{media});
 
     print qq|
     </td>
@@ -3262,16 +3267,16 @@
 
         $column_data{partnumber} =
 qq|<td><input type=hidden name="id_$i" value=$ref->{id}>$ref->{partnumber}</td>|;
-        $column_data{description} = "<td>$ref->{description}&nbsp;</td>";
-        $column_data{partsgroup}  = "<td>$ref->{partsgroup}&nbsp;</td>";
-        $column_data{fromwarehouse} =
-qq|<td><input type=hidden name="warehouse_id_$i" value=$ref->{warehouse_id}>$ref->{warehouse}&nbsp;</td>|;
-        $column_data{towarehouse} = qq|<td>$warehouse&nbsp;</td>|;
-        $column_data{qty} =
-            qq|<td><input type=hidden name="qty_$i" value=$ref->{qty}>|
-          . $form->format_amount( \%myconfig, $ref->{qty} )
-          . qq|</td>|;
-        $column_data{transfer} = qq|<td><input name="transfer_$i" size=4></td>|;
+        $column_data{description} = "<td>$ref->{description}&nbsp;</td>";
+        $column_data{partsgroup}  = "<td>$ref->{partsgroup}&nbsp;</td>";
+        $column_data{fromwarehouse} =
+qq|<td><input type=hidden name="warehouse_id_$i" value="$ref->{warehouse_id}">$ref->{warehouse}&nbsp;</td>|;
+        $column_data{towarehouse} = qq|<td>$warehouse&nbsp;</td>|;
+        $column_data{qty} =
+            qq|<td><input type=hidden name="qty_$i" value="$ref->{qty}">|
+          . $form->format_amount( \%myconfig, $ref->{qty} )
+          . qq|</td>|;
+        $column_data{transfer} = qq|<td><input name="transfer_$i" size=4></td>|;
 
         $j++;
         $j %= 2;
@@ -3507,13 +3512,13 @@
 
         for (qw(required leadtime lastcost fx)) {
             $column_data{$_} = qq|<td align=right>$form->{"${_}_$i"}</td>|;
-        }
-
-        $column_data{qty} =
-qq|<td align=right><input name="qty_$i" size=6 value=$form->{"qty_$i"}></td>|;
-
-        if ( $form->{"$form->{vc}_id_$i"} ) {
-            $name = $form->{"$form->{vc}_$i"};
+        }
+
+        $column_data{qty} =
+qq|<td align=right><input name="qty_$i" size="6" value="$form->{"qty_$i"}"></td>|;
+
+        if ( $form->{"$form->{vc}_id_$i"} ) {
+            $name = $form->{"$form->{vc}_$i"};
             $name =~ s/--.*//;
             $column_data{name} = qq|<td>$name</td>|;
             $form->hide_form( "$form->{vc}_id_$i", "$form->{vc}_$i" );

Modified: trunk/dists/rpm/ledgersmb.spec
===================================================================
--- trunk/dists/rpm/ledgersmb.spec	2012-01-16 23:32:37 UTC (rev 4263)
+++ trunk/dists/rpm/ledgersmb.spec	2012-01-17 01:51:53 UTC (rev 4264)
@@ -1,7 +1,7 @@
 # RPM spec written for and tested on CentOS 4 and CentOS 5 
 Summary: LedgerSMB - Open Source accounting software
 Name: ledgersmb
-Version: 1.3.9
+Version: 1.3.10
 Release: 1
 License: GPL
 URL: http://www.ledgersmb.org/

Deleted: trunk/doc/notes/foreign-currency-handling
===================================================================
--- branches/1.3/doc/notes/foreign-currency-handling	2012-01-13 07:16:07 UTC (rev 4262)
+++ trunk/doc/notes/foreign-currency-handling	2012-01-17 01:51:53 UTC (rev 4264)
@@ -1,109 +0,0 @@
-                                                -*- mode: text -*-
-
-A file to document our multi-currency handling, both actual as well
-as intended operation/design.
-
-
-Contents
-========
-
- * AR/AP Transactions
- * Invoices
- * Payments to AR/AP items
- * Taxation on AR/AP items
- * Reversal of AR/AP items
- * Reversal of payments to AR/AP items
- * Closed periods
-
-
-AR/AP Transactions
-==================
-
-
-Invoices
-========
-
-When calculating the amounts on an invoice, special care needs to be
-taken to ensure no amounts on the invoice use fractional cents.  This
-can become tedious when considering FX and discount effects.
-
-During the calculation of invoices, two sets of amounts are being
-calculated: fx-amounts and regular amounts.  The fx-amounts end up on
-the invoice while the regular amounts end up in the ledger.  Note that
-this applies on local currency invoices as well, using an FX rate of 1.
-
-The procedure to calculate the total invoice amount is to sum up the
-amounts of the lines, where each line total is calculated as follows:
-
- * Multiplication of amount and item cost
- * Application of optional discounts
- * Optionally factor out tax amounts,
-    if the sell price includes taxes
- * Rounding of the line total to the nearest cent
-
-The procedure should continue to convert the FX amounts to regular
-amounts which then can be posted - unrounded.
-
-Payments to AR/AP items
-=======================
-
-Payments are rounded to 2-digit precision (cents) in the foreign currency
-in the same way AR/AP totals are.  Amounts are translated to local currency
-before posting (unrounded).  Differences in value of the foreign currency
-amount in the local currency between creation of the item and payment
-are posted to the FX Gain (gains) and FX Loss (losses) P&L accounts.
-
-Taxation on AR/AP items
-=======================
-
-Once the line totals in an AR/AP invoice or general transaction have been
-calculated, the taxes can be calculated.
-
-The most precise approach -also also in light of numerical stability
-(considering that floats represent numbers close to 1.0 the most exact)- would
-be to calculate the tax amount (unrounded) per line.
-
-Per tax type, the invoice should list the rounded (at 2 decimals) tax amount.
-
-This leaves a fractional-cent difference between the actual tax liability
-and the amount charged.  Although this fractional difference should be
-charged to the income accounts involved in the invoice, this difference
-can't be part of the invoice itself and hence of the open AR/AP transaction.
-
-The transaction should post charge the tax difference directly from the
-income accounts, posting to the tax liability, without going through AR/AP.
-
-(### What's the current method of allocating this tax difference? Is that
- the most acceptable way??)
-
-
-Reversal of AR/AP items
-=======================
-
-
-Reversal of payments to AR/AP items
-===================================
-
-Reversal of a payment to an AR/AP item should include reversal of the
-posted gains/losses.  In order to calculate those correctly, the fx rate
-used in the posting of the payment should be used.  Unfortunately, in
-the exsiting structure, this is not possible - unless the item is posted on
-the same posting date - because the fx rate is dynamically looked up based
-on the posting date upon retrieval of the transaction.
-
-
-Closed periods
-==============
-
-Currently, AR/AP transactions are valued at the FX rate of the posting
-date of the document.  This means that there's no way to reverse an
-AR/AP transaction without side effects after the period in which the
-original posting was created -- assuming daily changing FX rates.
-
-Ideally, there should be a way for a (reversal) transaction to specify
-which exchange rate is to be used - or from which date to take it.
-
-The above issue is especially a problem when reversing payments, which
-cause FX gain/loss postings to the P&L.  In the scenario where it's impossible
-to use a specified date for the FX rate, it's impossible to completely
-reverse the P&L effect.

Copied: trunk/doc/notes/foreign-currency-handling (from rev 4262, branches/1.3/doc/notes/foreign-currency-handling)
===================================================================
--- trunk/doc/notes/foreign-currency-handling	                        (rev 0)
+++ trunk/doc/notes/foreign-currency-handling	2012-01-17 01:51:53 UTC (rev 4264)
@@ -0,0 +1,109 @@
+                                                -*- mode: text -*-
+
+A file to document our multi-currency handling, both actual as well
+as intended operation/design.
+
+
+Contents
+========
+
+ * AR/AP Transactions
+ * Invoices
+ * Payments to AR/AP items
+ * Taxation on AR/AP items
+ * Reversal of AR/AP items
+ * Reversal of payments to AR/AP items
+ * Closed periods
+
+
+AR/AP Transactions
+==================
+
+
+Invoices
+========
+
+When calculating the amounts on an invoice, special care needs to be
+taken to ensure no amounts on the invoice use fractional cents.  This
+can become tedious when considering FX and discount effects.
+
+During the calculation of invoices, two sets of amounts are being
+calculated: fx-amounts and regular amounts.  The fx-amounts end up on
+the invoice while the regular amounts end up in the ledger.  Note that
+this applies on local currency invoices as well, using an FX rate of 1.
+
+The procedure to calculate the total invoice amount is to sum up the
+amounts of the lines, where each line total is calculated as follows:
+
+ * Multiplication of amount and item cost
+ * Application of optional discounts
+ * Optionally factor out tax amounts,
+    if the sell price includes taxes
+ * Rounding of the line total to the nearest cent
+
+The procedure should continue to convert the FX amounts to regular
+amounts which then can be posted - unrounded.
+
+Payments to AR/AP items
+=======================
+
+Payments are rounded to 2-digit precision (cents) in the foreign currency
+in the same way AR/AP totals are.  Amounts are translated to local currency
+before posting (unrounded).  Differences in value of the foreign currency
+amount in the local currency between creation of the item and payment
+are posted to the FX Gain (gains) and FX Loss (losses) P&L accounts.
+
+Taxation on AR/AP items
+=======================
+
+Once the line totals in an AR/AP invoice or general transaction have been
+calculated, the taxes can be calculated.
+
+The most precise approach -also also in light of numerical stability
+(considering that floats represent numbers close to 1.0 the most exact)- would
+be to calculate the tax amount (unrounded) per line.
+
+Per tax type, the invoice should list the rounded (at 2 decimals) tax amount.
+
+This leaves a fractional-cent difference between the actual tax liability
+and the amount charged.  Although this fractional difference should be
+charged to the income accounts involved in the invoice, this difference
+can't be part of the invoice itself and hence of the open AR/AP transaction.
+
+The transaction should post charge the tax difference directly from the
+income accounts, posting to the tax liability, without going through AR/AP.
+
+(### What's the current method of allocating this tax difference? Is that
+ the most acceptable way??)
+
+
+Reversal of AR/AP items
+=======================
+
+
+Reversal of payments to AR/AP items
+===================================
+
+Reversal of a payment to an AR/AP item should include reversal of the
+posted gains/losses.  In order to calculate those correctly, the fx rate
+used in the posting of the payment should be used.  Unfortunately, in
+the exsiting structure, this is not possible - unless the item is posted on
+the same posting date - because the fx rate is dynamically looked up based
+on the posting date upon retrieval of the transaction.
+
+
+Closed periods
+==============
+
+Currently, AR/AP transactions are valued at the FX rate of the posting
+date of the document.  This means that there's no way to reverse an
+AR/AP transaction without side effects after the period in which the
+original posting was created -- assuming daily changing FX rates.
+
+Ideally, there should be a way for a (reversal) transaction to specify
+which exchange rate is to be used - or from which date to take it.
+
+The above issue is especially a problem when reversing payments, which
+cause FX gain/loss postings to the P&L.  In the scenario where it's impossible
+to use a specified date for the FX rate, it's impossible to completely
+reverse the P&L effect.

Copied: trunk/pos.conf.pl.template (from rev 4262, branches/1.3/pos.conf.pl.template)
===================================================================
--- trunk/pos.conf.pl.template	                        (rev 0)
+++ trunk/pos.conf.pl.template	2012-01-17 01:51:53 UTC (rev 4264)
@@ -0,0 +1,103 @@
+use LedgerSMB::Sysconfig;
+
+# This sets up the settings for the POS hardware.  You can use it to override
+# printing commands etc. as well.
+
+# Chris Travers
+# ..hidden..
+# 2004-02-07
+
+# Begin Editing Here
+
+$pos_config{'rem_host'} = $ENV{'REMOTE_ADDR'};
+
+$pos_config{'pd_host'}  = $pos_config{'rem_host'};
+$pos_config{'pd_port'}  = 6601;
+$pos_config{'pd_proto'} = 'udp';
+
+require "drivers/pd3000.pl";    # Use the PD3000 driver
+
+# Some businesses may want to Override this for custom apps
+$pos_config{'pd_host'} = $pos_config{'rem_host'};
+
+$pos_config{'rp_port'}  = 6602;
+$pos_config{'rp_proto'} = 'tcp';
+
+$pos_config{'rp_netdirect'} = 'yes';
+
+# Some businesses may want to Override this for custom apps
+$pos_config{'rp_host'} = $pos_config{'rem_host'};
+$pos_config{'rp_cash_open'} = pack( "CCCCC", 27, 112, 0, 25, 250 );
+
+$pos_config{'coa_prefix'} = 1300;
+
+$pos_config{'close_cash_accno'} = 1060;
+$pos_config{till_cash} = 200;
+
+# Add your sources here.
+
+$pos_sources{'visa'}  = $locale->text("Visa/MC");
+$pos_sources{'disc'}  = $locale->text("Discover");
+$pos_sources{'check'} = $locale->text('Check');
+$pos_sources{'cash'}  = $locale->text('Cash');
+$pos_sources{'gcert'} = $locale->text('Gift Cert');
+
+$pos_source_default = 'cash';
+
+# 1 for source = memo
+# 2 for credit card handling
+%pos_source_type = {
+    visa  => 2,
+    cash  => 1,
+    check => 1,
+    disc  => 2
+};
+
+${ $pos_config{'source_accno_override'}{'gcert'} } = '2105';
+
+# Define your till accno scheme here.  Current supported values are 'terminal'
+# and 'cashier'
+
+$pos_config{'till_type'} = 'cashier';
+
+# FLAGS: 1 = projects, 2 = departments
+$pos_config{'disable_tables'} = 3;
+
+# HTML for the appropriate currency symbol for your tills
+$pos_config{'curren'} = '$';
+
+# Number format to use
+$pos_config{'numberformat'} = '1,000.00';
+
+# Units of currency to use in the till closing cash breakdown relative to
+# your base unit of currency, formatted in your chosen format
..hidden.. $pos_config{'breakdown'} } =
+  ( '100', '50', '20', '10', '5', '2', '1', '0.25', '0.10', '0.05', '0.01' );
+
+# Stop Editing Here
+
+if ( lc( $pos_config{'till_type'} ) eq 'terminal' ) {
+    $pos_config{'till'} = ( split( /\./, $pos_config{'rem_host'} ) )[3];
+}
+elsif ( lc( $pos_config{'till_type'} ) eq 'cashier' ) {
+    use LedgerSMB::User;
+    $pos_config{'till'} = $form->get_my_emp_num(\%myconfig);
+}
+else {
+    $form->error("No till type defined in pos.conf.pl!");
+}
+$pos_config{till_accno} = "$pos_config{coa_prefix}.$pos_config{till}";
+$pos_config{'pd_dest'} = pack( 's n a4 x8',
+    2, $pos_config{'pd_port'},
+    pack( 'CCCC', split( /\./, $pos_config{'pd_host'} ) ) );
+
+$form->{pos_config}  = \%pos_config;
+$form->{pos_sources} = \%pos_sources;
+
+# Due to the architecture of SL, we need to use netcat to print.
+# Otherwise the document gets spooled twice and this interferes with timeliness.
+
+${'LedgerSMB::Sysconfig::printer'}{'Printer'} =
+"utils/pos/directnet.pl $pos_config{rp_host} $pos_config{rp_proto} $pos_config{rp_port}";
+
+1;

Modified: trunk/sql/Pg-database.sql
===================================================================
--- trunk/sql/Pg-database.sql	2012-01-16 23:32:37 UTC (rev 4263)
+++ trunk/sql/Pg-database.sql	2012-01-17 01:51:53 UTC (rev 4264)
@@ -1782,6 +1782,11 @@
   sell numeric,
   PRIMARY KEY (curr, transdate)
 );
+COMMENT ON TABLE exchangerate IS
+$$ When you receive money in a foreign currency, it is worth to you in your local currency
+whatever you can get for it when you sell the acquired currency (sell rate).
+When you have to pay someone in a foreign currency, the equivalent amount is the amount
+you have to spend to acquire the foreign currency (buy rate).$$;
 --
 CREATE TABLE project (
   id serial PRIMARY KEY,
@@ -2821,10 +2826,10 @@
 63	menu	1	146
 64	module	oe.pl	147
 64	action	search	148
+64	type	ship_order	149
 65	module	oe.pl	150
 65	action	search	151
 65	type	receive_order	152
-64	type	consolidate_sales_order	149
 66	module	oe.pl	153
 66	action	search_transfer	154
 67	menu	1	155
@@ -4423,4 +4428,49 @@
 
 COMMENT ON FUNCTION person__get_my_entity_id() IS
 $$ Returns the entity_id of the current, logged in user.$$;
+--
+-- WE NEED A PAYMENT TABLE 
+--
+
+CREATE TABLE payment (
+  id serial primary key,
+  reference text NOT NULL,
+  gl_id     integer references gl(id),
+  payment_class integer NOT NULL,
+  payment_date date default current_date,
+  closed bool default FALSE,
+  entity_credit_id   integer references entity_credit_account(id),
+  employee_id integer references person(id),
+  currency char(3),
+  notes text,
+  department_id integer default 0);
+              
+COMMENT ON TABLE payment IS $$ This table will store the main data on a payment, prepayment, overpayment, et$$;
+COMMENT ON COLUMN payment.reference IS $$ This field will store the code for both receipts and payment order  $$; 
+COMMENT ON COLUMN payment.closed IS $$ This will store the current state of a payment/receipt order $$;
+COMMENT ON COLUMN payment.gl_id IS $$ A payment should always be linked to a GL movement $$;
+CREATE  INDEX payment_id_idx ON payment(id);
+                  
+CREATE TABLE payment_links (
+  payment_id integer references Payment(id),
+  entry_id   integer references acc_trans(entry_id),
+  type       integer);
+COMMENT ON TABLE payment_links IS $$  
+ An explanation to the type field.
+ * A type 0 means the link is referencing an ar/ap  and was created
+   using an overpayment movement after the receipt was created 
+ * A type 1 means the link is referencing an ar/ap and  was made 
+   on the payment creation, its not the product of an overpayment movement 
+ * A type 2 means the link is not referencing an ar/ap and its the product
+   of the overpayment logic 
+
+ With this ideas in order we can do the following
+
+ To get the payment amount we will sum the entries with type > 0.
+ To get the linked amount we will sum the entries with type < 2.
+ The overpayment account can be obtained from the entries with type = 2.
+
+ This reasoning is hacky and i hope it can dissapear when we get to 1.4 - D.M.
+$$;
+ 
 commit;

Modified: trunk/sql/coa/uk/chart/General.sql
===================================================================
--- trunk/sql/coa/uk/chart/General.sql	2012-01-16 23:32:37 UTC (rev 4263)
+++ trunk/sql/coa/uk/chart/General.sql	2012-01-17 01:51:53 UTC (rev 4264)
@@ -26,8 +26,9 @@
 SELECT account_save(NULL,'2100','Creditors Control Account','L','', NULL, false, false, string_to_array('AP', ':'));
 SELECT account_save(NULL,'2102','Other Creditors','L','', NULL, false, false, string_to_array('AP', ':'));
 SELECT account_save(NULL,'2109','Accruals','L','', NULL, false, false, string_to_array('', ':'));
-SELECT account_save(NULL,'2200','VAT (17.5%)','L','', NULL, false, false, string_to_array('AR_tax:AP_tax:IC_taxpart:IC_taxservice', ':'));
-SELECT account_save(NULL,'2205','VAT (5%)','L','', NULL, false, false, string_to_array('AR_tax:AP_tax:IC_taxpart:IC_taxservice', ':'));
+SELECT account_save(NULL,'2200','VAT - Standard rate','L','', NULL, false, false, string_to_array('AR_tax:AP_tax:IC_taxpart:IC_taxservice', ':'));
+SELECT account_save(NULL,'2205','VAT - Reduced rate','L','', NULL, false, false, string_to_array('AR_tax:AP_tax:IC_taxpart:IC_taxservice', ':'));
+SELECT account_save(NULL,'2209','VAT - Zero rate','L','', NULL, false, false, string_to_array('AR_tax:AP_tax:IC_taxpart:IC_taxservice', ':'));
 SELECT account_save(NULL,'2210','P.A.Y.E. & National Insurance','L','', NULL, false, false, string_to_array('', ':'));
 SELECT account_save(NULL,'2220','Net Wages','L','', NULL, false, false, string_to_array('', ':'));
 SELECT account_save(NULL,'2250','Corporation Tax','L','', NULL, false, false, string_to_array('', ':'));
@@ -104,8 +105,9 @@
 SELECT account_save(NULL,'8600','Corporation Tax','E','', NULL, false, false, string_to_array('', ':'));
 SELECT account_save(NULL,'9999','Suspense Account','E','', NULL, false, false, string_to_array('', ':'));
 --
-INSERT INTO tax (chart_id,rate) VALUES ((SELECT id FROM chart WHERE accno = '2200'),0.175);
+INSERT INTO tax (chart_id,rate) VALUES ((SELECT id FROM chart WHERE accno = '2200'),0.20);
 INSERT INTO tax (chart_id,rate) VALUES ((SELECT id FROM chart WHERE accno = '2205'),0.05);
+INSERT INTO tax (chart_id,rate) VALUES ((SELECT id FROM chart WHERE accno = '2209'),0.00);
 --
 INSERT INTO defaults (setting_key, value) VALUES ('inventory_accno_id',  (SELECT id FROM chart WHERE accno = '1001'));
 

Modified: trunk/sql/modules/Fixes.sql
===================================================================
--- trunk/sql/modules/Fixes.sql	2012-01-16 23:32:37 UTC (rev 4263)
+++ trunk/sql/modules/Fixes.sql	2012-01-17 01:51:53 UTC (rev 4264)
@@ -79,3 +79,12 @@
                           OR op.inventory_accno_id = parts.inventory_accno_id 
                           or op.expense_accno_id = parts.expense_accno_id));
 COMMIT; 
+
+BEGIN;
+-- Fix menu Shipping -> Ship to actually point to the shipping interface
+-- used to point to sales order consolidation
+UPDATE menu_attribute
+ SET value = 'ship_order'
+ WHERE attribute='type'
+       AND node_id = (SELECT id FROM menu_node WHERE label = 'Ship');
+COMMIT;
\ No newline at end of file

Modified: trunk/sql/modules/Payment.sql
===================================================================
--- trunk/sql/modules/Payment.sql	2012-01-16 23:32:37 UTC (rev 4263)
+++ trunk/sql/modules/Payment.sql	2012-01-17 01:51:53 UTC (rev 4264)
@@ -1,3 +1,4 @@
+BEGIN;
 
 CREATE OR REPLACE FUNCTION payment_type__list() RETURNS SETOF payment_type AS
 $$
@@ -9,6 +10,8 @@
 END;
 $$ LANGUAGE PLPGSQL;
 
+DROP TYPE IF EXISTS payment_vc_info CASCADE;
+
 CREATE TYPE payment_vc_info AS (
 	id int,
 	name text,
@@ -78,13 +81,21 @@
 		JOIN company cp ON (cp.entity_id = e.id)
 			WHERE ec.entity_class = in_account_class
                         AND CASE WHEN in_account_class = 1 THEN
-	           		ec.id IN (SELECT entity_credit_account FROM ap 
-	           			WHERE amount <> paid
-		   			GROUP BY entity_credit_account)
+	           		ec.id IN (SELECT entity_credit_account
+                                            FROM ap
+                                            JOIN acc_trans ac ON ap.id = ac.trans_id
+                                            JOIN account_link al ON acc.chart_id = al.account_id
+                                           WHERE al.description = 'AP'
+                                           GROUP BY entity_credit_account
+                                           HAVING SUM(ac.amount) <> 0)
 		    	       WHEN in_account_class = 2 THEN
-		   		ec.id IN (SELECT entity_credit_account FROM ar
-		   			WHERE amount <> paid
-		   			GROUP BY entity_credit_account)
+		   		ec.id IN (SELECT entity_credit_account
+                                            FROM ar
+                                            JOIN acc_trans ac ON ar.id = ac.trans_id
+                                            JOIN account_link al ON acc.chart_id = al.account_id
+                                           WHERE al.description = 'AR'
+                                           GROUP BY entity_credit_account
+                                           HAVING SUM(ac.amount) <> 0)
 		   	  END
 	LOOP
 		RETURN NEXT out_entity;
@@ -117,10 +128,12 @@
 $$ This function takes a single argument (1 for vendor, 2 for customer as 
 always) and returns all entities with accounts of the appropriate type. $$;
 
+DROP TYPE IF EXISTS payment_invoice CASCADE;
 
 CREATE TYPE payment_invoice AS (
 	invoice_id int,
 	invnumber text,
+    invoice bool,
 	invoice_date date,
 	amount numeric,
 	amount_fx numeric,
@@ -145,13 +158,13 @@
 DECLARE payment_inv payment_invoice;
 BEGIN
 	FOR payment_inv IN
-		SELECT a.id AS invoice_id, a.invnumber AS invnumber, 
+		SELECT a.id AS invoice_id, a.invnumber AS invnumber,a.invoice AS invoice, 
 		       a.transdate AS invoice_date, a.amount AS amount, 
 		       a.amount/
 		       (CASE WHEN a.curr = (SELECT * from defaults_get_defaultcurrency())
                          THEN 1
 		        ELSE
-		        (CASE WHEN in_account_class =1
+		        (CASE WHEN in_account_class = 2
 		              THEN ex.buy
 		              ELSE ex.sell END)
 		        END) as amount_fx, 
@@ -166,7 +179,7 @@
 		        (CASE WHEN a.curr = (SELECT * from defaults_get_defaultcurrency())
                          THEN 1
 		        ELSE
-		        (CASE WHEN in_account_class =1
+		        (CASE WHEN in_account_class = 2
 		              THEN ex.buy
 		              ELSE ex.sell END)
 		        END) as discount_fx,		        
@@ -181,26 +194,28 @@
 		        (CASE WHEN a.curr = (SELECT * from defaults_get_defaultcurrency())
                          THEN 1
 		         ELSE
-		         (CASE WHEN in_account_class =1
+		         (CASE WHEN in_account_class = 2
 		              THEN ex.buy
 		              ELSE ex.sell END)
 		         END) AS due_fx,
 		        (CASE WHEN a.curr = (SELECT * from defaults_get_defaultcurrency())
 		         THEN 1
 		         ELSE
-		        (CASE WHEN in_account_class =1
+		        (CASE WHEN in_account_class = 2
 		         THEN ex.buy
 		         ELSE ex.sell END)
 		         END) AS exchangerate
-                 FROM  (SELECT id, invnumber, transdate, amount, entity_id,
-		               1 as invoice_class, paid, curr, 
+                 --TODO HV prepare drop entity_id from ap,ar
+                 --FROM  (SELECT id, invnumber, transdate, amount, entity_id,
+                 FROM  (SELECT id, invnumber, invoice, transdate, amount,
+		               1 as invoice_class, curr,
 		               entity_credit_account, department_id, approved
 		          FROM ap
                          UNION
-		         SELECT id, invnumber, transdate, amount, entity_id,
-		               2 AS invoice_class, paid, curr,
+		         --SELECT id, invnumber, transdate, amount, entity_id,
+		         SELECT id, invnumber, invoice, transdate, amount,
+		               2 AS invoice_class, curr,
 		               entity_credit_account, department_id, approved
-
 		         FROM ar
 		         ) a 
 		JOIN (SELECT trans_id, chart_id, sum(CASE WHEN in_account_class = 1 THEN amount
@@ -211,14 +226,14 @@
 		        GROUP BY trans_id, chart_id) ac ON (ac.trans_id = a.id)
 		        JOIN chart ON (chart.id = ac.chart_id)
 		        LEFT JOIN exchangerate ex ON ( ex.transdate = a.transdate AND ex.curr = a.curr )         
-		        JOIN entity_credit_account c ON (c.id = a.entity_credit_account
-                        OR (a.entity_credit_account IS NULL and a.entity_id = c.entity_id))
+		        JOIN entity_credit_account c ON (c.id = a.entity_credit_account)
+                --        OR (a.entity_credit_account IS NULL and a.entity_id = c.entity_id))
 	 	        WHERE ((chart.link = 'AP' AND in_account_class = 1)
 		              OR (chart.link = 'AR' AND in_account_class = 2))
               	        AND a.invoice_class = in_account_class
 		        AND c.entity_class = in_account_class
 		        AND c.id = in_entity_credit_id
-		        AND a.amount - a.paid <> 0
+                        --### short term: ignore fractional cent differences
 		        AND a.curr = in_curr
 		        AND (a.transdate >= in_datefrom 
 		             OR in_datefrom IS NULL)
@@ -232,7 +247,7 @@
 		             OR in_department_id IS NULL)
 		        AND due <> 0 
 		        AND a.approved = true         
-		        GROUP BY a.invnumber, a.transdate, a.amount, amount_fx, discount, discount_fx, ac.due, a.id, c.discount_terms, ex.buy, ex.sell, a.curr
+		        GROUP BY a.invnumber, a.transdate, a.amount, amount_fx, discount, discount_fx, ac.due, a.id, c.discount_terms, ex.buy, ex.sell, a.curr, a.invoice
 	LOOP
 		RETURN NEXT payment_inv;
 	END LOOP;
@@ -274,7 +289,7 @@
 if no in_invnumber is passed this function behaves the same as payment_get_open_invoices
 $$;
 
-
+DROP TYPE IF EXISTS payment_contact_invoice CASCADE;
 CREATE TYPE payment_contact_invoice AS (
 	contact_id int,
 	econtrol_code text,
@@ -341,7 +356,7 @@
 		    FROM entity e
 		    JOIN entity_credit_account c ON (e.id = c.entity_id)
 		    JOIN (SELECT ap.id, invnumber, transdate, amount, entity_id, 
-				 paid, curr, 1 as invoice_class, 
+				 curr, 1 as invoice_class,
 		                 entity_credit_account, on_hold, v.batch_id,
 				 approved
 		            FROM ap
@@ -351,7 +366,7 @@
 			         AND (v.batch_class = 1 or v.batch_id IS NULL)
 		           UNION
 		          SELECT ar.id, invnumber, transdate, amount, entity_id,
-		                 paid, curr, 2 as invoice_class, 
+		                 curr, 2 as invoice_class,
 		                 entity_credit_account, on_hold, v.batch_id,
 				 approved
 		            FROM ar
@@ -389,7 +404,7 @@
 		         AND a.curr = in_currency
 		         AND a.entity_credit_account = c.id
 			 AND p.due <> 0
-		         AND a.amount <> a.paid 
+                         --### short term: ignore fractional differences
 			 AND NOT a.on_hold
 		         AND EXISTS (select trans_id FROM acc_trans
 		                      WHERE trans_id = a.id AND
@@ -527,21 +542,8 @@
 		||$E$ 
 		FROM bulk_payments_in where amount <> 0 $E$;
 
-        IF in_account_class = 1 THEN
-        	EXECUTE $E$
-	        	UPDATE ap 
-		        set paid = paid + (select amount from bulk_payments_in b
-		         	where b.id = ap.id),
-                            datepaid = $E$ || quote_literal(in_payment_date) || $E$
-		         where id in (select id from bulk_payments_in) $E$;
-        ELSE
-        	EXECUTE $E$
-	        	UPDATE ar 
-		        set paid = paid + (select amount from bulk_payments_in b 
-		         	where b.id = ar.id),
-                            datepaid = $E$ || quote_literal(in_payment_date) || $E$
-		         where id in (select id from bulk_payments_in) $E$;
-        END IF;
+	-- ### BUG: Where's the FX gain/loss part for FX postings??
+
 	EXECUTE $E$ DROP TABLE bulk_payments_in $E$;
 	perform unlock_all();
 	return out_count;
@@ -560,51 +562,6 @@
 sub-array, the first element is the (integer) transaction id, and the second
 is the amount for that transaction.  $$;
 
---
--- WE NEED A PAYMENT TABLE 
---
-
-CREATE TABLE payment (
-  id serial primary key,
-  reference text NOT NULL,
-  gl_id     integer references gl(id),
-  payment_class integer NOT NULL,
-  payment_date date default current_date,
-  closed bool default FALSE,
-  entity_credit_id   integer references entity_credit_account(id),
-  employee_id integer references person(id),
-  currency char(3),
-  notes text,
-  department_id integer default 0);
-              
-COMMENT ON TABLE payment IS $$ This table will store the main data on a payment, prepayment, overpayment, et$$;
-COMMENT ON COLUMN payment.reference IS $$ This field will store the code for both receipts and payment order  $$; 
-COMMENT ON COLUMN payment.closed IS $$ This will store the current state of a payment/receipt order $$;
-COMMENT ON COLUMN payment.gl_id IS $$ A payment should always be linked to a GL movement $$;
-CREATE  INDEX payment_id_idx ON payment(id);
-                  
-CREATE TABLE payment_links (
-  payment_id integer references Payment(id),
-  entry_id   integer references acc_trans(entry_id),
-  type       integer);
-COMMENT ON TABLE payment_links IS $$  
- An explanation to the type field.
- * A type 0 means the link is referencing an ar/ap  and was created
-   using an overpayment movement after the receipt was created 
- * A type 1 means the link is referencing an ar/ap and  was made 
-   on the payment creation, its not the product of an overpayment movement 
- * A type 2 means the link is not referencing an ar/ap and its the product
-   of the overpayment logic 
-
- With this ideas in order we can do the following
-
- To get the payment amount we will sum the entries with type > 0.
- To get the linked amount we will sum the entries with type < 2.
- The overpayment account can be obtained from the entries with type = 2.
-
- This reasoning is hacky and i hope it can dissapear when we get to 1.4 - D.M.
-$$;
- 
 CREATE OR REPLACE FUNCTION payment_post 
 (in_datepaid      		  date,
  in_account_class 		  int,
@@ -639,7 +596,7 @@
 DECLARE default_currency char(3);
 DECLARE current_exchangerate numeric;
 DECLARE old_exchangerate numeric;
-DECLARE tmp_amount numeric;
+DECLARE fx_gain_loss_amount numeric;
 BEGIN
         
         SELECT * INTO default_currency  FROM defaults_get_defaultcurrency(); 
@@ -703,17 +660,23 @@
        	        trans_id = in_transaction_id[out_count] AND
        	        ( c.link = 'AP' OR c.link = 'AR' );
         -- We need to know the exchangerate of this transaction
-        IF (current_exchangerate = 1 ) THEN 
+	-- ### BUG: we don't have a guarantee that the transaction is
+	--          the same currency as in_curr, so, we can't use
+	--          current_exchangerate as the basis for fx gain/loss
+	--          calculations
+        IF (in_curr = default_currency) THEN 
            old_exchangerate := 1;
-        ELSIF (in_account_class = 1) THEN
+        ELSIF (in_account_class = 2) THEN
            SELECT buy INTO old_exchangerate 
            FROM exchangerate e
-           JOIN ap a on (a.transdate = e.transdate )
+           JOIN ar a ON (a.transdate = e.transdate)
+                        AND (a.curr = e.curr)
            WHERE a.id = in_transaction_id[out_count];
         ELSE 
            SELECT sell INTO old_exchangerate 
            FROM exchangerate e
-           JOIN ar a on (a.transdate = e.transdate )
+           JOIN ap a ON (a.transdate = e.transdate)
+                        AND (a.curr = e.curr)
            WHERE a.id = in_transaction_id[out_count];
         END IF;
         -- Now we post the AP/AR transaction
@@ -727,33 +690,24 @@
 		        END,
 		        in_transaction_id[out_count], in_datepaid,  coalesce(in_approved, true), 
 		        in_source[out_count], in_memo[out_count]);
-        -- Lets set the gain/loss, if tmp_amount equals zero then we dont need to post
+        -- Lets set the gain/loss, if  fx_gain_loss_amount equals zero then we dont need to post
         -- any transaction
-        tmp_amount := in_amount[out_count]*current_exchangerate - in_amount[out_count]*old_exchangerate;
-       IF (tmp_amount < 0) THEN
-          IF (in_account_class  = 1) THEN
+       fx_gain_loss_amount := in_amount[out_count]*current_exchangerate - in_amount[out_count]*old_exchangerate;
+       IF (in_account_class = 1) THEN
+         -- in case of vendor invoices, the invoice amounts have been negated, do the same with the diff
+         fx_gain_loss_amount := fx_gain_loss_amount * -1;
+       END IF;
+
+       IF (fx_gain_loss_amount < 0) THEN
            INSERT INTO acc_trans (chart_id, amount, trans_id, transdate, approved, source)
-            VALUES (CAST((select value from defaults where setting_key like 'fxloss_accno_id') AS INT),
-                    tmp_amount, in_transaction_id[out_count], in_datepaid, coalesce(in_approved, true),
+            VALUES ((select value::int from defaults WHERE setting_key = 'fxgain_accno_id'),
+                    fx_gain_loss_amount, in_transaction_id[out_count], in_datepaid, coalesce(in_approved, true),
                     in_source[out_count]);
-           ELSE
+        ELSIF (fx_gain_loss_amount > 0) THEN
             INSERT INTO acc_trans (chart_id, amount, trans_id, transdate, approved, source)
-            VALUES (CAST((select value from defaults where setting_key like 'fxgain_accno_id') AS INT),
-                    tmp_amount, in_transaction_id[out_count], in_datepaid, coalesce(in_approved, true),
+            VALUES ((select value::int from defaults WHERE setting_key = 'fxloss_accno_id'),
+                    fx_gain_loss_amount, in_transaction_id[out_count], in_datepaid, coalesce(in_approved, true),
                     in_source[out_count]);
-          END IF;
-        ELSIF (tmp_amount > 0) THEN
-          IF (in_account_class  = 1) THEN
-            INSERT INTO acc_trans (chart_id, amount, trans_id, transdate, approved, source)
-            VALUES (CAST((select value from defaults where setting_key like 'fxgain_accno_id') AS INT),
-                    tmp_amount, in_transaction_id[out_count], in_datepaid, coalesce(in_approved, true),
-                    in_source[out_count]);
-           ELSE
-            INSERT INTO acc_trans (chart_id, amount, trans_id, transdate, approved, source)
-            VALUES (CAST((select value from defaults where setting_key like 'fxloss_accno_id') AS INT),
-                    tmp_amount, in_transaction_id[out_count], in_datepaid, coalesce(in_approved, true),
-                    in_source[out_count]);
-          END IF; 
         END IF; 
         -- Now we set the links
          INSERT INTO payment_links 
@@ -934,7 +888,7 @@
         IF default_currency = in_currency THEN
            RETURN 1;
         END IF; 
-        IF in_account_class = 1 THEN
+        IF in_account_class = 2 THEN
           SELECT buy INTO out_exrate 
           FROM exchangerate
           WHERE transdate = in_date AND curr = in_currency;
@@ -953,6 +907,8 @@
 --  payment_location_result has the same arch as location_result, except for one field 
 --  This should be unified on the API when we get things working - David Mora
 --
+
+DROP TYPE IF EXISTS payment_location_result CASCADE;
 CREATE TYPE payment_location_result AS (
         id int,
         line_one text,
@@ -995,6 +951,7 @@
 COMMENT ON FUNCTION payment_get_vc_info(in_entity_id int, in_location_class_id int) IS
 $$ This function returns vendor or customer info $$;
 
+DROP TYPE IF EXISTS payment_record CASCADE;
 CREATE TYPE payment_record AS (
 	amount numeric,
 	meta_number text,
@@ -1127,30 +1084,6 @@
 			COALESCE(in_source, ''), 
 			case when in_batch_id is not null then false 
 			else true end, t_voucher_id);
-		IF in_account_class = 1 THEN
-			UPDATE ap SET paid = amount - 
-				(SELECT sum(a.amount) 
-				FROM acc_trans a
-				JOIN chart c ON (a.chart_id = c.id)
-				WHERE c.link = 'AP'
-					AND trans_id = pay_row.trans_id
-				), 
-                                force_closed = false 
-			WHERE id = pay_row.trans_id;
-		ELSIF in_account_class = 2 THEN
-			update ar SET paid = amount - 
-				(SELECT sum(a.amount) 
-				FROM acc_trans a
-				JOIN chart c ON (a.chart_id = c.id)
-				WHERE c.link = 'AR'
-					AND trans_id = pay_row.trans_id
-				) * -1,
-                                force_closed = false
-			WHERE id = pay_row.trans_id;
-		ELSE
-			RAISE EXCEPTION 'Unknown account class for payments %',
-				in_account_class;
-		END IF;
 	END LOOP;
 	RETURN 1;
 END;
@@ -1172,19 +1105,20 @@
 BEGIN
 select  * INTO current_exrate
         FROM  exchangerate 
-        WHERE transdate = in_date;
-IF current_exrate.transdate = in_date THEN
-   IF in_account_class = 1 THEN 
-      UPDATE exchangerate set buy = in_exchangerate  where transdate = in_date;
+        WHERE transdate = in_datepaid
+              AND curr = in_curr;
+IF current_exrate.transdate = in_datepaid THEN
+   IF in_account_class = 2 THEN 
+      UPDATE exchangerate set buy = in_exchangerate  where transdate = in_datepaid;
    ELSE
-      UPDATE exchangerate set sell = in_exchangerate where transdate = in_date;
+      UPDATE exchangerate set sell = in_exchangerate where transdate = in_datepaid;
    END IF;
    RETURN 0; 
 ELSE
-    IF in_account_class = 1 THEN
-     INSERT INTO exchangerate (curr, transdate, buy) values (in_currency, in_date, in_exchangerate);
+    IF in_account_class = 2 THEN
+     INSERT INTO exchangerate (curr, transdate, buy) values (in_curr, in_datepaid, in_exchangerate);
   ELSE   
-     INSERT INTO exchangerate (curr, transdate, sell) values (in_currency, in_date, in_exchangerate);
+     INSERT INTO exchangerate (curr, transdate, sell) values (in_curr, in_datepaid, in_exchangerate);
   END IF;                                       
 RETURN 0;
 END IF;
@@ -1198,6 +1132,7 @@
 This sets the exchange rate for a class of transactions (payable, receivable) 
 to a certain rate for a specific date.$$;
 
+DROP TYPE IF EXISTS payment_header_item CASCADE;
 CREATE TYPE payment_header_item AS (
 payment_id int,
 payment_reference int,
@@ -1247,6 +1182,7 @@
 $$ This function finds a payment based on the id and retrieves the record, 
 it is usefull for printing payments :) $$;
 
+DROP TYPE IF EXISTS payment_line_item CASCADE;
 CREATE TYPE payment_line_item AS (
   payment_id int,
   entry_id int,
@@ -1301,6 +1237,8 @@
 it is usefull for printing payments and build reports :) $$;
 
 -- We will use a view to handle all the overpayments
+
+DROP VIEW IF EXISTS overpayments CASCADE;
 CREATE VIEW overpayments AS
 SELECT p.id as payment_id, p.reference as payment_reference, p.payment_class, p.closed as payment_closed,
        p.payment_date, ac.chart_id, c.accno, c.description as chart_description,
@@ -1360,6 +1298,7 @@
 in_account_class int, in_entity_credit_id int, in_chart_id int) IS
 $$ Returns a list of available overpayments$$;
 
+DROP TYPE IF EXISTS payment_overpayments_available_amount CASCADE;
 CREATE TYPE payment_overpayments_available_amount AS (
         chart_id int,
         accno text,
@@ -1390,3 +1329,4 @@
 in_account_class int, in_entity_credit_id int, in_chart_id int) IS
 $$ Returns a list of available overpayments$$;
 
+COMMIT;

Modified: trunk/sql/modules/Roles.sql
===================================================================
--- trunk/sql/modules/Roles.sql	2012-01-16 23:32:37 UTC (rev 4263)
+++ trunk/sql/modules/Roles.sql	2012-01-17 01:51:53 UTC (rev 4264)
@@ -216,9 +216,12 @@
 -- AR
 CREATE ROLE "lsmb_<?lsmb dbname ?>__ar_transaction_create"
 WITH INHERIT NOLOGIN
-IN ROLE "lsmb_<?lsmb dbname ?>__contact_read",
-"lsmb_<?lsmb dbname ?>__exchangerate_edit";
+IN ROLE "lsmb_<?lsmb dbname ?>__contact_read";
 
+-- Role created later; using the GRANT construct, we support upgrades
+GRANT "lsmb_<?lsmb dbname ?>__exchangerate_edit"
+   TO "lsmb_<?lsmb dbname ?>__ar_transaction_create";
+
 GRANT INSERT ON ar, invoice_note 
 TO "lsmb_<?lsmb dbname ?>__ar_transaction_create";
 
@@ -328,9 +331,13 @@
 
 CREATE ROLE "lsmb_<?lsmb dbname ?>__sales_order_create"
 WITH INHERIT NOLOGIN
-IN ROLE "lsmb_<?lsmb dbname ?>__contact_read",
-"lsmb_<?lsmb dbname ?>__exchangerate_edit";
+IN ROLE "lsmb_<?lsmb dbname ?>__contact_read";
 
+-- Role created later; using the GRANT construct, we support upgrades
+GRANT "lsmb_<?lsmb dbname ?>__exchangerate_edit"
+   TO "lsmb_<?lsmb dbname ?>__sales_order_create";
+
+
 GRANT INSERT, UPDATE ON oe TO "lsmb_<?lsmb dbname ?>__sales_order_create";
 GRANT ALL ON oe_id_seq TO "lsmb_<?lsmb dbname ?>__sales_order_create";
 GRANT INSERT, UPDATE ON orderitems TO "lsmb_<?lsmb dbname ?>__sales_order_create";
@@ -348,9 +355,12 @@
 
 CREATE ROLE "lsmb_<?lsmb dbname ?>__sales_quotation_create"
 WITH INHERIT NOLOGIN
-IN ROLE "lsmb_<?lsmb dbname ?>__contact_read",
-"lsmb_<?lsmb dbname ?>__exchangerate_edit";
+IN ROLE "lsmb_<?lsmb dbname ?>__contact_read";
 
+-- Role created later; using the GRANT construct, we support upgrades
+GRANT "lsmb_<?lsmb dbname ?>__exchangerate_edit"
+   TO "lsmb_<?lsmb dbname ?>__sales_quotation_create";
+
 GRANT INSERT, UPDATE ON oe TO "lsmb_<?lsmb dbname ?>__sales_quotation_create";
 GRANT ALL ON oe_id_seq TO "lsmb_<?lsmb dbname ?>__sales_quotation_create";
 GRANT INSERT, UPDATE ON orderitems TO "lsmb_<?lsmb dbname ?>__sales_quotation_create";
@@ -408,9 +418,13 @@
 -- AP
 CREATE ROLE "lsmb_<?lsmb dbname ?>__ap_transaction_create"
 WITH INHERIT NOLOGIN
-IN ROLE "lsmb_<?lsmb dbname ?>__contact_read",
-"lsmb_<?lsmb dbname ?>__exchangerate_edit";
+IN ROLE "lsmb_<?lsmb dbname ?>__contact_read";
 
+-- Role created later; using the GRANT construct, we support upgrades
+GRANT "lsmb_<?lsmb dbname ?>__exchangerate_edit"
+   TO "lsmb_<?lsmb dbname ?>__ap_transaction_create";
+
+
 GRANT SELECT, INSERT ON ap, invoice_note 
 TO "lsmb_<?lsmb dbname ?>__ap_transaction_create";
 GRANT ALL ON id TO "lsmb_<?lsmb dbname ?>__ap_transaction_create";
@@ -516,9 +530,12 @@
 
 CREATE ROLE "lsmb_<?lsmb dbname ?>__purchase_order_create"
 WITH INHERIT NOLOGIN
-IN ROLE "lsmb_<?lsmb dbname ?>__contact_read",
-"lsmb_<?lsmb dbname ?>__exchangerate_edit";
+IN ROLE "lsmb_<?lsmb dbname ?>__contact_read";
 
+-- Role created later; using the GRANT construct, we support upgrades
+GRANT "lsmb_<?lsmb dbname ?>__exchangerate_edit"
+   TO "lsmb_<?lsmb dbname ?>__purchase_order_create";
+
 GRANT INSERT, UPDATE ON oe TO "lsmb_<?lsmb dbname ?>__purchase_order_create";
 GRANT INSERT, UPDATE ON orderitems TO "lsmb_<?lsmb dbname ?>__purchase_order_create";
 GRANT ALL ON oe_id_seq TO "lsmb_<?lsmb dbname ?>__purchase_order_create";
@@ -537,9 +554,12 @@
 
 CREATE ROLE "lsmb_<?lsmb dbname ?>__rfq_create"
 WITH INHERIT NOLOGIN
-IN ROLE "lsmb_<?lsmb dbname ?>__contact_read",
-"lsmb_<?lsmb dbname ?>__exchangerate_edit";
+IN ROLE "lsmb_<?lsmb dbname ?>__contact_read";
 
+-- Role created later; using the GRANT construct, we support upgrades
+GRANT "lsmb_<?lsmb dbname ?>__exchangerate_edit"
+   TO "lsmb_<?lsmb dbname ?>__rfq_create";
+
 GRANT INSERT, UPDATE ON oe TO "lsmb_<?lsmb dbname ?>__rfq_create";
 GRANT INSERT, UPDATE ON orderitems TO "lsmb_<?lsmb dbname ?>__rfq_create";
 GRANT ALL ON oe_id_seq TO "lsmb_<?lsmb dbname ?>__rfq_create";


Property changes on: trunk/sql/upgrade/1.2-1.3-manual.sql
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/1.3/sql/upgrade/1.2-1.3-manual.sql:3712-4215
/branches/1.3/sql/upgrade/1.2-1.3.sql:3711-3851
/trunk/sql/upgrade/1.2-1.3.sql:858-3710
   + /branches/1.3/sql/upgrade/1.2-1.3-manual.sql:3712-4262
/branches/1.3/sql/upgrade/1.2-1.3.sql:3711-3851
/trunk/sql/upgrade/1.2-1.3.sql:858-3710

Modified: trunk/templates/xedemo/balance_sheet.html
===================================================================
--- trunk/templates/xedemo/balance_sheet.html	2012-01-16 23:32:37 UTC (rev 4263)
+++ trunk/templates/xedemo/balance_sheet.html	2012-01-17 01:51:53 UTC (rev 4264)
@@ -152,7 +152,7 @@
 </tr>
 
 <tr valign="top">
-  <th align="left" colspan="2" style="text-transform: uppercase"><?lsmb escape(text('Total Liabilities & Equity')) ?></th>
+  <th align="left" colspan="2" style="text-transform: uppercase"><?lsmb text('Total Liabilities & Equity') ?></th>
   <td align="right"><?lsmb total_this_period ?><br /><hr noshade="noshade" size="2" /></td>
   <td align="right"><?lsmb total_last_period ?><br /><hr noshade="noshade" size="2" /></td>
 </tr>

Modified: trunk/tools/prepare-company-database.sh
===================================================================
--- trunk/tools/prepare-company-database.sh	2012-01-16 23:32:37 UTC (rev 4263)
+++ trunk/tools/prepare-company-database.sh	2012-01-17 01:51:53 UTC (rev 4264)
@@ -26,7 +26,7 @@
 usage () {
 script_name=`basename $0`
 cat <<USAGE
-usage: $script_name --company COMPANY --psql-contrib DIR [option1 .. optionN]
+usage: $script_name --company COMPANY --pgsql-contrib DIR [option1 .. optionN]
 
 This script wants to be run as the root user. If you don't, you'll be
 asked to enter the password of the 'postgres' user

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