#===================================================================== # SQL-Ledger Order Leaves # Copyright (c) 2007 Think Electric # Free software Licensed under the GPL # Author: Cedric Shock # Email: info@think-electric.com # Web: http://www.think-electric.com # #====================================================================== # # Show the leaves (fundamental parts) of an order (in sql-ledger) # # Depends on Perl module Rose-DB-Object #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ #Sample code to add to oe.pl: # Order Leaves # #====================================================================== use SL::DB::Part; use SL::DB::Order; use SL::DB::OrderItem; 1; sub totalize { $form->{title} = $locale->text('Totals of stuff'); $form->{orphaned} = 1; # What is this callback business?! $form->{callback} = "$form->{script}?action=totalize&login=$form->{login}&path=$form->{path}" unless $form->{callback}; &display_form; } sub display_form { $form->header; my $ids = $form->{id}; # hask table storing ammontsof each type of thing by their id in the parts table my $table = (); foreach my $id (split(',', $ids )) { my $order = SL::DB::Order->new (id => $id); $order->load; $table = total_order($table, $order); } # We should print a summary of what the order is here... # We really need a decent template system... # Print out a simple report # ID print ""; while ( my ($key, $value) = each(%$table) ) { my $part = SL::DB::Part->new (id => $key); $part->load; print ""; } print "
Part NumberDescriptionQtyUnit
"; #print $key; #print ""; print $part->partnumber; print ""; print $part->description; print ""; print $value; print ""; print $part->unit; print "
"; } sub total_order { my $table = shift; my $order = shift; my $items = $order->items; foreach my $item (@$items) { $table = total_part($table, $item->qty, $item->part) } return $table; } sub total_part { my $table = shift; my $multiplier = shift; my $part = shift; if ($part->assembly) { my $components = $part->components; foreach my $component (@$components) { $table = total_part($table, $multiplier * $component->qty, $component->component); } } else { # print "
  • "; # print $part->id; # print " X "; # print $multiplier; # print $part->description; $table->{$part->id} = $table->{$part->id} + $multiplier; } return $table; }