mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-12-17 14:19:05 +08:00
Add stock consumption to pdf and docx [SCI-6460] (#3816)
Co-authored-by: Anton <anton@scinote.net>
This commit is contained in:
parent
8604319c1b
commit
1efe3ddd37
5 changed files with 34 additions and 13 deletions
|
|
@ -20,7 +20,7 @@
|
||||||
|
|
||||||
el.handsontable({
|
el.handsontable({
|
||||||
disableVisualSelection: true,
|
disableVisualSelection: true,
|
||||||
rowHeaders: true,
|
rowHeaders: false,
|
||||||
colHeaders: headers,
|
colHeaders: headers,
|
||||||
columnSorting: false,
|
columnSorting: false,
|
||||||
editor: false,
|
editor: false,
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ class MyModuleRepositoriesController < ApplicationController
|
||||||
@datatable_params = {
|
@datatable_params = {
|
||||||
view_mode: params[:view_mode],
|
view_mode: params[:view_mode],
|
||||||
my_module: @my_module,
|
my_module: @my_module,
|
||||||
include_stock_consumption: @repository.has_stock_management?
|
include_stock_consumption: @repository.has_stock_management? && params[:assigned]
|
||||||
}
|
}
|
||||||
@all_rows_count = datatable_service.all_count
|
@all_rows_count = datatable_service.all_count
|
||||||
@columns_mappings = datatable_service.mappings
|
@columns_mappings = datatable_service.mappings
|
||||||
|
|
|
||||||
|
|
@ -294,24 +294,35 @@ class MyModule < ApplicationRecord
|
||||||
# Generate the repository rows belonging to this module
|
# Generate the repository rows belonging to this module
|
||||||
# in JSON form, suitable for display in handsontable.js
|
# in JSON form, suitable for display in handsontable.js
|
||||||
def repository_json_hot(repository, order)
|
def repository_json_hot(repository, order)
|
||||||
|
# Prepare column headers
|
||||||
|
headers = [
|
||||||
|
I18n.t('repositories.table.id'),
|
||||||
|
I18n.t('repositories.table.row_name'),
|
||||||
|
I18n.t('repositories.table.added_by'),
|
||||||
|
I18n.t('repositories.table.')
|
||||||
|
]
|
||||||
data = []
|
data = []
|
||||||
rows = repository.assigned_rows(self).includes(:created_by).order(created_at: order)
|
rows = repository.assigned_rows(self).includes(:created_by).order(created_at: order)
|
||||||
|
if repository.has_stock_management?
|
||||||
|
headers.push(I18n.t('repositories.table.row_consumption'))
|
||||||
|
rows = rows.joins(:my_module_repository_rows, repository_stock_value: :repository_stock_unit_item)
|
||||||
|
.where(my_module_repository_rows: { my_module: self })
|
||||||
|
.select(
|
||||||
|
'repository_rows.*',
|
||||||
|
'my_module_repository_rows.stock_consumption',
|
||||||
|
'repository_stock_unit_items.data AS stock_unit'
|
||||||
|
)
|
||||||
|
end
|
||||||
rows.find_each do |row|
|
rows.find_each do |row|
|
||||||
row_json = []
|
row_json = []
|
||||||
row_json << row.code
|
row_json << row.code
|
||||||
row_json << (row.archived ? "#{row.name} [#{I18n.t('general.archived')}]" : row.name)
|
row_json << (row.archived ? "#{row.name} [#{I18n.t('general.archived')}]" : row.name)
|
||||||
row_json << I18n.l(row.created_at, format: :full)
|
row_json << I18n.l(row.created_at, format: :full)
|
||||||
row_json << row.created_by.full_name
|
row_json << row.created_by.full_name
|
||||||
|
row_json << "#{row['stock_consumption'] || 0} #{row['stock_unit']}" if repository.has_stock_management?
|
||||||
data << row_json
|
data << row_json
|
||||||
end
|
end
|
||||||
|
|
||||||
# Prepare column headers
|
|
||||||
headers = [
|
|
||||||
I18n.t('repositories.table.id'),
|
|
||||||
I18n.t('repositories.table.row_name'),
|
|
||||||
I18n.t('repositories.table.added_on'),
|
|
||||||
I18n.t('repositories.table.added_by')
|
|
||||||
]
|
|
||||||
{ data: data, headers: headers }
|
{ data: data, headers: headers }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -326,7 +337,11 @@ class MyModule < ApplicationRecord
|
||||||
return false unless repository
|
return false unless repository
|
||||||
|
|
||||||
repository.repository_columns.order(:id).each do |column|
|
repository.repository_columns.order(:id).each do |column|
|
||||||
headers.push(column.name)
|
if column.data_type == 'RepositoryStockValue'
|
||||||
|
headers.push(I18n.t('repositories.table.row_consumption'))
|
||||||
|
else
|
||||||
|
headers.push(column.name)
|
||||||
|
end
|
||||||
custom_columns.push(column.id)
|
custom_columns.push(column.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ module Reports::Docx::DrawMyModuleRepository
|
||||||
|
|
||||||
return false unless repository_data[:rows].any? && can_read_repository?(@user, repository)
|
return false unless repository_data[:rows].any? && can_read_repository?(@user, repository)
|
||||||
|
|
||||||
table = prepare_row_columns(repository_data)
|
table = prepare_row_columns(repository_data, my_module)
|
||||||
|
|
||||||
@docx.p
|
@docx.p
|
||||||
@docx.p I18n.t('projects.reports.elements.module_repository.name',
|
@docx.p I18n.t('projects.reports.elements.module_repository.name',
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
module Reports::Docx::RepositoryHelper
|
module Reports::Docx::RepositoryHelper
|
||||||
include InputSanitizeHelper
|
include InputSanitizeHelper
|
||||||
|
|
||||||
def prepare_row_columns(repository_data)
|
def prepare_row_columns(repository_data, my_module)
|
||||||
result = [repository_data[:headers]]
|
result = [repository_data[:headers]]
|
||||||
repository_data[:rows].each do |record|
|
repository_data[:rows].each do |record|
|
||||||
row = []
|
row = []
|
||||||
|
|
@ -15,7 +15,13 @@ module Reports::Docx::RepositoryHelper
|
||||||
cell_values = {}
|
cell_values = {}
|
||||||
custom_cells = record.repository_cells
|
custom_cells = record.repository_cells
|
||||||
custom_cells.each do |cell|
|
custom_cells.each do |cell|
|
||||||
cell_values[cell.repository_column_id] = cell.value.formatted
|
if cell.value.instance_of? RepositoryStockValue
|
||||||
|
consumption = record.my_module_repository_rows.find_by(my_module: my_module).stock_consumption || 0
|
||||||
|
unit = cell.value.repository_stock_unit_item&.data
|
||||||
|
cell_values[cell.repository_column_id] = "#{consumption} #{unit}"
|
||||||
|
else
|
||||||
|
cell_values[cell.repository_column_id] = cell.value.formatted
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
repository_data[:custom_columns].each do |column_id|
|
repository_data[:custom_columns].each do |column_id|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue