Skip to content

Commit

Permalink
ANGOLASUP-909: changed pack and doses logic in order fulfillment (#175)
Browse files Browse the repository at this point in the history
* ANGOLASUO-909: second request

* code cleanup and test fixes
  • Loading branch information
DominikNoga authored Sep 3, 2024
1 parent 5e14d44 commit 8ee3d6f
Show file tree
Hide file tree
Showing 9 changed files with 627 additions and 23 deletions.
19 changes: 8 additions & 11 deletions src/proof-of-delivery-view/proof-of-delivery-view.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,11 @@

ProofOfDeliveryViewController.$inject = [
'proofOfDelivery', 'order', 'reasons', 'messageService', 'VVM_STATUS', 'orderLineItems', 'canEdit', '$q',
'accessTokenFactory', '$window', 'openlmisUrlFactory', 'ORDER_STATUSES'
'ORDER_STATUSES', 'ProofOfDeliveryPrinter'
];

function ProofOfDeliveryViewController(proofOfDelivery, order, reasons, messageService, VVM_STATUS, orderLineItems,
canEdit, $q, accessTokenFactory, $window, openlmisUrlFactory,
ORDER_STATUSES) {
canEdit, $q, ORDER_STATUSES, ProofOfDeliveryPrinter) {

var vm = this;

Expand Down Expand Up @@ -177,20 +176,18 @@
* Prints the proof of delivery.
*/
function printProofOfDelivery() {
var printer = new ProofOfDeliveryPrinter();

printer.openTab();

(vm.proofOfDelivery.isInitiated() ? vm.proofOfDelivery.save() : $q.resolve(vm.proofOfDelivery))
.then(function(proofOfDelivery) {
var popup = $window.open('', '_blank');
popup.location.href = accessTokenFactory.addAccessToken(getPrintUrl(proofOfDelivery.id));
printer.setId(proofOfDelivery.id);
printer.print();
})
.catch(function() {
$window.open(accessTokenFactory.addAccessToken(vm.getPrintUrl()), '_blank');
printer.closeTab();
});
}

function getPrintUrl(orderId) {
return openlmisUrlFactory('/api/reports/templates/common/2db2b18e-ceff-4d24-b20b-5a232608f8a4/pdf?orderId='
+ orderId);
}
}
}());
6 changes: 6 additions & 0 deletions src/shipment-view/messages_en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"shipmentView.unit": "Unit",
"shipmentView.fillQuantityInDoses": "Fill Quantity (in Doses)",
"shipmentView.fillQuantityTotal": "Fill Quantity (Total)",
"shipmentView.quantitiesProvidedInDoses": "These quantities are always provided in Doses"
}
114 changes: 114 additions & 0 deletions src/shipment-view/shipment-view-line-item-group.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*
* This program is part of the OpenLMIS logistics management information system platform software.
* Copyright © 2017 VillageReach
*
* This program is free software: you can redistribute it and/or modify it under the terms
* of the GNU Affero General Public License as published by the Free Software Foundation, either
* version 3 of the License, or (at your option) any later version.
*  
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
* See the GNU Affero General Public License for more details. You should have received a copy of
* the GNU Affero General Public License along with this program. If not, see
* http://www.gnu.org/licenses.  For additional information contact [email protected]
*/

