Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitffc48be

Browse files
authored
OBPIH-6993 add product filter to transaction report (#5558)
1 parent44736ed commitffc48be

File tree

5 files changed

+156
-12
lines changed

5 files changed

+156
-12
lines changed

‎grails-app/controllers/org/pih/warehouse/JsonController.groovy‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
packageorg.pih.warehouse
1111

1212
importgrails.converters.JSON
13+
importgrails.databinding.BindUsing
1314
importgroovy.sql.Sql
1415
importgrails.gorm.transactions.Transactional
1516
importgrails.validation.Validateable
@@ -1440,7 +1441,6 @@ class JsonController {
14401441
List<Category> categories= params.includeCategoryChildren
14411442
? category.children+ category
14421443
: [category]
1443-
14441444
// FIXME Command validation not working so we're doing it manually
14451445
if (!startDate||!endDate||!location) {
14461446
thrownewIllegalArgumentException("All parameter fields are required")
@@ -1455,7 +1455,15 @@ class JsonController {
14551455
}
14561456

14571457
Boolean isCsvReport= params.format=="text/csv"
1458-
List<Object> data= reportService.getTransactionReport(location, categories, tagList, catalogList, startDate, endDate, isCsvReport)
1458+
List<Object> data= reportService.getTransactionReport(
1459+
location,
1460+
categories,
1461+
tagList,
1462+
catalogList,
1463+
command.products,
1464+
startDate,
1465+
endDate,
1466+
isCsvReport)
14591467

14601468
if (isCsvReport) {
14611469
String csv= dataService.generateCsv(data)
@@ -1806,4 +1814,13 @@ class TransactionReportCommand implements Validateable {
18061814
Location location
18071815
List<TransactionType> transactionTypes
18081816
Category category
1817+
1818+
// TODO: The datatables plugin sends the ids as a single string (ex: products="1,2") so we need to split it up
1819+
// ourselves. Better would be to modify the usage of datatables to send up each id as a separate field
1820+
// (ex: products="1"&products="2") so that Grails can bind it normally. (see showTransactionReport.gsp)
1821+
@BindUsing({ obj, source ->
1822+
List<String>productIds= (source['products'] asString)?.split(',')
1823+
return productIds?Product.findAllByIdInList(productIds):null
1824+
})
1825+
List<Product> products
18091826
}

‎grails-app/services/org/pih/warehouse/report/ReportService.groovy‎

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,25 +1354,24 @@ class ReportService implements ApplicationContextAware {
13541354
return transactionEntry.transaction.transactionType.transactionCode==TransactionCode.CREDIT&& transactionEntry.quantity>0
13551355
}
13561356

1357-
List<TransactionEntry>getFilteredTransactionEntries(
1357+
privateList<TransactionEntry>getFilteredTransactionEntries(
13581358
List<TransactionCode>transactionCodes,
13591359
DatestartDate,
13601360
DateendDate,
13611361
List<Category>categories,
13621362
List<Tag>tagsList,
13631363
List<ProductCatalog>catalogsList,
13641364
Locationlocation,
1365-
ProductproductData,
1365+
List<Product>products,
13661366
StringorderBy,
13671367
StringsortOrder="desc"
13681368
) {
13691369
returnTransactionEntry.createCriteria().list {
13701370
inventoryItem {
1371+
if (products) {
1372+
'in'('product', products)
1373+
}
13711374
product {
1372-
if (productData) {
1373-
eq('id', productData.id)
1374-
}
1375-
13761375
if (categories) {
13771376
'in'('category', categories)
13781377
}
@@ -1420,8 +1419,9 @@ class ReportService implements ApplicationContextAware {
14201419
}asList<TransactionEntry>
14211420
}
14221421

1423-
List<TransactionEntry>getFilteredTransactionEntries(List<TransactionCode>transactionCodes,DatestartDate,DateendDate,Locationlocation,Productproduct,StringorderBy,StringsortOrder="desc") {
1424-
return getFilteredTransactionEntries(transactionCodes, startDate, endDate,null,null,null, location, product, orderBy, sortOrder)
1422+
privateList<TransactionEntry>getFilteredTransactionEntries(List<TransactionCode>transactionCodes,DatestartDate,DateendDate,Locationlocation,Productproduct,StringorderBy,StringsortOrder="desc") {
1423+
List<Product> products= product? [product]:null
1424+
return getFilteredTransactionEntries(transactionCodes, startDate, endDate,null,null,null, location, products, orderBy, sortOrder)
14251425
}
14261426

14271427
Map<Product,Map<String,Integer>>getDetailedTransactionReportData(Map<Product,List<TransactionEntry>>transactionEntries) {
@@ -1499,7 +1499,15 @@ class ReportService implements ApplicationContextAware {
14991499
]
15001500
}
15011501

1502-
List<Object>getTransactionReport(Locationlocation,List<Category>categories,List<Tag>tagsList,List<ProductCatalog>catalogsList,DatestartDate,DateendDate,BooleanincludeDetails) {
1502+
List<Object>getTransactionReport(Locationlocation,
1503+
List<Category>categories,
1504+
List<Tag>tagsList,
1505+
List<ProductCatalog>catalogsList,
1506+
List<Product>productList,
1507+
DatestartDate,
1508+
DateendDate,
1509+
BooleanincludeDetails) {
1510+
15031511
List<TransactionCode> adjustmentTransactionCodes= [
15041512
TransactionCode.CREDIT,
15051513
TransactionCode.DEBIT
@@ -1515,6 +1523,7 @@ class ReportService implements ApplicationContextAware {
15151523
tagsList,
15161524
catalogsList,
15171525
location,
1526+
productList,
15181527
null,
15191528
null
15201529
)

‎grails-app/taglib/org/pih/warehouse/SelectTagLib.groovy‎

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
packageorg.pih.warehouse
1111

1212
importorg.grails.core.artefact.DomainClassArtefactHandler
13+
importorg.springframework.beans.factory.annotation.Value
14+
1315
importorg.pih.warehouse.core.ActivityCode
1416
importorg.pih.warehouse.core.BudgetCode
1517
importorg.pih.warehouse.core.Constants
@@ -55,6 +57,107 @@ class SelectTagLib {
5557
def requisitionService
5658
def organizationService
5759

60+
/**
61+
* The minimum number of characters input into the search field before a request will be sent.
62+
*/
63+
@Value('${openboxes.typeahead.minLength}')
64+
String minSearchValueLength
65+
66+
/**
67+
* How long to wait after the user has stopped typing before sending the request.
68+
*/
69+
@Value('${openboxes.typeahead.delay}')
70+
String searchDelay
71+
72+
def selectProductAjax= {attrs,body->
73+
attrs.id= attrs.id?:"products-select"
74+
attrs.url="/api/products/search"
75+
attrs.searchParameter="name"
76+
out<< selectAjax(attrs, body)
77+
}
78+
79+
/**
80+
* A search and select field. Searches via AJAX API request using the Select2 jQuery plugin.
81+
*
82+
*@attr id Required. A unique identifier (within the current page) for the generated select element
83+
*@attr url Required. The path of the API request
84+
*@attr name The name of the select element. Defaults to the value of the id attr.
85+
*@attr searchParameter The name of the query parameter to use when making the API request
86+
*@attr multiple True if the select box should allow multiple items to be selected
87+
*/
88+
def selectAjax= {attrs,body->
89+
if (!attrs.containsKey('id')) {
90+
throwTagError("Attribute [id] is required.")
91+
}
92+
if (!attrs.containsKey('url')) {
93+
throwTagError("Attribute [url] is required.")
94+
}
95+
96+
String id= attrs.id
97+
String name= attrs.name?: attrs.id
98+
attrs.put('data-testid', attrs.get('data-testid')?: attrs.id)
99+
String url= attrs.url
100+
String searchParameter= attrs.searchParameter?:"name"
101+
boolean multiple= attrs.multiple?.asBoolean()?:false
102+
String placeholder="${g.message(code: 'default.selectOptions.label', default: 'Select Options')}"
103+
104+
def html="""
105+
<select id="${id}"
106+
name="${name}"
107+
${multiple ? "multiple" : ""}
108+
type="text">
109+
</select>
110+
111+
<script type=\'text/javascript\'>
112+
113+
jQuery(document).ready(function() {
114+
115+
jQuery('#${id}').select2({
116+
117+
placeholder: "${placeholder}",
118+
minimumInputLength: "${minSearchValueLength ?: "3"}",
119+
width: "100%",
120+
allowClear: true,
121+
cache: true,
122+
123+
ajax: {
124+
url: "${request.contextPath}${url}",
125+
dataType: "json",
126+
delay: "${searchDelay ?: "300"}",
127+
128+
// 'term' is the field that Select2 uses as the user-typed search value, so re-map it
129+
// to the query parameter that the API accepts.
130+
data: function (params) {
131+
return {
132+
${searchParameter}: params.term,
133+
};
134+
},
135+
136+
// Process the API response. Expects a response formatted like: { data: [{}, ...]}
137+
processResults: function (data, params) {
138+
var results = data.data.map(function (item) {
139+
return {
140+
id: item.id,
141+
${searchParameter}: item.${searchParameter},
142+
label: item.${searchParameter},
143+
text: item.${searchParameter},
144+
value: item.id,
145+
valueText: item.${searchParameter},
146+
};
147+
});
148+
return {
149+
results: results,
150+
};
151+
},
152+
},
153+
});
154+
});
155+
</script>
156+
"""
157+
158+
out<< html
159+
}
160+
58161
//@Cacheable("selectCategoryCache")
59162
def selectCategory= {attrs,body->
60163
attrs.from=Category.list().sort()// { it.name }

‎grails-app/views/layouts/custom.gsp‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,11 @@
494494
});
495495
496496
// Select 2 default configuration
497-
$(".select2")
497+
// Note that we only apply the default configuration to <select> elements that have the "select2" class because
498+
// we only want this default config to be applied to old selectors in the SelectTagLib (users of the taglib set
499+
// the "select2", "select2withTag", or "ajaxSelect2" classes to invoke specific defaults).
500+
// New flows use the g:selectAjax taglib as defined in SelectTagLib which handles setting its own defaults.
501+
$("select.select2")
498502
.select2({
499503
placeholder:$(this).data("placeholder")||'Select an option',
500504
width:'100%',

‎grails-app/views/report/showTransactionReport.gsp‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,15 @@
105105
</label>
106106
</p>
107107
</div>
108+
<divclass="filter-list-item">
109+
<label><g:messagecode="product.label"/></label>
110+
<p>
111+
<g:selectProductAjaxid="products-select"
112+
value="${params?.products}"
113+
multiple="true"
114+
/>
115+
</p>
116+
</div>
108117
<divclass="filter-list-item">
109118
<label><warehouse:messagecode="tag.label"/></label>
110119
<p>
@@ -250,6 +259,7 @@
250259
data.push({ name:"startDate", value:$("#startDate").val() });
251260
data.push({ name:"endDate", value:$("#endDate").val() });
252261
data.push({ name:"category", value:$("#category").val() });
262+
data.push({ name:"products", value:$("#products-select").val() });
253263
data.push({ name:"tags", value:$("#tags").val() });
254264
data.push({ name:"catalogs", value:$("#catalogs").val() });
255265
if($('#includeCategoryChildren').is(':checked')) {
@@ -372,6 +382,7 @@
372382
startDate:$("#startDate").val(),
373383
endDate:$("#endDate").val(),
374384
category:$("#category").val(),
385+
products:$("#products-select").val(),
375386
tags:$("#tags").val(),
376387
catalogs:$("#catalogs").val(),
377388
format:"text/csv"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp