fix some bugs from accounting 6

This commit is contained in:
2026-07-28 19:08:04 +03:30
parent 6bb9af9893
commit 09716054ce
2 changed files with 56 additions and 10 deletions
+47 -6
View File
@@ -127,6 +127,32 @@ class ZarinController extends Controller
return $value > 0 ? $value : 16;
}
/**
* نوع کار برای سند تعدادی (sabtSanadTedadi).
* روی زرین aygin: 16=گرمی (رد می‌شود)، 17=سکه-تعدادی، 18=اجرت تعدادی.
*/
private function zarinCountNoeKar(): int
{
$tedadi = (int) $this->Config('zarin_noe_kar_tedadi');
if (in_array($tedadi, [17, 18], true)) {
return $tedadi;
}
$configured = $this->zarinDefaultNoeKar();
if (in_array($configured, [17, 18], true)) {
return $configured;
}
// 16 و سایر مقادیر گرمی/نامرتبط برای sabtSanadTedadi قابل استفاده نیستند
return 17;
}
/** fkNoeهایی که sabtSanadTedadi قبول می‌کند */
private function zarinCountFkNoes(): array
{
return ['17', '18'];
}
private function zarinDefaultGoroheKar()
{
$value = (int) $this->Config('zarin_gorohe_kar');
@@ -279,7 +305,7 @@ class ZarinController extends Controller
$goroheKar = $goroheKar ?: $this->zarinDefaultGoroheKar();
$productName = $this->normalizeZarinName($product->title);
$fromList = $this->findZarinKarInListKarSakhte($productName, $exactOnly);
$fromList = $this->findZarinKarInListKarSakhte($productName, $exactOnly, true);
if ($fromList) {
return $fromList;
}
@@ -294,8 +320,9 @@ class ZarinController extends Controller
/**
* کاتالوگ کارهای ساخته (لیست ۴۷ زرین) — id همین idKar سند تعدادی است.
* برای سند تعدادی فقط fkNoe سکه-تعدادی/اجرت تعدادی (۱۷/۱۸) قبول می‌شود؛ گرمی(۱۶) رد.
*/
private function findZarinKarInListKarSakhte(string $productName, bool $exactOnly = false): ?array
private function findZarinKarInListKarSakhte(string $productName, bool $exactOnly = false, bool $countDocOnly = true): ?array
{
$response = $this->zarinRequest([
'kind' => 'listKarSakhte',
@@ -310,6 +337,7 @@ class ZarinController extends Controller
return null;
}
$allowedFk = $this->zarinCountFkNoes();
$exact = null;
$fuzzy = null;
@@ -318,6 +346,11 @@ class ZarinController extends Controller
continue;
}
$fkNoe = (string) ($row['fkNoe'] ?? $row['fknoe'] ?? '');
if ($countDocOnly && $fkNoe !== '' && !in_array($fkNoe, $allowedFk, true)) {
continue;
}
$name = $row['namFelezsakhthe']
?? $row['nam_kar_sakhte']
?? $row['nameKar']
@@ -336,6 +369,7 @@ class ZarinController extends Controller
'row' => $row,
'match' => 'exact',
'source' => 'listKarSakhte',
'fkNoe' => $fkNoe,
];
break;
}
@@ -352,6 +386,7 @@ class ZarinController extends Controller
'row' => $row,
'match' => 'fuzzy',
'source' => 'listKarSakhte',
'fkNoe' => $fkNoe,
];
}
}
@@ -602,7 +637,7 @@ class ZarinController extends Controller
$params = [
'kind' => 'addFelezsakhteModel',
'nameKar' => $product->title,
'noeKar' => $this->zarinDefaultNoeKar(),
'noeKar' => $this->zarinCountNoeKar(),
'gorooheKar' => $this->zarinDefaultGoroheKar(),
];
@@ -746,8 +781,14 @@ class ZarinController extends Controller
?? $existingRow['title']
?? ''
);
// اگر idKar موجود مال کالای دیگری است (مثلاً شمش برای گوی) قبول نکن
if ($rowName !== '' && $productName !== '' && $rowName !== $productName) {
$idGp = (string) ($existingRow['idGp'] ?? $existingRow['idgp'] ?? $existingRow['fkNoe'] ?? '');
$wrongType = $idGp !== '' && !in_array($idGp, $this->zarinCountFkNoes(), true);
// اگر idKar موجود مال کالای دیگری است یا نوع گرمی است (نه تعدادی) قبول نکن
if (
$wrongType
|| ($rowName !== '' && $productName !== '' && $rowName !== $productName)
) {
$this->clearProductZarinKar($product);
$product->refresh();
} else {
@@ -1835,7 +1876,7 @@ class ZarinController extends Controller
[$response, $httpError] = $this->zarinDecodeResponse($http);
$diag = 'idKar=' . $idKar
. ' noeKar=' . $this->zarinDefaultNoeKar()
. ' noeKar=' . $this->zarinCountNoeKar()
. ' goroheKar=' . $this->zarinDefaultGoroheKar()
. ' product=' . ($product->title ?? '')
. ' source=' . ($kar['source'] ?? '');