(function() {

'use strict';

/**
* @ngdoc service
* @name shipment-view.ShipmentViewLineItemGroup
*
* @description
* Represents a group of line items or line item groups.
*/
angular
.module('shipment-view')
.factory('ShipmentViewLineItemGroup', ShipmentViewLineItemGroup);

ShipmentViewLineItemGroup.inject = ['ShipmentViewLineItem', 'classExtender'];

function ShipmentViewLineItemGroup(ShipmentViewLineItem, classExtender) {

classExtender.extend(ShipmentViewLineItemGroup, ShipmentViewLineItem);

ShipmentViewLineItemGroup.prototype.getAvailableSoh = getAvailableSoh;
ShipmentViewLineItemGroup.prototype.getFillQuantity = getFillQuantity;
ShipmentViewLineItemGroup.prototype.getOrderQuantity = getOrderQuantity;

return ShipmentViewLineItemGroup;

/**
* @ngdoc method
* @methodOf shipment-view.ShipmentViewLineItemGroup
* @name ShipmentViewLineItemGroup
* @constructor
*
* @description
* Creates an instance of the ShipmentViewLineItemGroup.
*
* @param {Object} config configuration object used when creating new instance of the class
*/
function ShipmentViewLineItemGroup(config) {
this.super(config);
this.orderQuantity = config.orderQuantity;
this.lineItems = config.lineItems;
this.isMainGroup = config.isMainGroup;
this.noStockAvailable = this.getAvailableSoh() === 0;
this.isLot = false;
}

/**
* @ngdoc method
* @methodOf shipment-view.ShipmentViewLineItemGroup
* @name getAvailableSoh
*
* @description
* Returns a sum of all stock available for the children line items/line item groups.
*
* @return {number} the sum of all available stock on hand for the whole group
*/
function getAvailableSoh() {
return this.lineItems.reduce(function(availableSoh, lineItem) {
return availableSoh + lineItem.getAvailableSoh();
}, 0);
}

/**
* @ngdoc method
* @methodOf shipment-view.ShipmentViewLineItemGroup
* @name getFillQuantity
*
* @description
* Returns a sum of all fill quantities for the children line items/line item groups.
*
* @return {number} the sum of all fill quantities for the whole group
*/
function getFillQuantity() {
return this.lineItems.reduce(function(fillQuantity, lineItem) {
return fillQuantity + lineItem.getFillQuantity();
}, 0);
}

/**
* @ngdoc method
* @methodOf shipment-view.ShipmentViewLineItemGroup
* @name getOrderQuantity
*
* @description
* Returns an ordered quantity for the commodity type related with the line item.
*
* @return {number} the ordered quantity for the commodity type related with the
* line item
*/
function getOrderQuantity() {
if (this.orderQuantity === undefined || this.orderQuantity === null) {
return;
}
return this.orderQuantity;
}
}

})();
127 changes: 127 additions & 0 deletions src/shipment-view/shipment-view-line-item.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/*
* This program is part of the OpenLMIS logistics management information system platform software.
* Copyright © 2017 VillageReach
*
* This program is free software: you can redistribute it and/or modify it under the terms
* of the GNU Affero General Public License as published by the Free Software Foundation, either
* version 3 of the License, or (at your option) any later version.
*  
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
* See the GNU Affero General Public License for more details. You should have received a copy of
* the GNU Affero General Public License along with this program. If not, see
* http://www.gnu.org/licenses.  For additional information contact [email protected]
*/

