Skip to content

Commit

Permalink
Update at_optimoroute_import.js
Browse files Browse the repository at this point in the history
  • Loading branch information
cnative100 authored Apr 9, 2023
1 parent a39139e commit 0dd272d
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions at_optimoroute_import.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let deliveryCalendarTable = base.getTable("Delivery Calendar");
let deliveryCalendarView = deliveryCalendarTable.getView("Grid view");

let subscriberResults = await subscribersView.selectRecordsAsync({fields: ['Name', 'Route', 'Segment']});
let subscriptionsResults = await subscriptionsView.selectRecordsAsync({fields: ['Subscribers','Frequency (in weeks)']});
let subscriptionsResults = await subscriptionsView.selectRecordsAsync({fields: ['Subscribers','Frequency (in weeks)', 'Share']});
let deliveryCalendarResults = await deliveryCalendarView.selectRecordsAsync({fields: ['Delivery Weekend', 'Subscribers (from Subscriptions)', 'Subscriptions']});

let optimorouteImportTable = base.getTable("Optimoroute Import");
Expand All @@ -22,7 +22,11 @@ let deliveryDates = [new Date("April 11, 2023"),
new Date("April 18, 2023"),
new Date("April 19, 2023"),
new Date("April 20, 2023"),
new Date("April 21, 2023")];
new Date("April 21, 2023"),
new Date("April 25, 2023"),
new Date("April 26, 2023"),
new Date("April 27, 2023"),
new Date("April 28, 2023")];
let driver = "Matthew Nunnally";


Expand All @@ -38,25 +42,47 @@ for(let deliveryDate of deliveryDates){
deliveryDate.toLocaleDateString('en-us', {year:"numeric", month:"long", day:"numeric"})){

let subscribers = deliveryRecord.getCellValue("Subscribers (from Subscriptions)");
let subscriptions = deliveryRecord.getCellValue("Subscriptions");
let subscriberIdSet = new Set();

let subscriptionsIdSet = new Set();

// Add the IDs to a set, because there will be multiple entries for the same
// subscriber on a given delivery date
for(let subscriber of subscribers){
subscriberIdSet.add(subscriber.id);
}

for(let subscription of subscriptions){
subscriptionsIdSet.add(subscription.id);
}

for(let subscriberId of subscriberIdSet){
let subscriberDetails = await subscribersView.selectRecordAsync(subscriberId);

if(subscriberDetails && subscriberDetails.getCellValueAsString("Reserved") == "Yes"){
let subscriptionsDelivered = "";
for(let subscriptionId of subscriptionsIdSet){
let subscriptionDetails = await subscriptionsView.selectRecordAsync(subscriptionId);

if(subscriptionDetails && subscriptionDetails.getCellValue("Subscribers") &&
subscriptionDetails.getCellValueAsString("Subscribers") == subscriberDetails.getCellValueAsString("Name")){
subscriptionsDelivered = subscriptionsDelivered.concat(subscriptionDetails.getCellValueAsString("Share"))
.concat(" (")
.concat(subscriptionDetails.getCellValueAsString("Number of Shares"))
.concat(" shares)")
.concat(", ");
}
}

let newDeliveryID = await optimorouteImportTable.createRecordAsync({
"Customer": subscriberDetails.getCellValueAsString("Name"),
"Address": subscriberDetails.getCellValueAsString("Delivery Address"),
"Assigned to Driver": driver,
"Email": subscriberDetails.getCellValueAsString("Email"),
"Phone": subscriberDetails.getCellValueAsString("Cell Phone"),
"Date": deliveryDate,
"Duration": 2
"Duration": 2,
"Notes": subscriptionsDelivered.substring(0,subscriptionsDelivered.length-2)
});

}
Expand Down

0 comments on commit 0dd272d

Please sign in to comment.