Commit faa2c59b authored by Karamel's avatar Karamel
Browse files

Bye bye (shitty) fromStruct, hello (less shitty) load and merge.

Models are separated between MainModels and EmbeddedModels. The parent field is
not listed anymore in getAssociationFields.
Load is there to prepare using only references and using id only for internal
uses, loadFromId assures the compatibility where id is still used outside
(like in association).
parent 727897b9
......@@ -16,11 +16,12 @@ use \Pasteque\Server\System\DAO\DAOCondition;
* @SWG\Response(response="200", description="Get a Cash session")
* )
*/
$app->GET('/api/cashsession/{cashregisterid}/{sequence}', function($request, $response, $args) {
$app->GET('/api/cashsession/{cashregisterid}/{sequence}',
function($request, $response, $args) {
$ptApp = $this->get('settings')['ptApp'];
return $response->withApiResult(APICaller::run($ptApp, 'cashSession', 'get',
[['cashRegister' => $args['cashregisterid'],
'sequence' => $args['sequence']]]));
[['cashRegister' => $args['cashregisterid'],
'sequence' => $args['sequence']]]));
});
......@@ -30,7 +31,8 @@ $app->GET('/api/cashsession/{cashregisterid}/{sequence}', function($request, $re
* Notes: Update a Cash session
* Output-Formats: [application/json]
*/
$app->POST('/api/cash', function($request, $response, $args) {
$app->POST('/api/cash',
function($request, $response, $args) {
$ptApp = $this->get('settings')['ptApp'];
$data = $request->getParsedBody();
$jsonSess = $data['session'];
......@@ -40,8 +42,13 @@ $app->POST('/api/cash', function($request, $response, $args) {
}
$structSess['openDate'] = DateUtils::readDate($structSess['openDate']);
$structSess['closeDate'] = DateUtils::readDate($structSess['closeDate']);
$session = CashSession::fromStruct($structSess, $ptApp->getDao());
return $response->withAPIResult(APICaller::run($ptApp, 'cashSession', 'write', $session));
$session = CashSession::load($structSess, $ptApp->getDao());
if ($session == null) {
$session = new CashSession();
}
$session->merge($structSess, $ptApp->getDao());
return $response->withAPIResult(APICaller::run($ptApp, 'cashSession',
'write', $session));
});
......@@ -51,7 +58,8 @@ $app->POST('/api/cash', function($request, $response, $args) {
* Notes: Search and get a array of Cash
* Output-Formats: [application/json]
*/
$app->GET('/api/cash/search/', function($request, $response, $args) {
$app->GET('/api/cash/search/',
function($request, $response, $args) {
$ptApp = $this->get('settings')['ptApp'];
$queryParams = $request->getQueryParams();
$cashRegisterId = (empty($queryParams['cashRegister'])) ? null
......@@ -108,7 +116,8 @@ $app->GET('/api/cash/search/', function($request, $response, $args) {
* @SWG\Response(response="200", description="get a zticket of a cash session")
* )
*/
$app->GET('/api/cashsession/summary/{cashregisterid}/{sequence}', function($request, $response, $args) {
$app->GET('/api/cashsession/summary/{cashregisterid}/{sequence}',
function($request, $response, $args) {
$ptApp = $this->get('settings')['ptApp'];
$cashApiResp = APICaller::run($ptApp, 'cashSession', 'get',
[['cashRegister' => $args['cashregisterid'],
......
<?php
use \Pasteque\Server\Model\CashRegister;
use \Pasteque\Server\System\API\APICaller;
use \Pasteque\Server\System\API\APIResult;
......@@ -9,7 +10,8 @@ use \Pasteque\Server\System\API\APIResult;
* Notes: Get a array of all CashRegister
* Output-Formats: [application/json]
*/
$app->GET('/api/cashregister/getAll', function($request, $response, $args) {
$app->GET('/api/cashregister/getAll',
function($request, $response, $args) {
$ptApp = $this->get('settings')['ptApp'];
return $response->withApiResult(APICaller::run($ptApp, 'cashRegister', 'getAll'));
});
......@@ -21,7 +23,8 @@ $app->GET('/api/cashregister/getAll', function($request, $response, $args) {
* Notes: Get a cash register by this label
* Output-Formats: [application/json]
*/
$app->GET('/api/cashregister/getByReference/{reference}', function($request, $response, $args) {
$app->GET('/api/cashregister/getByReference/{reference}',
function($request, $response, $args) {
$ptApp = $this->get('settings')['ptApp'];
$apiRes = APICaller::run($ptApp, 'cashRegister', 'getByReference',
$args['reference']);
......@@ -32,7 +35,8 @@ $app->GET('/api/cashregister/getByReference/{reference}', function($request, $re
return $response->withApiResult($apiRes);
});
$app->GET('/api/cashregister/getByName/{name}', function($request, $response, $args) {
$app->GET('/api/cashregister/getByName/{name}',
function($request, $response, $args) {
$ptApp = $this->get('settings')['ptApp'];
$apiRes = APICaller::run($ptApp, 'cashRegister', 'getByName',
$args['name']);
......@@ -49,38 +53,46 @@ $app->GET('/api/cashregister/getByName/{name}', function($request, $response, $a
* Notes: Get a CashRegiter
* Output-Formats: [application/json]
*/
$app->GET('/api/cashregister/{id}', function($request, $response, $args) {
$app->GET('/api/cashregister/{id}',
function($request, $response, $args) {
$ptApp = $this->get('settings')['ptApp'];
return $response->withApiResult(APICaller::run($ptApp, 'cashRegister', 'get', $args['id']));
return $response->withApiResult(APICaller::run($ptApp, 'cashRegister',
'get', $args['id']));
});
/** Low level call. If an id is set, it's an update. If not, it's a create. */
$app->POST('/api/cashregister', function($request, $response, $args) {
$app->POST('/api/cashregister',
function($request, $response, $args) {
$ptApp = $this->get('settings')['ptApp'];
$tab = $request->getParsedBody();
$cr = \Pasteque\Server\Model\CashRegister::fromStruct($tab, $ptApp->getDao());
return $response->withApiResult(APICaller::run($ptApp, 'cashregister', 'write', $cr));
$cr = CashRegister::loadFromId($tab['id'], $ptApp->getDao());
if ($cr == null) {
$cr = new CashRegister();
}
$cr->merge($tab, $ptApp->getDao());
return $response->withApiResult(APICaller::run($ptApp, 'cashregister',
'write', $cr));
});
/** Create a new cash register from it's reference. The reference is read from url
* and ignored from data.
/**
* Create a new cash register from it's reference. The reference is read from
* url and ignored from data.
* Returns an error if an id is given or if a cash register already exists
* with the given reference. */
$app->PUT('/api/cashregister/{reference}', function($request, $response, $args) {
* with the given reference.
*/
$app->PUT('/api/cashregister/{reference}',
function($request, $response, $args) {
$ptApp = $this->get('settings')['ptApp'];
$tab = $request->getParsedBody();
if (!empty($tab['id'])) {
return $response->withStatus(400, 'New record cannot have an Id');
}
$tab['reference'] = $args['reference'];
$cr = \Pasteque\Server\Model\CashRegister::fromStruct($tab, $ptApp->getDao());
// Check for an existing reference
$existingCrReq = APICaller::run($ptApp, 'cashregister', 'getByReference', $cr->getReference());
if ($existingCrReq->getStatus() != APIResult::STATUS_CALL_OK) {
return $response->withAPIResult($existingCrReq);
}
if ($existingCrReq->getContent() != null) {
$cr = CashRegister::load($tab['reference'], $ptApp->getDao());
if ($cr != null) {
return $response->withStatus(400, 'Reference is already taken');
}
$cr = new CashRegister();
$cr->merge($tab);
return $response->withApiResult(APICaller::run($ptApp, 'cashregister', 'write', $cr));
});
<?php
use Pasteque\Server\Model\Category;
use Pasteque\Server\System\API\APICaller;
use Pasteque\Server\System\API\APIResult;
......@@ -8,15 +9,13 @@ use Pasteque\Server\System\API\APIResult;
* Notes: Get an array of all Categories
* Output-Formats: [application/json]
*/
$app->GET('/api/category/getAll', function($request, $response, $args) {
$app->GET('/api/category/getAll',
function($request, $response, $args) {
$ptApp = $this->get('settings')['ptApp'];
return $response->withApiResult(APICaller::run($ptApp, 'category','getAll'));
return $response->withApiResult(APICaller::run($ptApp, 'category',
'getAll'));
});
/**
* GET categoryGetChildrens
* Summary:
......@@ -27,15 +26,15 @@ $app->GET('/api/category/getAll', function($request, $response, $args) {
* @SWG\Response(response="200", description="Get an array of Categories from a parent Category Id")
* )
*/
$app->GET('/api/category/getChildrens', function($request, $response, $args) {
$app->GET('/api/category/getChildrens',
function($request, $response, $args) {
$queryParams = $request->getQueryParams();
$parentId = $queryParams['parentId'];
$ptApp = $this->get('settings')['ptApp'];
return $response->withApiResult(APICaller::run($ptApp, 'category','getChildren',[$parentId]));
return $response->withApiResult(APICaller::run($ptApp, 'category',
'getChildren',[$parentId]));
});
/**
* GET categoryId
* Summary:
......@@ -46,17 +45,13 @@ $app->GET('/api/category/getChildrens', function($request, $response, $args) {
* @SWG\Response(response="200", description="get a category")
* )
*/
$app->GET('/api/category/{id}', function($request, $response, $args) {
$app->GET('/api/category/{id}',
function($request, $response, $args) {
$ptApp = $this->get('settings')['ptApp'];
return $response->withApiResult(APICaller::run($ptApp, 'category','get',$args));
return $response->withApiResult(APICaller::run($ptApp, 'category', 'get',
$args));
});
/**
* @deprecated Use PUT with reference or POST instead.
* PUT categoryCreateupdate
......@@ -93,61 +88,74 @@ $app->GET('/api/category/{id}', function($request, $response, $args) {
* security={{"pasteque_auth":{"write:categories", "read:categories"}}}
* )
*/
$app->PUT('/api/category', function($request, $response, $args) {
$app->PUT('/api/category',
function($request, $response, $args) {
$ptApp = $this->get('settings')['ptApp'];
$tab = $request->getParsedBody();
$category = \Pasteque\Server\Model\Category::fromStruct($tab,$ptApp->getDao());
return $response->withApiResult(APICaller::run($ptApp, 'category', 'write', $category));
$cat = Category::load($tab['reference'], $ptApp->getDao());
if ($cat != null) {
$response->withStatus(400, 'Reference is already taken');
}
$cat = new Category();
$cat->merge($tab);
return $response->withApiResult(APICaller::run($ptApp, 'category', 'write',
$category));
});
/** Low level call. If an id is set, it's an update. If not, it's a create. */
$app->POST('/api/category', function($request, $response, $args) {
$app->POST('/api/category',
function($request, $response, $args) {
$ptApp = $this->get('settings')['ptApp'];
$tab = $request->getParsedBody();
$category = \Pasteque\Server\Model\Category::fromStruct($tab,$ptApp->getDao());
return $response->withApiResult(APICaller::run($ptApp, 'category', 'write', $category));
$cat = Category::load($tab['reference'], $ptApp->getDao());
if ($cat == null) {
$cat = new Category();
}
$cat->merge($tab);
return $response->withApiResult(APICaller::run($ptApp, 'category', 'write',
$cat));
});
/** Create a new category from it's reference. The reference is read from url
/**
* Create a new category from it's reference. The reference is read from url
* and ignored from data.
* Returns an error if an id is given or if a category already exists
* with the given reference. */
$app->PUT('/api/category/{reference}', function($request, $response, $args) {
* with the given reference.
*/
$app->PUT('/api/category/{reference}',
function($request, $response, $args) {
$ptApp = $this->get('settings')['ptApp'];
$tab = $request->getParsedBody();
if (!empty($tab['id'])) {
return $response->withStatus(400, 'New record cannot have an Id');
}
$tab['reference'] = $args['reference'];
$category = \Pasteque\Server\Model\Category::fromStruct($tab,$ptApp->getDao());
// Check for an existing reference
$existingCatReq = APICaller::run($ptApp, 'category', 'getByReference', $category->getReference());
if ($existingCatReq->getStatus() != APIResult::STATUS_CALL_OK) {
return $response->withAPIResult($existingCatReq);
}
if ($existingCatReq->getContent() != null) {
$cat = Category::load($tab['reference'], $ptApp->getDao());
if ($cat != null) {
return $response->withStatus(400, 'Reference is already taken');
}
return $response->withApiResult(APICaller::run($ptApp, 'category', 'write', $category));
$cat = new Category();
$cat->merge($tab, $ptApp->getDao());
return $response->withApiResult(APICaller::run($ptApp, 'category', 'write',
$cat));
});
/** Update an existing category from it's reference. Returns an error if an id
* is given or if there aren't any category with this reference. */
$app->PATCH('api/category/{reference}', function($request, $response, $args) {
/**
* Update an existing category from it's reference. Returns an error if an id
* is given or if there aren't any category with this reference.
*/
$app->PATCH('api/category/{reference}',
function($request, $response, $args) {
$ptApp = $this->get('settings')['ptApp'];
$tab = $request->getParsedBody();
if (!empty($tab['id'])) {
return $response->withStatus(400, 'Do not send Id, use reference instead.');
}
$tab['reference'] = $args['reference'];
$category = \Pasteque\Server\Model\Category::fromStruct($tab,$ptApp->getDao());
// Check for an existing reference
$existingCatReq = APICaller::run($ptApp, 'category', 'getByReference', $category->getReference());
if ($existingCatReq->getStatus() != APIResult::STATUS_CALL_OK) {
return $response->withAPIResult($existingCatReq);
}
if ($existingCatReq->getContent() == null) {
$cat = Category::load($args['reference'], $ptApp->getDao());
if ($cat == null) {
return $response->withStatus(404, 'No category found.');
}
if ($existingCatReq->getContent()->getId() != $category->getId()) {
return $response->withStatus(500, 'Id mismatch.');
}
return $response->withApiResult(APICaller::run($ptApp, 'category', 'write', $category));
$cat->merge($tab);
return $response->withApiResult(APICaller::run($ptApp, 'category', 'write',
$category));
});
<?php
use Pasteque\Server\Model\Currency;
use Pasteque\Server\System\API\APICaller;
use Pasteque\Server\System\API\APIResult;
......@@ -8,62 +10,66 @@ use Pasteque\Server\System\API\APIResult;
* Notes: Get an array of all Currencies
* Output-Formats: [application/json]
*/
$app->GET('/api/currency/getAll', function($request, $response, $args) {
$app->GET('/api/currency/getAll',
function($request, $response, $args) {
$ptApp = $this->get('settings')['ptApp'];
return $response->withApiResult(APICaller::run($ptApp, 'currency','getAll'));
return $response->withApiResult(APICaller::run($ptApp, 'currency',
'getAll'));
});
/** Low level call. If an id is set, it's an update. If not, it's a create. */
$app->POST('/api/currency', function($request, $response, $args) {
$app->POST('/api/currency',
function($request, $response, $args) {
$ptApp = $this->get('settings')['ptApp'];
$tab = $request->getParsedBody();
$currency = \Pasteque\Server\Model\Currency::fromStruct($tab,$ptApp->getDao());
return $response->withApiResult(APICaller::run($ptApp, 'currency', 'write', $currency));
$curr = Currency::loadFromId($tab['id'], $ptApp->getDao());
if ($curr == null) {
$curr = new Currency();
}
$curr->merge($tab,$ptApp->getDao());
return $response->withApiResult(APICaller::run($ptApp, 'currency', 'write',
$currency));
});
/** Create a new currency from it's reference. The reference is read from url
/**
* Create a new currency from it's reference. The reference is read from url
* and ignored from data.
* Returns an error if an id is given or if a currency already exists
* with the given reference. */
$app->PUT('/api/currency/{reference}', function($request, $response, $args) {
* with the given reference.
*/
$app->PUT('/api/currency/{reference}',
function($request, $response, $args) {
$ptApp = $this->get('settings')['ptApp'];
$tab = $request->getParsedBody();
if (!empty($tab['id'])) {
return $response->withStatus(400, 'New record cannot have an Id');
}
$tab['reference'] = $args['reference'];
$currency = \Pasteque\Server\Model\Currency::fromStruct($tab,$ptApp->getDao());
// Check for an existing reference
$existingCurrReq = APICaller::run($ptApp, 'currency', 'getByReference', $currency->getReference());
if ($existingCurrReq->getStatus() != APIResult::STATUS_CALL_OK) {
return $response->withAPIResult($existingCurrReq);
}
if ($existingCurrReq->getContent() != null) {
$curr = Currency::load($tab['reference'], $ptApp->getDao());
if ($curr !== null) {
return $response->withStatus(400, 'Reference is already taken');
}
return $response->withApiResult(APICaller::run($ptApp, 'currency', 'write', $currency));
$curr->merge($tab);
return $response->withApiResult(APICaller::run($ptApp, 'currency', 'write',
$currency));
});
/** Update an existing currency from it's reference. Returns an error if an id
* is given or if there aren't any category with this reference. */
$app->PATCH('api/currency/{reference}', function($request, $response, $args) {
/**
* Update an existing currency from it's reference. Returns an error if an id
* is given or if there aren't any currency with this reference.
*/
$app->PATCH('api/currency/{reference}',
function($request, $response, $args) {
$ptApp = $this->get('settings')['ptApp'];
$tab = $request->getParsedBody();
if (!empty($tab['id'])) {
return $response->withStatus(400, 'Do not send Id, use reference instead.');
}
$tab['reference'] = $args['reference'];
$currency = \Pasteque\Server\Model\Currency::fromStruct($tab,$ptApp->getDao());
// Check for an existing reference
$existingCurrReq = APICaller::run($ptApp, 'currency', 'getByReference', $currency->getReference());
if ($existingCurrReq->getStatus() != APIResult::STATUS_CALL_OK) {
return $response->withAPIResult($existingCurrReq);
}
if ($existingCurrReq->getContent() == null) {
$curr = Currency::load($tab['reference'], $ptApp->getDao());
if ($curr === null) {
return $response->withStatus(404, 'No currency found.');
}
if ($existingCurrReq->getContent()->getId() != $currency->getId()) {
return $response->withStatus(500, 'Id mismatch.');
}
return $response->withApiResult(APICaller::run($ptApp, 'currency', 'write', $currency));
$curr->merge($tab);
return $response->withApiResult(APICaller::run($ptApp, 'currency', 'write',
$currency));
});
......@@ -11,9 +11,11 @@ use \Pasteque\Server\System\API\APIResult;
* Notes: Get an array of all Customers
* Output-Formats: [application/json]
*/
$app->GET('/api/customer/getAll', function($request, $response, $args) {
$app->GET('/api/customer/getAll',
function($request, $response, $args) {
$ptApp = $this->get('settings')['ptApp'];
return $response->withApiResult(APICaller::run($ptApp, 'customer', 'getAll'));
return $response->withApiResult(APICaller::run($ptApp, 'customer',
'getAll'));
});
......@@ -23,9 +25,11 @@ $app->GET('/api/customer/getAll', function($request, $response, $args) {
* Notes: Get top (limit default 10) customer sorted by count of tickets
* Output-Formats: [application/json]
*/
$app->GET('/api/customer/getTop', function($request, $response, $args) {
$app->GET('/api/customer/getTop',
function($request, $response, $args) {
$ptApp = $this->get('settings')['ptApp'];
return $response->withApiResult(APICaller::run($ptApp, 'customer', 'getTop'));
return $response->withApiResult(APICaller::run($ptApp, 'customer',
'getTop'));
});
......@@ -35,13 +39,16 @@ $app->GET('/api/customer/getTop', function($request, $response, $args) {
* Notes: Get a Customer
* Output-Formats: [application/json]
*/
$app->GET('/api/customer/{id}', function($request, $response, $args) {
$app->GET('/api/customer/{id}',
function($request, $response, $args) {
$ptApp = $this->get('settings')['ptApp'];
return $response->withApiResult(APICaller::run($ptApp, 'customer', 'get', $args['id']));
return $response->withApiResult(APICaller::run($ptApp, 'customer', 'get',
$args['id']));
});
/** Create/update a customer without changing it's balance. */
$app->POST('/api/customer', function($request, $response, $args) {
$app->POST('/api/customer',
function($request, $response, $args) {
$ptApp = $this->get('settings')['ptApp'];
$structCust = $request->getParsedBody();
if (!empty($structCust['customers'])) {
......@@ -52,14 +59,22 @@ $app->POST('/api/customer', function($request, $response, $args) {
if ($structCust['expireDate'] === false) {
return $response->withStatus(400, 'Invalid expireDate');
}
$customer = Customer::fromStruct($structCust, $ptApp->getDao());
$customer = null;
if (!empty($structCust['id'])) {
$customer = Customer::loadFromId($structCust['id'], $ptApp->getDao());
}
if ($customer === null) {
$customer = new Customer();
}
$customer->merge($structCust, $ptApp->getDao());
return $response->withApiResult(APICaller::run($ptApp, 'customer', 'write',
$customer));
$customer));
});
/** @deprecated
* This is the POST api/customer route with 'customers' as POST parameter.
* It is there until it is removed from pasteque-android which uses it. */
* It is there until it is removed from pasteque-android which uses it.
*/
function oldApiCustomer($ptApp, $response, $jsonCusts) {
$structCusts = json_decode($jsonCusts, true);
if ($structCusts === null) {
......@@ -68,23 +83,32 @@ function oldApiCustomer($ptApp, $response, $jsonCusts) {
// Fill the array.
$customers = [];
foreach ($structCusts as $strC) {
$customers[] = Customer::fromStruct($strC, $ptApp->getDao());
$cust = null;
if (!empty($strC['id'])) {
$cust = Customer::loadFromId($strC['id'], $ptApp->getDao());
}
if ($cust === null) {
$cust = new Customer();
}
$cust->merge($strC, $ptApp->getDao());
$customers[] = $cust;
// There is no expireDate in the form from Android, so ignore it.
}
return $response->withApiResult(APICaller::run($ptApp, 'customer', 'write',
$customers));
$customers));
}
$app->PATCH('/api/customer/{id}/balance/{balance}', function($request, $response, $args) {
$app->PATCH('/api/customer/{id}/balance/{balance}',
function($request, $response, $args) {
$ptApp = $this->get('settings')['ptApp'];
if (!is_numeric($args['balance'])) {
return $response->withStatus(400, 'Invalid balance');
}
$custId = $args['id'];
$balance = floatval($args['balance']);
$custApiResp = APICaller::run($ptApp, 'customer', 'get', $custId);
if ($custApiResp->getStatus() != APIResult::STATUS_CALL_OK) {
return $response->withApiResult($custApiResp);
$cust = Customer::loadFromId($custId, $ptApp->getDao());
if ($cust === null) {
return $response->withStatus(404, 'Customer not found');
}
$balanceApiResp = APICaller::run($ptApp, 'customer', 'setBalance',
[$custId, $balance]);
......@@ -96,4 +120,4 @@ $app->PATCH('/api/customer/{id}/balance/{balance}', function($request, $response
} else {
return $response->withStatus(404, 'Customer not found');
}
});
\ No newline at end of file
});
......@@ -13,9 +13,11 @@ use \Pasteque\Server\System\API\APICaller;
* @SWG\Response(response="200", description="Get an array of all DiscountProfiles")
* )
*/
$app->GET('/api/discountprofile/getAll', function($request, $response, $args) {
$app->GET('/api/discountprofile/getAll',
function($request, $response, $args) {
$ptApp = $this->get('settings')['ptApp'];
return $response->withApiResult(APICaller::run($ptApp, 'discountprofile', 'getAll'));
return $response->withApiResult(APICaller::run($ptApp, 'discountprofile',
'getAll'));
});
......@@ -29,15 +31,26 @@ $app->GET('/api/discountprofile/getAll', function($request, $response, $args) {
* @SWG\Response(response="200", description="Get a DiscountProfile")
* )
*/
$app->GET('/api/discountprofile/{id}', function($request, $response, $args) {
$app->GET('/api/discountprofile/{id}',
function($request, $response, $args) {
$ptApp = $this->get('settings')['ptApp'];
return $response->withApiResult(APICaller::run($ptApp, 'discountprofile', 'get', $args['id']));
return $response->withApiResult(APICaller::run($ptApp, 'discountprofile',
'get', $args['id']));
});
/** Low level call. If an id is set, it's an update. If not, it's a create. */
$app->POST('/api/discountprofile', function($request, $response, $args) {
$app->POST('/api/discountprofile',
function($request, $response, $args) {
$ptApp = $this->get('settings')['ptApp'];
$tab = $request->getParsedBody();
$profile = DiscountProfile::fromStruct($tab, $ptApp->getDao());
return $response->withApiResult(APICaller::run($ptApp, 'discountprofile', 'write', $profile));
$profile = null;
if (!empty($tab['id'])) {
$profile = DiscountProfile::loadFromId($tab['id']);
}
if ($profile === null) {
$profile = new DiscountProfile();
}
$profile->merge($tab, $ptApp->getDao());
return $response->withApiResult(APICaller::run($ptApp, 'discountprofile',