progress in sell controller

This commit is contained in:
Hesabix 2024-05-22 17:01:31 +00:00
parent acbf6b27e4
commit 74dd972f3d
7 changed files with 216 additions and 23 deletions

View file

@ -26,6 +26,8 @@ services:
# please note that last definitions always *replace* previous ones
Jdate:
class: App\Service\Jdate
Exctractor:
class: App\Service\Exctractor
Log:
class: App\Service\Log
arguments: [ "@doctrine.orm.entity_manager" ]

View file

@ -614,8 +614,17 @@ class BusinessController extends AbstractController
'type' => 'buy',
]);
$buysTotal = 0;
foreach ($buys as $item)
$buysTotal += $item->getAmount();
foreach ($buys as $item) {
$canAdd = false;
foreach ($item->getHesabdariRows() as $row) {
if ($row->getCommodity())
$canAdd = true;
}
if ($canAdd) {
$buysTotal += $item->getAmount();
}
}
$sells = $entityManager->getRepository(HesabdariDoc::class)->findBy([
'bid' => $buss,
@ -623,8 +632,16 @@ class BusinessController extends AbstractController
'type' => 'sell',
]);
$sellsTotal = 0;
foreach ($sells as $item)
$sellsTotal += $item->getAmount();
foreach ($sells as $item) {
$canAdd = false;
foreach ($item->getHesabdariRows() as $row) {
if ($row->getCommodity())
$canAdd = true;
}
if ($canAdd) {
$sellsTotal += $item->getAmount();
}
}
$response = [
'personCount' => count($persons),
'bankCount' => count($banks),

View file

@ -110,6 +110,10 @@ class CommodityController extends AbstractController
$temp['id'] = $item->getId();
$temp['name'] = $item->getName();
$temp['unit'] = $item->getUnit()->getName();
$temp['unitData'] = [
'name' => $item->getUnit()->getName(),
'floatNumber' => $item->getUnit()->getFloatNumber(),
];
$temp['des'] = $item->getDes();
$temp['priceBuy'] = $item->getPriceBuy();
$temp['speedAccess'] = $item->isSpeedAccess();

View file

@ -5,7 +5,13 @@ namespace App\Controller;
use App\Service\Log;
use App\Service\Access;
use App\Service\Explore;
use App\Entity\Commodity;
use App\Service\Provider;
use App\Service\Extractor;
use App\Entity\HesabdariDoc;
use App\Entity\HesabdariRow;
use App\Entity\HesabdariTable;
use App\Entity\Person;
use App\Entity\StoreroomTicket;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\Request;
@ -17,43 +23,149 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class SellController extends AbstractController
{
#[Route('/api/sell/edit/can/{code}', name: 'app_sell_can_edit')]
public function app_sell_can_edit(Request $request,Access $access,Log $log,EntityManagerInterface $entityManager, string $code): JsonResponse
public function app_sell_can_edit(Request $request, Access $access, Log $log, EntityManagerInterface $entityManager, string $code): JsonResponse
{
$canEdit = true;
$acc = $access->hasRole('sell');
if(!$acc)
if (!$acc)
throw $this->createAccessDeniedException();
$doc = $entityManager->getRepository(HesabdariDoc::class)->findOneBy([
'bid'=>$acc['bid'],
'code'=>$code
'bid' => $acc['bid'],
'code' => $code
]);
//check related documents
if(count($doc->getRelatedDocs()) != 0)
if (count($doc->getRelatedDocs()) != 0)
$canEdit = false;
//check storeroom tickets
$tickets = $entityManager->getRepository(StoreroomTicket::class)->findBy(['doc'=>$doc]);
if(count($tickets) != 0)
$tickets = $entityManager->getRepository(StoreroomTicket::class)->findBy(['doc' => $doc]);
if (count($tickets) != 0)
$canEdit = false;
return $this->json([
'result'=> $canEdit
'result' => $canEdit
]);
}
#[Route('/api/sell/get/info/{code}', name: 'app_sell_get_info')]
public function app_sell_get_info(Request $request,Access $access,Log $log,EntityManagerInterface $entityManager, string $code): JsonResponse
public function app_sell_get_info(Request $request, Access $access, Log $log, EntityManagerInterface $entityManager, string $code): JsonResponse
{
$acc = $access->hasRole('sell');
if(!$acc)
if (!$acc)
throw $this->createAccessDeniedException();
$doc = $entityManager->getRepository(HesabdariDoc::class)->findOneBy([
'bid'=>$acc['bid'],
'code'=>$code
'bid' => $acc['bid'],
'code' => $code
]);
if(!$doc)
if (!$doc)
throw $this->createNotFoundException();
return $this->json(Explore::ExploreSellDoc($doc));
}
#[Route('/api/sell/mod', name: 'app_sell_mod')]
public function app_sell_mod(Provider $provider, Extractor $extractor, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse
{
$params = [];
if ($content = $request->getContent()) {
$params = json_decode($content, true);
}
$acc = $access->hasRole('sell');
if (!$acc)
throw $this->createAccessDeniedException();
if (!array_key_exists('update', $params)) {
return $this->json($extractor->paramsNotSend());
}
if ($params['update'] != '') {
$doc = $entityManager->getRepository(HesabdariDoc::class)->findOneBy([
'bid' => $acc['bid'],
'year' => $acc['year'],
'code' => $params['update']
]);
if (!$doc) $this->json($extractor->notFound());
$rows = $entityManager->getRepository(HesabdariRow::class)->findBy([
'doc' => $doc
]);
foreach ($rows as $row)
$entityManager->remove($row);
} else {
$doc = new HesabdariDoc();
$doc->setBid($acc['bid']);
$doc->setYear($acc['year']);
$doc->setDateSubmit(time());
$doc->setType('sell');
$doc->setSubmitter($this->getUser());
$doc->setMoney($acc['bid']->getMoney());
$doc->setCode($provider->getAccountingCode($acc['bid'], 'accounting'));
}
$doc->setDes($params['des']);
$doc->setDate($params['date']);
$sumTax = 0;
$sumTotal = 0;
foreach ($params['rows'] as $row) {
$sumTax += $row['tax'];
$sumTotal += $row['sumWithoutTax'];
$hesabdariRow = new HesabdariRow();
$hesabdariRow->setDes($row['des']);
$hesabdariRow->setBid($acc['bid']);
$hesabdariRow->setYear($acc['year']);
$hesabdariRow->setDoc($doc);
$hesabdariRow->setBs($row['sumWithoutTax'] + $row['tax']);
$hesabdariRow->setBd(0);
$hesabdariRow->setDiscount($row['discount']);
$hesabdariRow->setTax($row['tax']);
$ref = $entityManager->getRepository(HesabdariTable::class)->findOneBy([
'code' => '59' // sell commodity
]);
$hesabdariRow->setRef($ref);
$row['count'] = str_replace(',', '', $row['count']);
$commodity = $entityManager->getRepository(Commodity::class)->findOneBy([
'id' => $row['commodity']['id'],
'bid' => $acc['bid']
]);
if (!$commodity)
return $this->json($extractor->paramsNotSend());
$hesabdariRow->setCommodity($commodity);
$hesabdariRow->setCommdityCount($row['count']);
$entityManager->persist($hesabdariRow);
}
//set amount of document
$doc->setAmount($sumTax + $sumTotal);
//set person buyer
$hesabdariRow = new HesabdariRow();
$hesabdariRow->setDes('فاکتور فروش');
$hesabdariRow->setBid($acc['bid']);
$hesabdariRow->setYear($acc['year']);
$hesabdariRow->setDoc($doc);
$hesabdariRow->setBs(0);
$hesabdariRow->setBd($sumTax + $sumTotal);
$ref = $entityManager->getRepository(HesabdariTable::class)->findOneBy([
'code' => '3' // persons
]);
$hesabdariRow->setRef($ref);
$person = $entityManager->getRepository(Person::class)->findOneBy([
'bid' => $acc['bid'],
'code' => $params['buyer']['code']
]);
if (!$person)
return $this->json($extractor->paramsNotSend());
$hesabdariRow->setPerson($person);
$entityManager->persist($hesabdariRow);
//set tax info
$entityManager->persist($doc);
$entityManager->flush();
$log->insert(
'حسابداری',
'سند حسابداری شماره ' . $doc->getCode() . ' ثبت / ویرایش شد.',
$this->getUser(),
$request->headers->get('activeBid'),
$doc
);
return $this->json($extractor->operationSuccess());
}
}

View file

@ -23,6 +23,9 @@ class CommodityUnit
#[Ignore]
private $commodities;
#[ORM\Column(nullable: true)]
private ?int $floatNumber = null;
public function __construct()
{
$this->commodities = new ArrayCollection();
@ -74,4 +77,16 @@ class CommodityUnit
return $this;
}
public function getFloatNumber(): ?int
{
return $this->floatNumber;
}
public function setFloatNumber(?int $floatNumber): static
{
$this->floatNumber = $floatNumber;
return $this;
}
}

View file

@ -39,12 +39,9 @@ class Explore
{
$result = self::ExploreHesabdariDoc($hesabdariDoc);
$person = [];
$commodities = [];
foreach ($hesabdariDoc->getHesabdariRows() as $item) {
if ($item->getPerson()) {
$person = self::ExplorePerson($item->getPerson());
} elseif ($item->getCommodity()) {
$commodities[] = Explore::ExploreCommodity($item->getCommodity(), $item->getCommdityCount(), $item->getDes());
}
}
$result['person'] = $person;
@ -141,7 +138,9 @@ class Explore
'des' => $row->getDes(),
'plugin' => $row->getPlugin(),
'commodity_count' => $row->getCommdityCount(),
'commodity' => self::ExploreCommodity($row->getCommodity(), $row->getCommdityCount(), $row->getDes())
'commodity' => self::ExploreCommodity($row->getCommodity(), $row->getCommdityCount(), $row->getDes()),
'tax' =>$row->getTax(),
'discount' =>$row->getDiscount(),
];
}

View file

@ -0,0 +1,44 @@
<?php
namespace App\Service;
use App\Entity\BankAccount;
use App\Entity\User;
use App\Entity\Year;
use App\Entity\Business;
use App\Entity\Cashdesk;
use App\Entity\Cheque;
use App\Entity\Commodity;
use App\Entity\HesabdariDoc;
use App\Entity\HesabdariRow;
use App\Entity\HesabdariTable;
use App\Entity\Money;
use App\Entity\Person;
use App\Entity\PersonType;
use App\Entity\Salary;
class Extractor
{
public function operationSuccess($data = ''){
return [
'code' => 0,
'data' =>$data,
'message'=>'operation success'
];
}
public function notFound($data = ''){
return [
'code' => 404,
'data' =>$data,
'message'=>'item not found'
];
}
public function paramsNotSend(){
return [
'code' => 101,
'data' =>'',
'message'=>'parameters not send currectly'
];
}
}