I am trying to generate in a related table view a list of stock movements for an item.
I had been using static values and a global stock move method that would pick up the previous closing stock, set the new movement opening stock to that and then set the closing stock to that value + / - whatever the stock move was (a delivery [+] or usage [-]), but the problem is that not everything happens in the correct chronological order, so sometimes deliveries can't be entered until weeks later (when everything is confirmed about it) and so that means things don't 'flow' correctly with opening and closing values.
I tried doing this in the tables calculations
- Code: Select all
function c_qty_closing ()
{
return c_qty_opening + qty_added + qty_adjusted + stock_discrepency - qty_allocated - qty_subtracted;
}
function c_qty_opening ()
{
var i = currentcontroller.getSelectedIndex() ; // pick up which line in the related set we are?
if (i == 1)
{
return paper_stock_movement_by_paper_printer_to_paper_stock.opening_stock ; // picks up parent's opening stock value
}
else
{
return foundset.getRecord(i-1).c_qty_closing; // get the previous records closing value
}
}
but it didn't work (I have vague memories of calcs not being able to access some of these things...)
I hate to say it, but FileMaker has the ability to get a value from the previous record and do running totals, which I need to be able to do now... (this system replaced a FM system and I thought I'd managed to beat it, but now need those capabilities...)
The only other possible solution might be to put all the related stock movements into an array and then loop thru that calculating it all and then displaying that array in the form tab, instead of a table view (how??)
Thanks
Rafi