- Timestamp:
- Apr 22, 2011, 5:18:04 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/features/purchaseOrders/grails-app/services/PurchaseOrderService.groovy
r897 r898 1 /** 2 * Provides a service class for the PurchaseOrder and PurchaseOrderNumber domain classes. 3 */ 1 4 class PurchaseOrderService { 2 5 3 6 boolean transactional = false 7 8 def savePurchaseOrderNumberRange(prefix, startOfRange, endOfRange, suffix="") { 9 PurchaseOrderNumber.withTransaction { status -> 10 def result = [:] 11 12 def fail = { Map m -> 13 status.setRollbackOnly() 14 if(result.purchaseOrderNumber && m.field) 15 result.purchaseOrderNumber.errors.rejectValue(m.field, m.code) 16 result.error = [ code: m.code, args: ["PurchaseOrderNumber"] ] 17 return result 18 } 19 20 // Sanity checks. 21 if(startOfRange < 0) 22 return fail(code:"default.create.failure") 23 if(endOfRange < 0) 24 return fail(code:"default.create.failure") 25 // Auto swap range. 26 if(endOfRange < startOfRange) 27 (startOfRange, endOfRange) = [endOfRange, startOfRange] 28 29 def r 30 def p = [:] 31 for(i in startOfRange..endOfRange) { 32 p.value= "${prefix}${i}${suffix}" 33 r = savePurchaseOrderNumber(p) 34 if(r.error) 35 return fail(code: r.code) 36 37 } 38 39 // Success. 40 return result 41 } 42 } 4 43 5 44 PurchaseOrderNumber findNextUnusedPurchaseOrderNumber() { … … 37 76 return drafts 38 77 } 78 79 def savePurchaseOrderNumber(params) { 80 PurchaseOrderNumber.withTransaction { status -> 81 def result = [:] 82 83 def fail = { Map m -> 84 status.setRollbackOnly() 85 if(result.purchaseOrderNumber && m.field) 86 result.purchaseOrderNumber.errors.rejectValue(m.field, m.code) 87 result.error = [ code: m.code, args: ["PurchaseOrderNumber", params.id] ] 88 return result 89 } 90 91 result.purchaseOrderNumber = new PurchaseOrderNumber(params) 92 93 if(result.purchaseOrderNumber.hasErrors() || !result.purchaseOrderNumber.save()) 94 return fail(code:"default.create.failure") 95 96 // Success. 97 return result 98 } 99 } 100 39 101 }
Note: See TracChangeset
for help on using the changeset viewer.