fix title in transacrion
This commit is contained in:
@@ -324,6 +324,46 @@ class Controller extends BaseController
|
||||
return in_array($title, self::genericMetalTransactionTitles(), true);
|
||||
}
|
||||
|
||||
public static function rialDepositTitle(): string
|
||||
{
|
||||
return 'واریز ریالی';
|
||||
}
|
||||
|
||||
public static function rialWithdrawTitle(): string
|
||||
{
|
||||
return 'برداشت ریالی';
|
||||
}
|
||||
|
||||
/**
|
||||
* type و title تراکنش ریالی — بر اساس علامت cash (دادههای قدیمی گاهی type=4 با cash مثبت دارند).
|
||||
*/
|
||||
public static function normalizeRialTransactionPresentation($record, bool $persist = true): void
|
||||
{
|
||||
$type = (int) ($record->type ?? 0);
|
||||
if (!in_array($type, [3, 4], true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$cash = (float) ($record->cash ?? 0);
|
||||
$correctType = $cash >= 0 ? 3 : 4;
|
||||
$correctTitle = $correctType === 3 ? self::rialDepositTitle() : self::rialWithdrawTitle();
|
||||
|
||||
$dirty = false;
|
||||
if ($correctType !== $type) {
|
||||
$record->type = $correctType;
|
||||
$dirty = true;
|
||||
}
|
||||
|
||||
if (trim((string) ($record->title ?? '')) !== $correctTitle) {
|
||||
$record->title = $correctTitle;
|
||||
$dirty = true;
|
||||
}
|
||||
|
||||
if ($dirty && $persist && $record instanceof \Rooyesh\Wallet\models\Transaction) {
|
||||
$record->save();
|
||||
}
|
||||
}
|
||||
|
||||
public static function productBuyTitle(string $productTitle): string
|
||||
{
|
||||
return 'خرید ' . $productTitle;
|
||||
|
||||
Reference in New Issue
Block a user