This is an automated email from the ASF dual-hosted git repository.

deepak pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git

commit 014c488228cbc48420677dc487a330cc968c0b21
Author: Deepak Dixit <[email protected]>
AuthorDate: Mon Oct 27 17:23:00 2025 +0530

    Moved createFuturePeriod service definition and implementation from 
framework to applications/accounting component (OFBIZ-13307)
---
 .../accounting}/data/ScheduledServicesDemoData.xml |  0
 applications/accounting/ofbiz-component.xml        |  1 +
 .../accounting/servicedef/services_admin.xml       |  4 +
 .../accounting/admin/AcctgAdminServices.groovy     | 99 ++++++++++++++++++++++
 framework/common/servicedef/services.xml           |  4 -
 .../ofbiz/common/CommonServicesScript.groovy       | 97 ---------------------
 framework/service/ofbiz-component.xml              |  1 -
 7 files changed, 104 insertions(+), 102 deletions(-)

diff --git a/framework/service/data/ScheduledServicesDemoData.xml 
b/applications/accounting/data/ScheduledServicesDemoData.xml
similarity index 100%
rename from framework/service/data/ScheduledServicesDemoData.xml
rename to applications/accounting/data/ScheduledServicesDemoData.xml
diff --git a/applications/accounting/ofbiz-component.xml 
b/applications/accounting/ofbiz-component.xml
index 4f3ca68728..497dea31f0 100644
--- a/applications/accounting/ofbiz-component.xml
+++ b/applications/accounting/ofbiz-component.xml
@@ -30,6 +30,7 @@ under the License.
     <entity-resource type="data" reader-name="seed" loader="main" 
location="data/AccountingSystemPropertyData.xml"/>
     <entity-resource type="data" reader-name="seed" loader="main" 
location="data/AccountingPortletData.xml"/>
     <entity-resource type="data" reader-name="seed-initial" loader="main" 
location="data/AccountingScheduledServiceData.xml"/>
+    <entity-resource type="data" reader-name="demo" loader="main" 
location="data/ScheduledServicesDemoData.xml"/>
 
     <!-- General Payment Service Definitions -->
     <service-resource type="model" loader="main" 
location="servicedef/services_agreement.xml"/>
diff --git a/applications/accounting/servicedef/services_admin.xml 
b/applications/accounting/servicedef/services_admin.xml
index 369e8f62ff..8edebefc4a 100644
--- a/applications/accounting/servicedef/services_admin.xml
+++ b/applications/accounting/servicedef/services_admin.xml
@@ -149,4 +149,8 @@ under the License.
         <attribute type="Timestamp" mode="IN" name="asOfTimestamp" 
optional="true"/>
         <attribute type="BigDecimal" mode="OUT" name="conversionRate" 
optional="false"/>
     </service>
+    <service name="createFuturePeriod" engine="groovy"
+             
location="component://accounting/src/main/groovy/org/apache/ofbiz/accounting/admin/AcctgAdminServices.groovy"
 invoke="createFuturePeriod" auth="true">
+        <description>Create a future CustomTimePeriod</description>
+    </service>
 </services>
diff --git 
a/applications/accounting/src/main/groovy/org/apache/ofbiz/accounting/admin/AcctgAdminServices.groovy
 
b/applications/accounting/src/main/groovy/org/apache/ofbiz/accounting/admin/AcctgAdminServices.groovy
index c938bb1a79..7c56689def 100644
--- 
a/applications/accounting/src/main/groovy/org/apache/ofbiz/accounting/admin/AcctgAdminServices.groovy
+++ 
b/applications/accounting/src/main/groovy/org/apache/ofbiz/accounting/admin/AcctgAdminServices.groovy
@@ -28,6 +28,8 @@ import 
org.apache.ofbiz.entity.condition.EntityConditionBuilder
 import org.apache.ofbiz.entity.util.EntityUtil
 import org.apache.ofbiz.service.ModelService
 
