bug fix devesion by zero
This commit is contained in:
parent
83baf8ffb4
commit
2f38d5dc6b
|
@ -47,14 +47,14 @@ class SellController extends AbstractController
|
||||||
'code' => $code,
|
'code' => $code,
|
||||||
'money' => $acc['money']
|
'money' => $acc['money']
|
||||||
]);
|
]);
|
||||||
if (!$doc){
|
if (!$doc) {
|
||||||
$canEdit = false;
|
$canEdit = false;
|
||||||
}
|
}
|
||||||
$year = $entityManager->getRepository(Year::class)->findOneBy([
|
$year = $entityManager->getRepository(Year::class)->findOneBy([
|
||||||
'bid' => $acc['bid'],
|
'bid' => $acc['bid'],
|
||||||
'head' => true
|
'head' => true
|
||||||
]);
|
]);
|
||||||
if($doc->getYear()->getId() != $year->getId()){
|
if ($doc->getYear()->getId() != $year->getId()) {
|
||||||
$canEdit = false;
|
$canEdit = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -225,7 +225,7 @@ class SellController extends AbstractController
|
||||||
// ذخیره نوع تخفیف و درصد آن
|
// ذخیره نوع تخفیف و درصد آن
|
||||||
$doc->setDiscountType($params['discountType'] ?? 'fixed');
|
$doc->setDiscountType($params['discountType'] ?? 'fixed');
|
||||||
if (isset($params['discountPercent'])) {
|
if (isset($params['discountPercent'])) {
|
||||||
$doc->setDiscountPercent((float)$params['discountPercent']);
|
$doc->setDiscountPercent((float) $params['discountPercent']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$doc->setDes($params['des']);
|
$doc->setDes($params['des']);
|
||||||
|
@ -770,7 +770,7 @@ class SellController extends AbstractController
|
||||||
$this->renderView('pdf/printers/sell.html.twig', [
|
$this->renderView('pdf/printers/sell.html.twig', [
|
||||||
'bid' => $acc['bid'],
|
'bid' => $acc['bid'],
|
||||||
'doc' => $doc,
|
'doc' => $doc,
|
||||||
'rows' => array_map(function($row) {
|
'rows' => array_map(function ($row) {
|
||||||
return [
|
return [
|
||||||
'commodity' => $row->getCommodity(),
|
'commodity' => $row->getCommodity(),
|
||||||
'commodityCount' => $row->getCommdityCount(),
|
'commodityCount' => $row->getCommdityCount(),
|
||||||
|
@ -802,7 +802,7 @@ class SellController extends AbstractController
|
||||||
$this->renderView('pdf/posPrinters/justSell.html.twig', [
|
$this->renderView('pdf/posPrinters/justSell.html.twig', [
|
||||||
'bid' => $acc['bid'],
|
'bid' => $acc['bid'],
|
||||||
'doc' => $doc,
|
'doc' => $doc,
|
||||||
'rows' => array_map(function($row) {
|
'rows' => array_map(function ($row) {
|
||||||
return [
|
return [
|
||||||
'commodity' => $row->getCommodity(),
|
'commodity' => $row->getCommodity(),
|
||||||
'commodityCount' => $row->getCommdityCount(),
|
'commodityCount' => $row->getCommdityCount(),
|
||||||
|
@ -877,7 +877,8 @@ class SellController extends AbstractController
|
||||||
Access $access,
|
Access $access,
|
||||||
Log $log,
|
Log $log,
|
||||||
EntityManagerInterface $entityManager,
|
EntityManagerInterface $entityManager,
|
||||||
registryMGR $registryMGR
|
registryMGR $registryMGR,
|
||||||
|
Jdate $jdate
|
||||||
): JsonResponse {
|
): JsonResponse {
|
||||||
$params = [];
|
$params = [];
|
||||||
if ($content = $request->getContent()) {
|
if ($content = $request->getContent()) {
|
||||||
|
@ -941,12 +942,22 @@ class SellController extends AbstractController
|
||||||
}
|
}
|
||||||
|
|
||||||
// تنظیم اطلاعات اصلی فاکتور
|
// تنظیم اطلاعات اصلی فاکتور
|
||||||
|
if (isset($params['invoiceDescription'])) {
|
||||||
$doc->setDes($params['invoiceDescription']);
|
$doc->setDes($params['invoiceDescription']);
|
||||||
|
} else {
|
||||||
|
$doc->setDes('');
|
||||||
|
}
|
||||||
|
if (isset($params['invoiceDate'])) {
|
||||||
$doc->setDate($params['invoiceDate']);
|
$doc->setDate($params['invoiceDate']);
|
||||||
|
} else {
|
||||||
|
$doc->setDate($jdate->jdate('Y/n/d', time()));
|
||||||
|
}
|
||||||
|
if (isset($params['taxPercent'])) {
|
||||||
$doc->setTaxPercent($params['taxPercent'] ?? 0);
|
$doc->setTaxPercent($params['taxPercent'] ?? 0);
|
||||||
|
}
|
||||||
|
|
||||||
// افزودن هزینه حمل
|
// افزودن هزینه حمل
|
||||||
if ($params['shippingCost'] > 0) {
|
if (isset($params['shippingCost']) && $params['shippingCost'] > 0) {
|
||||||
$hesabdariRow = new HesabdariRow();
|
$hesabdariRow = new HesabdariRow();
|
||||||
$hesabdariRow->setDes('حمل و نقل کالا');
|
$hesabdariRow->setDes('حمل و نقل کالا');
|
||||||
$hesabdariRow->setBid($acc['bid']);
|
$hesabdariRow->setBid($acc['bid']);
|
||||||
|
@ -961,17 +972,21 @@ class SellController extends AbstractController
|
||||||
|
|
||||||
// افزودن تخفیف کلی
|
// افزودن تخفیف کلی
|
||||||
$totalDiscount = 0;
|
$totalDiscount = 0;
|
||||||
if ($params['discountType'] === 'percent') {
|
if (isset($params['discountType']) && $params['discountType'] === 'percent') {
|
||||||
$totalDiscount = round(($params['totalInvoice'] * $params['discountPercent']) / 100);
|
$totalDiscount = round(($params['totalInvoice'] * $params['discountPercent']) / 100);
|
||||||
$doc->setDiscountType('percent');
|
$doc->setDiscountType('percent');
|
||||||
$doc->setDiscountPercent((float)$params['discountPercent']);
|
$doc->setDiscountPercent((float) $params['discountPercent']);
|
||||||
} else {
|
} else {
|
||||||
|
if (isset($params['totalDiscount']) && $params['totalDiscount'] > 0) {
|
||||||
$totalDiscount = $params['totalDiscount'];
|
$totalDiscount = $params['totalDiscount'];
|
||||||
|
} else {
|
||||||
|
$totalDiscount = 0;
|
||||||
|
}
|
||||||
$doc->setDiscountType('fixed');
|
$doc->setDiscountType('fixed');
|
||||||
$doc->setDiscountPercent(null);
|
$doc->setDiscountPercent(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($totalDiscount > 0) {
|
if (isset($totalDiscount) && $totalDiscount > 0) {
|
||||||
$hesabdariRow = new HesabdariRow();
|
$hesabdariRow = new HesabdariRow();
|
||||||
$hesabdariRow->setDes('تخفیف فاکتور');
|
$hesabdariRow->setDes('تخفیف فاکتور');
|
||||||
$hesabdariRow->setBid($acc['bid']);
|
$hesabdariRow->setBid($acc['bid']);
|
||||||
|
@ -1055,10 +1070,25 @@ class SellController extends AbstractController
|
||||||
$ref = $entityManager->getRepository(HesabdariTable::class)->findOneBy(['code' => '3']);
|
$ref = $entityManager->getRepository(HesabdariTable::class)->findOneBy(['code' => '3']);
|
||||||
$hesabdariRow->setRef($ref);
|
$hesabdariRow->setRef($ref);
|
||||||
|
|
||||||
|
if (!isset($params['customer']) || $params['customer'] == '') {
|
||||||
|
$person = $entityManager->getRepository(Person::class)->findOneBy([
|
||||||
|
'bid' => $acc['bid'],
|
||||||
|
'nikename' => 'مشتری پیش فرض'
|
||||||
|
]);
|
||||||
|
if (!$person) {
|
||||||
|
$person = new Person();
|
||||||
|
$person->setBid($acc['bid']);
|
||||||
|
$person->setNikename('مشتری پیش فرض');
|
||||||
|
$person->setCode($provider->getAccountingCode($acc['bid'], 'person'));
|
||||||
|
$entityManager->persist($person);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
$person = $entityManager->getRepository(Person::class)->findOneBy([
|
$person = $entityManager->getRepository(Person::class)->findOneBy([
|
||||||
'bid' => $acc['bid'],
|
'bid' => $acc['bid'],
|
||||||
'id' => $params['customer']
|
'id' => $params['customer']
|
||||||
]);
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
if (!$person) {
|
if (!$person) {
|
||||||
throw new \Exception('خریدار یافت نشد');
|
throw new \Exception('خریدار یافت نشد');
|
||||||
}
|
}
|
||||||
|
@ -1200,7 +1230,8 @@ class SellController extends AbstractController
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return $this->json([
|
return $this->json([
|
||||||
'result' => 0,
|
'result' => 0,
|
||||||
'message' => $e->getMessage()
|
'message' => $e->getMessage(),
|
||||||
|
'data' => $params
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -230,7 +230,12 @@
|
||||||
<td class="center item">
|
<td class="center item">
|
||||||
{% if item.commodityCount > 0 %}
|
{% if item.commodityCount > 0 %}
|
||||||
{% if item.showPercentDiscount %}
|
{% if item.showPercentDiscount %}
|
||||||
{% set originalPrice = item.bs / (1 - (item.discountPercent / 100)) %}
|
{% set discountDivisor = 1 - (item.discountPercent / 100) %}
|
||||||
|
{% if discountDivisor <= 0 %}
|
||||||
|
{% set originalPrice = item.bs %}
|
||||||
|
{% else %}
|
||||||
|
{% set originalPrice = item.bs / discountDivisor %}
|
||||||
|
{% endif %}
|
||||||
{% set unitPrice = originalPrice / item.commodityCount %}
|
{% set unitPrice = originalPrice / item.commodityCount %}
|
||||||
{% else %}
|
{% else %}
|
||||||
{% set originalPrice = item.bs + item.discount %}
|
{% set originalPrice = item.bs + item.discount %}
|
||||||
|
@ -252,7 +257,12 @@
|
||||||
</td>
|
</td>
|
||||||
<td class="center item">
|
<td class="center item">
|
||||||
{% if item.showPercentDiscount %}
|
{% if item.showPercentDiscount %}
|
||||||
{% set originalPrice = item.bs / (1 - (item.discountPercent / 100)) %}
|
{% set discountDivisor = 1 - (item.discountPercent / 100) %}
|
||||||
|
{% if discountDivisor <= 0 %}
|
||||||
|
{% set originalPrice = item.bs %}
|
||||||
|
{% else %}
|
||||||
|
{% set originalPrice = item.bs / discountDivisor %}
|
||||||
|
{% endif %}
|
||||||
{{ originalPrice|round|number_format }} {{ doc.money.shortName }}
|
{{ originalPrice|round|number_format }} {{ doc.money.shortName }}
|
||||||
{% else %}
|
{% else %}
|
||||||
{{ (item.bs + item.discount)|number_format }} {{ doc.money.shortName }}
|
{{ (item.bs + item.discount)|number_format }} {{ doc.money.shortName }}
|
||||||
|
|
Loading…
Reference in a new issue