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