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

SF.net SVN: ledger-smb:[4559] addons/1.3/b_units/trunk



Revision: 4559
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=4559&view=rev
Author:   einhverfr
Date:     2012-03-25 06:47:23 +0000 (Sun, 25 Mar 2012)
Log Message:
-----------
Adding patch to ar/ap/etc

Added Paths:
-----------
    addons/1.3/b_units/trunk/patches/
    addons/1.3/b_units/trunk/patches/b_units.patch

Added: addons/1.3/b_units/trunk/patches/b_units.patch
===================================================================
--- addons/1.3/b_units/trunk/patches/b_units.patch	                        (rev 0)
+++ addons/1.3/b_units/trunk/patches/b_units.patch	2012-03-25 06:47:23 UTC (rev 4559)
@@ -0,0 +1,515 @@
+Index: bin/aa.pl
+===================================================================
+--- bin/aa.pl	(revision 4545)
++++ bin/aa.pl	(working copy)
+@@ -435,6 +435,10 @@
+ 
+     $title = $form->{title};
+ 
++    $form->all_business_units($form->{transdate}, 
++                              $form->{"$form->{vc}_id"}, 
++                              $form->{ARAP});
++
+     if($form->{batch_id})
+     {
+ 		$form->{batch_control_code}=$form->get_batch_control_code($form->{dbh},$form->{batch_id});
+@@ -738,7 +742,13 @@
+ 	  <th>| . $locale->text('Account') . qq|</th>
+ 	  <th>| . $locale->text('Description') . qq|</th>
+ 	  <th>| . $locale->text('Tax Form Applied') . qq|</th>
+-	  $project
++	  $project|;
++    for my $cls (@{$form->{bu_class}}){
++        if (scalar @{$form->{b_units}->{"$cls->{id}"}}){
++            print qq|<th>| . $locale->text($cls->{label}) . qq|</th>|;
++        }
++    }
++       print qq|
+ 	</tr>
+ |;
+ 
+@@ -786,7 +796,27 @@
+ 	  <td><select name="$form->{ARAP}_amount_$i">$selectamount</select></td>
+ 	  $description
+           $taxformcheck
+-	  $project
++	  $project|;
++
++        for my $cls (@{$form->{bu_class}}){
++            if (scalar @{$form->{b_units}->{"$cls->{id}"}}){
++                print qq|<td><select name="b_unit_$cls->{id}_$i">
++                                    <option></option>|;
++                      for my $bu (@{$form->{b_units}->{"$cls->{id}"}}){
++                         my $selected = '';
++                         if ($form->{"b_unit_$cls->{id}_$i"} eq $bu->{id}){
++                            $selected = "SELECTED='SELECTED'";
++                         }
++                         print qq|  <option value="$bu->{id}" $selected>
++                                        $bu->{control_code}
++                                    </option>|;
++                      }
++                print qq|
++                             </select>
++                        </th>|;
++            }
++        }
++        print qq|
+ 	</tr>
+ |;
+ 
+@@ -1486,6 +1516,9 @@
+         $selectname = qq|<input name=$form->{vc} size=35>|;
+     }
+ 
++    # Business Reporting Units
++    $form->all_business_units;
++
+     # departments
+     if ( @{ $form->{all_department} } ) {
+         $form->{selectdepartment} = "<option>\n";
+Index: bin/io.pl
+===================================================================
+--- bin/io.pl	(revision 4473)
++++ bin/io.pl	(working copy)
+@@ -124,6 +124,15 @@
+ 
+ sub display_row {
+     my $numrows = shift;
++    my $lsmb_module;
++    if ($form->{vc} eq 'customer'){
++       $lsmb_module = 'AR';
++    } elsif ($form->{vc} eq 'vendor'){
++       $lsmb_module = 'AP';
++    }
++    $form->all_business_units($form->{transdate}, 
++                              $form->{"$form->{vc}_id"}, 
++                              $lsmb_module);
+ 
+     @column_index = qw(runningnumber partnumber description qty);
+ 
+@@ -172,6 +181,14 @@
+ 
+     push @column_index, @{LedgerSMB::Sysconfig::io_lineitem_columns};
+ 
++    for my $cls(@{$form->{bu_class}}){
++        if (scalar @{$form->{b_units}->{"$cls->{id}"}}){
++             push @column_index, "b_unit_$cls->{id}";
++             $column_data{"b_unit_$cls->{id}"} = 
++               qq|<th class=listheading nowrap>| . $cls->{label} . qq|</th>|;
++        }
++    }
++
+     push @column_index, "taxformcheck";#increase the number of elements by pushing into column_index.(Ex: NEw added element 
+ 				       # taxformcheck & check the screen AR->Sales Invoice) do everything before colspan ;
+ 
+@@ -334,6 +351,26 @@
+ 
+ 	}
+ 
++        for my $cls(@{$form->{bu_class}}){
++            if (scalar @{$form->{b_units}->{"$cls->{id}"}}){
++                $column_data{"b_unit_$cls->{id}"} = 
++                   qq|<td><select name="b_unit_$cls->{id}_$i">
++                           <option></option>|;
++                for my $bu (@{$form->{b_units}->{"$cls->{id}"}}){
++                   my $selected = "";
++                   if ($bu->{id} eq $form->{"b_unit_$cls->{id}_$i"}){
++                       $selected = "SELECTED='SELECTED'";
++                   }
++                   $column_data{"b_unit_$cls->{id}"} .= qq|
++                       <option value="$bu->{id}" $selected >
++                               $bu->{control_code}
++                       </option>|;
++                }
++                $column_data{"b_unit_$cls->{id}"} .= qq|
++                     </select></td>|;
++                   
++            }
++        }
+ 
+ $column_data{runningnumber} =
+           qq|<td><input name="runningnumber_$i" size=3 value=$i></td>|;
+Index: LedgerSMB/IR.pm
+===================================================================
+--- LedgerSMB/IR.pm	(revision 4473)
++++ LedgerSMB/IR.pm	(working copy)
+@@ -63,6 +63,7 @@
+ sub post_invoice {
+     my ( $self, $myconfig, $form ) = @_;
+ 
++    $form->all_business_units;
+     if ($form->{id}){
+         delete_invoice($self, $myconfig, $form);
+     }
+@@ -199,6 +200,15 @@
+     
+     my $taxformfound=IR->taxform_exist($form,$form->{"vendor_id"});#tshvr this always returns true!!
+   
++    my $b_unit_sth = $dbh->prepare(
++         "INSERT INTO business_unit_inv (entry_id, class_id, bu_id)
++          VALUES (currval('invoice_id_seq'), ?, ?)"
++    );
++
++    my $b_unit_sth_ac = $dbh->prepare(
++         "INSERT INTO business_unit_ac (entry_id, class_id, bu_id)
++          VALUES (currval('acc_trans_entry_id_seq'), ?, ?)"
++    );
+     for my $i ( 1 .. $form->{rowcount} ) {
+         $form->{"qty_$i"} = $form->parse_amount( $myconfig, $form->{"qty_$i"} );
+ 
+@@ -331,6 +341,12 @@
+                 $invoice_id
+             ) || $form->dberror($query);
+ 
++            for my $cls(@{$form->{bu_class}}){
++                if ($form->{"b_unit_$cls->{id}_$i"}){
++                 $b_unit_sth->execute($cls->{id}, $form->{"b_unit_$cls->{id}_$i"});
++                }
++            }
++
+             if($taxformfound)
+             {
+              my $report=$form->{"taxformcheck_$i"}?"true":"false";
+@@ -477,6 +493,11 @@
+                             $ref->{transdate}, $ref->{transdate},
+                         ) || $form->dberror($query);
+ 
++                        for my $cls(@{$form->{bu_class}}){
++                            if ($form->{"b_unit_$cls->{id}_$i"}){
++                             $b_unit_sth_ac->execute($cls->{id}, $form->{"b_unit_$cls->{id}_$i"});
++                            }
++                        }
+                         # add expense
+                         $query = qq|
+ 				INSERT INTO acc_trans 
+@@ -501,6 +522,12 @@
+                         ) || $form->dberror($query);
+                     }
+ 
++
++                    for my $cls(@{$form->{bu_class}}){
++                        if ($form->{"b_unit_$cls->{id}_$i"}){
++                         $b_unit_sth_ac->execute($cls->{id}, $form->{"b_unit_$cls->{id}_$i"});
++                        }
++                    }
+                     # update allocated for sold item
+                     $form->update_balance( $dbh, "invoice", "allocated",
+                         qq|id = $ref->{id}|,
+@@ -1269,7 +1296,13 @@
+         $sth->execute( $form->{language_code}, $form->{id} )
+           || $form->dberror($query);
+ 
++        my $bu_sth = $dbh->prepare(
++            qq|SELECT * FROM business_unit_inv
++                WHERE entry_id = ?  |
++        );
++
+         # exchangerate defaults
++        # exchangerate defaults
+         &exchangerate_defaults( $dbh, $form );
+ 
+         # price matrix and vendor partnumber
+@@ -1294,6 +1327,11 @@
+             $dec = length $dec;
+             my $decimalplaces = ( $dec > 2 ) ? $dec : 2;
+ 
++            $bu_sth->execute($ref->{invoice_id});
++            while ( $buref = $bu_sth->fetchrow_hashref(NAME_lc) ) {
++                $ref->{"b_unit_$buref->{class_id}"} = $buref->{bu_id};
++            }
++
+             $tth->execute( $ref->{id} );
+             $ref->{taxaccounts} = "";
+             my $taxrate = 0;
+Index: LedgerSMB/AA.pm
+===================================================================
+--- LedgerSMB/AA.pm	(revision 4473)
++++ LedgerSMB/AA.pm	(working copy)
+@@ -60,6 +60,7 @@
+ 	use strict;
+ 
+     my ( $self, $myconfig, $form ) = @_;
++    $form->all_business_units;
+ 
+     my $exchangerate;
+     my $batch_class;
+@@ -461,6 +462,14 @@
+            $dbh->prepare($query)->execute(@queryargs)
+               || $form->dberror($query);
+ 
++           if ($ref->{row_num} and !$ref->{fx_transaction}){
++              my $i = $ref->{row_num};
++              for my $cls(@{$form->{bu_class}}){
++                  if ($form->{"b_unit_$cls->{id}_$i"}){
++                     $b_unit_sth->execute($cls->{id}, $form->{"b_unit_$cls->{id}_$i"});
++                  }
++              }
++           }
+            if($taxformfound)
+            {
+             $query="select max(entry_id) from acc_trans;";
+Index: LedgerSMB/OE.pm
+===================================================================
+--- LedgerSMB/OE.pm	(revision 4473)
++++ LedgerSMB/OE.pm	(working copy)
+@@ -301,6 +301,7 @@
+ sub save {
+     my ( $self, $myconfig, $form ) = @_;
+   
++    $form->all_business_units;
+     $form->db_prepare_vars(
+         "quonumber", "transdate",     "vendor_id",     "entity_id",
+         "reqdate",   "taxincluded",   "shippingpoint", "shipvia",
+@@ -309,6 +310,10 @@
+     );
+     # connect to database, turn off autocommit
+     my $dbh = $form->{dbh};
++    my $b_unit_sth = $dbh->prepare(
++         "INSERT INTO business_unit_oitem (entry_id, class_id, bu_id)
++          VALUES (currval('orderitems_id_seq'), ?, ?)"
++    );
+     my @queryargs;
+     my $quotation;
+     my $ordnumber;
+@@ -564,6 +569,11 @@
+             $sth->execute(@queryargs) || $form->dberror($query);
+ 	    $dbh->commit;
+             $form->{"sellprice_$i"} = $fxsellprice;
++            for my $cls(@{$form->{bu_class}}){
++                if ($form->{"b_unit_$cls->{id}_$i"}){
++                 $b_unit_sth->execute($cls->{id}, $form->{"b_unit_$cls->{id}_$i"});
++                }
++            }
+         }
+         $form->{"discount_$i"} *= 100;
+  
+@@ -808,6 +818,11 @@
+     # connect to database
+     my $dbh = $form->{dbh};
+ 
++    my $bu_sth = $dbh->prepare(
++            qq|SELECT * FROM business_unit_oitem
++                WHERE entry_id = ?  |
++    );
++
+     my $query;
+     my $sth;
+     my $var;
+@@ -922,6 +937,11 @@
+         while ( $ref = $sth->fetchrow_hashref('NAME_lc') ) {
+             $form->db_parse_numeric(sth=>$sth, hashref=>$ref);
+ 
++            $bu_sth->execute($ref->{invoice_id});
++            while ( $buref = $bu_sth->fetchrow_hashref(NAME_lc) ) {
++                $ref->{"b_unit_$buref->{class_id}"} = $buref->{bu_id};
++            }
++
+             ($decimalplaces) = ( $ref->{sellprice} =~ /\.(\d+)/ );
+             $decimalplaces = length $decimalplaces;
+             $decimalplaces = ( $decimalplaces > 2 ) ? $decimalplaces : 2;
+Index: LedgerSMB/IS.pm
+===================================================================
+--- LedgerSMB/IS.pm	(revision 4473)
++++ LedgerSMB/IS.pm	(working copy)
+@@ -903,6 +903,7 @@
+ sub post_invoice {
+ 
+     my ( $self, $myconfig, $form ) = @_;
++    $form->all_business_units;
+     $form->{invnumber} = $form->update_defaults( $myconfig, "sinumber", $dbh )
+       unless $form->{invnumber};
+ 
+@@ -1029,6 +1030,10 @@
+ 
+     my $taxformfound=IS->taxform_exist($form,$form->{"customer_id"});
+ 
++    my $b_unit_sth = $dbh->prepare(
++         "INSERT INTO business_unit_inv (entry_id, class_id, bu_id)
++          VALUES (currval('invoice_id_seq'), ?, ?)"
++    );
+ 
+     foreach $i ( 1 .. $form->{rowcount} ) {
+         my $allocated = 0;
+@@ -1241,6 +1246,11 @@
+                 $invoice_id
+             ) || $form->dberror($query);
+ 
++            for my $cls(@{$form->{bu_class}}){
++                if ($form->{"b_unit_$cls->{id}_$i"}){
++                 $b_unit_sth->execute($cls->{id}, $form->{"b_unit_$cls->{id}_$i"});
++                }
++            }
+ 	   my $report=($taxformfound and $form->{"taxformcheck_$i"})?"true":"false";
+ 
+ 	   IS->update_invoice_tax_form($form,$dbh,$invoice_id,$report);
+@@ -1291,6 +1301,56 @@
+     $invnetamount = $amount;
+ 
+     $amount = 0;
++	   my $report=($taxformfound and $form->{"taxformcheck_$i"})?"true":"false";
++
++	   IS->update_invoice_tax_form($form,$dbh,$invoice_id,$report);
++
++
++            if (defined $form->{approved}) {
++
++                $query = qq| UPDATE ar SET approved = ? WHERE id = ?|;
++                $dbh->prepare($query)->execute($form->{approved}, $form->{id}) 
++                     || $form->dberror($query);
++                if (!$form->{approved}){
++                   if (not defined $form->{batch_id}){
++                       $form->error($locale->text('Batch ID Missing'));
++                   }
++                   $query = qq| 
++			INSERT INTO voucher (batch_id, trans_id) VALUES (?, ?)|;
++                   $sth = $dbh->prepare($query);
++                   $sth->execute($form->{batch_id}, $form->{id}) ||
++                        $form->dberror($query);
++               }
++            }
++
++            # add invoice_id
++            $form->{acc_trans}{lineitems}[$ndx]->{invoice_id} = $invoice_id;
++
++        }
++    }
++
++    $form->{paid} = 0;
++    for $i ( 1 .. $form->{paidaccounts} ) {
++        $form->{"paid_$i"} =
++          $form->parse_amount( $myconfig, $form->{"paid_$i"} )->bstr();
++        $form->{paid} += $form->{"paid_$i"};
++        $form->{datepaid} = $form->{"datepaid_$i"}
++          if ( $form->{"paid_$i"} );
++    }
++
++    # add lineitems + tax
++    $amount        = 0;
++    $grossamount   = 0;
++    $fxgrossamount = 0;
++
++    for ( @{ $form->{acc_trans}{lineitems} } ) {
++        $amount        += $_->{amount};
++        $grossamount   += $_->{grossamount};
++        $fxgrossamount += $_->{fxgrossamount};
++    }
++    $invnetamount = $amount;
++
++    $amount = 0;
+     for ( split / /, $form->{taxaccounts} ) {
+         $amount += $form->{acc_trans}{ $form->{id} }{$_}{amount} =
+           $form->round_amount( $form->{acc_trans}{ $form->{id} }{$_}{amount},
+@@ -1300,6 +1360,11 @@
+ 
+     $diff = 0;
+ 
++    $b_unit_sth = $dbh->prepare(
++         "INSERT INTO business_unit_ac (entry_id, class_id, bu_id)
++          VALUES (currval('acc_trans_entry_id_seq'), ?, ?)"
++    );
++
+     if ( $form->{taxincluded} ) {
+         $diff = $form->round_amount( $grossamount - $invamount, 2 );
+         $invamount += $diff;
+@@ -1332,6 +1397,11 @@
+           || $form->dberror($query);
+         $diff   = 0;
+         $fxdiff = 0;
++        for my $cls(@{$form->{bu_class}}){
++            if ($form->{"b_unit_$cls->{id}_$i"}){
++               $b_unit_sth->execute($cls->{id}, $form->{"b_unit_$cls->{id}_$i"});
++            }
++        }
+     }
+ 
+     $form->{receivables} = $invamount * -1;
+@@ -2154,6 +2224,12 @@
+           || $form->dberror($query);
+ 
+         
++        my $bu_sth = $dbh->prepare(
++            qq|SELECT * FROM business_unit_inv
++                WHERE entry_id = ?  |
++        );
++
++        
+         # foreign currency
+         &exchangerate_defaults( $dbh, $form );
+ 
+@@ -2180,6 +2256,11 @@
+             $dec = length $dec;
+             my $decimalplaces = ( $dec > 2 ) ? $dec : 2;
+ 
++            $bu_sth->execute($ref->{invoice_id});
++            while ( $buref = $bu_sth->fetchrow_hashref(NAME_lc) ) {
++                $ref->{"b_unit_$buref->{class_id}"} = $buref->{bu_id};
++            }
++
+             $tth->execute( $ref->{id} );
+ 
+             $ref->{taxaccounts} = "";
+Index: LedgerSMB/Form.pm
+===================================================================
+--- LedgerSMB/Form.pm	(revision 4473)
++++ LedgerSMB/Form.pm	(working copy)
+@@ -1903,6 +1903,45 @@
+     return $i;
+ }
+ 
++=item $form->all_business_units([$transdate, $credit_id]);
++
++Returns a list at bu_class with class information, ordered by order information
++and a list of units in lists at bu_units->$class_id.  $transdate is used to
++filter projects active at specified date.  $credit_id is to filter out 
++units assigned to other customers.
++
++=cut
++
++sub all_business_units {
++
++    my ( $self, $transdate, $credit_id, $module_name) = @_;
++    $self->{bu_class} = [];
++    $self->{b_units} = {};
++
++    my $dbh       = $self->{dbh};
++    my $class_sth = $dbh->prepare(
++                q|SELECT * FROM business_unit__list_classes('1', ?)|
++    );
++    $class_sth->execute($module_name);
++
++    my $bu_sth    = $dbh->prepare(
++                q|SELECT * 
++                    FROM business_unit__list_by_class(?, ?, ?, 'false')|
++    );
++
++    while (my $classref = $class_sth->fetchrow_hashref('NAME_lc')){
++        push @{$self->{bu_class}}, $classref;
++        $bu_sth->execute($classref->{id}, $transdate, $credit_id);
++        $self->{b_units}->{$classref->{id}} = [];
++        while (my $buref = $bu_sth->fetchrow_hashref('NAME_lc')){
++           push @{$self->{b_units}->{$classref->{id}}}, $buref;
++        }
++    }
++    $class_sth->finish;
++    $bu_sth->finish;
++
++}
++
+ =item $form->all_vc($myconfig, $vc, $module, $dbh, $transdate, $job);
+ 
+ Populates the list referred to by $form->{all_${vc}} with hashes of either
+@@ -2583,10 +2622,13 @@
+         $query = qq|
+ 			SELECT c.accno, c.description, a.source, a.amount,
+ 				a.memo,a.entry_id, a.transdate, a.cleared, a.project_id,
+-				p.projectnumber
++				p.projectnumber,
++                                compound_array(ARRAY[ARRAY[bul.class_id, bul.bu_id]])
++                                AS bu_lines
+ 			FROM acc_trans a
+ 			JOIN chart c ON (c.id = a.chart_id)
+ 			LEFT JOIN project p ON (p.id = a.project_id)
++                   LEFT JOIN business_unit_ac bul ON a.entry_id = bul.entry_id
+ 			WHERE a.trans_id = ?
+ 				AND a.fx_transaction = '0'
+ 			ORDER BY transdate|;

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