progress in calculate profit of invoices
This commit is contained in:
parent
928f77866d
commit
89ffdb9aea
|
@ -130,6 +130,11 @@ class BusinessController extends AbstractController
|
|||
$response['walletMatchBank'] = null;
|
||||
$response['updateSellPrice'] = $bus->isCommodityUpdateSellPriceAuto();
|
||||
$response['updateBuyPrice'] = $bus->isCommodityUpdateBuyPriceAuto();
|
||||
if (!$bus->getProfitCalctype()) {
|
||||
$response['profitCalcType'] = 'lis';
|
||||
} else {
|
||||
$response['profitCalcType'] = $bus->getProfitCalctype();
|
||||
}
|
||||
if ($bus->isWalletEnable())
|
||||
$response['walletMatchBank'] = $provider->Entity2Array($bus->getWalletMatchBank(), 0);
|
||||
$year = $entityManager->getRepository(Year::class)->findOneBy([
|
||||
|
@ -235,6 +240,14 @@ class BusinessController extends AbstractController
|
|||
$business->setCommodityUpdateSellPriceAuto(false);
|
||||
}
|
||||
}
|
||||
if (array_key_exists('profitCalcType', $params)) {
|
||||
if ($params['profitCalcType'] == 'lis' || $params['profitCalcType'] == 'avgis') {
|
||||
$business->setProfitCalcType($params['profitCalcType']);
|
||||
}
|
||||
}
|
||||
else{
|
||||
$business->setProfitCalcType('lis');
|
||||
}
|
||||
$business->setCommodityUpdateSellPriceAuto($params['commodityUpdateSellPriceAuto']);
|
||||
if (array_key_exists('walletEnabled', $params)) {
|
||||
if ($params['walletEnabled']) {
|
||||
|
|
|
@ -70,7 +70,7 @@ class SellController extends AbstractController
|
|||
}
|
||||
|
||||
#[Route('/api/sell/mod', name: 'app_sell_mod')]
|
||||
public function app_sell_mod(registryMGR $registryMGR,PluginService $pluginService,SMS $SMS,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 = [];
|
||||
if ($content = $request->getContent()) {
|
||||
|
@ -214,7 +214,7 @@ class SellController extends AbstractController
|
|||
return $this->json([
|
||||
'result' =>
|
||||
$SMS->sendByBalance(
|
||||
[$person->getnikename(), 'sell/' . $acc['bid']->getId() . '/' . $doc->getShortLink() , $acc['bid']->getName(), $acc['bid']->getTel()],
|
||||
[$person->getnikename(), 'sell/' . $acc['bid']->getId() . '/' . $doc->getShortLink(), $acc['bid']->getName(), $acc['bid']->getTel()],
|
||||
$registryMGR->get('sms', 'plugAccproSharefaktor'),
|
||||
$person->getMobile(),
|
||||
$acc['bid'],
|
||||
|
@ -343,13 +343,33 @@ class SellController extends AbstractController
|
|||
$pays += $relatedDoc->getAmount();
|
||||
}
|
||||
$temp['relatedDocsPays'] = $pays;
|
||||
|
||||
// this variable is for store profit of invoice
|
||||
$temp['profit'] = 0;
|
||||
foreach ($item->getHesabdariRows() as $item) {
|
||||
if ($item->getRef()->getCode() == '104') {
|
||||
$temp['discountAll'] = $item->getBd();
|
||||
} elseif ($item->getRef()->getCode() == '61') {
|
||||
$temp['transferCost'] = $item->getBs();
|
||||
}
|
||||
|
||||
//calculate profit
|
||||
if ($item->getCommodity()) {
|
||||
if ($acc['bid']->getProfitCalctype() == 'lis') {
|
||||
$last = $entityManager->getRepository(HesabdariRow::class)->findOneBy([
|
||||
'commodity' => $item->getCommodity(),
|
||||
'bs' => 0
|
||||
], [
|
||||
'id' => 'DESC'
|
||||
]);
|
||||
if ($last) {
|
||||
$price = $last->getBd() / $last->getCommdityCount();
|
||||
$temp['profit'] = $temp['profit'] + (($item->getBs() / $last->getCommdityCount()) - $price);
|
||||
}
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if (!array_key_exists('discountAll', $temp))
|
||||
$temp['discountAll'] = 0;
|
||||
|
|
|
@ -243,6 +243,9 @@ class Business
|
|||
#[ORM\Column(nullable: true)]
|
||||
private ?bool $CommodityUpdateBuyPriceAuto = null;
|
||||
|
||||
#[ORM\Column(length: 30, nullable: true)]
|
||||
private ?string $profitCalcType = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->logs = new ArrayCollection();
|
||||
|
@ -1735,4 +1738,16 @@ class Business
|
|||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getProfitCalcType(): ?string
|
||||
{
|
||||
return $this->profitCalcType;
|
||||
}
|
||||
|
||||
public function setProfitCalcType(?string $profitCalcType): static
|
||||
{
|
||||
$this->profitCalcType = $profitCalcType;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Commodity;
|
||||
use App\Entity\HesabdariRow;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\ORM\NonUniqueResultException;
|
||||
|
@ -40,20 +41,6 @@ class HesabdariRowRepository extends ServiceEntityRepository
|
|||
}
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @return HesabdariRow[] Returns an array of HesabdariRow objects
|
||||
// */
|
||||
// public function findByExampleField($value): array
|
||||
// {
|
||||
// return $this->createQueryBuilder('h')
|
||||
// ->andWhere('h.exampleField = :val')
|
||||
// ->setParameter('val', $value)
|
||||
// ->orderBy('h.id', 'ASC')
|
||||
// ->setMaxResults(10)
|
||||
// ->getQuery()
|
||||
// ->getResult()
|
||||
// ;
|
||||
// }
|
||||
|
||||
/**
|
||||
* @throws NonUniqueResultException
|
||||
|
|
Loading…
Reference in a new issue