title: Get attribute values at beginning and end of a date range
body: <p>I have a database table <strong>stockmovements</strong> with columns DATE, PRODUCT, UNITS,TYPE, STOCK. STOCK saves the value of stock at that date when a certain stock movement was done. TYPE can be purchase or sold or return. </p>
  
  <p>I group by product so that any row of the table in my view shows a product. Then I want to create 2 columns. Stock start and stock end. Showing stock values at the first and last date of a date range. So that later let say I apply I filter 1st october - 31st october the 2 columns will show stock value at 1st october and stock value at 31st october. </p>
  
  <p>If no filters are applied columns will show stock value of earliest and latest stockmovement among all values in database.</p>
  
  <p>And in the middle columns to show units for each stockmovement type. So that in the end will be product, stock start, purchased, sold, returned, stock end. This is just to give an idea about the general logic but it doesn't really matter for the question. </p>
  
  <p>I have this in my controller:</p>
  
  <pre><code>@stockmovements = Stockmovement.all.group(:PRODUCT)
  </code></pre>
  
  <p>What should I add to my view:</p>
  
  <pre><code> &lt;td&gt;&lt;%= number_to_human stockmovement.STOCK, precision: 0 %&gt;&lt;/td&gt;
  </code></pre>
  
  <p>to get the stock values at beginning and end of the date range? Or should this be done in the model? I basically need STOCK where DATE= start date and STOCK where DATE= end date. But I can't find any helper to do that.</p>