#===================================================================== # LedgerSMB # Small Medium Business Accounting software # http://www.ledgersmb.org/ # # Copyright (C) 2006 # This work contains copyrighted information from a number of sources all used # with permission. # # This file contains source code included with or based on SQL-Ledger which # is Copyright Dieter Simader and DWS Systems Inc. 2000-2005 and licensed # under the GNU General Public License version 2 or, at your option, any later # version. For a full list including contact information of contributors, # maintainers, and copyright holders, see the CONTRIBUTORS file. # # Original Copyright Notice from SQL-Ledger 2.6.17 (before the fork): # Copyright (C) 2000 # # Author: DWS Systems Inc. # Web: http://www.sql-ledger.org # # Contributors: # #====================================================================== # # This file has NOT undergone whitespace cleanup. # #====================================================================== # # Inventory Control backend # #====================================================================== package IC; sub get_part { my ( $self, $myconfig, $form ) = @_; # connect to db my $dbh = $form->{dbh}; my $i; my $query = qq| SELECT p.*, c1.accno AS inventory_accno, c1.description AS inventory_description, c2.accno AS income_accno, c2.description AS income_description, c3.accno AS expense_accno, c3.description AS expense_description, pg.partsgroup FROM parts p LEFT JOIN chart c1 ON (p.inventory_accno_id = c1.id) LEFT JOIN chart c2 ON (p.income_accno_id = c2.id) LEFT JOIN chart c3 ON (p.expense_accno_id = c3.id) LEFT JOIN partsgroup pg ON (p.partsgroup_id = pg.id) WHERE p.id = ?|; my $sth = $dbh->prepare($query); $sth->execute( $form->{id} ) || $form->dberror($query); my $ref = $sth->fetchrow_hashref(NAME_lc); $form->db_parse_numeric(sth => $sth, hashref => $ref); # copy to $form variables for ( keys %$ref ) { $form->{$_} = $ref->{$_} } $sth->finish; # part, service item or labor $form->{item} = ( $form->{inventory_accno_id} ) ? 'part' : 'service'; $form->{item} = 'labor' if !$form->{income_accno_id}; if ( $form->{assembly} ) { $form->{item} = 'assembly'; # retrieve assembly items $query = qq| SELECT p.id, p.partnumber, p.description, p.sellprice, p.weight, a.qty, a.bom, a.adj, p.unit, p.lastcost, p.listprice, pg.partsgroup, p.assembly, p.partsgroup_id FROM parts p JOIN assembly a ON (a.parts_id = p.id) LEFT JOIN partsgroup pg ON (p.partsgroup_id = pg.id) WHERE a.id = ?|; $sth = $dbh->prepare($query); $sth->execute( $form->{id} ) || $form->dberror($query); $form->{assembly_rows} = 0; while ( my $ref = $sth->fetchrow_hashref('NAME_lc') ) { $form->db_parse_numeric(sth => $sth, hashref => $ref); $form->{assembly_rows}++; foreach my $key ( keys %{$ref} ) { $form->{"${key}_$form->{assembly_rows}"} = $ref->{$key}; } } $sth->finish; } # setup accno hash for