Skip to content

Commit

Permalink
Merge pull request #110 from Salesforce-org-Impact-Labs/lwc_Service_Reqs
Browse files Browse the repository at this point in the history
Lwc service reqs
  • Loading branch information
AIrwin33 authored Jul 1, 2020
2 parents de0a286 + 9affd98 commit 45ff12d
Show file tree
Hide file tree
Showing 9 changed files with 1,362 additions and 61 deletions.
128 changes: 121 additions & 7 deletions force-app/main/default/classes/ServicePrint.cls
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,137 @@ public class ServicePrint {


@AuraEnabled
public String serviceId {get;set;}
public Service__c service {get;set;}
public String Sunday {
get {
if(Sunday == null){
Sunday = 'S: Closed';
}else{
Sunday = Sunday;
}
return Sunday;}
set;
}
public String Monday {
get {
if(Monday == null){
Monday = 'M: Closed';
}else{
Monday = Monday;
}
return Monday;}
set;
}
public String Tuesday {
get {
if(Tuesday == null){
Tuesday = 'T: Closed';
}else{
Tuesday = Tuesday;
}
return Tuesday;}
set;
}
public String Wednesday {
get {
if(Wednesday == null){
Wednesday = 'W: Closed';
}else{
Wednesday = Wednesday;
}
return Wednesday;}
set;
}
public String Thursday {
get {
if(Thursday == null){
Thursday = 'T: Closed';
}else{
Thursday = Thursday;
}
return Thursday;}
set;
}
public String Friday {
get {
if(Friday == null){
Friday = 'F: Closed';
}else{
Friday = Friday;
}
return Friday;}
set;
}
public String Saturday {
get {
if(Saturday == null){
Saturday = 'S: Closed';
}else{
Saturday = Saturday;
}
return Saturday;}
set;
}

public ServicePrint() {
String servId = ApexPages.currentPage().getParameters().get('servId');
System.debug('serviceId' + servId);
List<Open_Hours__c> allHours = getOpenHours(servId);
}

public Service__c getServices(string serviceId) {
Service__c newserv = [SELECT Id, Name, Account__r.Name, Type__c,Description__c, Website__c, Street__c, City__c, Zip_Code__c, Phone__c FROM Service__c WHERE Id = :serviceId];
system.debug('serv' + newserv);
return newserv;
}

public List<Open_Hours__c> getOpenHours(string serviceId){
system.debug('serviceId' + serviceId);
List<Open_Hours__c> hrs = [SELECT Id,Day__c, End_Time__c, Start_Time__c, Service__c FROM Open_Hours__c WHERE Service__c = :serviceId];

for(Open_Hours__c hour: hrs){
System.debug(hour.Day__c);
System.debug(String.valueOf(hour.Start_Time__c));
switch on hour.Day__c {
when 'Sunday' {
Sunday = 'S: ' + Datetime.newInstance(Date.Today(), hour.Start_Time__c).format('hh:mm a') + ' - ' + Datetime.newInstance(Date.Today(), hour.End_Time__c).format('hh:mm a');
}
when 'Monday' {
Monday = 'M: ' + Datetime.newInstance(Date.Today(), hour.Start_Time__c).format('hh:mm a') + ' - ' + Datetime.newInstance(Date.Today(), hour.End_Time__c).format('hh:mm a');
}
when 'Tuesday' {
Tuesday = 'T: ' + Datetime.newInstance(Date.Today(), hour.Start_Time__c).format('hh:mm a') + ' - ' + Datetime.newInstance(Date.Today(), hour.End_Time__c).format('hh:mm a');
}
when 'Wednesday' {
Wednesday = 'W: ' + Datetime.newInstance(Date.Today(), hour.Start_Time__c).format('hh:mm a') + ' - ' + Datetime.newInstance(Date.Today(), hour.End_Time__c).format('hh:mm a');
}
when 'Thursday' {
Thursday = 'T: ' + Datetime.newInstance(Date.Today(), hour.Start_Time__c).format('hh:mm a') + ' - ' + Datetime.newInstance(Date.Today(), hour.End_Time__c).format('hh:mm a');
System.debug(Thursday);
}
when 'Friday' {
Friday = 'F: ' + Datetime.newInstance(Date.Today(), hour.Start_Time__c).format('hh:mm a') + ' - ' + Datetime.newInstance(Date.Today(), hour.End_Time__c).format('hh:mm a');
}
when 'Saturday' {
Saturday = 'S: ' + Datetime.newInstance(Date.Today(), hour.Start_Time__c).format('hh:mm a') + ' - ' + Datetime.newInstance(Date.Today(), hour.End_Time__c).format('hh:mm a');
}
}
}
service = getServices(serviceId);
system.debug(service);
return hrs;

}

@AuraEnabled
public static String PrintPage(Id serviceId){
public static String PrintPage(String serviceId){
Attachment attach = new Attachment();
attach.body = Blob.valueOf('');
Blob body = Blob.valueOf('');
System.debug('serviceId' + serviceId);

Service__c service = [SELECT Id, Name FROM Service__c WHERE Id =:serviceId];

try {
PageReference nr = new PageReference('/apex/ServicePrintPage');
PageReference nr = new PageReference('/apex/ServicePrintPage?servId=' + serviceId);
//nr.getParameters().put('service', service);
body = nr.getContentAsPDF();

Expand All @@ -37,8 +151,8 @@ public class ServicePrint {
attach.ParentId = serviceId; //attach pdf to record
insert attach;

String fullURL = URL.getSalesforceBaseUrl().toExternalForm() + '/apex/ServicePrintPage';

String fullURL = URL.getSalesforceBaseUrl().toExternalForm() + '/apex/ServicePrintPage?servId=' + serviceId;
System.debug(fullURL);
return fullURL;

}
Expand Down
12 changes: 11 additions & 1 deletion force-app/main/default/classes/ServiceRecommendation.cls
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,17 @@ public class ServiceRecommendation {
public String MailingCity { get; set; }

@AuraEnabled
public String Website { get; set; }
public String Website {
get {
if(Website.startsWith('https://')){
Website = Website;
}else{

Website = 'https://'+ Website;
}
return Website;}
set;
}

@AuraEnabled
public Decimal Rating { get; set; }
Expand Down
80 changes: 80 additions & 0 deletions force-app/main/default/classes/Test_ServicePrint.cls
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,73 @@
private with sharing class Test_ServicePrint {
@testSetup
static void makeData() {
Time start = Time.newInstance(9,0,0,0);
Time stop = Time.newInstance(17,0,0,0);
contact c = new Contact();
c.LastName = 'TestContact';
insert c;

Service__c s = new Service__c();
s.Name = 'Test Service for Printing';
insert s;

Open_Hours__c ohSun = new Open_Hours__c();
ohSun.Service__c = s.Id;
ohSun.End_Time__c = stop;
ohSun.Start_Time__c = start;
ohSun.Day__c = 'Sunday';
insert ohSun;

Open_Hours__c ohM = new Open_Hours__c();
ohM.Service__c = s.Id;
ohM.End_Time__c = stop;
ohM.Start_Time__c = start;
ohM.Day__c = 'Monday';
insert ohM;

Open_Hours__c ohTu = new Open_Hours__c();
ohTu.Service__c = s.Id;
ohTu.End_Time__c = stop;
ohTu.Start_Time__c = start;
ohTu.Day__c = 'Tuesday';
insert ohTu;

Open_Hours__c ohW = new Open_Hours__c();
ohW.Service__c = s.Id;
ohW.End_Time__c = stop;
ohW.Start_Time__c = start;
ohW.Day__c = 'Wednesday';
insert ohW;

Open_Hours__c ohT = new Open_Hours__c();
ohT.Service__c = s.Id;
ohT.End_Time__c = stop;
ohT.Start_Time__c = start;
ohT.Day__c = 'Thursday';
insert ohT;

Open_Hours__c ohF = new Open_Hours__c();
ohF.Service__c = s.Id;
ohF.End_Time__c = stop;
ohF.Start_Time__c = start;
ohF.Day__c = 'Friday';
insert ohF;

Open_Hours__c ohSat = new Open_Hours__c();
ohSat.Service__c = s.Id;
ohSat.End_Time__c = stop;
ohSat.Start_Time__c = start;
ohSat.Day__c = 'Saturday';
insert ohSat;

}

static testMethod void printReferral() {
id contactId = getTestContactId();
id serviceId = getTestServiceId();

Test.StartTest();

ServicePrint.PrintPage(serviceId);
Test.StopTest();

Expand All @@ -24,6 +77,31 @@ private with sharing class Test_ServicePrint {
System.assertEquals(attachs[0].ParentId, serviceId);
}

static testMethod void openHours() {
system.debug('running open hours');
id serviceId = getTestServiceId();

ApexPages.CurrentPage().getParameters().put('servId',serviceId);
System.debug(serviceId);
Test.StartTest();
ServicePrint servP = new ServicePrint();
servP.Saturday = null;
servP.Sunday = null;
servP.Wednesday = null;
servP.Friday = null;
Test.StopTest();

List<Open_Hours__c> openHrs = [SELECT Id,Day__c, End_Time__c, Start_Time__c, Service__c FROM Open_Hours__c WHERE Service__c = :serviceId];

system.assertEquals(openHrs.Size(), 7);
system.assertEquals(servP.Saturday, 'S: Closed');
system.assertEquals(servP.Sunday, 'S: Closed');
system.assertEquals(servP.Wednesday, 'W: Closed');
system.assertEquals(servP.Friday, 'F: Closed');


}


private static Id getTestContactId() {
return [SELECT id FROM Contact WHERE LastName = 'TestContact'].Id;
Expand All @@ -32,5 +110,7 @@ private with sharing class Test_ServicePrint {
private static Id getTestServiceId() {
return [SELECT id FROM Service__c WHERE Name = 'Test Service for Printing'].Id;
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default class ServiceRecommendation extends LightningElement {
@track newComment;

connectedCallback(rec = this.servicerecommendation){
window.console.log(rec.Website);
if(rec.ProgramType === 'Food'){
this.programTypeFood = true
} else if(rec.ProgramType === 'Education'){
Expand Down Expand Up @@ -159,9 +160,10 @@ export default class ServiceRecommendation extends LightningElement {
window.console.log(this.serviceid);
print({serviceId : this.serviceid})
.then((result)=>{
window.console.log('result' + result);

let downloadLink = document.createElement("a");
downloadLink.href = result;
window.console.log(downloadLink.href);
downloadLink.download = "referral.pdf";


Expand Down
Loading

0 comments on commit 45ff12d

Please sign in to comment.