update for Hooks

This commit is contained in:
Gloomy 2025-07-27 14:27:17 +00:00
parent 195e6c0693
commit be782e14bd
8 changed files with 123 additions and 10 deletions

View file

@ -69,7 +69,6 @@ class PersonService
$response['bs'] = $bs;
$response['bd'] = $bd;
$response['balance'] = $bs - $bd;
return $response;
}
@ -229,6 +228,7 @@ class PersonService
if (isset($params['codeeghtesadi'])) $person->setCodeeghtesadi($params['codeeghtesadi']);
if (isset($params['shenasemeli'])) $person->setShenasemeli($params['shenasemeli']);
if (isset($params['company'])) $person->setCompany($params['company']);
if (isset($params['tags'])) $person->setTags($params['tags']);
if (array_key_exists('prelabel', $params)) {
if ($params['prelabel'] != '') {
$prelabel = $em->getRepository(\App\Entity\PersonPrelabel::class)->findOneBy(['label' => $params['prelabel']]);
@ -278,6 +278,6 @@ class PersonService
}
$em->persist($person);
$em->flush();
return ['Success' => true, 'result' => 1];
return ['Success' => true, 'result' => 1, 'code' => $person->getCode()];
}
}

View file

@ -675,7 +675,7 @@ class CommodityController extends AbstractController
}
}
$res['Success'] = true;
return $this->json($res);
}
@ -691,11 +691,14 @@ class CommodityController extends AbstractController
}
if (!array_key_exists('items', $paramsAll))
return $this->json($extractor->paramsNotSend());
$results = [];
$createdItems = [];
foreach ($paramsAll['items'] as $params) {
if (!array_key_exists('name', $params))
return $this->json(['result' => -1]);
if (count_chars(trim($params['name'])) == 0)
return $this->json(['result' => 3]);
$isNew = false;
if ($code == 0) {
$data = $entityManager->getRepository(Commodity::class)->findOneBy([
'name' => $params['name'],
@ -705,6 +708,7 @@ class CommodityController extends AbstractController
if (!$data) {
$data = new Commodity();
$data->setCode($provider->getAccountingCode($request->headers->get('activeBid'), 'Commodity'));
$isNew = true;
}
} else {
$data = $entityManager->getRepository(Commodity::class)->findOneBy([
@ -791,6 +795,13 @@ class CommodityController extends AbstractController
}
}
}
if (array_key_exists('Tag', $params)) {
$tagValue = $params['Tag'];
if (is_string($tagValue)) {
$tagValue = json_decode($tagValue, true);
}
$data->setTags($tagValue);
}
$entityManager->persist($data);
//save prices list
@ -819,11 +830,42 @@ class CommodityController extends AbstractController
}
$entityManager->flush();
$log->insert('کالا و خدمات', 'کالا / خدمات با نام ' . $params['name'] . ' افزوده/ویرایش شد.', $this->getUser(), $request->headers->get('activeBid'));
$createdItems[] = [
'id' => $data->getId(),
'name' => $data->getName(),
'code' => $data->getCode(),
'unit' => $data->getUnit() ? $data->getUnit()->getName() : null,
'khadamat' => $data->isKhadamat(),
'withoutTax' => $data->isWithoutTax(),
'des' => $data->getDes(),
'priceSell' => $data->getPriceSell(),
'priceBuy' => $data->getPriceBuy(),
'commodityCountCheck' => $data->isCommodityCountCheck(),
'barcodes' => $data->getBarcodes(),
'taxCode' => $data->getTaxCode(),
'taxType' => $data->getTaxType(),
'taxUnit' => $data->getTaxUnit(),
'minOrderCount' => $data->getMinOrderCount(),
'speedAccess' => $data->isSpeedAccess(),
'dayLoading' => $data->getDayLoading(),
'orderPoint' => $data->getOrderPoint(),
'cat' => $data->getCat() ? $data->getCat()->getId() : null,
'tags' => $data->getTags(),
];
}
if (isset($paramsAll['reqType']) && $paramsAll['reqType'] === 'woocommercePlugin') {
return $this->json([
'Success' => 1,
'result' => 1,
'createdItems' => $createdItems
]);
} else {
return $this->json([
'Success' => 1,
'result' => 1
]);
}
return $this->json([
'Success' => true,
'result' => 1,
]);
}
#[Route('/api/commodity/mod/{id}', name: 'app_commodity_mod')]
public function app_commodity_mod(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager, $id = 0): JsonResponse

View file

@ -20,7 +20,7 @@ use App\Entity\Permission;
use App\Entity\BankAccount;
use App\Entity\CommodityCat;
use App\Entity\HesabdariDoc;
use App\Cog\PersonService;
use App\Entity\HesabdariRow;
use App\Entity\CommodityUnit;
use Doctrine\ORM\EntityManagerInterface;
@ -71,6 +71,42 @@ class HookController extends AbstractController
]);
}
#[Route('/hooks/modify/person', name: 'hook_modify_person')]
public function hook_modify_person(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager, $code = 0): JsonResponse
{
$acc = $access->hasRole('person');
if (!$acc)
throw $this->createAccessDeniedException();
$params = [];
if ($content = $request->getContent()) {
$params = json_decode($content, true);
}
$personService = new \App\Cog\PersonService($entityManager);
$result = $personService->addOrUpdatePerson($params, $acc, $code);
if (isset($result['error'])) {
return $this->json($result, 400);
}
$log->insert('اشخاص', 'شخص با نام مستعار ' . $params['nikename'] . ' افزوده/ویرایش شد.', $this->getUser(), $acc['bid']);
$person = $personService->getPersonInfo($result['code'], $acc);
$result['person'] = $person;
return $this->json($result);
}
#[Route('/hooks/info/person', name: 'hook_info_person')]
public function hook_info_person($code, Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager, PersonService $personService): JsonResponse
{
$acc = $access->hasRole('person');
if (!$acc)
throw $this->createAccessDeniedException();
$response = $personService->getPersonInfo($code, $acc);
$response['Success'] = true;
return $this->json($response);
}
#[Route('hooks/setting/getCurrency', name: 'api_hooks_getcurrency')]
public function api_hooks_getcurrency(Access $access, Log $log, Request $request, EntityManagerInterface $entityManager): JsonResponse
{

View file

@ -132,8 +132,13 @@ class PersonsController extends AbstractController
$person->setName($params['name']);
if (array_key_exists('birthday', $params))
$person->setBirthday($params['birthday']);
if (array_key_exists('tel', $params))
$person->setTel($params['tel']);
if (array_key_exists('tel', $params)) {
if (is_string($params['tel']) && strlen(preg_replace('/[^0-9]/', '', $params['tel'])) > 11) {
$person->setTel('');
} else {
$person->setTel($params['tel']);
}
}
if (array_key_exists('speedAccess', $params))
$person->setSpeedAccess($params['speedAccess']);
if (array_key_exists('address', $params))

View file

@ -1236,6 +1236,7 @@ class SellController extends AbstractController
}
return $this->json([
'Success' => 1,
'result' => 1,
'message' => 'فاکتور با موفقیت ثبت شد',
'data' => [

View file

@ -104,6 +104,9 @@ class Commodity
#[ORM\OneToMany(mappedBy: 'commodity', targetEntity: PreInvoiceItem::class, orphanRemoval: true)]
private Collection $preInvoiceItems;
#[ORM\Column(type: Types::JSON, nullable: true)]
private ?array $tags = null;
public function __construct()
{
$this->setPriceBuy(0);
@ -540,4 +543,15 @@ class Commodity
return $this;
}
public function getTags(): ?array
{
return $this->tags;
}
public function setTags(?array $tags): static
{
$this->tags = $tags;
return $this;
}
}

View file

@ -158,6 +158,9 @@ class Person
#[ORM\OneToMany(targetEntity: PlugGhestaDoc::class, mappedBy: 'person', orphanRemoval: true)]
private Collection $PlugGhestaDocs;
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $tags = null;
public function __construct()
{
$this->hesabdariRows = new ArrayCollection();
@ -899,4 +902,15 @@ class Person
return $this;
}
public function getTags(): ?string
{
return $this->tags;
}
public function setTags(?string $tags): self
{
$this->tags = $tags;
return $this;
}
}

View file

@ -346,6 +346,7 @@ class Explore
'speedAccess' => $person->isSpeedAccess(),
'address' => $person->getAddress(),
'prelabel' => null,
'tags' => $person->getTags(),
];
if ($person->getPrelabel()) {
$res['prelabel'] = $person->getPrelabel()->getLabel();