PHP code example of robgridley / pace-api
1. Go to this page and download the library: Download robgridley/pace-api library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
robgridley / pace-api example snippets
use Pace\Client as Pace;
use Pace\Soap\Factory as SoapFactory;
$pace = new Pace(new SoapFactory(), 'epace-staging.domain.com', 'apiuser', 'apipassword');
$csr = $pace->model('CSR');
// or the shorter, prettier:
$csr = $pace->csr;
$csr->name = 'John Smith';
$csr->email = '[email protected] ';
$csr->save();
$csr = $pace->csr->read(1);
echo $csr->email; // prints "[email protected] "
$jobPart = $pace->jobPart->read('12345:01');
$csr = $pace->csr->read(1);
$csr->active = false;
$csr->save();
$csr = $pace->csr->read(1);
$csr->name = 'Jane Smith';
$newCsr = $csr->duplicate();
echo $csr->name; // prints "John Smith"
echo $newCsr->name; // prints "Jane Smith"
$csr = $pace->csr->read(1);
$csr->delete();
$jobs = $pace->job
->filter('adminStatus/@openJob', true)
->filter('@jobType', 1)
->find();
$csr = $pace->csr->filter('@name', 'Jane Smith')->first();
$millionPlus = $pace->salesPerson->filter('@annualQuota', '>=', 1000000)->find();
$coated = $pace->inventoryItem->contains('@description', 'C2S')->find();
$tango = $pace->inventoryItem->startsWith('@description', 'Tango')->find();
$customers = $pace->customer
->filter('@state', 'ON')
->filter(function ($xpath) {
$xpath->filter('@city', 'Toronto');
$xpath->orFilter('@city', 'Ottawa');
})
->find();
$jobs = $pace->job
->filter('adminStatus/@openJob', true)
->sort('customer/@custName')
->sort('@job', true)
->find();
$estimates = $pace->estimate->filter('@entryDate', '>=', Carbon::yesterday())->find();
foreach ($estimates as $estimate) {
if ($estimate->enteredBy == 'jsmith') {
echo "John has entered an estimate since yesterday!"
break;
}
}
$customer = $pace->customer->read('HOUSE');
$houseCsr = $customer->csr();
$customer = $pace->customer->read('HOUSE');
$houseJobs = $customer->jobs()->filter('@adminStatus', 'O')->get();
$notes = $customer->customerNotes()->get();
$notes = $customer->hasMany('CustomerNote', 'customer', 'id')->get();
$jobPart = $pace->jobPart->read('12345:01');
$jobMaterials = $jobPart->hasMany('JobMaterial', 'job:jobPart')->get();
$batch = $pace->inventoryBatch;
$batch->save(); // save the model to generate a primary key
$line = $pace->inventoryLine;
$line->inventoryBatch = $batch;
$pace->transaction(function () use ($pace) {
$job = $pace->model('Job');
$job->customer = 'HOUSE';
$job->description = 'Test Order';
$job->jobType = 10;
$job->adminStatus = 'O';
$job->save();
$jobPart = $job->jobParts()->first();
$jobMaterial = $pace->model('JobMaterial');
$jobMaterial->job = $jobPart->job;
$jobMaterial->jobPart = $jobPart->jobPart;
$jobMaterial->inventoryItem = 'ABC123';
$jobMaterial->plannedQuantity = 100;
$jobMaterial->save();
throw new Exception('Just kidding. Roll it back.');
});
$pace->startTransaction();
$csr = $pace->model('CSR');
$csr->name = 'Definitely Not Evil';
$csr->save();
if ($csr->id == 666) {
// Oh no. They are evil!
$pace->rollbackTransaction();
} else {
$pace->commitTransaction();
}
// print a JSON representation of the House account
echo $pace->customer->read('HOUSE');
$job = $pace->model('Job')->read('12345');
$attachment = $job->attachFile('test.txt', file_get_contents('test.txt'));
$attachment->description = 'A test file';
$attachment->save();
$company = $pace->model('Company')->read('001');
$company->attachFile('logo.png', file_get_contents('logo.png'), 'logo');
$attachments = $job->fileAttachments()->get();
$logo = $company->fileAttachments()->filter('@field', 'logo')->first();
$spreadsheets = $job->fileAttachments()->filter('@ext', 'xls')->get();
$attachment->getContent();
$pace->report(1000)
->parameter(10001, '2019-12-01')
->parameter(10002, '2019-12-31')
->parameter(10003, 'D');
$pace->report(1000)
->namedParameter('Start Date', '2019-12-01')
->namedParameter('End Date', '2019-12-31')
->namedParameter('Report Format', 'D');
$job = $pace->model('Job')->read('90000');
$pace->report(100)
->baseObjectKey($job)
->namedParameter('Include Kit Detail', 'N');
$file = $pace->report(200)->get();
if ($file->getMediaType() == 'application/vnd.ms-excel') {
file_put_contents('report.xls', $file->getContent());
}
$pace->report(100)
->baseObjectKey('90000')
->namedParameter('Include Kit Detail', 'N')
->print();
$pace->version();