add sms to sell invoices and auto update prices

This commit is contained in:
babak alizadeh 2024-10-23 02:26:51 +03:30
parent 2b2abff420
commit 928f77866d
3 changed files with 108 additions and 41 deletions

View file

@ -221,9 +221,20 @@ class BusinessController extends AbstractController
$business->setWesite($params['website']); $business->setWesite($params['website']);
if ($params['email']) if ($params['email'])
$business->setEmail($params['email']); $business->setEmail($params['email']);
if ($params['commodityUpdateBuyPriceAuto']) if (array_key_exists('commodityUpdateBuyPriceAuto', $params)) {
$business->setCommodityUpdateBuyPriceAuto($params['commodityUpdateBuyPriceAuto']); if ($params['commodityUpdateBuyPriceAuto'] == true) {
if ($params['commodityUpdateSellPriceAuto']) $business->setCommodityUpdateBuyPriceAuto(true);
} else {
$business->setCommodityUpdateBuyPriceAuto(false);
}
}
if (array_key_exists('commodityUpdateSellPriceAuto', $params)) {
if ($params['commodityUpdateSellPriceAuto'] == true) {
$business->setCommodityUpdateSellPriceAuto(true);
} else {
$business->setCommodityUpdateSellPriceAuto(false);
}
}
$business->setCommodityUpdateSellPriceAuto($params['commodityUpdateSellPriceAuto']); $business->setCommodityUpdateSellPriceAuto($params['commodityUpdateSellPriceAuto']);
if (array_key_exists('walletEnabled', $params)) { if (array_key_exists('walletEnabled', $params)) {
if ($params['walletEnabled']) { if ($params['walletEnabled']) {

View file

@ -177,6 +177,12 @@ class BuyController extends AbstractController
$hesabdariRow->setCommodity($commodity); $hesabdariRow->setCommodity($commodity);
$hesabdariRow->setCommdityCount($row['count']); $hesabdariRow->setCommdityCount($row['count']);
$entityManager->persist($hesabdariRow); $entityManager->persist($hesabdariRow);
//update commodity price for auto update price option
if($acc['bid']->isCommodityUpdateBuyPriceAuto() == true && $commodity->getPriceBuy() != $row['price']){
$commodity->setPriceBuy($row['price']);
$entityManager->persist($commodity);
}
} }
//set amount of document //set amount of document
$doc->setAmount($sumTax + $sumTotal - $params['discountAll'] + $params['transferCost']); $doc->setAmount($sumTax + $sumTotal - $params['discountAll'] + $params['transferCost']);

View file

@ -6,6 +6,7 @@ use App\Service\Log;
use App\Service\Access; use App\Service\Access;
use App\Service\Explore; use App\Service\Explore;
use App\Entity\Commodity; use App\Entity\Commodity;
use App\Service\PluginService;
use App\Service\Provider; use App\Service\Provider;
use App\Service\Extractor; use App\Service\Extractor;
use App\Entity\HesabdariDoc; use App\Entity\HesabdariDoc;
@ -16,6 +17,8 @@ use App\Entity\Person;
use App\Entity\PrintOptions; use App\Entity\PrintOptions;
use App\Entity\StoreroomTicket; use App\Entity\StoreroomTicket;
use App\Service\Printers; use App\Service\Printers;
use App\Service\registryMGR;
use App\Service\SMS;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
@ -67,7 +70,7 @@ class SellController extends AbstractController
} }
#[Route('/api/sell/mod', name: 'app_sell_mod')] #[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 public function app_sell_mod(registryMGR $registryMGR,PluginService $pluginService,SMS $SMS,Provider $provider, Extractor $extractor, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse
{ {
$params = []; $params = [];
if ($content = $request->getContent()) { if ($content = $request->getContent()) {
@ -87,7 +90,8 @@ class SellController extends AbstractController
'year' => $acc['year'], 'year' => $acc['year'],
'code' => $params['update'] 'code' => $params['update']
]); ]);
if (!$doc) return $this->json($extractor->notFound()); if (!$doc)
return $this->json($extractor->notFound());
$rows = $entityManager->getRepository(HesabdariRow::class)->findBy([ $rows = $entityManager->getRepository(HesabdariRow::class)->findBy([
'doc' => $doc 'doc' => $doc
@ -162,6 +166,12 @@ class SellController extends AbstractController
$hesabdariRow->setCommodity($commodity); $hesabdariRow->setCommodity($commodity);
$hesabdariRow->setCommdityCount($row['count']); $hesabdariRow->setCommdityCount($row['count']);
$entityManager->persist($hesabdariRow); $entityManager->persist($hesabdariRow);
//update commodity price for auto update price option
if ($acc['bid']->isCommodityUpdateSellPriceAuto() == true && $commodity->getPriceSell() != $row['price']) {
$commodity->setPriceSell($row['price']);
$entityManager->persist($commodity);
}
} }
//set amount of document //set amount of document
$doc->setAmount($sumTax + $sumTotal - $params['discountAll'] + $params['transferCost']); $doc->setAmount($sumTax + $sumTotal - $params['discountAll'] + $params['transferCost']);
@ -197,6 +207,36 @@ class SellController extends AbstractController
$request->headers->get('activeBid'), $request->headers->get('activeBid'),
$doc $doc
); );
//send sms to customer
if (array_key_exists('sms', $params)) {
if ($params['sms'] == true) {
if ($pluginService->isActive('accpro', $acc['bid']) && $person->getMobile() != '' && $acc['bid']->getTel()) {
return $this->json([
'result' =>
$SMS->sendByBalance(
[$person->getnikename(), 'sell/' . $acc['bid']->getId() . '/' . $doc->getShortLink() , $acc['bid']->getName(), $acc['bid']->getTel()],
$registryMGR->get('sms', 'plugAccproSharefaktor'),
$person->getMobile(),
$acc['bid'],
$this->getUser(),
3
)
]);
} else {
return $this->json([
'result' =>
$SMS->sendByBalance(
[$acc['bid']->getName(), 'sell/' . $acc['bid']->getId() . '/' . $doc->getShortLink()],
$registryMGR->get('sms', 'sharefaktor'),
$person->getMobile(),
$acc['bid'],
$this->getUser(),
3
)
]);
}
}
}
return $this->json($extractor->operationSuccess()); return $this->json($extractor->operationSuccess());
} }
@ -216,7 +256,8 @@ class SellController extends AbstractController
'code' => $params['label']['code'], 'code' => $params['label']['code'],
'type' => 'sell' 'type' => 'sell'
]); ]);
if (!$label) return $this->json($extractor->notFound()); if (!$label)
return $this->json($extractor->notFound());
} }
foreach ($params['items'] as $item) { foreach ($params['items'] as $item) {
$doc = $entityManager->getRepository(HesabdariDoc::class)->findOneBy([ $doc = $entityManager->getRepository(HesabdariDoc::class)->findOneBy([
@ -224,7 +265,8 @@ class SellController extends AbstractController
'year' => $acc['year'], 'year' => $acc['year'],
'code' => $item['code'] 'code' => $item['code']
]); ]);
if (!$doc) return $this->json($extractor->notFound()); if (!$doc)
return $this->json($extractor->notFound());
if ($params['label'] != 'clear') { if ($params['label'] != 'clear') {
$doc->setInvoiceLabel($label); $doc->setInvoiceLabel($label);
$entityManager->persist($doc); $entityManager->persist($doc);
@ -309,8 +351,10 @@ class SellController extends AbstractController
$temp['transferCost'] = $item->getBs(); $temp['transferCost'] = $item->getBs();
} }
} }
if(!array_key_exists('discountAll',$temp)) $temp['discountAll'] = 0; if (!array_key_exists('discountAll', $temp))
if(!array_key_exists('transferCost',$temp)) $temp['transferCost'] = 0; $temp['discountAll'] = 0;
if (!array_key_exists('transferCost', $temp))
$temp['transferCost'] = 0;
$dataTemp[] = $temp; $dataTemp[] = $temp;
} }
return $this->json($dataTemp); return $this->json($dataTemp);
@ -325,13 +369,15 @@ class SellController extends AbstractController
} }
$acc = $access->hasRole('sell'); $acc = $access->hasRole('sell');
if (!$acc) throw $this->createAccessDeniedException(); if (!$acc)
throw $this->createAccessDeniedException();
$doc = $entityManager->getRepository(HesabdariDoc::class)->findOneBy([ $doc = $entityManager->getRepository(HesabdariDoc::class)->findOneBy([
'bid' => $acc['bid'], 'bid' => $acc['bid'],
'code' => $params['code'] 'code' => $params['code']
]); ]);
if (!$doc) throw $this->createNotFoundException(); if (!$doc)
throw $this->createNotFoundException();
$pdfPid = 0; $pdfPid = 0;
if ($params['pdf']) { if ($params['pdf']) {
$pdfPid = $provider->createPrint( $pdfPid = $provider->createPrint(
@ -388,13 +434,15 @@ class SellController extends AbstractController
} }
$acc = $access->hasRole('sell'); $acc = $access->hasRole('sell');
if (!$acc) throw $this->createAccessDeniedException(); if (!$acc)
throw $this->createAccessDeniedException();
$doc = $entityManager->getRepository(HesabdariDoc::class)->findOneBy([ $doc = $entityManager->getRepository(HesabdariDoc::class)->findOneBy([
'bid' => $acc['bid'], 'bid' => $acc['bid'],
'code' => $params['code'] 'code' => $params['code']
]); ]);
if (!$doc) throw $this->createNotFoundException(); if (!$doc)
throw $this->createNotFoundException();
$person = null; $person = null;
$discount = 0; $discount = 0;
$transfer = 0; $transfer = 0;
@ -439,7 +487,9 @@ class SellController extends AbstractController
} }
$note = ''; $note = '';
$printSettings = $entityManager->getRepository(PrintOptions::class)->findOneBy(['bid' => $acc['bid']]); $printSettings = $entityManager->getRepository(PrintOptions::class)->findOneBy(['bid' => $acc['bid']]);
if($printSettings){$note = $printSettings->getSellNoteString();} if ($printSettings) {
$note = $printSettings->getSellNoteString();
}
$pdfPid = $provider->createPrint( $pdfPid = $provider->createPrint(
$acc['bid'], $acc['bid'],
$this->getUser(), $this->getUser(),