-
Notifications
You must be signed in to change notification settings - Fork 156
add a fincancial balance for each stock taking #1213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,11 +8,16 @@ | |
| %th= t '.date' | ||
| %th= t '.note' | ||
| %th | ||
| %th | ||
| %tbody | ||
| - for stock_taking in @stock_takings | ||
|
lentschi marked this conversation as resolved.
|
||
| %tr | ||
| %td= link_to format_date(stock_taking.date), stock_taking | ||
| %td= truncate stock_taking.note | ||
| - balance = 0 | ||
| - for stock_change in stock_taking.stock_changes | ||
| - balance += stock_change.quantity * stock_change.stock_article.gross_price | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In general, building sums like this may raise performance issues.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes a db function would be much more effective, I will try to implement it this way. I am not very familiar with this kind of programming and was glad that I could get working it this way on my local foodsoft installation to get the balances for our foodcoop...
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Admittedly what I'm suggesting here is quite complicated as we have to take article versioning into account (Something that your @stock_takings = StockEvent
.select(%(
`#{StockEvent.table_name}`.*,
SUM(
`#{StockChange.table_name}`.`quantity`
* (`#{ArticleVersion.table_name}`.`price` + (`#{ArticleVersion.table_name}`.`deposit`) * ((`#{ArticleVersion.table_name}`.`tax`) + 1))
) AS balance
))
.joins(stock_changes: { stock_article: [:article_versions] })
.joins(ArticleVersion.latest_outer_join_sql("#{Article.table_name}.#{Article.primary_key}"))
.where(later_article_versions: { id: nil })
.group('stock_event_id')
.order('date DESC')
.page(params[:page]).per(@per_page)Then in the view you can use |
||
| %td.numeric{style: 'width:5em'}= format_currency(balance) | ||
| %td | ||
| = link_to t('ui.edit'), edit_stock_taking_path(stock_taking), class: 'btn btn-mini' | ||
| = link_to t('ui.delete'), stock_taking, :data => {:confirm => t('.confirm_delete')}, :method => :delete, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,13 +12,27 @@ | |
| %th= t '.article' | ||
| %th= t '.supplier' | ||
| %th= t '.unit' | ||
| %th | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't there be a table heading for this new 'balance' column? 🤔 |
||
| %th= t '.amount' | ||
| %th | ||
| - balance = 0 | ||
| - for stock_change in @stock_taking.stock_changes | ||
| %tr | ||
| %td= stock_change.stock_article.name | ||
| %td= stock_change.stock_article.supplier.name | ||
| %td= stock_change.stock_article.unit | ||
| %td= stock_change.quantity | ||
| %td.numeric{style: 'width:5em'}= format_currency(stock_change.stock_article.gross_price) | ||
| %td.numeric{style: 'width:5em'}= stock_change.quantity | ||
| - amount = stock_change.quantity * stock_change.stock_article.gross_price | ||
| - balance += amount | ||
|
mjavurek marked this conversation as resolved.
|
||
| %td.numeric{style: 'width:5em'}= format_currency(amount) | ||
| %tr | ||
| %th | ||
| %th | ||
| %th | ||
| %th | ||
| %th | ||
| %th.numeric{style: 'width:5em'}= format_currency(balance) | ||
|
|
||
| .btn-group | ||
| = link_to t('ui.edit'), edit_stock_taking_path(@stock_taking), class: 'btn' | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't there be a table heading for this new 'balance' column? 🤔