in src/libs/zuora.ts [82:203]
function zuoraBatchQueries(date: string, today: string) {
// https://knowledgecenter.zuora.com/Zuora_Central_Platform/Query/Export_ZOQL
/*
Query fields:
Subscription.Name,
Subscription.DeliveryAgent__c,
SoldToContact.Address1,
SoldToContact.Address2,
SoldToContact.City,
SoldToContact.PostalCode,
SoldToContact.FirstName,
SoldToContact.LastName,
SoldToContact.SpecialDeliveryInstructions__c,
RateplanCharge.quantity,
RatePlanCharge.name,
SoldToContact.workEmail
Headers and some values of the csv files we are aiming to generate:
Customer Reference : A-S6813425 # Subscription.Name
Delivery Reference : 41285784 # (generate randomly)
Retailer Reference : 36 # Subscription.DeliveryAgent__c
Customer Full Name : FirstName LastName # SoldToContact.FirstName, SoldToContact.LastName
Customer Address Line 1 : 15 London Road # SoldToContact.Address1
Customer Address Line 2 # SoldToContact.Address1
Customer Address Line 3 # (not defined)
Customer Town : Bristol # SoldToContact.City
Customer PostCode : SW1A 2AA # SoldToContact.PostalCode
Delivery Quantity : 1 # RateplanCharge.quantity
Delivery Information : Dark green door, post through letterbox # SoldToContact.SpecialDeliveryInstructions__c
Sent Date : 10/07/2023 # initially equal to Delivery Date, but investigate the meaning
Delivery Date : 11/07/2023 # (generate according to the contextual date)
Source campaign # reserved for future use
Additional Comms # reserved for future use
Email : luke.skywalker@theresistance.org # SoldToContact.workEmail
*/
const dayMapping = (index: number): string => {
const days = [
'Sunday',
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Saturday',
];
return days[index];
};
const dayOfTheWeekNumber = moment(date, 'YYYY-MM-DD').day();
const dayOfTheWeekName = dayMapping(dayOfTheWeekNumber);
console.log(`date ${date} maps to day ${dayOfTheWeekName}`);
const subscriptionsQuery = `
SELECT
Subscription.Name,
Subscription.DeliveryAgent__c,
SoldToContact.Address1,
SoldToContact.Address2,
SoldToContact.City,
SoldToContact.PostalCode,
SoldToContact.FirstName,
SoldToContact.LastName,
SoldToContact.SpecialDeliveryInstructions__c,
RateplanCharge.quantity,
RatePlanCharge.name,
SoldToContact.workEmail
FROM
RatePlanCharge
WHERE
(Subscription.Status = 'Active' OR Subscription.Status = 'Cancelled') AND
Product.Name = 'Newspaper - National Delivery' AND
RatePlanCharge.name = '${dayOfTheWeekName}' AND
RatePlanCharge.effectiveStartDate <= '${date}' AND
(
RatePlanCharge.effectiveEndDate > '${date}' OR
(
RatePlanCharge.EffectiveEndDate >= '${today}' AND
Subscription.Status = 'Active' AND
Subscription.AutoRenew = true AND
(RatePlan.AmendmentType IS NULL OR RatePlan.AmendmentType != 'RemoveProduct')
)
)
`;
const holidayQuery = `
SELECT
Subscription.Name
FROM
RatePlanCharge
WHERE
(Subscription.Status = 'Active' OR Subscription.Status = 'Cancelled') AND
ProductRatePlanCharge.ProductType__c = 'Adjustment' AND
RatePlanCharge.Name = 'Holiday Credit' AND
RatePlanCharge.HolidayStart__c <= '${date}' AND
RatePlanCharge.HolidayEnd__c >= '${date}' AND
RatePlan.AmendmentType != 'RemoveProduct'
`;
return {
format: 'csv',
version: '1.0',
name: `National Delivery Fulfilment @ ${date}`,
encrypted: 'none',
useQueryLabels: 'true',
dateTimeUtc: 'true',
queries: [
{
name: 'national-delivery-fulfilment-subscriptions',
query: subscriptionsQuery,
type: 'zoqlexport',
},
{
name: 'national-delivery-fulfilment-holiday-names',
query: holidayQuery,
type: 'zoqlexport',
},
],
};
}