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

Issue 307: POWF - to make the expenseClass optional. #310

Merged
merged 2 commits into from
Oct 10, 2023
Merged
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
37 changes: 23 additions & 14 deletions purchase-orders/nodes/js/buildCompositePurchaseOrder.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,38 @@ if (logLevel === 'DEBUG') {
print('\nacquisitionMethodsResponse = ' + acquisitionMethodsResponse + '\n');
}

var poNumber = JSON.parse(poNumberResponse).poNumber;
var extractResponseArray = function (response, key, firstId) {
if (!response || !response.totalRecords || response.totalRecords == 0 || !response[key]) {
return (firstId === true) ? undefined : [];
}

if (firstId === true) {
return (response[key].length > 0 && !!response[key][0] && !!response[key][0].id) ? response[key][0].id : undefined;
}

var vendorId = JSON.parse(vendorsResponse).organizations[0].id;
return response[key];
};

var expenseClassId = JSON.parse(expenseClassesResponse).expenseClasses[0].id;
var poNumberObj = JSON.parse(poNumberResponse);
var poNumber = !!poNumberObj && !!poNumberObj.poNumber ? poNumberObj.poNumber : undefined;

var configurationEntryId = JSON.parse(configurationEntriesResponse).configs[0].id;
var vendorId = extractResponseArray(JSON.parse(vendorsResponse), 'organizations', true);

var fund = JSON.parse(fundsResponse).funds[0];
var expenseClassId = extractResponseArray(JSON.parse(expenseClassesResponse), 'expenseClasses', true);

var locations = JSON.parse(locationsResponse).locations;
var configurationEntryId = extractResponseArray(JSON.parse(configurationEntriesResponse), 'configs', true);

var materialTypes = JSON.parse(materialTypesResponse).mtypes;
var funds = extractResponseArray(JSON.parse(fundsResponse), 'funds');

var materialTypes = JSON.parse(materialTypesResponse).mtypes;
var locations = extractResponseArray(JSON.parse(locationsResponse), 'locations');

var acquisitionMethods = JSON.parse(acquisitionMethodsResponse).acquisitionMethods;
var materialTypes = extractResponseArray(JSON.parse(materialTypesResponse), 'mtypes');

var acquisitionMethods = extractResponseArray(JSON.parse(acquisitionMethodsResponse), 'acquisitionMethods');

var marcOrderDataObj = JSON.parse(marcOrderData);

var electronic = marcOrderDataObj.electronicIndicator && marcOrderDataObj.electronicIndicator.toLowerCase().indexOf('electronic') >= 0;
var electronic = !!marcOrderDataObj.electronicIndicator && marcOrderDataObj.electronicIndicator.toLowerCase().indexOf('electronic') >= 0;

var findLocationIdByName = function (locationName) {
for (var i = 0; i < locations.length; ++i) {
Expand Down Expand Up @@ -63,9 +74,9 @@ var orderLine = {
},
details: {},
fundDistribution: [{
code: fund.code,
code: funds.length > 0 ? funds[0].code : undefined,
distributionType: 'percentage',
fundId: fund.id,
fundId: funds.length > 0 ? funds[0].id : undefined,
expenseClassId: expenseClassId,
value: 100
}],
Expand Down Expand Up @@ -98,8 +109,6 @@ var compositePurchaseOrder = {

var tagList = [];



if (electronic) {
orderLine.orderFormat = 'Electronic Resource';

Expand Down