+import java.text.SimpleDateFormat
+
 Map createPartyAcctgPreference() {
     //check that the party is an INTERNAL_ORGANIZATION, as defined in PartyRole
     partyRole = select().from('PartyRole').where([partyId: parameters.partyId, 
roleTypeId: 'INTERNAL_ORGANIZATIO']).queryOne()
@@ -170,3 +172,100 @@ Map getFXConversion() {
     result.put('conversionRate', conversionRate)
     return result
 }
+
+Map createFuturePeriod() {
+    applTypes = []
+    grain = null
+    intermediate = null
+    List parties = from('PartyAcctgPreference').where('enableAccounting', 
'Y').queryList()
+    parties.each {
+        parameters.organizationPartyId = it.partyId
+        createCustomTimePeriod = from('SystemProperty')
+                .where('systemResourceId', 'general', 'systemPropertyId', 
'CustomTimePeriod.create').queryOne()
+        if (createCustomTimePeriod.systemPropertyValue == 'Y') {
+            // get list of CustomTypePeriod types
+            applTypes = from('SystemProperty')
+                    .where('systemResourceId', 'general', 'systemPropertyId', 
'CustomTimePeriod.applType').queryOne()
+            List types = 
Arrays.asList(applTypes.systemPropertyValue.split('\\s*,\\s*'))
+            types.each { periodTypeId ->
+                Calendar periodCal = Calendar.getInstance()
+                systemPropertyId = 'CustomTimePeriod.' + periodTypeId + 
'.intermediate'
+                applTypeInter = from('SystemProperty')
+                        .where('systemResourceId', 'general', 
'systemPropertyId', systemPropertyId).queryOne()
+                if (applTypeInter) {
+                    intermediate = applTypeInter.systemPropertyValue
+                }
+                // get grain for application type
+                systemPropertyId = 'CustomTimePeriod.' + periodTypeId + 
'.grain'
+                applTypeGrain = from('SystemProperty')
+                        .where('systemResourceId', 'general', 
'systemPropertyId', systemPropertyId).queryOne()
+                if (applTypeGrain) {
+                    grain = applTypeGrain.systemPropertyValue
+                    if (grain == 'MONTH') {
+                        periodCal.add(Calendar.MONTH, 1)
+                        monthName = new SimpleDateFormat('MMM', 
locale).format(periodCal.getTime())
+                        year = periodCal.get(Calendar.YEAR)
+                        month = (periodCal.get(Calendar.MONTH) + 1).toString()
+                        if (month.length() == 1) {
+                            month = '0' + month
+                        }
+                        periodCal.set(Calendar.DATE, 1)
+                        periodStart = new 
java.sql.Date(periodCal.getTimeInMillis())
+                        periodStartDate = periodStart.toString() + ' 
00:00:00.000'
+                        lastPeriodDay =  
periodCal.getActualMaximum(Calendar.DAY_OF_MONTH)
+                        periodCal.set(Calendar.DATE, lastPeriodDay)
+                        periodEnd = new 
java.sql.Date(periodCal.getTimeInMillis())
+                        periodEndDate = periodEnd.toString() + ' 23:59:59.999'
+                        parameters.isClosed = 'N'
+                        // check whether the period for the year exists
+                        yearStartDate = Timestamp.valueOf(year + '-01-01 
00:00:00.000')
+                        yearEndDate = Timestamp.valueOf(year + '-12-31 
23:59:59.999')
+                        yearPeriodType = periodTypeId + '_YEAR'
+                        existingYear = from('CustomTimePeriod')
+                                .where('fromDate', yearStartDate, 'thruDate', 
yearEndDate, 'organizationPartyId', parameters.organizationPartyId,
+                                        'periodTypeId', 
yearPeriodType).queryFirst()
+                        if (existingYear) {
+                            parameters.parentPeriodId = 
existingYear.customTimePeriodId
+                        } else {
+                            parameters.fromDate = yearStartDate
+                            parameters.thruDate = yearEndDate
+                            parameters.periodTypeId = yearPeriodType
+                            parameters.periodNum = year + '00'
+                            parameters.periodName = year.toString()
+                            // persist the future period
+                            inMap = 
dispatcher.getDispatchContext().makeValidContext('createCustomTimePeriod', 
ModelService.IN_PARAM, parameters)
+                            serviceResult = run service: 
'createCustomTimePeriod', with: inMap
+                            if (ServiceUtil.isSuccess(serviceResult)) {
+                                parameters.parentPeriodId = 
serviceResult.customTimePeriodId
+                            } else {
+                                return error(serviceResult.errorMessage)
+                            }
+                        }
+                        // check whether the future period exists
+                        parameters.customTimePeriodId = year + month
+                        parameters.periodNum = year + month
+                        parameters.periodName = (year + '-' + 
monthName).toUpperCase()
+                        fromDate = Timestamp.valueOf(periodStartDate)
+                        thruDate = Timestamp.valueOf(periodEndDate)
+                        parameters.periodTypeId = periodTypeId + '_' + grain
+                        existingPeriod = from('CustomTimePeriod')
+                                .where('fromDate', fromDate, 'thruDate', 
thruDate, 'organizationPartyId', parameters.organizationPartyId,
+                                        'periodTypeId', 
parameters.periodTypeId).queryFirst()
+                        if (!existingPeriod) {
+                            parameters.fromDate = periodStartDate
+                            parameters.thruDate = periodEndDate
+                            // persist the future period
+                            inMap = 
dispatcher.getDispatchContext().makeValidContext('createCustomTimePeriod', 
ModelService.IN_PARAM, parameters)
+                            serviceResult = run service: 
'createCustomTimePeriod', with: inMap
+                            if (!ServiceUtil.isSuccess(serviceResult)) {
+                                return error(serviceResult.errorMessage)
+                            }
+                        }
+                        parameters.parentPeriodId = ''
+                    }
+                }
+            }
+        }
+    }
+    return success()
+}
diff --git a/framework/common/servicedef/services.xml 
b/framework/common/servicedef/services.xml
index 16cdf97253..cc68a7495c 100644
--- a/framework/common/servicedef/services.xml
+++ b/framework/common/servicedef/services.xml
@@ -185,10 +185,6 @@ under the License.
         <required-permissions join-type="AND"><check-permission 
permission="PERIOD_MAINT"/></required-permissions>
         <auto-attributes mode="IN" include="pk" optional="false"/>
     </service>
-    <service name="createFuturePeriod" engine="groovy"
-            
location="component://common/src/main/groovy/org/apache/ofbiz/common/CommonServicesScript.groovy"
 invoke="createFuturePeriod" auth="true">
-        <description>Create a future CustomTimePeriod</description>
-    </service>
 
     <!-- Status services -->
     <service name="getStatusItems" engine="java"
diff --git 
a/framework/common/src/main/groovy/org/apache/ofbiz/common/CommonServicesScript.groovy
 
b/framework/common/src/main/groovy/org/apache/ofbiz/common/CommonServicesScript.groovy
index cf07e7634e..2d77ecc497 100644
--- 
a/framework/common/src/main/groovy/org/apache/ofbiz/common/CommonServicesScript.groovy
+++ 
b/framework/common/src/main/groovy/org/apache/ofbiz/common/CommonServicesScript.groovy
@@ -345,100 +345,3 @@ Map deleteKeywordThesaurus() {
     delegator.removeByAnd('KeywordThesaurus', newEntity)
     return success()
 }
-
-Map createFuturePeriod() {
-    applTypes = []
-    grain = null
-    intermediate = null
-    List parties = from('PartyAcctgPreference').where('enableAccounting', 
'Y').queryList()
-    parties.each {
-        parameters.organizationPartyId = it.partyId
-        createCustomTimePeriod = from('SystemProperty')
-                .where('systemResourceId', 'general', 'systemPropertyId', 
'CustomTimePeriod.create').queryOne()
-        if (createCustomTimePeriod.systemPropertyValue == 'Y') {
-            // get list of CustomTypePeriod types
-            applTypes = from('SystemProperty')
-                    .where('systemResourceId', 'general', 'systemPropertyId', 
'CustomTimePeriod.applType').queryOne()
-            List types = 
Arrays.asList(applTypes.systemPropertyValue.split('\\s*,\\s*'))
-            types.each { periodTypeId ->
-                Calendar periodCal = Calendar.getInstance()
-                systemPropertyId = 'CustomTimePeriod.' + periodTypeId + 
'.intermediate'
-                applTypeInter = from('SystemProperty')
-                    .where('systemResourceId', 'general', 'systemPropertyId', 
systemPropertyId).queryOne()
-                if (applTypeInter) {
-                    intermediate = applTypeInter.systemPropertyValue
-                }
-                // get grain for application type
-                systemPropertyId = 'CustomTimePeriod.' + periodTypeId + 
'.grain'
-                applTypeGrain = from('SystemProperty')
-                        .where('systemResourceId', 'general', 
'systemPropertyId', systemPropertyId).queryOne()
-                if (applTypeGrain) {
-                    grain = applTypeGrain.systemPropertyValue
-                    if (grain == 'MONTH') {
-                        periodCal.add(Calendar.MONTH, 1)
-                        monthName = new SimpleDateFormat('MMM', 
locale).format(periodCal.getTime())
-                        year = periodCal.get(Calendar.YEAR)
-                        month = (periodCal.get(Calendar.MONTH) + 1).toString()
-                        if (month.length() == 1) {
-                            month = '0' + month
-                        }
-                        periodCal.set(Calendar.DATE, 1)
-                        periodStart = new 
java.sql.Date(periodCal.getTimeInMillis())
-                        periodStartDate = periodStart.toString() + ' 
00:00:00.000'
-                        lastPeriodDay =  
periodCal.getActualMaximum(Calendar.DAY_OF_MONTH)
-                        periodCal.set(Calendar.DATE, lastPeriodDay)
-                        periodEnd = new 
java.sql.Date(periodCal.getTimeInMillis())
-                        periodEndDate = periodEnd.toString() + ' 23:59:59.999'
-                        parameters.isClosed = 'N'
-                        // check whether the period for the year exists
-                        yearStartDate = Timestamp.valueOf(year + '-01-01 
00:00:00.000')
-                        yearEndDate = Timestamp.valueOf(year + '-12-31 
23:59:59.999')
-                        yearPeriodType = periodTypeId + '_YEAR'
-                        existingYear = from('CustomTimePeriod')
-                                .where('fromDate', yearStartDate, 'thruDate', 
yearEndDate, 'organizationPartyId', parameters.organizationPartyId,
-                                        'periodTypeId', 
yearPeriodType).queryFirst()
-                        if (existingYear) {
-                            parameters.parentPeriodId = 
existingYear.customTimePeriodId
-                        } else {
-                            parameters.fromDate = yearStartDate
-                            parameters.thruDate = yearEndDate
-                            parameters.periodTypeId = yearPeriodType
-                            parameters.periodNum = year + '00'
-                            parameters.periodName = year.toString()
-                            // persist the future period
-                            inMap = 
dispatcher.getDispatchContext().makeValidContext('createCustomTimePeriod', 
ModelService.IN_PARAM, parameters)
-                            serviceResult = run service: 
'createCustomTimePeriod', with: inMap
-                            if (ServiceUtil.isSuccess(serviceResult)) {
-                                parameters.parentPeriodId = 
serviceResult.customTimePeriodId
-                            } else {
-                                return error(serviceResult.errorMessage)
-                            }
-                        }
-                        // check whether the future period exists
-                        parameters.customTimePeriodId = year + month
-                        parameters.periodNum = year + month
-                        parameters.periodName = (year + '-' + 
monthName).toUpperCase()
-                        fromDate = Timestamp.valueOf(periodStartDate)
-                        thruDate = Timestamp.valueOf(periodEndDate)
-                        parameters.periodTypeId = periodTypeId + '_' + grain
-                        existingPeriod = from('CustomTimePeriod')
-                                .where('fromDate', fromDate, 'thruDate', 
thruDate, 'organizationPartyId', parameters.organizationPartyId,
-                                        'periodTypeId', 
parameters.periodTypeId).queryFirst()
-                        if (!existingPeriod) {
-                            parameters.fromDate = periodStartDate
-                            parameters.thruDate = periodEndDate
-                            // persist the future period
-                            inMap = 
dispatcher.getDispatchContext().makeValidContext('createCustomTimePeriod', 
ModelService.IN_PARAM, parameters)
-                            serviceResult = run service: 
'createCustomTimePeriod', with: inMap
-                            if (!ServiceUtil.isSuccess(serviceResult)) {
-                                return error(serviceResult.errorMessage)
-                            }
-                        }
-                        parameters.parentPeriodId = ''
-                    }
-                }
-            }
-        }
-    }
-    return success()
-}
diff --git a/framework/service/ofbiz-component.xml 
b/framework/service/ofbiz-component.xml
index ffa7bd1678..d4e6213383 100644
--- a/framework/service/ofbiz-component.xml
+++ b/framework/service/ofbiz-component.xml
@@ -31,7 +31,6 @@ under the License.
     <entity-resource type="data" reader-name="seed" loader="main" 
location="data/ServiceSecurityPermissionSeedData.xml"/>
     <entity-resource type="data" reader-name="demo" loader="main" 
location="data/ServiceSecurityGroupDemoData.xml"/>
     <entity-resource type="data" reader-name="demo" loader="main" 
location="data/ServiceDemoData.xml"/>
-    <entity-resource type="data" reader-name="demo" loader="main" 
location="data/ScheduledServicesDemoData.xml"/>
     
 
     <service-resource type="model" loader="main" 
location="servicedef/services.xml"/>

Reply via email to