progress in calculate profit of invoices

This commit is contained in:
babak alizadeh 2024-10-23 22:22:39 +03:30
parent 928f77866d
commit 89ffdb9aea
4 changed files with 52 additions and 17 deletions

View file

@ -130,6 +130,11 @@ class BusinessController extends AbstractController
$response['walletMatchBank'] = null; $response['walletMatchBank'] = null;
$response['updateSellPrice'] = $bus->isCommodityUpdateSellPriceAuto(); $response['updateSellPrice'] = $bus->isCommodityUpdateSellPriceAuto();
$response['updateBuyPrice'] = $bus->isCommodityUpdateBuyPriceAuto(); $response['updateBuyPrice'] = $bus->isCommodityUpdateBuyPriceAuto();
if (!$bus->getProfitCalctype()) {
$response['profitCalcType'] = 'lis';
} else {
$response['profitCalcType'] = $bus->getProfitCalctype();
}
if ($bus->isWalletEnable()) if ($bus->isWalletEnable())
$response['walletMatchBank'] = $provider->Entity2Array($bus->getWalletMatchBank(), 0); $response['walletMatchBank'] = $provider->Entity2Array($bus->getWalletMatchBank(), 0);
$year = $entityManager->getRepository(Year::class)->findOneBy([ $year = $entityManager->getRepository(Year::class)->findOneBy([
@ -235,6 +240,14 @@ class BusinessController extends AbstractController
$business->setCommodityUpdateSellPriceAuto(false); $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']); $business->setCommodityUpdateSellPriceAuto($params['commodityUpdateSellPriceAuto']);
if (array_key_exists('walletEnabled', $params)) { if (array_key_exists('walletEnabled', $params)) {
if ($params['walletEnabled']) { if ($params['walletEnabled']) {

View file

@ -343,13 +343,33 @@ class SellController extends AbstractController
$pays += $relatedDoc->getAmount(); $pays += $relatedDoc->getAmount();
} }
$temp['relatedDocsPays'] = $pays; $temp['relatedDocsPays'] = $pays;
// this variable is for store profit of invoice
$temp['profit'] = 0;
foreach ($item->getHesabdariRows() as $item) { foreach ($item->getHesabdariRows() as $item) {
if ($item->getRef()->getCode() == '104') { if ($item->getRef()->getCode() == '104') {
$temp['discountAll'] = $item->getBd(); $temp['discountAll'] = $item->getBd();
} elseif ($item->getRef()->getCode() == '61') { } elseif ($item->getRef()->getCode() == '61') {
$temp['transferCost'] = $item->getBs(); $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)) if (!array_key_exists('discountAll', $temp))
$temp['discountAll'] = 0; $temp['discountAll'] = 0;

View file

@ -243,6 +243,9 @@ class Business
#[ORM\Column(nullable: true)] #[ORM\Column(nullable: true)]
private ?bool $CommodityUpdateBuyPriceAuto = null; private ?bool $CommodityUpdateBuyPriceAuto = null;
#[ORM\Column(length: 30, nullable: true)]
private ?string $profitCalcType = null;
public function __construct() public function __construct()
{ {
$this->logs = new ArrayCollection(); $this->logs = new ArrayCollection();
@ -1735,4 +1738,16 @@ class Business
return $this; return $this;
} }
public function getProfitCalcType(): ?string
{
return $this->profitCalcType;
}
public function setProfitCalcType(?string $profitCalcType): static
{
$this->profitCalcType = $profitCalcType;
return $this;
}
} }

View file

@ -2,6 +2,7 @@
namespace App\Repository; namespace App\Repository;
use App\Entity\Commodity;
use App\Entity\HesabdariRow; use App\Entity\HesabdariRow;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\ORM\NonUniqueResultException; 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 * @throws NonUniqueResultException