<commit_before><?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
-->

<simple-methods xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/simple-methods-v2.xsd">
    <!-- ProductPrice methods -->
    <simple-method method-name="createProductPrice" short-description="Create a Product Price">
        <set field="callingMethodName" value="createProductPrice"/>
        <set field="checkAction" value="CREATE"/>
        <call-simple-method method-name="checkProductRelatedPermission" xml-resource="component://product/script/org/ofbiz/product/product/ProductServices.xml"/>
        <check-permission permission="CATALOG_PRICE_MAINT">
            <fail-property resource="ProductUiLabels" property="ProductPriceMaintPermissionError"/>
        </check-permission>
        <check-errors/>
        
        <call-simple-method method-name="inlineHandlePriceWithTaxIncuded"/>

        <make-value value-field="newEntity" entity-name="ProductPrice"/>
        <set-nonpk-fields map="parameters" value-field="newEntity"/>
        <set-pk-fields map="parameters" value-field="newEntity"/>
        
        <now-timestamp field="nowTimestamp"/>
        
        <if-empty field="newEntity.fromDate">
            <set field="newEntity.fromDate" from-field="nowTimestamp"/>
        </if-empty>
        <field-to-result field="newEntity.fromDate" result-name="fromDate"/>
        
        <set field="newEntity.lastModifiedDate" from-field="nowTimestamp"/>
        <set field="newEntity.createdDate" from-field="nowTimestamp"/>
        <set field="newEntity.lastModifiedByUserLogin" from-field="userLogin.userLoginId"/>
        <set field="newEntity.createdByUserLogin" from-field="userLogin.userLoginId"/>

        <create-value value-field="newEntity"/>
    </simple-method>
    <simple-method method-name="updateProductPrice" short-description="Update an ProductPrice">
        <set field="callingMethodName" value="updateProductPrice"/>
        <set field="checkAction" value="UPDATE"/>
        <call-simple-method method-name="checkProductRelatedPermission" xml-resource="component://product/script/org/ofbiz/product/product/ProductServices.xml"/>
        <check-permission permission="CATALOG_PRICE_MAINT">
            <fail-property resource="ProductUiLabels" property="ProductPriceMaintPermissionError"/>
        </check-permission>
        <check-errors/>

        <call-simple-method method-name="inlineHandlePriceWithTaxIncuded"/>
        
        <entity-one entity-name="ProductPrice" value-field="lookedUpValue"/>

        <!-- grab the old price value before setting nonpk parameter fields -->
        <field-to-result field="lookedUpValue.price" result-name="oldPrice"/>

        <set-nonpk-fields map="parameters" value-field="lookedUpValue"/>

        <now-timestamp field="nowTimestamp"/>
        <set field="lookedUpValue.lastModifiedDate" from-field="nowTimestamp"/>
        <set field="lookedUpValue.lastModifiedByUserLogin" from-field="userLogin.userLoginId"/>

        <store-value value-field="lookedUpValue"/>
    </simple-method>
    <simple-method method-name="deleteProductPrice" short-description="Delete an ProductPrice">
        <set field="callingMethodName" value="deleteProductPrice"/>
        <set field="checkAction" value="DELETE"/>
        <call-simple-method method-name="checkProductRelatedPermission" xml-resource="component://product/script/org/ofbiz/product/product/ProductServices.xml"/>
        <check-permission permission="CATALOG_PRICE_MAINT">
            <fail-property resource="ProductUiLabels" property="ProductPriceMaintPermissionError"/>
        </check-permission>
        <check-errors/>

        <make-value entity-name="ProductPrice" value-field="lookupPKMap"/>
        <set-pk-fields map="parameters" value-field="lookupPKMap"/>
        <find-by-primary-key entity-name="ProductPrice" map="lookupPKMap" value-field="lookedUpValue"/>

        <!-- grab the old price value before setting nonpk parameter fields -->
        <field-to-result field="lookedUpValue.price" result-name="oldPrice"/>

        <remove-value value-field="lookedUpValue"/>
    </simple-method>
    <simple-method method-name="inlineHandlePriceWithTaxIncuded" short-description="Inline Handle Price with Tax Included">
        <if-not-empty field="parameters.taxAuthCombinedId">
            <set field="taxAuthCombinedId" from-field="parameters.taxAuthCombinedId"/>
            <!-- if passed in value will be split based on: "${taxAuthGeoId}::${taxAuthPartyId}" -->
            <set field="parameters.taxAuthGeoId" 
                value="${groovy:taxAuthCombinedId.substring(0,taxAuthCombinedId.indexOf('::'))}"/>
            <set field="parameters.taxAuthPartyId" 
                value="${groovy:taxAuthCombinedId.substring(taxAuthCombinedId.indexOf('::')+2)}"/>
        </if-not-empty>
        
        <!-- handle price with tax included related fields (priceWithTax, taxAmount, taxPercentage, taxAuthPartyId, taxAuthGeoId) -->
        <if>
            <condition>
                <and>
                    <not><if-empty field="parameters.taxAuthPartyId"></if-empty></not>
                    <not><if-empty field="parameters.taxAuthGeoId"></if-empty></not>
                </and>
            </condition>
            <then>
                <set field="parameters.priceWithTax" from-field="parameters.price"/>
                
                <!-- if taxPercentage not passed in look it up based on taxAuthGeoId and taxAuthPartyId -->
                <if-empty field="parameters.taxPercentage">
                    <!-- we only have basic data to constrain by here, so assume that if it is a VAT tax setup it should be pretty simple -->
                    <entity-condition entity-name="TaxAuthorityRateProduct" list="taxAuthorityRateProductList" filter-by-date="true">
                        <condition-list combine="and">
                            <condition-expr field-name="taxAuthGeoId" from-field="parameters.taxAuthGeoId"/>
                            <condition-expr field-name="taxAuthPartyId" from-field="parameters.taxAuthPartyId"/>
                            <condition-list combine="or">
                                <condition-expr field-name="taxAuthorityRateTypeId" value="SALES_TAX"/>
                                <condition-expr field-name="taxAuthorityRateTypeId" value="VAT_TAX"/>
                            </condition-list>
                        </condition-list>
                    </entity-condition>
                    <set field="parameters.taxPercentage" from-field="taxAuthorityRateProductList[0].taxPercentage" type="BigDecimal"/>
                </if-empty>
                
                <if-empty field="parameters.taxPercentage">
                    <add-error>
                        <fail-property resource="ProductUiLabels" property="ProductPriceTaxPercentageNotFound"/>
                    </add-error>
                    <check-errors/>
                </if-empty>
                
                <!-- in short the formula is: taxAmount = priceWithTax - (priceWithTax/(1+taxPercentage/100)) -->
                <calculate field="parameters.taxAmount" type="BigDecimal" decimal-scale="3" rounding-mode="HalfUp">
                    <calcop operator="subtract">
                        <calcop operator="get" field="parameters.priceWithTax"/>
                        <calcop operator="divide">
                            <calcop operator="get" field="parameters.priceWithTax"/>
                            <calcop operator="add">
                                <number value="1"/>
                                <calcop operator="divide">
                                    <calcop operator="get" field="parameters.taxPercentage"/>
                                    <number value="100"/>
                                </calcop>
                            </calcop>
                        </calcop>
                    </calcop>
                </calculate>
                
                <calculate field="parameters.priceWithoutTax" type="BigDecimal" decimal-scale="3" rounding-mode="HalfUp">
                    <calcop operator="subtract">
                        <calcop operator="get" field="parameters.priceWithTax"/>
                        <calcop operator="get" field="parameters.taxAmount"></calcop>
                    </calcop>
                </calculate>
                
                <if-compare field="parameters.taxInPrice" operator="equals" value="Y">
                    <!-- the price passed in has tax included, and we want to store it with tax included -->
                    <set field="parameters.price" from-field="parameters.priceWithTax"/>
                    
                    <else>
                        <!-- the price passed in has tax included, but we want to store it without tax included -->
                        <set field="parameters.price" from-field="parameters.priceWithoutTax"/>
                    </else>
                </if-compare>
            </then>
        </if>
    </simple-method>

    <simple-method method-name="saveProductPriceChange" short-description="Save History of ProductPrice Change">
        <check-permission permission="CATALOG" action="_UPDATE">
            <alt-permission permission="CATALOG" action="_CREATE"/>
            <alt-permission permission="CATALOG" action="_DELETE"/>
            <alt-permission permission="CATALOG_ROLE" action="_CREATE"/>
            <alt-permission permission="CATALOG_ROLE" action="_UPDATE"/>
            <alt-permission permission="CATALOG_ROLE" action="_DELETE"/>
            <fail-property resource="ProductUiLabels" property="ProductCatalogCreatePermissionError"/>
        </check-permission>
        <check-errors/>

        <!-- Note that this is kept pretty simple: if a price is specific but no oldPrice, then it is generally a create, if both are specified it is generally an update, if only the oldPrice is specified it is generally a delete -->
        <make-value value-field="newEntity" entity-name="ProductPriceChange"/>
        <set-nonpk-fields map="parameters" value-field="newEntity"/>

        <sequenced-id sequence-name="ProductPriceChange" field="productPriceChangeId"/>
        <set field="newEntity.productPriceChangeId" from-field="productPriceChangeId"/>
        <now-timestamp field="nowTimestamp"/>
        <set field="newEntity.changedDate" from-field="nowTimestamp"/>
        <set field="newEntity.changedByUserLogin" from-field="userLogin.userLoginId"/>

        <create-value value-field="newEntity"/>
    </simple-method>

    <!-- ProductPaymentMethodType methods -->
    <simple-method method-name="createProductPaymentMethodType" short-description="create a ProductPaymentMethodType">
        <set field="callingMethodName" value="createProductPaymentMethodType"/>
        <set field="checkAction" value="CREATE"/>
        <call-simple-method method-name="checkProductRelatedPermission" xml-resource="component://product/script/org/ofbiz/product/product/ProductServices.xml"/>
        <check-errors/>
        <make-value entity-name="ProductPaymentMethodType" value-field="newEntity"/>
        <set-pk-fields map="parameters" value-field="newEntity"/>
        <if-empty field="newEntity.fromDate"><now-timestamp field="newEntity.fromDate"/></if-empty>
        <set-nonpk-fields map="parameters" value-field="newEntity"/>
        <create-value value-field="newEntity"/>
    </simple-method>
    <simple-method method-name="updateProductPaymentMethodType" short-description="update a ProductPaymentMethodType">
        <set field="callingMethodName" value="updateProductPaymentMethodType"/>
        <set field="checkAction" value="UPDATE"/>
        <call-simple-method method-name="checkProductRelatedPermission" xml-resource="component://product/script/org/ofbiz/product/product/ProductServices.xml"/>
        <check-errors/>
        <entity-one entity-name="ProductPaymentMethodType" value-field="lookedUpValue"/>
        <set-nonpk-fields value-field="lookedUpValue" map="parameters"/>
        <store-value value-field="lookedUpValue"/>
    </simple-method>
    <simple-method method-name="deleteProductPaymentMethodType" short-description="delete a ProductPaymentMethodType">
        <set field="callingMethodName" value="deleteProductPaymentMethodType"/>
        <set field="checkAction" value="DELETE"/>
        <call-simple-method method-name="checkProductRelatedPermission" xml-resource="component://product/script/org/ofbiz/product/product/ProductServices.xml"/>
        <check-errors/>
        <entity-one entity-name="ProductPaymentMethodType" value-field="lookedUpValue"/>
        <remove-value value-field="lookedUpValue"/>
    </simple-method>

    <!-- ProductPriceRule methods -->
    <simple-method method-name="createProductPriceRule" short-description="Create an ProductPriceRule">
        <check-permission permission="CATALOG" action="_CREATE">
            <fail-property resource="ProductUiLabels" property="ProductCatalogCreatePermissionError"/>
        </check-permission>
        <check-permission permission="CATALOG_PRICE_MAINT">
            <fail-property resource="ProductUiLabels" property="ProductPriceMaintPermissionError"/>
        </check-permission>
        <check-errors/>

        <make-value value-field="newEntity" entity-name="ProductPriceRule"/>
        <set-nonpk-fields map="parameters" value-field="newEntity"/>
        <if-empty field="parameters.fromDate">
            <now-timestamp field="newEntity.fromDate"/>
        </if-empty>
        <sequenced-id sequence-name="ProductPriceRule" field="newEntity.productPriceRuleId"/>
        <field-to-result field="newEntity.productPriceRuleId" result-name="productPriceRuleId"/>

        <create-value value-field="newEntity"/>
    </simple-method>
    <simple-method method-name="updateProductPriceRule" short-description="Update an ProductPriceRule">
        <check-permission permission="CATALOG" action="_UPDATE">
            <fail-property resource="ProductUiLabels" property="ProductCatalogUpdatePermissionError"/>
        </check-permission>
        <check-permission permission="CATALOG_PRICE_MAINT">
            <fail-property resource="ProductUiLabels" property="ProductPriceMaintPermissionError"/>
        </check-permission>
        <check-errors/>

        <make-value entity-name="ProductPriceRule" value-field="lookupPKMap"/>
        <set-pk-fields map="parameters" value-field="lookupPKMap"/>
        <find-by-primary-key entity-name="ProductPriceRule" map="lookupPKMap" value-field="lookedUpValue"/>
        <set-nonpk-fields map="parameters" value-field="lookedUpValue"/>
        <store-value value-field="lookedUpValue"/>
    </simple-method>
    <simple-method method-name="deleteProductPriceRule" short-description="Delete an ProductPriceRule">
        <check-permission permission="CATALOG" action="_DELETE">
            <fail-property resource="ProductUiLabels" property="ProductCatalogDeletePermissionError"/>
        </check-permission>
        <check-permission permission="CATALOG_PRICE_MAINT">
            <fail-property resource="ProductUiLabels" property="ProductPriceMaintPermissionError"/>
        </check-permission>
        <check-errors/>

        <make-value entity-name="ProductPriceRule" value-field="lookupPKMap"/>
        <set-pk-fields map="parameters" value-field="lookupPKMap"/>
        <find-by-primary-key entity-name="ProductPriceRule" map="lookupPKMap" value-field="lookedUpValue"/>
        <remove-value value-field="lookedUpValue"/>
    </simple-method>

    <!-- ProductPriceCond methods -->
    <simple-method method-name="createProductPriceCond" short-description="Create an ProductPriceCond">
        <check-permission permission="CATALOG" action="_CREATE">
            <fail-property resource="ProductUiLabels" property="ProductCatalogCreatePermissionError"/>
        </check-permission>
        <check-permission permission="CATALOG_PRICE_MAINT">
            <fail-property resource="ProductUiLabels" property="ProductPriceMaintPermissionError"/>
        </check-permission>
        <check-errors/>

        <if-not-empty field="parameters.condValueInput">
            <set field="parameters.condValue" from-field="parameters.condValueInput"/>
        </if-not-empty>
        <make-value value-field="newEntity" entity-name="ProductPriceCond"/>
        <set-nonpk-fields map="parameters" value-field="newEntity"/>
        <set-pk-fields map="parameters" value-field="newEntity"/>
        <make-next-seq-id value-field="newEntity" seq-field-name="productPriceCondSeqId" numeric-padding="2"/>
        <field-to-result field="newEntity.productPriceCondSeqId" result-name="productPriceCondSeqId"/>

        <create-value value-field="newEntity"/>
    </simple-method>
    <simple-method method-name="updateProductPriceCond" short-description="Update an ProductPriceCond">
        <check-permission permission="CATALOG" action="_UPDATE">
            <fail-property resource="ProductUiLabels" property="ProductCatalogUpdatePermissionError"/>
        </check-permission>
        <check-permission permission="CATALOG_PRICE_MAINT">
            <fail-property resource="ProductUiLabels" property="ProductPriceMaintPermissionError"/>
        </check-permission>
        <check-errors/>

        <if-compare field="parameters.inputParamEnumId" operator="equals" value="PRIP_QUANTITY">
            <set field="parameters.condValue" from-field="parameters.condValueInput"/>
        </if-compare>
        <if-compare field="parameters.inputParamEnumId" operator="equals" value="PRIP_LIST_PRICE">
            <set field="parameters.condValue" from-field="parameters.condValueInput"/>
        </if-compare>
        <make-value entity-name="ProductPriceCond" value-field="lookupPKMap"/>
        <set-pk-fields map="parameters" value-field="lookupPKMap"/>
        <find-by-primary-key entity-name="ProductPriceCond" map="lookupPKMap" value-field="lookedUpValue"/>
        <set-nonpk-fields map="parameters" value-field="lookedUpValue"/>
        <store-value value-field="lookedUpValue"/>
    </simple-method>
    <simple-method method-name="deleteProductPriceCond" short-description="Delete an ProductPriceCond">
        <check-permission permission="CATALOG" action="_DELETE">
            <fail-property resource="ProductUiLabels" property="ProductCatalogDeletePermissionError"/>
        </check-permission>
        <check-permission permission="CATALOG_PRICE_MAINT">
            <fail-property resource="ProductUiLabels" property="ProductPriceMaintPermissionError"/>
        </check-permission>
        <check-errors/>

        <make-value entity-name="ProductPriceCond" value-field="lookupPKMap"/>
        <set-pk-fields map="parameters" value-field="lookupPKMap"/>
        <find-by-primary-key entity-name="ProductPriceCond" map="lookupPKMap" value-field="lookedUpValue"/>
        <remove-value value-field="lookedUpValue"/>
    </simple-method>

    <!-- ProductPriceAction methods -->
    <simple-method method-name="createProductPriceAction" short-description="Create an ProductPriceAction">
        <check-permission permission="CATALOG" action="_CREATE">
            <fail-property resource="ProductUiLabels" property="ProductCatalogCreatePermissionError"/>
        </check-permission>
        <check-permission permission="CATALOG_PRICE_MAINT">
            <fail-property resource="ProductUiLabels" property="ProductPriceMaintPermissionError"/>
        </check-permission>
        <check-errors/>

        <make-value value-field="newEntity" entity-name="ProductPriceAction"/>
        <set-nonpk-fields map="parameters" value-field="newEntity"/>
        <set-pk-fields map="parameters" value-field="newEntity"/>
        <make-next-seq-id value-field="newEntity" seq-field-name="productPriceActionSeqId" numeric-padding="2"/>
        <field-to-result field="newEntity.productPriceActionSeqId" result-name="productPriceActionSeqId"/>

        <create-value value-field="newEntity"/>
    </simple-method>
    <simple-method method-name="updateProductPriceAction" short-description="Update an ProductPriceAction">
        <check-permission permission="CATALOG" action="_UPDATE">
            <fail-property resource="ProductUiLabels" property="ProductCatalogUpdatePermissionError"/>
        </check-permission>
        <check-permission permission="CATALOG_PRICE_MAINT">
            <fail-property resource="ProductUiLabels" property="ProductPriceMaintPermissionError"/>
        </check-permission>
        <check-errors/>

        <make-value entity-name="ProductPriceAction" value-field="lookupPKMap"/>
        <set-pk-fields map="parameters" value-field="lookupPKMap"/>
        <find-by-primary-key entity-name="ProductPriceAction" map="lookupPKMap" value-field="lookedUpValue"/>
        <set-nonpk-fields map="parameters" value-field="lookedUpValue"/>
        <store-value value-field="lookedUpValue"/>
    </simple-method>
    <simple-method method-name="deleteProductPriceAction" short-description="Delete an ProductPriceAction">
        <check-permission permission="CATALOG" action="_DELETE">
            <fail-property resource="ProductUiLabels" property="ProductCatalogDeletePermissionError"/>
        </check-permission>
        <check-permission permission="CATALOG_PRICE_MAINT">
            <fail-property resource="ProductUiLabels" property="ProductPriceMaintPermissionError"/>
        </check-permission>
        <check-errors/>

        <make-value entity-name="ProductPriceAction" value-field="lookupPKMap"/>
        <set-pk-fields map="parameters" value-field="lookupPKMap"/>
        <find-by-primary-key entity-name="ProductPriceAction" map="lookupPKMap" value-field="lookedUpValue"/>
        <remove-value value-field="lookedUpValue"/>
    </simple-method>
    
    <simple-method method-name="getAssociatedPriceRulesConds" short-description="Set the Value options for selected Price Rule Condition Input" login-required="false">
        <if>
            <condition>
                <or>
                    <if-compare field="parameters.inputParamEnumId" operator="equals" value="PRIP_QUANTITY"/>
                    <if-compare field="parameters.inputParamEnumId" operator="equals" value="PRIP_LIST_PRICE"/>
                </or>
            </condition>
            <then>
                <return/>
            </then>
        </if>
        
        <if-compare field="parameters.inputParamEnumId" operator="equals" value="PRIP_PRODUCT_ID">
            <entity-condition entity-name="Product" list="condValues">
                <!-- May prove more useful rather than an entity-and in custom cases-->
            </entity-condition>
            <iterate list="condValues" entry="condValue">
                <set field="option" value="${condValue.internalName}: ${condValue.productId}"/>
                <field-to-list list="productPriceRulesCondValues" field="option"/>
            </iterate>
        </if-compare>
        <if-compare field="parameters.inputParamEnumId" operator="equals" value="PRIP_PROD_CAT_ID">
            <entity-condition entity-name="ProductCategory" list="condValues">
                <!-- May prove more useful rather than an entity-and in custom cases-->
            </entity-condition>
            <iterate list="condValues" entry="condValue">
                <set field="option" value="${condValue.categoryName} ${condValue.description} ${groovy: condValue?.longDescription?.substring(0,10)} [${condValue.productCategoryId}]: ${condValue.productCategoryId}"/>
                <field-to-list list="productPriceRulesCondValues" field="option"/>
            </iterate>
        </if-compare>
        <if-compare field="parameters.inputParamEnumId" operator="equals" value="PRIP_PROD_FEAT_ID">
            <entity-condition entity-name="ProductFeatureType" list="condValues">
                <!-- May prove more useful rather than an entity-and in custom cases-->
            </entity-condition>
            <iterate list="condValues" entry="condValue">
                <set field="option" value="${condValue.description}: ${condValue.productFeatureTypeId}"/>
                <field-to-list list="productPriceRulesCondValues" field="option"/>
            </iterate>
        </if-compare>
        <if>
            <condition>
                <or>
                    <if-compare field="parameters.inputParamEnumId" operator="equals" value="PRIP_PARTY_ID"/>
                    <if-compare field="parameters.inputParamEnumId" operator="equals" value="PRIP_PARTY_GRP_MEM"/><commit_msg>NoRef/OFBIZ patch: PriceServices.xml: fix index out of bounds in description<commit_after><?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
