PsionBlue
2007-Mar-12 21:14 UTC
Newb in need - trying to subtract from an array? or table?
Here is my problem in english. I have an INVOICE table which has orders with a quantity. I need to take those orders out and make new 12 pack boxes from the original invoice. For example: Invoice 1 is an order for 3 widgets Invoice 2 is an order for 12 widgets Invoice 3 is an order for 6 widgets What should happen is the 3 widgets from order one is combined with 9 widgets in order two to make a packing slip for 12 widgets. The remaining total is less that 12 so nothing happens with the rest. The transaction would need to be logged as weel but that is another issue. I was initially planning on just turning every invoice into rows and the just grabbing the top 12 or with a do 12 times or whatever. That way I get only what I need. I am just wondering if there is a way without creating so many records in the database. Thanks in advance! brendan --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Chris Hall
2007-Mar-12 22:45 UTC
Re: Newb in need - trying to subtract from an array? or table?
you could combine the arrays of widgets into one array then use the rails helper in_groups_of to go through them>> a = [1,2,3]=> [1, 2, 3]>> b = [4,5,6,7,8]=> [4, 5, 6, 7, 8]>> c = [9,10,11,12]=> [9, 10, 11, 12]>> n = a + b + c=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]>> n.in_groups_of(7)=> [[1, 2, 3, 4, 5, 6, 7], [8, 9, 10, 11, 12, nil, nil]] On 3/12/07, PsionBlue <bmalloy-ZqJcLYiWgNQsV2N9l4h3zg@public.gmane.org> wrote:> > Here is my problem in english. > > I have an INVOICE table which has orders with a quantity. I need to > take those orders out and make new 12 pack boxes from the original > invoice. For example: > > Invoice 1 is an order for 3 widgets > > Invoice 2 is an order for 12 widgets > > Invoice 3 is an order for 6 widgets > > What should happen is the 3 widgets from order one is combined with 9 > widgets in order two to make a packing slip for 12 widgets. The > remaining total is less that 12 so nothing happens with the rest. The > transaction would need to be logged as weel but that is another issue. > > I was initially planning on just turning every invoice into rows and > the just grabbing the top 12 or with a do 12 times or whatever. That > way I get only what I need. I am just wondering if there is a way > without creating so many records in the database. > > Thanks in advance! > > brendan > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---