Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/ob129 bulk receive shipment #130

Merged
merged 3 commits into from
Mar 31, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ app.grails.version=1.3.7
app.name=openboxes
app.revisionNumber=11160
app.servlet.version=2.4
app.version=0.7.4
app.version=0.7.5
plugins.barcode4j=0.2.1
plugins.bubbling=2.1.4
plugins.clickstream=0.2.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,32 @@ class ShipmentController {
}
redirect(controller:"shipment", action : "showDetails", id: shipmentInstance.id)
}


def bulkReceiveShipments = {
def shipmentIds = params.list("shipment.id")
try {
shipmentService.receiveShipments(shipmentIds, null, session.user.id, session.warehouse.id, true)
flash.message = "Successfully received shipments"

} catch (Exception e) {
flash.message = "Error occurred while bulk receiving shipments: " + e.message
}
redirect(action: "list", params:[type:params.type, status: params.status])
}


def bulkRollbackShipments = {
def shipmentIds = params.list("shipment.id")
try {
shipmentService.rollbackShipments(shipmentIds)
flash.message = "Successfully rolled back last event for selected shipments"

} catch (Exception e) {
flash.message = "Error occurred while bulk receiving shipments: " + e.message
}
redirect(action: "list", params:[type:params.type, status: params.status])
}


def receiveShipment = { ReceiveShipmentCommand command ->
Expand Down
9 changes: 7 additions & 2 deletions grails-app/i18n/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,11 @@ default.item.label = Item
default.items.label = Items
default.label = Default
default.lastUpdated.label = Last Updated
default.lastUpdated.day.label = {0} Day(s)
default.lastUpdated.week.label = {0} Week(s)
default.lastUpdated.month.label = {0} Month(s)
default.lastUpdated.year.label = {0} Year(s)

default.layout.label = Layout
default.lbs.label = lbs
default.list.label = List {0}
Expand Down Expand Up @@ -730,11 +735,11 @@ import.manufacturer.label = Manufacturer
import.manufacturerCode.label = Manufacturer Code
import.lotNumber.label = Lot Number
import.expirationDate.label = Expiration Date
import.quantity.label = Quantity
import.quantity.label = Quantity
import.unitOfMeasure.label = Unit of measure
import.idaCode.label = IDA Code
import.openBoxesId.label = OpenBoxes ID
import.french.label = French
import.french.label = French
import.search1.label = Search 1
import.search2.label = Search 2
import.packaging.label = Packaging
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1131,11 +1131,44 @@ class ShipmentService {
}

}





void receiveShipments(List shipmentIds, String comment, String userId, String locationId, Boolean creditStockOnReceipt) {
if (!shipmentIds) {
throw new IllegalArgumentException("Must select at least one shipment in order to use bulk receipt")
}
shipmentIds.each { shipmentId ->
Shipment shipment = Shipment.get(shipmentId)
shipment.receipt = createReceipt(shipment, shipment.actualShippingDate+1)
receiveShipment(shipmentId, comment, userId, locationId, creditStockOnReceipt)
}
}

void rollbackShipments(List shipmentIds) {
if (!shipmentIds) {
throw new IllegalArgumentException("Must select at least one shipment in order to use bulk rollback")
}
shipmentIds.each { shipmentId ->
Shipment.withNewSession {
Shipment shipment = Shipment.get(shipmentId)
rollbackLastEvent(shipment)
}
}
}

void markShipmentsAsReceived(List shipmentIds) {
if (!shipmentIds) {
throw new IllegalArgumentException("Must select at least one shipment in order to use mark as received")
}

Location location = Location.get(session.warehouse.id)
shipmentIds.each { shipmentId ->
Shipment shipment = Shipment.get(shipmentId)
markAsReceived(shipment, location)
}
}



