I can not run actionCreate function. I am writing custom controller for entity, but am getting error.I can not add records to the database. --> "bad server response"
Code:
<?php
namespace Espo\Custom\Controllers;
class BesProduct extends \Espo\Core\Templates\Controllers\Base
{
protected function getEntityManager()
{
return $this->getContainer()->get('entityManager');
}
public function actionCreate($params, $data, $request)
{
//return json_encode($data);
$pdo = $this->getEntityManager()->getPDO();
if($data->status == "3"){
/* Get user */
$userSql = "SELECT career_steps_id FROM user WHERE id='".$data->assignedUserId."'";
$userResult = $pdo->prepare($userSql);
$userResult->execute();
$userRow = $userResult->fetch(\PDO::FETCH_ASSOC);
/* Get career step */
$stepCommissionSql = "SELECT * FROM career_commissions WHERE career_steps_id='".$userRow['career_steps_id']."'";
$stepCommissionResult = $pdo->prepare($stepCommissionSql);
$stepCommissionResult->execute();
$stepCommissionRow = $stepCommissionResult->fetchAll(\PDO::FETCH_ASSOC);
$x = 1;
while($x <= $stepCommissionRow['payment_period']){
$commissionValue = $data->amount * $stepCommissionRow['commission_value'] / 100;
$totalPay = $commissionValue / $stepCommissionRow['payment_period'];
/* Update career history table */
$id = uniqid();
$commissionSql = "INSERT INTO career_history (id,name,deleted,description,created_at,modified_at,created_by_id,modified_by_id,assigned_user_id,payable,month)
VALUES ('".$id."','','0','','".$date."','".$date."','1','1','".$data->assignedUserId."','".$totalPay."','".$x."')";
$sthCommission = $pdo->prepare($commissionSql);
$sthCommission->execute();
$x++;
}
}
}
}

Comment