-->

<simple-methods xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/simple-methods-v2.xsd">
    <!-- ProductPrice methods -->
    <simple-method method-name="createProductPrice" short-description="Create a Product Price">
        <set field="callingMethodName" value="createProductPrice"/>
        <set field="checkAction" value="CREATE"/>
        <call-simple-method method-name="checkProductRelatedPermission" xml-resource="component://product/script/org/ofbiz/product/product/ProductServices.xml"/>
        <check-permission permission="CATALOG_PRICE_MAINT">
            <fail-property resource="ProductUiLabels" property="ProductPriceMaintPermissionError"/>
        </check-permission>
        <check-errors/>
        
        <call-simple-method method-name="inlineHandlePriceWithTaxIncuded"/>

        <make-value value-field="newEntity" entity-name="ProductPrice"/>
        <set-nonpk-fields map="parameters" value-field="newEntity"/>
        <set-pk-fields map="parameters" value-field="newEntity"/>
        
        <now-timestamp field="nowTimestamp"/>
        
        <if-empty field="newEntity.fromDate">
            <set field="newEntity.fromDate" from-field="nowTimestamp"/>
        </if-empty>
        <field-to-result field="newEntity.fromDate" result-name="fromDate"/>
        
        <set field="newEntity.lastModifiedDate" from-field="nowTimestamp"/>
        <set field="newEntity.createdDate" from-field="nowTimestamp"/>
        <set field="newEntity.lastModifiedByUserLogin" from-field="userLogin.userLoginId"/>
        <set field="newEntity.createdByUserLogin" from-field="userLogin.userLoginId"/>

        <create-value value-field="newEntity"/>
    </simple-method>
    <simple-method method-name="updateProductPrice" short-description="Update an ProductPrice">
        <set field="callingMethodName" value="updateProductPrice"/>
        <set field="checkAction" value="UPDATE"/>
        <call-simple-method method-name="checkProductRelatedPermission" xml-resource="component://product/script/org/ofbiz/product/product/ProductServices.xml"/>
        <check-permission permission="CATALOG_PRICE_MAINT">
            <fail-property resource="ProductUiLabels" property="ProductPriceMaintPermissionError"/>
        </check-permission>
        <check-errors/>

        <call-simple-method method-name="inlineHandlePriceWithTaxIncuded"/>
        
        <entity-one entity-name="ProductPrice" value-field="lookedUpValue"/>

        <!-- grab the old price value before setting nonpk parameter fields -->
        <field-to-result field="lookedUpValue.price" result-name="oldPrice"/>

        <set-nonpk-fields map="parameters" value-field="lookedUpValue"/>

        <now-timestamp field="nowTimestamp"/>
        <set field="lookedUpValue.lastModifiedDate" from-field="nowTimestamp"/>
        <set field="lookedUpValue.lastModifiedByUserLogin" from-field="userLogin.userLoginId"/>

        <store-value value-field="lookedUpValue"/>
    </simple-method>
    <simple-method method-name="deleteProductPrice" short-description="Delete an ProductPrice">
        <set field="callingMethodName" value="deleteProductPrice"/>
        <set field="checkAction" value="DELETE"/>
        <call-simple-method method-name="checkProductRelatedPermission" xml-resource="component://product/script/org/ofbiz/product/product/ProductServices.xml"/>
        <check-permission permission="CATALOG_PRICE_MAINT">
            <fail-property resource="ProductUiLabels" property="ProductPriceMaintPermissionError"/>
        </check-permission>
        <check-errors/>

        <make-value entity-name="ProductPrice" value-field="lookupPKMap"/>
        <set-pk-fields map="parameters" value-field="lookupPKMap"/>
        <find-by-primary-key entity-name="ProductPrice" map="lookupPKMap" value-field="lookedUpValue"/>

        <!-- grab the old price value before setting nonpk parameter fields -->
        <field-to-result field="lookedUpValue.price" result-name="oldPrice"/>

        <remove-value value-field="lookedUpValue"/>
    </simple-method>
    <simple-method method-name="inlineHandlePriceWithTaxIncuded" short-description="Inline Handle Price with Tax Included">
        <if-not-empty field="parameters.taxAuthCombinedId">
            <set field="taxAuthCombinedId" from-field="parameters.taxAuthCombinedId"/>
            <!-- if passed in value will be split based on: "${taxAuthGeoId}::${taxAuthPartyId}" -->
            <set field="parameters.taxAuthGeoId" 
                value="${groovy:taxAuthCombinedId.substring(0,taxAuthCombinedId.indexOf('::'))}"/>
            <set field="parameters.taxAuthPartyId" 
                value="${groovy:taxAuthCombinedId.substring(taxAuthCombinedId.indexOf('::')+2)}"/>
        </if-not-empty>
        
        <!-- handle price with tax included related fields (priceWithTax, taxAmount, taxPercentage, taxAuthPartyId, taxAuthGeoId) -->
        <if>
            <condition>
                <and>
                    <not><if-empty field="parameters.taxAuthPartyId"></if-empty></not>
                    <not><if-empty field="parameters.taxAuthGeoId"></if-empty></not>
                </and>
            </condition>
            <then>
                <set field="parameters.priceWithTax" from-field="parameters.price"/>
                
                <!-- if taxPercentage not passed in look it up based on taxAuthGeoId and taxAuthPartyId -->
                <if-empty field="parameters.taxPercentage">
                    <!-- we only have basic data to constrain by here, so assume that if it is a VAT tax setup it should be pretty simple -->
                    <entity-condition entity-name="TaxAuthorityRateProduct" list="taxAuthorityRateProductList" filter-by-date="true">
                        <condition-list combine="and">
                            <condition-expr field-name="taxAuthGeoId" from-field="parameters.taxAuthGeoId"/>
                            <condition-expr field-name="taxAuthPartyId" from-field="parameters.taxAuthPartyId"/>
                            <condition-list combine="or">
                                <condition-expr field-name="taxAuthorityRateTypeId" value="SALES_TAX"/>
                                <condition-expr field-name="taxAuthorityRateTypeId" value="VAT_TAX"/>
                            </condition-list>
                        </condition-list>
                    </entity-condition>
                    <set field="parameters.taxPercentage" from-field="taxAuthorityRateProductList[0].taxPercentage" type="BigDecimal"/>
                </if-empty>
                
                <if-empty field="parameters.taxPercentage">
                    <add-error>
                        <fail-property resource="ProductUiLabels" property="ProductPriceTaxPercentageNotFound"/>
                    </add-error>
                    <check-errors/>
                </if-empty>
                
                <!-- in short the formula is: taxAmount = priceWithTax - (priceWithTax/(1+taxPercentage/100)) -->
                <calculate field="parameters.taxAmount" type="BigDecimal" decimal-scale="3" rounding-mode="HalfUp">
                    <calcop operator="subtract">
                        <calcop operator="get" field="parameters.priceWithTax"/>
                        <calcop operator="divide">
                            <calcop operator="get" field="parameters.priceWithTax"/>
                            <calcop operator="add">
                                <number value="1"/>
                                <calcop operator="divide">
                                    <calcop operator="get" field="parameters.taxPercentage"/>
                                    <number value="100"/>
                                </calcop>
                            </calcop>
                        </calcop>
                    </calcop>
                </calculate>
                
                <calculate field="parameters.priceWithoutTax" type="BigDecimal" decimal-scale="3" rounding-mode="HalfUp">
                    <calcop operator="subtract">
                        <calcop operator="get" field="parameters.priceWithTax"/>
                        <calcop operator="get" field="parameters.taxAmount"></calcop>
                    </calcop>
                </calculate>
                
                <if-compare field="parameters.taxInPrice" operator="equals" value="Y">
                    <!-- the price passed in has tax included, and we want to store it with tax included -->
                    <set field="parameters.price" from-field="parameters.priceWithTax"/>
                    
                    <else>
                        <!-- the price passed in has tax included, but we want to store it without tax included -->
                        <set field="parameters.price" from-field="parameters.priceWithoutTax"/>
                    </else>
                </if-compare>
            </then>
        </if>
    </simple-method>

    <simple-method method-name="saveProductPriceChange" short-description="Save History of ProductPrice Change">
        <check-permission permission="CATALOG" action="_UPDATE">
            <alt-permission permission="CATALOG" action="_CREATE"/>
            <alt-permission permission="CATALOG" action="_DELETE"/>
            <alt-permission permission="CATALOG_ROLE" action="_CREATE"/>
            <alt-permission permission="CATALOG_ROLE" action="_UPDATE"/>
            <alt-permission permission="CATALOG_ROLE" action="_DELETE"/>
            <fail-property resource="ProductUiLabels" property="ProductCatalogCreatePermissionError"/>
        </check-permission>
        <check-errors/>

        <!-- Note that this is kept pretty simple: if a price is specific but no oldPrice, then it is generally a create, if both are specified it is generally an update, if only the oldPrice is specified it is generally a delete -->
        <make-value value-field="newEntity" entity-name="ProductPriceChange"/>
        <set-nonpk-fields map="parameters" value-field="newEntity"/>

        <sequenced-id sequence-name="ProductPriceChange" field="productPriceChangeId"/>
        <set field="newEntity.productPriceChangeId" from-field="productPriceChangeId"/>
        <now-timestamp field="nowTimestamp"/>
        <set field="newEntity.changedDate" from-field="nowTimestamp"/>
        <set field="newEntity.changedByUserLogin" from-field="userLogin.userLoginId"/>

        <create-value value-field="newEntity"/>
    </simple-method>

    <!-- ProductPaymentMethodType methods -->
    <simple-method method-name="createProductPaymentMethodType" short-description="create a ProductPaymentMethodType">
        <set field="callingMethodName" value="createProductPaymentMethodType"/>
        <set field="checkAction" value="CREATE"/>
        <call-simple-method method-name="checkProductRelatedPermission" xml-resource="component://product/script/org/ofbiz/product/product/ProductServices.xml"/>
        <check-errors/>
        <make-value entity-name="ProductPaymentMethodType" value-field="newEntity"/>
        <set-pk-fields map="parameters" value-field="newEntity"/>
        <if-empty field="newEntity.fromDate"><now-timestamp field="newEntity.fromDate"/></if-empty>
        <set-nonpk-fields map="parameters" value-field="newEntity"/>
        <create-value value-field="newEntity"/>
    </simple-method>
    <simple-method method-name="updateProductPaymentMethodType" short-description="update a ProductPaymentMethodType">
        <set field="callingMethodName" value="updateProductPaymentMethodType"/>
        <set field="checkAction" value="UPDATE"/>
        <call-simple-method method-name="checkProductRelatedPermission" xml-resource="component://product/script/org/ofbiz/product/product/ProductServices.xml"/>
        <check-errors/>
        <entity-one entity-name="ProductPaymentMethodType" value-field="lookedUpValue"/>
        <set-nonpk-fields value-field="lookedUpValue" map="parameters"/>
        <store-value value-field="lookedUpValue"/>
    </simple-method>
    <simple-method method-name="deleteProductPaymentMethodType" short-description="delete a ProductPaymentMethodType">
        <set field="callingMethodName" value="deleteProductPaymentMethodType"/>
        <set field="checkAction" value="DELETE"/>
        <call-simple-method method-name="checkProductRelatedPermission" xml-resource="component://product/script/org/ofbiz/product/product/ProductServices.xml"/>
        <check-errors/>
        <entity-one entity-name="ProductPaymentMethodType" value-field="lookedUpValue"/>
        <remove-value value-field="lookedUpValue"/>
    </simple-method>

    <!-- ProductPriceRule methods -->
    <simple-method method-name="createProductPriceRule" short-description="Create an ProductPriceRule">
        <check-permission permission="CATALOG" action="_CREATE">
            <fail-property resource="ProductUiLabels" property="ProductCatalogCreatePermissionError"/>
        </check-permission>
        <check-permission permission="CATALOG_PRICE_MAINT">
            <fail-property resource="ProductUiLabels" property="ProductPriceMaintPermissionError"/>
        </check-permission>
        <check-errors/>

        <make-value value-field="newEntity" entity-name="ProductPriceRule"/>
        <set-nonpk-fields map="parameters" value-field="newEntity"/>
        <if-empty field="parameters.fromDate">
            <now-timestamp field="newEntity.fromDate"/>
        </if-empty>
        <sequenced-id sequence-name="ProductPriceRule" field="newEntity.productPriceRuleId"/>
        <field-to-result field="newEntity.productPriceRuleId" result-name="productPriceRuleId"/>

        <create-value value-field="newEntity"/>
    </simple-method>
    <simple-method method-name="updateProductPriceRule" short-description="Update an ProductPriceRule">
        <check-permission permission="CATALOG" action="_UPDATE">
            <fail-property resource="ProductUiLabels" property="ProductCatalogUpdatePermissionError"/>
        </check-permission>
        <check-permission permission="CATALOG_PRICE_MAINT">
            <fail-property resource="ProductUiLabels" property="ProductPriceMaintPermissionError"/>
        </check-permission>
        <check-errors/>

        <make-value entity-name="ProductPriceRule" value-field="lookupPKMap"/>
        <set-pk-fields map="parameters" value-field="lookupPKMap"/>
        <find-by-primary-key entity-name="ProductPriceRule" map="lookupPKMap" value-field="lookedUpValue"/>
        <set-nonpk-fields map="parameters" value-field="lookedUpValue"/>
        <store-value value-field="lookedUpValue"/>
    </simple-method>
    <simple-method method-name="deleteProductPriceRule" short-description="Delete an ProductPriceRule">
        <check-permission permission="CATALOG" action="_DELETE">
            <fail-property resource="ProductUiLabels" property="ProductCatalogDeletePermissionError"/>
        </check-permission>
        <check-permission permission="CATALOG_PRICE_MAINT">
            <fail-property resource="ProductUiLabels" property="ProductPriceMaintPermissionError"/>
        </check-permission>
        <check-errors/>

        <make-value entity-name="ProductPriceRule" value-field="lookupPKMap"/>
        <set-pk-fields map="parameters" value-field="lookupPKMap"/>
        <find-by-primary-key entity-name="ProductPriceRule" map="lookupPKMap" value-field="lookedUpValue"/>
        <remove-value value-field="lookedUpValue"/>
    </simple-method>

    <!-- ProductPriceCond methods -->
    <simple-method method-name="createProductPriceCond" short-description="Create an ProductPriceCond">
        <check-permission permission="CATALOG" action="_CREATE">
            <fail-property resource="ProductUiLabels" property="ProductCatalogCreatePermissionError"/>
        </check-permission>
        <check-permission permission="CATALOG_PRICE_MAINT">
            <fail-property resource="ProductUiLabels" property="ProductPriceMaintPermissionError"/>
        </check-permission>
        <check-errors/>

        <if-not-empty field="parameters.condValueInput">
            <set field="parameters.condValue" from-field="parameters.condValueInput"/>
        </if-not-empty>
        <make-value value-field="newEntity" entity-name="ProductPriceCond"/>
        <set-nonpk-fields map="parameters" value-field="newEntity"/>
        <set-pk-fields map="parameters" value-field="newEntity"/>
        <make-next-seq-id value-field="newEntity" seq-field-name="productPriceCondSeqId" numeric-padding="2"/>
        <field-to-result field="newEntity.productPriceCondSeqId" result-name="productPriceCondSeqId"/>

        <create-value value-field="newEntity"/>
    </simple-method>
    <simple-method method-name="updateProductPriceCond" short-description="Update an ProductPriceCond">
        <check-permission permission="CATALOG" action="_UPDATE">
            <fail-property resource="ProductUiLabels" property="ProductCatalogUpdatePermissionError"/>
        </check-permission>
        <check-permission permission="CATALOG_PRICE_MAINT">
            <fail-property resource="ProductUiLabels" property="ProductPriceMaintPermissionError"/>
        </check-permission>
        <check-errors/>

        <if-compare field="parameters.inputParamEnumId" operator="equals" value="PRIP_QUANTITY">
            <set field="parameters.condValue" from-field="parameters.condValueInput"/>
        </if-compare>
        <if-compare field="parameters.inputParamEnumId" operator="equals" value="PRIP_LIST_PRICE">
            <set field="parameters.condValue" from-field="parameters.condValueInput"/>
        </if-compare>
        <make-value entity-name="ProductPriceCond" value-field="lookupPKMap"/>
        <set-pk-fields map="parameters" value-field="lookupPKMap"/>
        <find-by-primary-key entity-name="ProductPriceCond" map="lookupPKMap" value-field="lookedUpValue"/>
        <set-nonpk-fields map="parameters" value-field="lookedUpValue"/>
        <store-value value-field="lookedUpValue"/>
    </simple-method>
    <simple-method method-name="deleteProductPriceCond" short-description="Delete an ProductPriceCond">
        <check-permission permission="CATALOG" action="_DELETE">
            <fail-property resource="ProductUiLabels" property="ProductCatalogDeletePermissionError"/>
        </check-permission>
        <check-permission permission="CATALOG_PRICE_MAINT">
            <fail-property resource="ProductUiLabels" property="ProductPriceMaintPermissionError"/>
        </check-permission>
        <check-errors/>

        <make-value entity-name="ProductPriceCond" value-field="lookupPKMap"/>
        <set-pk-fields map="parameters" value-field="lookupPKMap"/>
        <find-by-primary-key entity-name="ProductPriceCond" map="lookupPKMap" value-field="lookedUpValue"/>
        <remove-value value-field="lookedUpValue"/>
    </simple-method>

    <!-- ProductPriceAction methods -->
    <simple-method method-name="createProductPriceAction" short-description="Create an ProductPriceAction">
        <check-permission permission="CATALOG" action="_CREATE">
            <fail-property resource="ProductUiLabels" property="ProductCatalogCreatePermissionError"/>
        </check-permission>
        <check-permission permission="CATALOG_PRICE_MAINT">
            <fail-property resource="ProductUiLabels" property="ProductPriceMaintPermissionError"/>
        </check-permission>
        <check-errors/>

        <make-value value-field="newEntity" entity-name="ProductPriceAction"/>
        <set-nonpk-fields map="parameters" value-field="newEntity"/>
        <set-pk-fields map="parameters" value-field="newEntity"/>
        <make-next-seq-id value-field="newEntity" seq-field-name="productPriceActionSeqId" numeric-padding="2"/>
        <field-to-result field="newEntity.productPriceActionSeqId" result-name="productPriceActionSeqId"/>

        <create-value value-field="newEntity"/>
    </simple-method>
    <simple-method method-name="updateProductPriceAction" short-description="Update an ProductPriceAction">
        <check-permission permission="CATALOG" action="_UPDATE">
            <fail-property resource="ProductUiLabels" property="ProductCatalogUpdatePermissionError"/>
        </check-permission>
        <check-permission permission="CATALOG_PRICE_MAINT">
            <fail-property resource="ProductUiLabels" property="ProductPriceMaintPermissionError"/>
        </check-permission>
        <check-errors/>

        <make-value entity-name="ProductPriceAction" value-field="lookupPKMap"/>
        <set-pk-fields map="parameters" value-field="lookupPKMap"/>
        <find-by-primary-key entity-name="ProductPriceAction" map="lookupPKMap" value-field="lookedUpValue"/>
        <set-nonpk-fields map="parameters" value-field="lookedUpValue"/>
        <store-value value-field="lookedUpValue"/>
    </simple-method>
    <simple-method method-name="deleteProductPriceAction" short-description="Delete an ProductPriceAction">
        <check-permission permission="CATALOG" action="_DELETE">
            <fail-property resource="ProductUiLabels" property="ProductCatalogDeletePermissionError"/>
        </check-permission>
        <check-permission permission="CATALOG_PRICE_MAINT">
            <fail-property resource="ProductUiLabels" property="ProductPriceMaintPermissionError"/>
        </check-permission>
        <check-errors/>

        <make-value entity-name="ProductPriceAction" value-field="lookupPKMap"/>
        <set-pk-fields map="parameters" value-field="lookupPKMap"/>
        <find-by-primary-key entity-name="ProductPriceAction" map="lookupPKMap" value-field="lookedUpValue"/>
        <remove-value value-field="lookedUpValue"/>
    </simple-method>
    
    <simple-method method-name="getAssociatedPriceRulesConds" short-description="Set the Value options for selected Price Rule Condition Input" login-required="false">
        <if>
            <condition>
                <or>
                    <if-compare field="parameters.inputParamEnumId" operator="equals" value="PRIP_QUANTITY"/>
                    <if-compare field="parameters.inputParamEnumId" operator="equals" value="PRIP_LIST_PRICE"/>
                </or>
            </condition>
            <then>
                <return/>
            </then>
        </if>
        
        <if-compare field="parameters.inputParamEnumId" operator="equals" value="PRIP_PRODUCT_ID">
            <entity-condition entity-name="Product" list="condValues">
                <!-- May prove more useful rather than an entity-and in custom cases-->
            </entity-condition>
            <iterate list="condValues" entry="condValue">
                <set field="option" value="${condValue.internalName}: ${condValue.productId}"/>
                <field-to-list list="productPriceRulesCondValues" field="option"/>
            </iterate>
        </if-compare>
        <if-compare field="parameters.inputParamEnumId" operator="equals" value="PRIP_PROD_CAT_ID">
            <entity-condition entity-name="ProductCategory" list="condValues">
                <!-- May prove more useful rather than an entity-and in custom cases-->
            </entity-condition>
            <iterate list="condValues" entry="condValue">
                <!-- SCIPIO: This crashes and is excessive anyway
                <set field="option" value="${condValue.categoryName} ${condValue.description} ${groovy: condValue?.longDescription?.substring(0,10)} [${condValue.productCategoryId}]: ${condValue.productCategoryId}"/> -->
                <set field="option" value="${condValue.categoryName} ${condValue.description} [${condValue.productCategoryId}]: ${condValue.productCategoryId}"/>
                <field-to-list list="productPriceRulesCondValues" field="option"/>
            </iterate>
        </if-compare>
        <if-compare field="parameters.inputParamEnumId" operator="equals" value="PRIP_PROD_FEAT_ID">
            <entity-condition entity-name="ProductFeatureType" list="condValues">
                <!-- May prove more useful rather than an entity-and in custom cases-->
            </entity-condition>
            <iterate list="condValues" entry="condValue">
                <set field="option" value="${condValue.description}: ${condValue.productFeatureTypeId}"/>
                <field-to-list list="productPriceRulesCondValues" field="option"/>
            </iterate>
        </if-compare>
        <if>
            <condition>
                <or>
                    <if-compare field="parameters.inputParamEnumId" operator="equals" value="PRIP_PARTY_ID"/>
                    <if-compare field="parameters.inputParamEnumId" operator="equals" value="PRIP_PARTY_GRP_MEM"/>
{'fraction_non_alphanumeric': 0.12892964439295462, 'fraction_numerical': 0.0012174288687729494, 'mean_word_length': 2.9657374240772465, 'pattern_counts': {'":': 0, '<': 751, '<?xml version=': 2, '>': 751, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 29}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4154779', 'n_tokens_mistral': 13232, 'n_tokens_neox': 12878, 'n_words': 2351}