void markAsReceived(Shipment shipment, Location location) {
try {
// Add a Received event to the shipment
Expand Down Expand Up @@ -1169,7 +1202,7 @@ class ShipmentService {
* @param location
*/
void receiveShipment(String shipmentId, String comment, String userId, String locationId, Boolean creditStockOnReceipt) {

log.info "Receiving shipment " + shipmentId
User user = User.get(userId)
Location location = Location.get(locationId)
Shipment shipmentInstance = Shipment.get(shipmentId)
Expand Down
22 changes: 21 additions & 1 deletion grails-app/views/shipment/_filters.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,26 @@
</div>
</td>
</tr>
<%-- working on this - can't get the translation to work correctly because there's no way to pass number of days or weeks as an argument --%>
<%--
<tr class="prop">
<td>
<div>
<div>
<label>${warehouse.message(code: 'shipping.lastUpdated.label')}</label>
</div>
<div>
<g:select name="lastUpdated" class="chzn-select-deselect"
from="${[1:'default.lastUpdated.day.label', 7:'default.lastUpdated.week.label', 30: 'default.lastUpdated.month.label', 365:'default.lastUpdated.year.label' ]}"
optionKey="key"
optionValue="${{warehouse.message(code:it.value, args:[1])}}"
value="${params.statusChanged}"
noSelection="['':warehouse.message(code:'default.all.label')]" />
</div>
</div>
</td>
</tr>
--%>
<tr class="prop">
<td>
<div>
Expand All @@ -28,7 +48,7 @@
<div>
<g:select name="status" class="chzn-select-deselect"
from="${org.pih.warehouse.shipping.ShipmentStatusCode.list()}"
optionKey="name" optionValue="${{format.metadata(obj:it)}}"
optionKey="name" optionValue="${format.metadata(obj:it)}"
value="${status}"
noSelection="['':warehouse.message(code:'default.all.label')]" />
</div>
Expand Down
52 changes: 33 additions & 19 deletions grails-app/views/shipment/_list.gsp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="list box">
<h2>${warehouse.message(code:'shipments.label')}</h2>
<table>
<table id="shipments" class="dataTable">
<thead>
<tr>
<%--
Expand All @@ -9,6 +9,9 @@
</th>
--%>
<th>
<g:checkBox class="checkAll" data-status="${statusCode}" name="checkAll"/>
</th>
<th>
</th>
<th class="center">
${warehouse.message(code: 'shipping.shipmentNumber.label')}
Expand Down Expand Up @@ -58,6 +61,9 @@
</div>
</td>
--%>
<td>
<g:checkBox class="${shipmentInstance?.status.code}" name="shipment.id" value="${shipmentInstance.id}" checked="${params['shipment.id']}" />
</td>
<td class="center middle"><img
src="${createLinkTo(dir:'images/icons/shipmentType',file: 'ShipmentType' + format.metadata(obj:shipmentInstance?.shipmentType, locale:null) + '.png')}"
alt="${format.metadata(obj:shipmentInstance?.shipmentType)}"
Expand All @@ -84,23 +90,27 @@
${fieldValue(bean: shipmentInstance, field: "destination.name")}
</td>

<td class="middle"><g:set var="today" value="${new Date() }" /> <format:metadata
obj="${shipmentInstance?.status.code}" /> <g:if
test="${shipmentInstance?.status.date}">
<g:if test="${shipmentInstance?.status?.date?.equals(today) }">
<warehouse:message code="default.today.label" />
</g:if>
<g:else>
<g:prettyDateFormat date="${shipmentInstance?.status?.date}" />
</g:else>
<td class="middle">
<g:set var="today" value="${new Date() }" />
<format:metadata obj="${shipmentInstance?.status.code}" />
<g:if test="${shipmentInstance?.status.date}">
<div title="${g.formatDate(date: shipmentInstance?.status?.date)}">
<g:if test="${shipmentInstance?.status?.date?.equals(today) }">
<warehouse:message code="default.today.label" />
</g:if>
<g:else>
<g:prettyDateFormat date="${shipmentInstance?.status?.date}" />
</g:else>
</div>
<%--
<format:date obj="${shipmentInstance?.status.date}"/>
--%>
</g:if> <g:else>
<format:date obj="${shipmentInstance?.status.date}"/>
--%>
</g:if>
<g:else>
- Expected to ship
<%--
<format:date obj="${shipmentInstance?.expectedShippingDate}"/>
--%>
<%--
<format:date obj="${shipmentInstance?.expectedShippingDate}"/>
--%>
<g:if
test="${shipmentInstance?.expectedShippingDate?.equals(today) }">
<warehouse:message code="default.today.label" />
Expand All @@ -109,9 +119,13 @@
<g:prettyDateFormat
date="${shipmentInstance?.expectedShippingDate}" />
</g:else>
</g:else></td>
<td class="middle center"><format:date
obj="${shipmentInstance?.lastUpdated}" /></td>
</g:else>
</td>
<td class="middle center">
<div title="${g.formatDate(date: shipmentInstance?.lastUpdated)}">
${g.formatDate(date: shipmentInstance?.lastUpdated)}
</div>
</td>
</tr>
</g:each>
</tbody>
Expand Down
70 changes: 64 additions & 6 deletions grails-app/views/shipment/list.gsp
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<html>
<head>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="layout" content="custom" />
<g:set var="messagePrefix" value="${incoming ? 'shipping.shipmentsTo' : 'shipping.shipmentsFrom'}"/>
<title><warehouse:message code="${messagePrefix}.label" args="[session.warehouse.name]"/></title>
</head>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/datatables/1.9.4/css/jquery.dataTables.css" type="text/css" media="all" />
</head>
<body>
<div class="body">
<g:if test="${flash.message}">
Expand All @@ -16,11 +17,15 @@

</div>
<div class="yui-u">
<g:form action="list" method="post">


<g:form name="listForm" action="bulkReceiveShipments" method="post">
<g:if test="${incoming}">
<g:hiddenField name="type" value="incoming"/>
</g:if>



<g:set var="shipments" value="${shipments.sort { it.status.code }}"/>
<g:set var="shipmentMap" value="${shipments.groupBy { it.status.code }}"/>
<g:if test="${shipments.size()}">
Expand All @@ -37,8 +42,27 @@
</ul>
<g:each var="shipmentStatusCode" in="${shipmentMap.keySet() }">
<div id="${format.metadata(obj: shipmentStatusCode) }" style="padding: 10px;">
<g:render template="list" model="[incoming:incoming, shipments:shipmentMap[shipmentStatusCode]]"/>


<g:if test="${shipmentStatusCode== org.pih.warehouse.shipping.ShipmentStatusCode.SHIPPED}">
<div class="button-group">
<button id="bulkReceive" type="submit" class="button icon approve">
<warehouse:message code="bulk.receive.label" default="Bulk Receive"/>
</button>
<button id="bulkMarkAsReceived" type="submit" class="button icon tag">
<warehouse:message code="bulk.markAsReceived.label" default="Bulk Mark as Received"/>
</button>
</div>
</g:if>
<g:if test="${shipmentStatusCode== org.pih.warehouse.shipping.ShipmentStatusCode.RECEIVED}">
<div class="button-group">
<button id="bulkRollback" type="submit" class="button icon approve">
<warehouse:message code="bulk.receive.label" default="Bulk Rollback"/>
</button>
</div>
</g:if>

<g:render template="list" model="[incoming:incoming, shipments:shipmentMap[shipmentStatusCode], statusCode:shipmentStatusCode]"/>
</div>
</g:each>
</div>
Expand All @@ -59,7 +83,10 @@
</div>
</div>

</div>
</div>


<script src="//cdnjs.cloudflare.com/ajax/libs/datatables/1.9.4/jquery.dataTables.js" type="text/javascript" ></script>
<script type="text/javascript">
$(function() {
//$(".clear-dates").click(function() {
Expand All @@ -84,8 +111,39 @@

var index = $('.tabs li a').index($('a[href="#add"]').get(0));
$('.tabs').tabs({selected: index});



$("#bulkReceive").click(function(event){
event.preventDefault();
$("#listForm").attr("action", "bulkReceiveShipments")
$("#listForm").submit();
});

$("#bulkRollback").click(function(event){
event.preventDefault();
$("#listForm").attr("action", "bulkRollbackShipments")
$("#listForm").submit();
});

$("#bulkMarkAsReceived").click(function(event){
event.preventDefault();
$("#listForm").attr("action", "markShipmentsAsReceived")
$("#listForm").submit();
});


$(".checkAll").change(function () {
var status = $(this).data("status");
$("input:checkbox." + status).prop('checked', $(this).prop("checked"));
});

});

$(document).ready(function(){
$('.dataTable').dataTable({
"bJQueryUI": true
});
});
</script>

</body>
Expand Down