(function() {

'use strict';

/**
* @ngdoc service
* @name shipment-view.ShipmentViewLineItem
*
* @description
* Represents a single shipment view line item. It can represent either a single lot or a
* generic orderable.
*/
angular
.module('shipment-view')
.factory('ShipmentViewLineItem', ShipmentViewLineItem);

function ShipmentViewLineItem() {

ShipmentViewLineItem.prototype.getAvailableSoh = getAvailableSoh;
ShipmentViewLineItem.prototype.getFillQuantity = getFillQuantity;
ShipmentViewLineItem.prototype.getRemainingSoh = getRemainingSoh;
ShipmentViewLineItem.prototype.getOrderQuantity = getOrderQuantity;

return ShipmentViewLineItem;

/**
* @ngdoc method
* @methodOf shipment-view.ShipmentViewLineItem
* @name ShipmentViewLineItem
* @constructor
*
* @description
* Creates an instance of the ShipmentViewLineItem.
*
* @param {Object} config configuration object used when creating new instance of the class
*/
function ShipmentViewLineItem(config) {
this.productCode = config.productCode;
this.productName = config.productName;
this.lot = config.lot;
this.vvmStatus = config.vvmStatus;
this.shipmentLineItem = config.shipmentLineItem;
this.netContent = config.netContent;
this.isLot = true;
this.orderQuantity = config.orderQuantity;
}

/**
* @ngdoc method
* @methodOf shipment-view.ShipmentViewLineItem
* @name getAvailableSoh
*
* @description
* Returns available stock on hand for the commodity type or lot.
*
* @return {number} the available stock on hand for the specific commodity type or
* lot
*/
function getAvailableSoh() {
return this.shipmentLineItem.stockOnHand;
}

/**
* @ngdoc method
* @methodOf shipment-view.ShipmentViewLineItem
* @name getFillQuantity
*
* @description
* Returns available stock on hand for the commodity type or lot.
*
* @return {number} the fill quantity for the specific commodity type or lot
*/
function getFillQuantity() {
return this.shipmentLineItem.quantityShipped || 0;
}

/**
* @ngdoc method
* @methodOf shipment-view.ShipmentViewLineItem
* @name getRemainingSoh
*
* @description
* Returns the remaining stock after fulfilling the order for a specific commodity type or
* lot
*
* @return {number} the remaining stock after fulfilling the order for a specific
* commodity type or lot
*/
function getRemainingSoh() {
return this.getAvailableSoh() - this.getFillQuantity();
}

/**
* @ngdoc method
* @methodOf shipment-view.ShipmentViewLineItem
* @name getOrderQuantity
*
* @description
* Returns an ordered quantity for the commodity type related with the line item.
*
* @return {number} the ordered quantity for the commodity type related with the
* line item
*/
function getOrderQuantity() {
if (this.orderQuantity === undefined || this.orderQuantity === null) {
return;
}
return this.orderQuantity;
}
}

})();
98 changes: 98 additions & 0 deletions src/shipment-view/shipment-view-line-item.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* This program is part of the OpenLMIS logistics management information system platform software.
* Copyright © 2017 VillageReach
*
* This program is free software: you can redistribute it and/or modify it under the terms
* of the GNU Affero General Public License as published by the Free Software Foundation, either
* version 3 of the License, or (at your option) any later version.
*  
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
* See the GNU Affero General Public License for more details. You should have received a copy of
* the GNU Affero General Public License along with this program. If not, see
* http://www.gnu.org/licenses.  For additional information contact [email protected]
*/

describe('ShipmentViewLineItem', function() {

var shipmentViewLineItem, ShipmentViewLineItem, OrderableDataBuilder, orderable;

beforeEach(function() {
module('shipment-view');

inject(function($injector) {
ShipmentViewLineItem = $injector.get('ShipmentViewLineItem');
OrderableDataBuilder = $injector.get('OrderableDataBuilder');
});

orderable = new OrderableDataBuilder()
.withNetContent(5)
.buildJson();

shipmentViewLineItem = new ShipmentViewLineItem(orderable);
});

describe('constructor', function() {

it('should set net content', function() {
var result = new ShipmentViewLineItem(orderable);

expect(result.netContent).toEqual(orderable.netContent);
});

});

describe('getRemainingSoh', function() {

beforeEach(function() {
spyOn(shipmentViewLineItem, 'getAvailableSoh');
spyOn(shipmentViewLineItem, 'getFillQuantity');
});

it('should return quantity in packs by default', function() {
shipmentViewLineItem.getAvailableSoh.andReturn(160);
shipmentViewLineItem.getFillQuantity.andReturn(33);

var result = shipmentViewLineItem.getRemainingSoh();

expect(result).toEqual(127);
});
});

describe('getOrderQuantity', function() {

it('should return 0 if order quantity is equal to zero', function() {
var lineItem = new ShipmentViewLineItem({
orderQuantity: 0,
lineItems: []
});

var result = lineItem.getOrderQuantity(false);

expect(result).toBe(0);
});

it('should return undefined if order quantity is undefined', function() {
var lineItem = new ShipmentViewLineItem({
lineItems: []
});

var result = lineItem.getOrderQuantity(false);

expect(result).toBeUndefined();
});

it('should return undefined if order quantity is null', function() {
var lineItem = new ShipmentViewLineItem({
orderQuantity: null,
lineItems: []
});

var result = lineItem.getOrderQuantity(false);

expect(result).toBeUndefined();
});

});

});
Loading

0 comments on commit 8ee3d6f

Please sign in to comment.