2018-08-08 16:46:14 +02:00
|
|
|
import moment from 'moment';
|
2018-08-15 09:58:13 +02:00
|
|
|
import {fromWiaasProcessStep} from './ProcessHelper';
|
|
|
|
|
|
|
|
|
|
const tempTransformationFunction = (order) => {
|
|
|
|
|
let processInfo = Object.assign({},order['delivery-process']);
|
|
|
|
|
if (order['delivery-process']){
|
|
|
|
|
processInfo.steps = order['delivery-process'].steps.map(step=>fromWiaasProcessStep(step));
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
let processInfo = Object.assign({},order['delivery-process']);
|
|
|
|
|
processInfo.steps = order['delivery-process'].steps.map(step=>fromWiaasProcessStep(step));
|
|
|
|
|
/*
|
|
|
|
|
processInfo[order['delivery-process'].id] = {
|
|
|
|
|
idProcess: order['delivery-process'].id,
|
|
|
|
|
processName: order['delivery-process'].name,
|
|
|
|
|
steps: order['delivery-process'].steps.map(step => {
|
|
|
|
|
return transformProcessStep(step, order['delivery-process'].id);
|
|
|
|
|
})
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
let TransformedPackagesArray = order.line_items.map(packageItem => {
|
|
|
|
|
return {
|
|
|
|
|
endOfLife: null,
|
|
|
|
|
units: packageItem.quantity,
|
|
|
|
|
packageFixedPrice: packageItem.price,
|
|
|
|
|
packageRecurringPrice: 0,
|
|
|
|
|
packageServicePrice: 0,
|
|
|
|
|
status: 'no-process',
|
|
|
|
|
packagePayPeriod: 0,
|
|
|
|
|
servicesContractPeriod: 0,
|
|
|
|
|
maxContractPeriod: 0,
|
|
|
|
|
periodUnit: 'months',
|
|
|
|
|
paymentType: 'Managed service 36M rent',
|
|
|
|
|
idOrder: order.id,
|
|
|
|
|
idPackage: packageItem.id,
|
|
|
|
|
packageName: packageItem.name,
|
|
|
|
|
packageCurrency: {
|
|
|
|
|
currency: order.currency
|
|
|
|
|
},
|
|
|
|
|
documents: [{
|
|
|
|
|
idDocument: 1,
|
|
|
|
|
documentName: 'customerQuestionaire_343_32_2',
|
|
|
|
|
documentPath: 'path/to/document/withExtension.docx',
|
|
|
|
|
extension: 'docx',
|
|
|
|
|
documentType: 'Order Questionaire',
|
|
|
|
|
documentTypeName: 'orderQuestionarie',
|
|
|
|
|
idPackage: packageItem.id
|
|
|
|
|
}],
|
|
|
|
|
options: [],
|
|
|
|
|
additionalPackages: [],
|
|
|
|
|
idOrderPackagePair: `${order.id}-${packageItem.id}`
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
//going through same array again - for cleaner code
|
|
|
|
|
let newProductsObject = {};
|
|
|
|
|
order.line_items.forEach(element => {
|
|
|
|
|
newProductsObject[element.id] = {
|
|
|
|
|
software: [{
|
|
|
|
|
productName: 'Software product',
|
|
|
|
|
category: 'software',
|
|
|
|
|
idPackage: element.id
|
|
|
|
|
}],
|
|
|
|
|
hardware: [{
|
|
|
|
|
productName: 'Hardware product',
|
|
|
|
|
category: 'hardware',
|
|
|
|
|
idPackage: element.id
|
|
|
|
|
}],
|
|
|
|
|
service: [{
|
|
|
|
|
productName: 'Service product',
|
|
|
|
|
category: 'service',
|
|
|
|
|
idPackage: element.id
|
|
|
|
|
}],
|
|
|
|
|
installation: [{
|
|
|
|
|
productName: 'Installation product',
|
|
|
|
|
category: 'installation',
|
|
|
|
|
idPackage: element.id
|
|
|
|
|
}]
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
let comments = [];
|
|
|
|
|
let processID = null;
|
|
|
|
|
order.meta_data.forEach(element => {
|
|
|
|
|
if (element.key.substring(0, 7) === 'comment') {
|
|
|
|
|
comments.push(element.value);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
info: {
|
|
|
|
|
id: order.id,
|
|
|
|
|
orderNumber: order.number,
|
|
|
|
|
orderDate: moment(order.date_created).format("Do MMM, YYYY"),
|
|
|
|
|
estimatedDeliveryDate: null,
|
|
|
|
|
billingFirstName: order.billing.first_name,
|
|
|
|
|
billingLastName: order.billing.last_name,
|
|
|
|
|
billingMail: order.billing.email,
|
|
|
|
|
billingAddress: order.billing.address_1 + ' ' + order.billing.address_2,
|
|
|
|
|
status: order.status,
|
|
|
|
|
reference: 'reference field',
|
|
|
|
|
tender: 'tender field',
|
|
|
|
|
idTerms: null,
|
|
|
|
|
idProject: null,
|
|
|
|
|
projectName: 'project name field',
|
|
|
|
|
assignedTo: 'assigned to',
|
|
|
|
|
customer: 'customer field',
|
|
|
|
|
phone: null,
|
|
|
|
|
mail: '',
|
|
|
|
|
idCommercialLead: null,
|
|
|
|
|
commercialLead: '',
|
|
|
|
|
endOfLife: null,
|
|
|
|
|
idProcess: processID,
|
|
|
|
|
},
|
|
|
|
|
products: newProductsObject,
|
|
|
|
|
packages: TransformedPackagesArray,
|
|
|
|
|
process: processInfo,
|
|
|
|
|
orderDocuments: [],
|
|
|
|
|
selections: [],
|
|
|
|
|
orderComments: comments,
|
|
|
|
|
availableProcesses: [],
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-08-08 16:46:14 +02:00
|
|
|
|
2018-08-09 12:20:20 +02:00
|
|
|
function formatDate(date) {
|
|
|
|
|
return date ? moment(date).format("Do MMM, YYYY") : undefined;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function formatAddress(addressObject) {
|
|
|
|
|
return `${addressObject.address_1}, ${addressObject.city}, ${addressObject.country}, ${addressObject.postcode}`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const fromWCOrder = (WCOrder) => {
|
2018-08-08 16:46:14 +02:00
|
|
|
return {
|
2018-08-09 12:20:20 +02:00
|
|
|
id: WCOrder.id,
|
|
|
|
|
number: WCOrder.number,
|
|
|
|
|
isMyOrder: WCOrder['is_my_order'],
|
|
|
|
|
dateCreated: formatDate(WCOrder['date_created']),
|
|
|
|
|
dateCompleted: formatDate(WCOrder['date_completed']),
|
|
|
|
|
estimatedDeliveryDate: undefined,
|
2018-08-29 07:56:37 +02:00
|
|
|
reference: WCOrder['reference'],
|
2018-08-08 16:46:14 +02:00
|
|
|
assignedTo: 'assigned to',
|
2018-08-09 12:20:20 +02:00
|
|
|
fixedPrice: WCOrder.total,
|
2018-08-08 16:46:14 +02:00
|
|
|
recurringPrice: 0,
|
2018-08-09 12:20:20 +02:00
|
|
|
status: WCOrder.status,
|
|
|
|
|
currency: WCOrder.currency,
|
|
|
|
|
packages: WCOrder['line_items'].map(packageLine => {
|
|
|
|
|
return {
|
|
|
|
|
id: packageLine['product_id'],
|
|
|
|
|
name: packageLine.name,
|
|
|
|
|
quantity: packageLine.quantity,
|
|
|
|
|
price: packageLine.price,
|
|
|
|
|
status: packageLine.status,
|
|
|
|
|
paymentType: packageLine['payment_type'],
|
|
|
|
|
servicePrice: packageLine['service_price'],
|
|
|
|
|
serviceContractPeriod: packageLine['service_contract_period'],
|
|
|
|
|
maxContractPeriod: packageLine['max_contract_period'],
|
|
|
|
|
periodUnit: packageLine['period_unit'],
|
|
|
|
|
recurringPrice: packageLine['recurring_price'],
|
|
|
|
|
payPeriod: packageLine['pay_period'],
|
|
|
|
|
shortDesc: packageLine['short_desc'],
|
|
|
|
|
dateCompleted: formatDate(packageLine['date_completed']),
|
|
|
|
|
};
|
|
|
|
|
}),
|
|
|
|
|
deliveryAddress: formatAddress(WCOrder.shipping),
|
|
|
|
|
customer: WCOrder.customer,
|
|
|
|
|
commercialLead: WCOrder['commercial_lead']
|
2018-08-08 16:46:14 +02:00
|
|
|
}
|
2018-08-09 12:20:20 +02:00
|
|
|
};
|