public with sharing class OFSRepairConsignPDFOuterController {
|
public Repair__c rp { get; private set; }
|
|
public string signStr { get; set; }
|
|
public void init() {
|
String id = ApexPages.currentPage().getParameters().get('id');
|
rp = this.getReportData(id);
|
}
|
|
public void saveSign() {
|
// Sign画像は一つでいいじゃない?Delete⇒Insertにする
|
List<Attachment> atts = [select Id from Attachment where ParentId = :rp.Id and Name = :(rp.Name + '_Sign')];
|
if (atts.size() > 0) delete atts;
|
|
Attachment ac = new Attachment();
|
ac.Body = EncodingUtil.base64Decode(this.signStr.removeStart('data:image/png;base64,'));
|
ac.Name = rp.Name + '_Sign';
|
ac.ParentId = rp.Id;
|
ac.ContentType = 'jpg';
|
try {
|
insert ac;
|
rp.Sign__c = '<img src="/servlet/servlet.FileDownload?file=' + ac.Id + '"/>';
|
rp.SignUrl__c = '/servlet/servlet.FileDownload?file=' + ac.Id;
|
rp.SignDate__c = Date.today();
|
update rp;
|
} catch (Exception ex) {
|
ApexPages.addMessages(ex);
|
//return;
|
}
|
}
|
|
public void savePDF() {
|
String pdfPageURL = '/apex/OFSRepairConsignPDF?id=' + rp.Id;
|
PageReference pageRef = new PageReference(pdfPageURL);
|
|
Attachment att = new Attachment();
|
// TODO TestMethodはgetContentをサポートしない
|
if (!Test.isRunningTest()) {
|
att.body = pageRef.getContent();
|
} else {
|
att.body = EncodingUtil.base64Decode('test');
|
}
|
att.Name = rp.Name + '_维修委托书_' + String.valueOf(Datetime.now()) + '.pdf';
|
att.ParentId = rp.Id;
|
try {
|
insert att;
|
} catch (Exception ex) {
|
ApexPages.addMessages(ex);
|
//return;
|
}
|
}
|
|
private Repair__c getReportData(String id) {
|
Schema.DescribeSobjectResult d = Repair__c.sObjectType.getDescribe();
|
Map<String, Schema.SObjectField> fieldMap = d.fields.getMap();
|
|
String soql = 'select ';
|
String fields = '';
|
for (String field : fieldMap.keySet()) {
|
if (fields.length() > 0) {
|
fields += ', ';
|
}
|
fields += field;
|
}
|
soql += fields;
|
soql += ' from Repair__c where Id = \'' + id + '\'';
|
|
return Database.query(soql);
|
}
|
}
|