Changeset 597 for trunk/grails-app
- Timestamp:
- Jun 15, 2010, 9:18:21 AM (14 years ago)
- Location:
- trunk/grails-app
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/controllers/InventoryItemPurchaseDetailedController.groovy
r596 r597 320 320 321 321 def approveInvoicePayment = { 322 // Read the values from Order Received. 322 323 def inventoryItemPurchaseInstance = InventoryItemPurchase.read( params.id ) 323 324 … … 331 332 params.returnTo = params.returnTo ?: 'inventoryItem' 332 333 return ['inventoryItemPurchaseInstance':inventoryItemPurchaseInstance, 333 ' orderId': inventoryItemPurchaseInstance.id]334 'receivedId': inventoryItemPurchaseInstance.id] 334 335 } 335 336 … … 359 360 render(view:'approveInvoicePayment', 360 361 model:['inventoryItemPurchaseInstance': result.inventoryItemPurchaseInstance, 361 ' orderId': result.orderId])362 'receivedId': result.receivedId]) 362 363 } 363 364 } -
trunk/grails-app/services/CreateDataService.groovy
r587 r597 637 637 description: "Order has been partially received.") 638 638 saveAndTest(inventoryItemPurchaseTypeInstance) 639 639 640 // InventoryItemPurchaseType #3 640 641 inventoryItemPurchaseTypeInstance = new InventoryItemPurchaseType(name: "Received Complete", -
trunk/grails-app/services/InventoryPurchaseService.groovy
r596 r597 11 11 * @param order An inventory puchase that was the source of the order. 12 12 * @returns A result map containing the totalOrdered, totalReceived, totalRemaining, thisOrderRemaining, 13 * totalOrderedAmount, totalReceivedAmount, totalRemainingAmount, thisOrderRemainingAmount. 13 * totalOrderedAmount, totalReceivedAmount, totalRemainingAmount, thisOrderRemainingAmount, 14 * totalPaymentApproved. 14 15 */ 15 16 def calcQuantities(order) { … … 19 20 result.totalOrdered = 0 20 21 result.totalOrderedAmount = 0 22 result.totalReceived = 0 23 result.totalReceivedAmount = 0 24 result.totalPaymentApproved = 0 21 25 InventoryItemPurchase.withCriteria { 22 26 eq("inventoryItem", order.inventoryItem) 23 27 eq("purchaseOrderNumber", order.purchaseOrderNumber) 24 inventoryItemPurchaseType {25 eq("id", 1L)26 }27 28 }.each() { 28 result.totalOrdered += it.quantity 29 result.totalOrderedAmount += it.orderValueAmount 30 } 31 32 result.totalReceived = 0 33 result.totalReceivedAmount = 0 34 InventoryItemPurchase.withCriteria { 35 eq("inventoryItem", order.inventoryItem) 36 eq("purchaseOrderNumber", order.purchaseOrderNumber) 37 inventoryItemPurchaseType { 38 or { 39 eq("id", 2L) 40 eq("id", 3L) 41 } 42 } 43 }.each() { 44 result.totalReceived += it.quantity 45 result.totalReceivedAmount += it.orderValueAmount 29 if(it.inventoryItemPurchaseType.id == 1L) { // Orders. 30 result.totalOrdered += it.quantity 31 result.totalOrderedAmount += it.orderValueAmount 32 } 33 if(it.inventoryItemPurchaseType.id == 2L || it.inventoryItemPurchaseType.id == 3L) { // Received B/order and Complete. 34 result.totalReceived += it.quantity 35 result.totalReceivedAmount += it.orderValueAmount 36 } 37 if(it.inventoryItemPurchaseType.id == 4L) { // Approved. 38 result.totalPaymentApproved += it.orderValueAmount 39 } 46 40 } 47 41 … … 71 65 72 66 return result 67 } 68 69 /** 70 * Get the original order for an inventoryItemPurchase and InventoryItem. 71 * @param inventoryItemPurchase An inventory puchase. 72 * @returns The order. 73 */ 74 def getOriginalOrder(inventoryItemPurchase) { 75 76 def namedParams = [:] 77 78 namedParams.inventoryItem = inventoryItemPurchase.inventoryItem 79 namedParams.purchaseOrderNumber = inventoryItemPurchase.purchaseOrderNumber 80 namedParams.orderPlaced = InventoryItemPurchaseType.read(1) 81 82 def order = InventoryItemPurchase.find("from InventoryItemPurchase as p \ 83 where( p.inventoryItem = :inventoryItem \ 84 and p.purchaseOrderNumber = :purchaseOrderNumber \ 85 and p.inventoryItemPurchaseType = :orderPlaced )", 86 namedParams) 87 88 return order 73 89 } 74 90 … … 93 109 94 110 // Handle Invoice Payment Approved. 95 // Find and mark all orders as invoicePaymentApproved = false.96 111 if(purchaseTypeId == 4) { 112 // Find and mark all orders as invoicePaymentApproved = false. 97 113 InventoryItemPurchase.withCriteria { 98 114 eq("inventoryItem", result.inventoryItemPurchaseInstance.inventoryItem) … … 104 120 it.invoicePaymentApproved = false 105 121 } 122 // Find and mark last orderReceived as invoicePaymentApproved = false. 123 InventoryItemPurchase.withCriteria { 124 eq("inventoryItem", result.inventoryItemPurchaseInstance.inventoryItem) 125 eq("purchaseOrderNumber", result.inventoryItemPurchaseInstance.purchaseOrderNumber) 126 inventoryItemPurchaseType { 127 or { 128 eq("id", 2L) // Received B/order To Come 129 eq("id", 3L) // Received Complete 130 } 131 } 132 }.last().invoicePaymentApproved = false 106 133 } 107 134 … … 129 156 between("date", startOfDay, startOfDay+1) 130 157 inventoryMovementType { 131 eq("id", 3L) // purchaseReceived.158 eq("id", 3L) // purchaseReceived. 132 159 } 133 160 order('id', 'desc') // The newest one will be first. … … 324 351 } 325 352 326 def order = InventoryItemPurchase.get(params.orderId) 353 def received = InventoryItemPurchase.get(params.receivedId) 354 if(!received) 355 return fail(code:"default.not.found") 356 result.receivedId = received.id 357 358 def order = getOriginalOrder(received) 327 359 if(!order) 328 360 return fail(code:"default.not.found") 329 361 result.orderId = order.id 330 331 result.inventoryItemPurchaseInstance = new InventoryItemPurchase(params)332 362 333 363 result.inventoryItemPurchaseInstance = new InventoryItemPurchase(params) … … 338 368 result.inventoryItemPurchaseInstance.inventoryItemPurchaseType = InventoryItemPurchaseType.read(4) // Approve. 339 369 340 order.invoicePaymentApproved = true370 received.invoicePaymentApproved = true 341 371 result.inventoryItemPurchaseInstance.invoicePaymentApproved = true 372 373 // Update orderValueAmount and invoicePaymentApproved if processing a receivedComplete. 374 if(received.inventoryItemPurchaseType.id == 3L) { 375 order.invoicePaymentApproved = true 376 result.inventoryItemPurchaseInstance.receivedComplete = true 377 def calcQuantities = calcQuantities(order) 378 if(result.inventoryItemPurchaseInstance.orderValueAmount) 379 calcQuantities.totalPaymentApproved += result.inventoryItemPurchaseInstance.orderValueAmount 380 order.orderValueAmount = calcQuantities.totalPaymentApproved 381 } 342 382 343 383 // Fetch to prevent lazy initialization error. … … 347 387 return fail(field:"invoiceNumber", code:"inventoryItemPurchase.invoiceNumber.required") 348 388 349 order.invoicePaymentApproved = true350 351 389 if(order.hasErrors() || !order.save()) 352 390 return fail(code:"default.create.failure") -
trunk/grails-app/views/inventoryItemPurchaseDetailed/approveInvoicePayment.gsp
r595 r597 20 20 <g:form action="approveInvoicePaymentSave" method="post" > 21 21 <g:hiddenField name="inventoryItem.id" value="${inventoryItemPurchaseInstance.inventoryItem?.id}" /> 22 <g:hiddenField name=" orderId" value="${orderId}" />22 <g:hiddenField name="receivedId" value="${receivedId}" /> 23 23 <g:hiddenField name="returnTo" value="${params.returnTo}" /> 24 24 <div class="dialog">
Note: See TracChangeset
for help on using the changeset viewer.