Skip to content

Commit

Permalink
Added label generator
Browse files Browse the repository at this point in the history
  • Loading branch information
Salamek committed Aug 17, 2016
1 parent 4ba4555 commit 8a696e1
Show file tree
Hide file tree
Showing 10 changed files with 513 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/tmp
/test/config.json
/vendor
/composer.lock
39 changes: 38 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ $ composer require salamek/ppl-my-api:dev-master

### Is API healthy

Check if PPL MyApi is in working shape

```php
$pplMyApi = new Salamek\PplMyApi\Api();
if ($pplMyApi->isHealthy())
Expand All @@ -35,13 +37,17 @@ else

### Get API version

Returns version of PPL MyApi

```php
$pplMyApi = new Salamek\PplMyApi\Api();
echo $pplMyApi->getVersion() . PHP_EOL;
```

### Get parcel shops

Returns array of parcel shops filtered by `$code` and `$countryCode`

```php
$pplMyApi = new Salamek\PplMyApi\Api();
$result = $pplMyApi->getParcelShops($code = null, $countryCode = Country::CZ);
Expand All @@ -50,13 +56,17 @@ print_r($result);

### Get sprint routes

Returns array of sprint routes

```php
$pplMyApi = new Salamek\PplMyApi\Api();
$result = $pplMyApi->getSprintRoutes();
print_r($result);
```

### Create Package
### Create Packages

Creates package/s on PPL MyApi (sends Package object to PPL)

```php

Expand Down Expand Up @@ -86,6 +96,8 @@ catch (\Exception $e)

### Create Orders

Creates order/s on PPL MyApi (send Order object to PPL)

```php

$username = 'my_api_username';
Expand All @@ -110,6 +122,8 @@ catch (\Exception $e)

### Create Pickup Orders

Creates pickup order/s on PPL MyApi (send PickupOrder object to PPL)

```php

$username = 'my_api_username';
Expand All @@ -133,6 +147,8 @@ catch (\Exception $e)

### Get Cities Routing

Returns cities routing filtered by `$countryCode`, `$dateFrom`, `$zipCode`

```php
$username = 'my_api_username';
$password = 'my_api_password';
Expand All @@ -145,6 +161,8 @@ print_r($result);

### Get Packages

Returns package/s info from ppl filtered by `$customRefs`, `$dateFrom`, `$dateTo`, `$packageNumbers` useful for tracking and checking status of package/s

```php
$username = 'my_api_username';
$password = 'my_api_password';
Expand All @@ -153,4 +171,23 @@ $customerId = 'my_api_customer_id';
$pplMyApi = new Salamek\PplMyApi\Api($username, $password, $customerId);
$result = $pplMyApi->getPackages($customRefs = null, \DateTimeInterface $dateFrom = null, \DateTimeInterface $dateTo = null, array $packageNumbers = []);
print_r($result);
```

### Get Labels

Returns PDF with label/s for print on paper, two decompositions are supported, LabelDecomposition::FULL (one A4 Label per page) or LabelDecomposition::QUARTER (one label per 1/4 of A4 page)

```php
$pplMyApi = new Salamek\PplMyApi\Api();

$sender = new Salamek\PplMyApi\Model\Sender('Olomouc', 'My Compamy s.r.o.', 'My Address', '77900', '[email protected]', '+420123456789', 'http://www.example.cz', Country::CZ);
$recipient = new Salamek\PplMyApi\Model\Recipient('Olomouc', 'Adam Schubert', 'My Address', '77900', '[email protected]', '+420123456789', 'http://www.salamek.cz', Country::CZ, 'My Compamy a.s.');

$myPackageIdFromNumberSeries = 115;
$weight = 3.15;
$package = new Salamek\PplMyApi\Model\Package($myPackageIdFromNumberSeries, Product::PPL_PARCEL_CZ_PRIVATE, $weight, 'Testpvaci balik', Depo::CODE_09, $sender, $recipient);


$rawPdf = $pplMyApi->getLabels([$package]);
file_put_contents($package->getPackageNumber() . '.pdf', $rawPdf);
```
Binary file added assets/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"classmap": ["src/"]
},
"require": {
"php": ">=5.3.0"
"php": ">=5.3.0",
"tecnickcom/tcpdf": "^6.2"
},
"require-dev": {
"phpunit/phpunit": "4.8"
Expand Down
13 changes: 13 additions & 0 deletions src/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace Salamek\PplMyApi;

use Salamek\PplMyApi\Enum\Country;
use Salamek\PplMyApi\Enum\LabelDecomposition;
use Salamek\PplMyApi\Model\Order;
use Salamek\PplMyApi\Model\Package;
use Salamek\PplMyApi\Model\PickUpOrder;
Expand Down Expand Up @@ -479,4 +480,16 @@ public function login()

return $result->LoginResult->AuthToken;
}

/**
* @param array $packages
* @param int $decomposition
* @return string
* @throws \Exception
*/
public function getLabels(array $packages, $decomposition = LabelDecomposition::QUARTER)
{
$label = new Label();
return $label->generateLabels($packages, $decomposition);
}
}
19 changes: 19 additions & 0 deletions src/Enum/LabelDecomposition.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
/**
* Copyright (C) 2016 Adam Schubert <[email protected]>.
*/

namespace Salamek\PplMyApi\Enum;


class LabelDecomposition
{
const FULL = 1;
const QUARTER = 4;

/** @var array */
public static $list = [
self::FULL,
self::QUARTER
];
}
23 changes: 23 additions & 0 deletions src/Enum/LabelPosition.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
/**
* Copyright (C) 2016 Adam Schubert <[email protected]>.
*/

namespace Salamek\PplMyApi\Enum;


class LabelPosition
{
const TOP_LEFT = 1;
const TOP_RIGHT = 2;
const BOTTOM_LEFT = 3;
const BOTTOM_RIGHT = 4;

/** @var array */
public static $list = [
self::TOP_LEFT,
self::TOP_RIGHT,
self::BOTTOM_LEFT,
self::BOTTOM_RIGHT
];
}
Loading

0 comments on commit 8a696e1

Please sign in to comment.