<commit_before>Router.configure({
  layoutTemplate: "layout"
});

Meteor.startup(function () {
  if (Meteor.isClient) {
    var location = Iron.Location.get();
    if (location.queryObject.platformOverride) {
      Session.set("platformOverride", location.queryObject.platformOverride);
    }
  }
});

Router.map(function() {
  this.route("home", {
    path: "/"
  });
  this.route("/about/", {
    name: "about"
  });
  this.route("/householdList/", {
    name: "householdList",
    fastRender: true
  });
  this.route("/memberList/", {
    name: "memberList",
    waitOn: function () {
      return [
        Meteor.subscribe("memberPublication"),
        Meteor.subscribe("userPublication")
      ]
    },
    data: function() {
      return {
        memberData: memberCollection.find({})
      };
    },
    fastRender: true
  });
  this.route("/memberSelect/", {
    name: "memberSelect",
    waitOn: function () {
      return [
        Meteor.subscribe("memberPublication"),
        Meteor.subscribe("userPublication")
      ]
    },
    fastRender: true
  });
  this.route("/member/:individualId", {
    name: "member",
    waitOn: function () {
      return [
        Meteor.subscribe("memberPublication"),
        Meteor.subscribe("householdPublication")
      ]
    },
    data: function() {

      var selector = {$or: [
        {"headOfHouse.individualId": parseInt(this.params.individualId)},
        {"spouse.individualId": parseInt(this.params.individualId)},
        {"children.individualId": parseInt(this.params.individualId)}
      ]};

      return {
        memberData: memberCollection.findOne({individualId: parseInt(this.params.individualId)}),
        householdData: householdCollection.findOne(selector)
      };
    },
    fastRender: true
  });
  this.route("/callingSelect/", {
    name: "callingSelect",
    waitOn: function () {
      return Meteor.subscribe("callingPublication")
    },
    fastRender: true
  });
  this.route("/callingGroupList/", {
    name: "callingGroupList",
    waitOn: function () {
      return Meteor.subscribe("callingGroupPublication")
    },
    data: function() {
      return {
        callingData: callingGroupCollection.find({})
      };
    },
    fastRender: true
  });
  this.route("/callingGroup/:_id", {
    name: "callingGroup",
    waitOn: function () {
      return Meteor.subscribe("callingGroupPublication")
    },
    data: function() {
      return {
        callingData: callingGroupCollection.findOne(this.params._id)
      };
    },
    fastRender: true
  });
  this.route("/callingChangeList/", {
    name: "callingChangeList",
    waitOn: function () {
      return Meteor.subscribe("callingChangePublication")
    },
    fastRender: true
  });
  this.route("/callingChangeCreate/", {
    name: "callingChangeCreate",
    waitOn: function () {
      return [
        Meteor.subscribe("callingChangePublication"),
        Meteor.subscribe("userPublication")
      ]
    },
    fastRender: true
  });
  this.route("/callingChangeEdit/:_id", {
    name: "callingChangeEdit",
    waitOn: function () {
      return [
        Meteor.subscribe("callingChangePublication"),
        Meteor.subscribe("meetingPublication"),
        Meteor.subscribe("userPublication")
      ]
    },
    data: function() {
      return {
        callingChangeData: callingChangeCollection.findOne(this.params._id)
      };
    },
    fastRender: true
  });
  this.route("/callingChangeTypeSelect/", {
    name: "callingChangeTypeSelect",
    fastRender: true
  });
  this.route("/meetingList/", {
    name: "meetingList",
    waitOn: function () {
      return Meteor.subscribe("meetingPublication")
    },
    data: function() {
      return {
        meetingData: meetingCollection.find({}, {sort: {meetingDate: -1}})
      };
    },
    fastRender: true
  });
  this.route("/meetingCreate/", {
    name: "meetingCreate",
    waitOn: function () {
      return [
        Meteor.subscribe("meetingPublication"),
        Meteor.subscribe("userPublication")
      ]
    },
  });
  this.route("/meetingEdit/:_id", {
    name: "meetingEdit",
    waitOn: function () {
      return [
        Meteor.subscribe("meetingPublication"),
        Meteor.subscribe("musicalNumberPublication"),
        Meteor.subscribe("intermediateHymnPublication"),
        Meteor.subscribe("announcementPublication"),
        Meteor.subscribe("speakerPublication"),
        Meteor.subscribe("recognitionPublication"),
        Meteor.subscribe("callingChangePublication"),
        Meteor.subscribe("userPublication")
      ]
    },
    data: function() {
      //console.log(this.params._id);
      //console.log(callingChangeCollection.find({"meeting._id": this.params._id}).fetch());
      return {
        meetingData: meetingCollection.findOne(this.params._id),
        musicalNumberData: musicalNumberCollection.find({meetingId: this.params._id}),
        intermediateHymnData: intermediateHymnCollection.find({meetingId: this.params._id}),
        announcementData: announcementCollection.find({meetingId: this.params._id}),
        speakerData: speakerCollection.find({meetingId: this.params._id}),
        recognitionData: recognitionCollection.find({meetingId: this.params._id}),
        callingChangeData: callingChangeCollection.find({"meeting._id": this.params._id}, {sort: {type: -1}})
      };
    },
    fastRender: true
  });
  this.route("/meetingSelect/", {
    name: "meetingSelect",
    waitOn: function () {
      return Meteor.subscribe("meetingPublication")
    },
    data: function() {
      return {
        meetingData: meetingCollection.find({})
      };
    },
    fastRender: true
  });
  this.route("/hymnSelect/", {
    name: "hymnSelect",
    waitOn: function () {
      return Meteor.subscribe("hymnPublication")
    },
    fastRender: true
  });
  this.route("/attendanceSelect/", {
    name: "attendanceSelect",
    fastRender: true
  });
  this.route("/recognitionTypeSelect/", {
    name: "recognitionTypeSelect",
    waitOn: function () {
      return Meteor.subscribe("recognitionTypePublication")
    },
    data: function() {
      return {
        recognitionTypeData: recognitionTypeCollection.find({})
      };
    },
    fastRender: true
  });
  this.route("/sync/", {
    name: "sync",
    waitOn: function () {
      return [
        Meteor.subscribe("userPublication"),
        Meteor.subscribe("memberPublication"),
        Meteor.subscribe("stakeCallingPublication"),
        Meteor.subscribe("reportPublication")
      ]
    },
    fastRender: true
  });
  this.route("userAccounts");
  this.route("/meetingPrint/:_id", function() {

    meeting = meetingCollection.findOne(this.params._id);

    //meetingDateFormatted = moment(meeting.title).tz("Etc/GMT").format("YYYY-MM-DD");
    meetingDateFormatted = meeting.meetingDate;
    releaseResultArray = callingChangeCollection.find({"meeting._id" : this.params._id, type: "Release"}).fetch();
    callingResultArray = callingChangeCollection.find({"meeting._id" : this.params._id, type: "Call"}).fetch();
    intermediateHymnArray = intermediateHymnCollection.find({meetingId : this.params._id}).fetch();
    musicalNumberArray = musicalNumberCollection.find({meetingId : this.params._id}).fetch();
    announcementArray = announcementCollection.find({meetingId : this.params._id}).fetch();
    speakerArray = speakerCollection.find({meetingId : this.params._id}).fetch();
    recognitionArray = recognitionCollection.find({meetingId : this.params._id}).fetch();

    var doc = new PDFDocument({size: "A4", margin: 50});

    var pageWidth = 520;
    var halfPageWidth = pageWidth / 2;
    var labelColumnWidth = 70;
    var distanceFromTop = 40;
    var distanceFromLeft1 = 40;
    var distanceFromLeft2 = distanceFromLeft1 + labelColumnWidth;
    var distanceFromLeft3 = distanceFromLeft2 + 40;
    var distanceFromLeft4 = distanceFromLeft1 + halfPageWidth;
    var distanceFromLeft5 = distanceFromLeft4 + labelColumnWidth;
    var verticalPositionIncrement = 14;

    doc.fontSize(16);
    doc.text("Sacrament Meeting Agenda", distanceFromLeft1, distanceFromTop, {align: "center", width: pageWidth});
    distanceFromTop += verticalPositionIncrement+10;

    doc.fontSize(12);
    doc.text(moment(meeting.meetingDate).format("dddd, MMMM Do YYYY"), distanceFromLeft1, distanceFromTop, {align: "center", width: pageWidth});
    distanceFromTop += verticalPositionIncrement+10;

    doc.text("Conducting: ___________________________", distanceFromLeft1, distanceFromTop, {align: "left", width: halfPageWidth});
    if (typeof meeting.conducting.switchedPreferredName != "undefined") {
      doc.text(meeting.conducting.switchedPreferredName, distanceFromLeft2, distanceFromTop, {align: "left", width: halfPageWidth});
    }
    doc.text("Presiding: _____________________________", distanceFromLeft4, distanceFromTop, {align: "left", width: halfPageWidth});
    if (typeof meeting.presiding.switchedPreferredName != "undefined") {
      doc.text(meeting.presiding.switchedPreferredName, distanceFromLeft5, distanceFromTop, {align: "left", width: halfPageWidth});
    }
    distanceFromTop += verticalPositionIncrement;

    doc.text("Chorister: _____________________________", distanceFromLeft1, distanceFromTop, {align: "left", width: halfPageWidth});
    if (typeof meeting.chorister.switchedPreferredName != "undefined") {
      doc.text(meeting.chorister.switchedPreferredName, distanceFromLeft2, distanceFromTop, {align: "left", width: halfPageWidth});
    }
    doc.text("Organist: ______________________________", distanceFromLeft4, distanceFromTop, {align: "left", width: halfPageWidth});
    if (typeof meeting.organist.switchedPreferredName != "undefined") {
      doc.text(meeting.organist.switchedPreferredName, distanceFromLeft5, distanceFromTop, {align: "left", width: halfPageWidth});
    }
    distanceFromTop += verticalPositionIncrement;

    doc.text("Visiting Authorities: _____________________________________________________________", distanceFromLeft1, distanceFromTop, {align: "left", width: pageWidth});
    if (typeof meeting.visitingAuthority.switchedPreferredName != "undefined") {
      doc.text(meeting.visitingAuthority.switchedPreferredName, distanceFromLeft3, distanceFromTop, {align: "left", width: pageWidth});
    }
    distanceFromTop += verticalPositionIncrement;

    doc.text("Welcome Visitors", distanceFromLeft1, distanceFromTop, {align: "left", width: pageWidth});
    distanceFromTop += verticalPositionIncrement;

    doc.text("Announcements: _______________________________________________________________", distanceFromLeft1, distanceFromTop, {align: "left", width: pageWidth});
    distanceFromTop += verticalPositionIncrement;

    if (typeof announcementArray != "undefined") {
      for(var announcementIndex in announcementArray) {
        doc.text(announcementArray[announcementIndex].text, distanceFromLeft1, distanceFromTop, {align: "left", width: pageWidth});
        doc.text("_____________________________________________________________________________", distanceFromLeft1, distanceFromTop, {align: "left", width: pageWidth});
        distanceFromTop += verticalPositionIncrement;
      }
    }
    doc.text("_____________________________________________________________________________", distanceFromLeft1, distanceFromTop, {align: "left", width: pageWidth});
    distanceFromTop += verticalPositionIncrement;

    doc.text("Opening Hymn: ________________________________________________________________", distanceFromLeft1, distanceFromTop, {align: "left", width: pageWidth});
    if (typeof meeting.openingHymn.name != "undefined") {
      doc.text(meeting.openingHymn.number + " - " + meeting.openingHymn.name, distanceFromLeft3, distanceFromTop, {align: "left", width: pageWidth});
    }
    distanceFromTop += verticalPositionIncrement;

    doc.text("Invocation: ____________________________________________________________________", distanceFromLeft1, distanceFromTop, {align: "left", width: pageWidth});
    if (typeof meeting.invocation.switchedPreferredName != "undefined") {
      doc.text(meeting.invocation.switchedPreferredName, distanceFromLeft3, distanceFromTop, {align: "left", width: pageWidth});
    }
    distanceFromTop += verticalPositionIncrement;

    doc.fontSize(14);
    distanceFromTop += 5;
    doc.text("Ward and Stake Business", distanceFromLeft1, distanceFromTop, {align: "left", width: pageWidth});
    distanceFromTop += verticalPositionIncrement+5;
    doc.fontSize(12);

    if (releaseResultArray.length > 0) {
      doc.text('Releases: "We have released the following individuals."', distanceFromLeft1, distanceFromTop, {align: "left", width: pageWidth});
      distanceFromTop += verticalPositionIncrement;

      for(var releaseResultIndex in releaseResultArray) {
        doc.text("_____________________________________________________________________________", distanceFromLeft1, distanceFromTop, {align: "left", width: pageWidth});
        doc.text(releaseResultArray[releaseResultIndex].member.switchedPreferredName, distanceFromLeft1, distanceFromTop, {align: "left", width: pageWidth});
        doc.text(releaseResultArray[releaseResultIndex].calling.callingName, distanceFromLeft4, distanceFromTop, {align: "left", width: pageWidth});
        distanceFromTop += verticalPositionIncrement;
      }

      doc.text('"We propose that they be given a vote of thanks for their service. Those who wish to express appreciation may manifest it by the uplifted hand."', distanceFromLeft1, distanceFromTop, {align: "left", width: pageWidth});
      distanceFromTop += verticalPositionIncrement;
      distanceFromTop += verticalPositionIncrement;
    }

    if (callingResultArray.length > 0) {
      doc.text('Sustainings: "The following people have been called and we propose that they be sustained."', distanceFromLeft1, distanceFromTop, {align: "left", width: pageWidth});
      distanceFromTop += verticalPositionIncrement;

      for(var callingResultIndex in callingResultArray) {
        doc.text("____________________________________________________________________________", distanceFromLeft1, distanceFromTop, {align: "left", width: pageWidth});
        doc.text(callingResultArray[callingResultIndex].member.switchedPreferredName, distanceFromLeft1, distanceFromTop, {align: "left", width: pageWidth});
        doc.text(callingResultArray[callingResultIndex].calling.callingName, distanceFromLeft4, distanceFromTop, {align: "left", width: pageWidth});
        distanceFromTop += verticalPositionIncrement;
      }

      doc.text('"Those in favor may manifest it by the uplifted hand.  Those opposed, if any, may manifest it.  We invite those sustained to come to the Bishop’s office immediately after the block to be set apart."', distanceFromLeft1, distanceFromTop, {align: "left", width: pageWidth});
      distanceFromTop += verticalPositionIncrement;
      distanceFromTop += verticalPositionIncrement;
    }

    doc.text("Ordinances and Recognitions: ____________________________________________________", distanceFromLeft1, distanceFromTop, {align: "left", width: pageWidth});
    distanceFromTop += verticalPositionIncrement;

    if (typeof recognitionArray != "undefined") {
      for(var recognitionIndex in recognitionArray) {
        doc.text(recognitionArray[recognitionIndex].recognitionType.typeName, distanceFromLeft1, distanceFromTop, {align: "left", width: pageWidth});
        doc.text(recognitionArray[recognitionIndex].member.switchedPreferredName, distanceFromLeft4, distanceFromTop, {align: "left", width: pageWidth});
        doc.text("_____________________________________________________________________________", distanceFromLeft1, distanceFromTop, {align: "left", width: pageWidth});
        distanceFromTop += verticalPositionIncrement;
      }
    }

    doc.fontSize(14);
    distanceFromTop += 5;
    doc.text("Sacrament", distanceFromLeft1, distanceFromTop, {align: "left", width: pageWidth});
    distanceFromTop += verticalPositionIncrement+5;
    doc.fontSize(12);

    doc.text("Sacrament Hymn: ______________________________________________________________", distanceFromLeft1, distanceFromTop, {align: "left", width: pageWidth});
    if (typeof meeting.sacramentHymn.name != "undefined") {
      doc.text(meeting.sacramentHymn.number + " - " + meeting.sacramentHymn.name, distanceFromLeft3, distanceFromTop, {align: "left", width: pageWidth});
    }
    distanceFromTop += verticalPositionIncrement;

    doc.text("Administration of the Sacrament", distanceFromLeft1, distanceFromTop, {align: "left", width: pageWidth});
    distanceFromTop += verticalPositionIncrement;

    doc.text('"We thank you for your reverence during the sacrament, and we thank the Priesthood for administering it."', distanceFromLeft1, distanceFromTop, {align: "left", width: pageWidth});
    distanceFromTop += verticalPositionIncrement;
    distanceFromTop += verticalPositionIncrement;

    doc.fontSize(14);
    distanceFromTop += 5;
    doc.text("Program", distanceFromLeft1, distanceFromTop, {align: "left", width: pageWidth});
    distanceFromTop += verticalPositionIncrement+5;
    doc.fontSize(12);

    if (typeof speakerArray != "undefined") {
      for(var speakerIndex in speakerArray) {
        doc.text(speakerArray[speakerIndex].speaker.switchedPreferredName, distanceFromLeft3, distanceFromTop, {align: "left", width: pageWidth});
        doc.text("Speaker: _____________________________________________________________________", distanceFromLeft1, distanceFromTop, {align: "left", width: pageWidth});
        distanceFromTop += verticalPositionIncrement;

        for(var intermediateHymnIndex in intermediateHymnArray) {
          if ((intermediateHymnArray[intermediateHymnIndex].afterSpeaker - 1) == speakerIndex) {
            doc.text("Intermediate Hymn: _____________________________________________________________", distanceFromLeft1, distanceFromTop, {align: "left", width: pageWidth});
            if (intermediateHymnArray[intermediateHymnIndex].hymn.number) {
              doc.text(intermediateHymnArray[intermediateHymnIndex].hymn.number + " - " + intermediateHymnArray[intermediateHymnIndex].hymn.name, distanceFromLeft3, distanceFromTop, {align: "left", width: pageWidth});
            } else {
              doc.text(intermediateHymnArray[intermediateHymnIndex].hymn.name, distanceFromLeft3, distanceFromTop, {align: "left", width: pageWidth});
            }
            distanceFromTop += verticalPositionIncrement;
          }
        }
        for(var musicalNumberIndex in musicalNumberArray) {
          if ((musicalNumberArray[musicalNumberIndex].afterSpeaker - 1) == speakerIndex) {
            doc.text("Musical Number", distanceFromLeft1, distanceFromTop, {align: "left", width: pageWidth});
            distanceFromTop += verticalPositionIncrement;
            doc.text("Song: ________________________________________________________________________", distanceFromLeft1, distanceFromTop, {align: "left", width: pageWidth});
            if (musicalNumberArray[musicalNumberIndex].hymn.number) {
              doc.text(musicalNumberArray[musicalNumberIndex].hymn.number + " - " + musicalNumberArray[musicalNumberIndex].hymn.name, distanceFromLeft3, distanceFromTop, {align: "left", width: pageWidth});
            } else {
              doc.text(musicalNumberArray[musicalNumberIndex].hymn.name, distanceFromLeft3, distanceFromTop, {align: "left", width: pageWidth});<commit_msg>small formatting fixes<commit_after>Router.configure({
  layoutTemplate: "layout"
});

Meteor.startup(function () {
  if (Meteor.isClient) {
    var location = Iron.Location.get();
    if (location.queryObject.platformOverride) {
      Session.set("platformOverride", location.queryObject.platformOverride);
    }
  }
});

Router.map(function() {
  this.route("home", {
    path: "/"
  });
  this.route("/about/", {
    name: "about"
  });
  this.route("/householdList/", {
    name: "householdList",
    fastRender: true
  });
  this.route("/memberList/", {
    name: "memberList",
    waitOn: function () {
      return [
        Meteor.subscribe("memberPublication"),
        Meteor.subscribe("userPublication")
      ]
    },
    data: function() {
      return {
        memberData: memberCollection.find({})
      };
    },
    fastRender: true
  });
  this.route("/memberSelect/", {
    name: "memberSelect",
    waitOn: function () {
      return [
        Meteor.subscribe("memberPublication"),
        Meteor.subscribe("userPublication")
      ]
    },
    fastRender: true
  });
  this.route("/member/:individualId", {
    name: "member",
    waitOn: function () {
      return [
        Meteor.subscribe("memberPublication"),
        Meteor.subscribe("householdPublication")
      ]
    },
    data: function() {

      var selector = {$or: [
        {"headOfHouse.individualId": parseInt(this.params.individualId)},
        {"spouse.individualId": parseInt(this.params.individualId)},
        {"children.individualId": parseInt(this.params.individualId)}
      ]};

      return {
        memberData: memberCollection.findOne({individualId: parseInt(this.params.individualId)}),
        householdData: householdCollection.findOne(selector)
      };
    },
    fastRender: true
  });
  this.route("/callingSelect/", {
    name: "callingSelect",
    waitOn: function () {
      return Meteor.subscribe("callingPublication")
    },
    fastRender: true
  });
  this.route("/callingGroupList/", {
    name: "callingGroupList",
    waitOn: function () {
      return Meteor.subscribe("callingGroupPublication")
    },
    data: function() {
      return {
        callingData: callingGroupCollection.find({})
      };
    },
    fastRender: true
  });
  this.route("/callingGroup/:_id", {
    name: "callingGroup",
    waitOn: function () {
      return Meteor.subscribe("callingGroupPublication")
    },
    data: function() {
      return {
        callingData: callingGroupCollection.findOne(this.params._id)
      };
    },
    fastRender: true
  });
  this.route("/callingChangeList/", {
    name: "callingChangeList",
    waitOn: function () {
      return Meteor.subscribe("callingChangePublication")
    },
    fastRender: true
  });
  this.route("/callingChangeCreate/", {
    name: "callingChangeCreate",
    waitOn: function () {
      return [
        Meteor.subscribe("callingChangePublication"),
        Meteor.subscribe("userPublication")
      ]
    },
    fastRender: true
  });
  this.route("/callingChangeEdit/:_id", {
    name: "callingChangeEdit",
    waitOn: function () {
      return [
        Meteor.subscribe("callingChangePublication"),
        Meteor.subscribe("meetingPublication"),
        Meteor.subscribe("userPublication")
      ]
    },
    data: function() {
      return {
        callingChangeData: callingChangeCollection.findOne(this.params._id)
      };
    },
    fastRender: true
  });
  this.route("/callingChangeTypeSelect/", {
    name: "callingChangeTypeSelect",
    fastRender: true
  });
  this.route("/meetingList/", {
    name: "meetingList",
    waitOn: function () {
      return Meteor.subscribe("meetingPublication")
    },
    data: function() {
      return {
        meetingData: meetingCollection.find({}, {sort: {meetingDate: -1}})
      };
    },
    fastRender: true
  });
  this.route("/meetingCreate/", {
    name: "meetingCreate",
    waitOn: function () {
      return [
        Meteor.subscribe("meetingPublication"),
        Meteor.subscribe("userPublication")
      ]
    },
  });
  this.route("/meetingEdit/:_id", {
    name: "meetingEdit",
    waitOn: function () {
      return [
        Meteor.subscribe("meetingPublication"),
        Meteor.subscribe("musicalNumberPublication"),
        Meteor.subscribe("intermediateHymnPublication"),
        Meteor.subscribe("announcementPublication"),
        Meteor.subscribe("speakerPublication"),
        Meteor.subscribe("recognitionPublication"),
        Meteor.subscribe("callingChangePublication"),
        Meteor.subscribe("userPublication")
      ]
    },
    data: function() {
      //console.log(this.params._id);
      //console.log(callingChangeCollection.find({"meeting._id": this.params._id}).fetch());
      return {
        meetingData: meetingCollection.findOne(this.params._id),
        musicalNumberData: musicalNumberCollection.find({meetingId: this.params._id}),
        intermediateHymnData: intermediateHymnCollection.find({meetingId: this.params._id}),
        announcementData: announcementCollection.find({meetingId: this.params._id}),
        speakerData: speakerCollection.find({meetingId: this.params._id}),
        recognitionData: recognitionCollection.find({meetingId: this.params._id}),
        callingChangeData: callingChangeCollection.find({"meeting._id": this.params._id}, {sort: {type: -1}})
      };
    },
    fastRender: true
  });
  this.route("/meetingSelect/", {
    name: "meetingSelect",
    waitOn: function () {
      return Meteor.subscribe("meetingPublication")
    },
    data: function() {
      return {
        meetingData: meetingCollection.find({})
      };
    },
    fastRender: true
  });
  this.route("/hymnSelect/", {
    name: "hymnSelect",
    waitOn: function () {
      return Meteor.subscribe("hymnPublication")
    },
    fastRender: true
  });
  this.route("/attendanceSelect/", {
    name: "attendanceSelect",
    fastRender: true
  });
  this.route("/recognitionTypeSelect/", {
    name: "recognitionTypeSelect",
    waitOn: function () {
      return Meteor.subscribe("recognitionTypePublication")
    },
    data: function() {
      return {
        recognitionTypeData: recognitionTypeCollection.find({})
      };
    },
    fastRender: true
  });
  this.route("/sync/", {
    name: "sync",
    waitOn: function () {
      return [
        Meteor.subscribe("userPublication"),
        Meteor.subscribe("memberPublication"),
        Meteor.subscribe("stakeCallingPublication"),
        Meteor.subscribe("reportPublication")
      ]
    },
    fastRender: true
  });
  this.route("userAccounts");
  this.route("/meetingPrint/:_id", function() {

    meeting = meetingCollection.findOne(this.params._id);

    //meetingDateFormatted = moment(meeting.title).tz("Etc/GMT").format("YYYY-MM-DD");
    meetingDateFormatted = meeting.meetingDate;
    releaseResultArray = callingChangeCollection.find({"meeting._id" : this.params._id, type: "Release"}).fetch();
    callingResultArray = callingChangeCollection.find({"meeting._id" : this.params._id, type: "Call"}).fetch();
    intermediateHymnArray = intermediateHymnCollection.find({meetingId : this.params._id}).fetch();
    musicalNumberArray = musicalNumberCollection.find({meetingId : this.params._id}).fetch();
    announcementArray = announcementCollection.find({meetingId : this.params._id}).fetch();
    speakerArray = speakerCollection.find({meetingId : this.params._id}).fetch();
    recognitionArray = recognitionCollection.find({meetingId : this.params._id}).fetch();

    var doc = new PDFDocument({size: "A4", margin: 50});

    var pageWidth = 520;
    var halfPageWidth = pageWidth / 2;
    var labelColumnWidth = 70;
    var distanceFromTop = 40;
    var distanceFromLeft1 = 40;
    var distanceFromLeft2 = distanceFromLeft1 + labelColumnWidth;
    var distanceFromLeft3 = distanceFromLeft2 + 40;
    var distanceFromLeft4 = distanceFromLeft1 + halfPageWidth;
    var distanceFromLeft5 = distanceFromLeft4 + labelColumnWidth;
    var verticalPositionIncrement = 14;

    doc.fontSize(16);
    doc.text("Sacrament Meeting Agenda", distanceFromLeft1, distanceFromTop, {align: "center", width: pageWidth});
    distanceFromTop += verticalPositionIncrement+10;

    doc.fontSize(12);
    doc.text(moment(meeting.meetingDate).format("dddd, MMMM Do YYYY"), distanceFromLeft1, distanceFromTop, {align: "center", width: pageWidth});
    distanceFromTop += verticalPositionIncrement+10;

    doc.text("Conducting: ___________________________", distanceFromLeft1, distanceFromTop, {align: "left", width: halfPageWidth});
    if (typeof meeting.conducting.switchedPreferredName != "undefined") {
      doc.text(meeting.conducting.switchedPreferredName, distanceFromLeft2, distanceFromTop, {align: "left", width: halfPageWidth});
    }
    doc.text("Presiding: _____________________________", distanceFromLeft4, distanceFromTop, {align: "left", width: halfPageWidth});
    if (typeof meeting.presiding.switchedPreferredName != "undefined") {
      doc.text(meeting.presiding.switchedPreferredName, distanceFromLeft5, distanceFromTop, {align: "left", width: halfPageWidth});
    }
    distanceFromTop += verticalPositionIncrement;

    doc.text("Chorister: _____________________________", distanceFromLeft1, distanceFromTop, {align: "left", width: halfPageWidth});
    if (typeof meeting.chorister.switchedPreferredName != "undefined") {
      doc.text(meeting.chorister.switchedPreferredName, distanceFromLeft2, distanceFromTop, {align: "left", width: halfPageWidth});
    }
    doc.text("Organist: ______________________________", distanceFromLeft4, distanceFromTop, {align: "left", width: halfPageWidth});
    if (typeof meeting.organist.switchedPreferredName != "undefined") {
      doc.text(meeting.organist.switchedPreferredName, distanceFromLeft5, distanceFromTop, {align: "left", width: halfPageWidth});
    }
    distanceFromTop += verticalPositionIncrement;

    doc.text("Visiting Authorities: _____________________________________________________________", distanceFromLeft1, distanceFromTop, {align: "left", width: pageWidth});
    if (typeof meeting.visitingAuthority.switchedPreferredName != "undefined") {
      doc.text(meeting.visitingAuthority.switchedPreferredName, distanceFromLeft3, distanceFromTop, {align: "left", width: pageWidth});
    }
    distanceFromTop += verticalPositionIncrement;

    doc.text("Welcome Visitors", distanceFromLeft1, distanceFromTop, {align: "left", width: pageWidth});
    distanceFromTop += verticalPositionIncrement;

    doc.text("Announcements: _______________________________________________________________", distanceFromLeft1, distanceFromTop, {align: "left", width: pageWidth});
    distanceFromTop += verticalPositionIncrement;

    if (typeof announcementArray != "undefined") {
      for(var announcementIndex in announcementArray) {
        doc.text(announcementArray[announcementIndex].text, distanceFromLeft1, distanceFromTop, {align: "left", width: pageWidth});
        doc.text("_____________________________________________________________________________", distanceFromLeft1, distanceFromTop, {align: "left", width: pageWidth});
        distanceFromTop += verticalPositionIncrement;
      }
    }
    doc.text("_____________________________________________________________________________", distanceFromLeft1, distanceFromTop, {align: "left", width: pageWidth});
    distanceFromTop += verticalPositionIncrement;

    doc.text("Opening Hymn: ________________________________________________________________", distanceFromLeft1, distanceFromTop, {align: "left", width: pageWidth});
    if (typeof meeting.openingHymn.name != "undefined") {
      doc.text(meeting.openingHymn.number + " - " + meeting.openingHymn.name, distanceFromLeft3, distanceFromTop, {align: "left", width: pageWidth});
    }
    distanceFromTop += verticalPositionIncrement;

    doc.text("Invocation: ____________________________________________________________________", distanceFromLeft1, distanceFromTop, {align: "left", width: pageWidth});
    if (typeof meeting.invocation.switchedPreferredName != "undefined") {
      doc.text(meeting.invocation.switchedPreferredName, distanceFromLeft3, distanceFromTop, {align: "left", width: pageWidth});
    }
    distanceFromTop += verticalPositionIncrement;

    doc.fontSize(14);
    distanceFromTop += 5;
    doc.text("Ward and Stake Business", distanceFromLeft1, distanceFromTop, {align: "left", width: pageWidth});
    distanceFromTop += verticalPositionIncrement+5;
    doc.fontSize(12);

    if (releaseResultArray.length > 0) {
      doc.text('Releases: "We have released the following individuals."', distanceFromLeft1, distanceFromTop, {align: "left", width: pageWidth});
      distanceFromTop += verticalPositionIncrement;

      for(var releaseResultIndex in releaseResultArray) {
        doc.text("_____________________________________________________________________________", distanceFromLeft1, distanceFromTop, {align: "left", width: pageWidth});
        doc.text(releaseResultArray[releaseResultIndex].member.switchedPreferredName, distanceFromLeft1, distanceFromTop, {align: "left", width: pageWidth});
        doc.text(releaseResultArray[releaseResultIndex].calling.callingName, distanceFromLeft4, distanceFromTop, {align: "left", width: pageWidth});
        distanceFromTop += verticalPositionIncrement;
      }

      doc.text('"We propose that they be given a vote of thanks for their service. Those who wish to express appreciation may manifest it by the uplifted hand."', distanceFromLeft1, distanceFromTop, {align: "left", width: pageWidth});
      distanceFromTop += verticalPositionIncrement;
      distanceFromTop += verticalPositionIncrement;
    }

    if (callingResultArray.length > 0) {
      doc.text('Sustainings: "The following people have been called and we propose that they be sustained."', distanceFromLeft1, distanceFromTop, {align: "left", width: pageWidth});
      distanceFromTop += verticalPositionIncrement;

      for(var callingResultIndex in callingResultArray) {
        doc.text("____________________________________________________________________________", distanceFromLeft1, distanceFromTop, {align: "left", width: pageWidth});
        doc.text(callingResultArray[callingResultIndex].member.switchedPreferredName, distanceFromLeft1, distanceFromTop, {align: "left", width: pageWidth});
        doc.text(callingResultArray[callingResultIndex].calling.callingName, distanceFromLeft4, distanceFromTop, {align: "left", width: pageWidth});
        distanceFromTop += verticalPositionIncrement;
      }

      doc.text('"Those in favor may manifest it by the uplifted hand.  Those opposed, if any, may manifest it.  We invite those sustained to come to the Bishop’s office immediately after the block to be set apart."', distanceFromLeft1, distanceFromTop, {align: "left", width: pageWidth});
      distanceFromTop += verticalPositionIncrement;
      distanceFromTop += verticalPositionIncrement;
    }

    if (recognitionArray.length > 0) {
      doc.text("Ordinances and Recognitions", distanceFromLeft1, distanceFromTop, {align: "left", width: pageWidth});
      distanceFromTop += verticalPositionIncrement;

      if (typeof recognitionArray != "undefined") {
        for(var recognitionIndex in recognitionArray) {
          doc.text(recognitionArray[recognitionIndex].recognitionType.typeName, distanceFromLeft1, distanceFromTop, {align: "left", width: pageWidth});
          doc.text(recognitionArray[recognitionIndex].member.switchedPreferredName, distanceFromLeft4, distanceFromTop, {align: "left", width: pageWidth});
          doc.text("_____________________________________________________________________________", distanceFromLeft1, distanceFromTop, {align: "left", width: pageWidth});
          distanceFromTop += verticalPositionIncrement;
        }
      }
    }

    doc.fontSize(14);
    distanceFromTop += 5;
    doc.text("Sacrament", distanceFromLeft1, distanceFromTop, {align: "left", width: pageWidth});
    distanceFromTop += verticalPositionIncrement+5;
    doc.fontSize(12);

    doc.text("Sacrament Hymn: ______________________________________________________________", distanceFromLeft1, distanceFromTop, {align: "left", width: pageWidth});
    if (typeof meeting.sacramentHymn.name != "undefined") {
      doc.text(meeting.sacramentHymn.number + " - " + meeting.sacramentHymn.name, distanceFromLeft3, distanceFromTop, {align: "left", width: pageWidth});
    }
    distanceFromTop += verticalPositionIncrement;

    doc.text("Administration of the Sacrament", distanceFromLeft1, distanceFromTop, {align: "left", width: pageWidth});
    distanceFromTop += verticalPositionIncrement;

    doc.text('"We thank you for your reverence during the sacrament, and we thank the Priesthood for administering it."', distanceFromLeft1, distanceFromTop, {align: "left", width: pageWidth});
    distanceFromTop += verticalPositionIncrement;
    distanceFromTop += verticalPositionIncrement;

    doc.fontSize(14);
    distanceFromTop += 5;
    doc.text("Gospel Messages, Testimonies, and Music", distanceFromLeft1, distanceFromTop, {align: "left", width: pageWidth});
    distanceFromTop += verticalPositionIncrement+5;
    doc.fontSize(12);

    if (meeting.fastAndTestimony) {
      doc.text("Bear own testimony then turn time over to members of congregation to bear testimonies.", distanceFromLeft1, distanceFromTop, {align: "left", width: pageWidth});
      distanceFromTop += verticalPositionIncrement;
      doc.text('"We will end at X minutes after the hour."', distanceFromLeft1, distanceFromTop, {align: "left", width: pageWidth});
      distanceFromTop += verticalPositionIncrement;
    }

    if (typeof speakerArray != "undefined") {
      for(var speakerIndex in speakerArray) {
        doc.text(speakerArray[speakerIndex].speaker.switchedPreferredName, distanceFromLeft3, distanceFromTop, {align: "left", width: pageWidth});
        doc.text("Speaker: _____________________________________________________________________", distanceFromLeft1, distanceFromTop, {align: "left", width: pageWidth});
        distanceFromTop += verticalPositionIncrement;

        for(var intermediateHymnIndex in intermediateHymnArray) {
          if ((intermediateHymnArray[intermediateHymnIndex].afterSpeaker - 1) == speakerIndex) {
            doc.text("Intermediate Hymn: _____________________________________________________________", distanceFromLeft1, distanceFromTop, {align: "left", width: pageWidth});
            if (intermediateHymnArray[intermediateHymnIndex].hymn.number) {
              doc.text(intermediateHymnArray[intermediateHymnIndex].hymn.number + " - " + intermediateHymnArray[intermediateHymnIndex].hymn.name, distanceFromLeft3, distanceFromTop, {align: "left", width: pageWidth});
            } else {
              doc.text(intermediateHymnArray[intermediateHymnIndex].hymn.name, distanceFromLeft3, distanceFromTop, {align: "left", width: pageWidth});
            }
            distanceFromTop += verticalPositionIncrement;
          }
        }
        for(var musicalNumberIndex in musicalNumberArray) {
          if ((musicalNumberArray[musicalNumberIndex].afterSpeaker - 1) == speakerIndex) {
            doc.text("Musical Number", distanceFromLeft1, distanceFromTop, {align: "left", width: pageWidth});
            distanceFromTop += verticalPositionIncrement;
            doc.text("Song: ________________________________________________________________________", distanceFromLeft1, distanceFromTop, {align: "left", width: pageWidth});
            if (musicalNumberArray[musicalNumberIndex].hymn.number) {
              doc.text(musicalNumberArray[musicalNumberIndex].hymn.number + " - " + musicalNumberArray[musicalNumberIndex].hymn.name, distanceFromLeft3, distanceFromTop, {align: "left", width: pageWidth});
            } else {
              doc.text(musicalNumberArray[musicalNumberIndex].hymn.name, distanceFromLeft3, distanceFromTop, {align: "left", width: pageWidth});
{'fraction_non_alphanumeric': 0.12277368194370551, 'fraction_numerical': 0.0055990474018899955, 'mean_word_length': 4.219783126157101, 'pattern_counts': {'":': 10, '<': 3, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6385809', 'n_tokens_mistral': 10932, 'n_tokens_neox': 10713, 'n_words': 2039}