Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- "use strict";
- importScript( "app_cc2_asda:library/c2_asda/webservice/vieworderdetails/libPopulateDTOFromDwareOrder.ds" );
- importScript("bc_ecm:library/utility/logging/libLog.ds");
- importScript( "app_ecm:util/libDateHelper.ds" );
- importScript( "bc_ecm:library/order/libOrderCalculations.ds");
- var guard = require('~/cartridge/scripts/guard');
- var ISML = require('dw/template/ISML');
- var ContentMgr = require('dw/content/ContentMgr');
- var ProductLineItem = require('dw/order/ProductLineItem');
- var PromotionMgr = require('dw/campaign/PromotionMgr');
- function Show() {
- var orderDetailsDTO = getOrderDetailsDTO();
- var vatReceipt = {};
- vatReceipt.billingInformation = getCustomerBillingInformationFromOrderDTO(orderDetailsDTO);
- vatReceipt.productsInformation = getListOfProductsFromOrderDTO(orderDetailsDTO);
- vatReceipt.orderInformation = getOrderInformationFromOrderDTO(orderDetailsDTO);
- vatReceipt.orderPromotions = getOrderPromotions(orderDetailsDTO);
- ISML.renderTemplate('bill_vat_details.isml', {"output" : vatReceipt});
- }
- function getOrderDetailsDTO() {
- var _logger = new Log();
- var dwOrder = require('dw/order/OrderMgr').getOrder('00011503_dev293');
- var orderDetailsDTO = new PopulateDTOFromDwareOrderHelper(_logger, dwOrder);
- return orderDetailsDTO.getOrderDetailsDTO();
- }
- function getCustomerBillingInformationFromOrderDTO(orderDTO) {
- return {
- title: orderDTO._dwareOrder.getBillingAddress().getTitle(),
- fullName: orderDTO._dwareOrder.getBillingAddress().getFullName(),
- address1: orderDTO._dwareOrder.getBillingAddress().getAddress1(),
- address2: orderDTO._dwareOrder.getBillingAddress().getAddress2(),
- city: orderDTO._dwareOrder.getBillingAddress().getCity(),
- county: orderDTO._dwareOrder.getBillingAddress().getStateCode(),
- postalCode: orderDTO._dwareOrder.currentOrder.getBillingAddress().getPostalCode(),
- country: orderDTO._dwareOrder.getBillingAddress().getCountryCode().value
- };
- }
- function getListOfProductsFromOrderDTO(orderDTO) {
- var listOfProducts = {};
- var plis = orderDTO._dwareOrder.getProductLineItems().iterator();
- while(plis.hasNext()){
- var productLineItem = plis.next();
- listOfProducts[productLineItem.getProductID()] = getProductInformationFromProductLineItem(productLineItem);
- }
- return listOfProducts;
- }
- function getProductInformationFromProductLineItem(productLineItem) {
- return {
- productID: productLineItem.getProductID(),
- productName: productLineItem.getProductName(),
- quantity: productLineItem.getQuantity().value,
- totalPrice: productLineItem.getProratedPrice().decimalValue.toString(),
- vatPercentage: productLineItem.getTaxRate()*100,
- excludingVatPrice: productLineItem.getAdjustedNetPrice().decimalValue.toString(),
- vatPrice: productLineItem.getAdjustedTax().decimalValue.toString(),
- productPromotion: getProductPromotions(productLineItem)
- }
- }
- function getOrderInformationFromOrderDTO(orderDTO) {
- var asdaVatContent = ContentMgr.getContent('ACCOUNT_SETTINGS_YOUR_ORDERS_VAT_REGISTRATION_NUMBER').custom.body;
- return {
- orderNumber:orderDTO._dwareOrder.getOrderNo(),
- orderDate: DateHelper.formatDate( new Date(orderDTO._dwareOrder.originalOrder.creationDate), 'dd/MM/YYYY'),
- invoiceDate: DateHelper.formatDate( new Date(), 'dd/MM/YYYY'),
- vatRegistrationNumber: asdaVatContent.toString().replace('The Asda VAT registration number is ', '').replace('.', '')
- }
- }
- function getOrderPromotions(orderDTO) {
- var orderPromotions = {};
- var orderPromotionsArrayList = new OrderCalculations().getOrderPromotionsText(orderDTO._dwareOrder);
- for(promotion in orderPromotionsArrayList) {
- orderPromotions[orderPromotionsArrayList[promotion]] = {
- "Name": orderPromotionsArrayList[promotion],
- "Discount": new OrderCalculations().getOrderLevelDiscounts(orderDTO._dwareOrder)
- }
- }
- return orderPromotions;
- }
- function getProductPromotions(productLineItem) {
- var productPromotions = {};
- var productPromotionsArrayList = new OrderCalculations().getLinePromotionsText(productLineItem);
- var productPriceAdjustments = productLineItem.getPriceAdjustments();
- var productAdjustmentsItr = productPriceAdjustments.iterator();
- var totalProductAdjustments = 0;
- while(productAdjustmentsItr.hasNext()) {
- var priceAdjustment = productAdjustmentsItr.next();
- totalProductAdjustments = totalProductAdjustments + priceAdjustment.grossPrice;
- }
- for(promotion in productPromotionsArrayList) {
- productPromotions[productPromotionsArrayList[promotion]] = {
- "Name": productPromotionsArrayList[promotion],
- "Discount": totalProductAdjustments
- }
- }
- return productPromotions;
- }
- module.exports.Show = guard.ensure(['get'], Show);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement