-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPricefxSnipped.groovy
168 lines (168 loc) · 5.95 KB
/
PricefxSnipped.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
//// [MASTER DATA] Working with stream
//def resultIterator = api.stream('PR', null, ['lineId', 'sourceId', 'sku', 'customerId'])
//resultIterator.each {
// api.trace(it)
//}
//
//// [PARAMETER] findLookupTableValues
//def targetDate = api.targetDate().format('yyyy-MM')
//def PriceFxClient = api.findLookupTableValues('ExchangeRatePerMonth', ['key1', 'key2', 'attribute1'], '-key2', *[
// Filter.equal('key1', 'USD'),
// Filter.lessOrEqual('key2', targetDate)
//])
//if (PriceFxClient) [
// PriceFxClient[0]
//]
//
//// [PARAMETER] vLookup
//api.vLookup("MarginAdj", 'Lamb') = 0.18 // Simple
//api.vLookup('Region', 'Currency', ['name': 'America'])// Matrix
//
//// [PRODUCT EXTENDSION]
//def targetDate = new Date(2022-1900, Calendar.OCTOBER, 1)
//def currency = 'EUR'
//def sku = api.product('sku')
//def productCostAvg = api.find("PX", 0, 1, '-attribute1', ['sku', 'attribute1', 'attribute2'], *[
// Filter.equal("name", 'ProductCost'),
// Filter.equal("sku", sku),
// Filter.equal("attribute3", currency),
// Filter.lessOrEqual("attribute1", targetDate)
//])?.getAt(0)?.attribute2 as BigDecimal
//productCostAvg
//
//
//// [QUOTE, REBATE HEADER] Create input
//if (quoteProcessor.isPostPhase()) return
//def deliveryType = api.inputBuilderFactory()
// .createOptionEntry("DeliveryType")
// .setLabel("Delivery Type")
// .setRequired(true)
// .setOptions(["Express", "Standard"])
// .setLabels(["Express": "Express Delivery", "Standard": "Standard Delivery"])
// .buildMap()
//quoteProcessor.addOrUpdateInput(deliveryType)
//
//// [CHART] Create Select
//def ctx = api.getDatamartContext()
//def dm = ctx.getDatamart("Transaction")
//def column = dm.getColumn("InvoiceDateYear")
//ctx.dimFilterEntry("Year", column)?.getValue()
//
//// [LINE ITEM] Create input
//def country = api.inputBuilderFactory()
// .createOptionEntry("Country")
// .setLabel("Select Country")
// .setOptions(["CZ", "DE", "UK"])
// // .buildContextParameter() for Configurators;
// // .getInput() Only use for line item
//
//
//// [DMDS] Working with stream
//def target = api.getDatamartRowSet('target')
//if (!target) return
//def ctx = api.getDatamartContext()
//def table = ctx.getDataSource('Transaction')
//def query = ctx.newQuery(table, false).selectAll()
//def rowStream = ctx.streamQuery(query)
//def rows = []
//while (rowStream.next()) {
// rows << rowStream.get()
//}
//rowStream.close()
//def targetRow = [:]
//rows.each { row ->
// row.each {
// targetRow[it.key.replace(" ", "") as String] = it.value
// }
// target.addRow(targetRow)
// targetRow = [:]
//}
//
//// [QUOTE HEADER] Calculate total
//if (quoteProcessor.isPostPhase()) {
// def quoteView = quoteProcessor.getQuoteView()
//
// def quoteTotalInvoicePrice = 0
// quoteView?.lineItems?.each { lineItem ->
// if (!lineItem.folder) {
// quoteTotalInvoicePrice += lineItem.outputs.find { it.resultName == 'TotalInvoicePrice' }?.result
// }
// }
//}
//
//// [DASHBOARD] Create years input
//def ctx = api.getDatamartContext()
//def dm = ctx.getDatamart("Transaction")
//def column = dm.getColumn("InvoiceDateYear")
//ctx.dimFilterEntry("Year", column)?.getValue()
//
//
//// [NONAME]
//def dmCtx = api.getDatamartContext()
//def dmTable = dmCtx.getDatamart("Transaction")
//def customerGroup = ["customerFieldLabel": "CustomerGroup", "customerFieldName": "attribute1", "customerFieldValue": "APPO AG"] as net.pricefx.domain.CustomerGroup
//def productGroup = ["productFieldLabel": "ProductGroup", "productFieldName": "attribute1", "productFieldValue": "Beef"] as net.pricefx.domain.ProductGroup
//def query = dmCtx.newQuery(dmTable, true)
// .select("CustomerId", "CustomerId")
// .select("SUM(InvoicePrice)", "TotalRevenue")
// .where(customerGroup)
// .where(productGroup)
// .where(
// Filter.greaterOrEqual("InvoiceDate", out.StartDate),
// Filter.lessOrEqual("InvoiceDate", out.EndDateOrToday)
// )
//
//def result = dmCtx.executeQuery(query)
//def r = result?.data?.collectEntries { row ->
// [(row.CustomerId): row.TotalRevenue]
//}
//api.trace(r)
//
//// [WORKFLOW] Build workflow
//workflow.addApprovalStep('SalesManager')
// .withApprovers("john.cena")
// .withMinApprovalsNeeded(1)
// .withReasons("SalesManager needs to approve this shit")
//
//// ExchangeMoney for exam partition
///**
// * Only work with EUR
// * @param moneyAmount How much money to convert
// * @param fromCurrency In which currency is the provided moneyAmount
// * @param toCurrency In which currency would you like the result
// * @return Amount of Money in the toCurrency, or null, if error occurred
// */
//BigDecimal convertMoney(BigDecimal moneyAmount, String fromCurrency, String toCurrency, Date conversionDate = api.targetDate()) {
// if (moneyAmount == null || moneyAmount < 0) {
// api.addWarning("Money amount is empty or less than 0")
// return
// }
//
// if (fromCurrency != toCurrency) {
// def filters = [
// "key1": fromCurrency != 'EUR' ? fromCurrency : toCurrency,
// "key2": conversionDate?.format("yyyy-MM")
// ]
// BigDecimal exchangeRate = api.vLookup('ExchangeRatePerMonth', 'InEuros', filters) as BigDecimal
//
// if (exchangeRate != null) {
// exchangeRate = fromCurrency != 'EUR' ? exchangeRate : (1 / exchangeRate)
// return moneyAmount * exchangeRate
// } else {
// api.addWarning("Cannot convert money because exchange rate is empty")
// return
// }
// } else {
// return moneyAmount
// }
//}
//
//def deliveryType = api.inputBuilderFactory() // (2)
// .createOptionEntry("SalesDiscountPct")
// .setLabel("Sales Discount %")
// .setFrom(0)
// .setValue(0)
// .setLabels(["Express": "Express Delivery", "Standard": "Standard Delivery"])
// .buildMap()
//
//