From ae2bcd9b5eab06b6dc8d53d10fb85c1684600454 Mon Sep 17 00:00:00 2001 From: merdan Date: Fri, 19 Nov 2021 20:15:59 +0500 Subject: [PATCH] transaction balance page prodlenie, udalenie --- plugins/tps/birzha/Plugin.php | 2 +- plugins/tps/birzha/components/OfferForm.php | 11 +++- .../tps/birzha/controllers/Transactions.php | 3 +- .../transactions/config_filter.yaml | 10 +++ .../controllers/transactions/config_form.yaml | 10 +++ .../controllers/transactions/config_list.yaml | 2 + .../controllers/transactions/update.htm | 54 ++++++++++++++++ plugins/tps/birzha/models/Payment.php | 7 ++- plugins/tps/birzha/models/Product.php | 13 ++-- .../birzha/models/transaction/columns.yaml | 6 +- .../tps/birzha/models/transaction/fields.yaml | 8 +++ ...table_update_tps_birzha_transactions_2.php | 23 +++++++ ...table_update_tps_birzha_transactions_3.php | 23 +++++++ plugins/tps/birzha/updates/version.yaml | 6 ++ themes/birzha/pages/kabinet/transactions.htm | 62 +++++++++++++++++++ themes/birzha/partials/header.htm | 8 +-- 16 files changed, 228 insertions(+), 20 deletions(-) create mode 100644 plugins/tps/birzha/controllers/transactions/config_filter.yaml create mode 100644 plugins/tps/birzha/controllers/transactions/config_form.yaml create mode 100644 plugins/tps/birzha/controllers/transactions/update.htm create mode 100644 plugins/tps/birzha/updates/builder_table_update_tps_birzha_transactions_2.php create mode 100644 plugins/tps/birzha/updates/builder_table_update_tps_birzha_transactions_3.php create mode 100644 themes/birzha/pages/kabinet/transactions.htm diff --git a/plugins/tps/birzha/Plugin.php b/plugins/tps/birzha/Plugin.php index 231425c4e..3167ce233 100644 --- a/plugins/tps/birzha/Plugin.php +++ b/plugins/tps/birzha/Plugin.php @@ -50,7 +50,7 @@ class Plugin extends PluginBase } public function moneyColumn($value, $column, $record){ - return ''.$value.'tmt'; + return ''.number_format($value,2).' tmt'; } public function userLinkListColumn($value, $column, $record){ diff --git a/plugins/tps/birzha/components/OfferForm.php b/plugins/tps/birzha/components/OfferForm.php index 5025ca94d..938286f0d 100644 --- a/plugins/tps/birzha/components/OfferForm.php +++ b/plugins/tps/birzha/components/OfferForm.php @@ -83,6 +83,12 @@ class OfferForm extends ComponentBase if(isset($data['productForEditing'])) { $product = Product::find($data['productForEditing']); + //approved edilen produkty prodlenie uchin drafta tayinlamak, bagly transacsiasyny goparmak, + if($product && $product->status == 'approved' && $product->transaction) + { + $product->transaction()->update(['description'=>"Lot #{$product->id} {$product->name} harydyn onki publikasia tolegidir.(bu haryt prodlenia uchin taze transaksia doredilyar)"]); + $product->transaction = null; + } } else { $product = new Product; } @@ -190,8 +196,9 @@ class OfferForm extends ComponentBase // step3 public function onPublish() { - $user = \Auth::user(); - if($user->balance - Settings::getValue('fee') < 0) { + $balance = \Auth::user()->getBalance(); + + if($balance - Settings::getValue('fee') < 0) { // ... message about not enough money throw new ValidationException(['money' => trans('validation.low_balance')]); } else { diff --git a/plugins/tps/birzha/controllers/Transactions.php b/plugins/tps/birzha/controllers/Transactions.php index 643c3312e..c6263b301 100644 --- a/plugins/tps/birzha/controllers/Transactions.php +++ b/plugins/tps/birzha/controllers/Transactions.php @@ -5,9 +5,10 @@ use BackendMenu; class Transactions extends Controller { - public $implement = [ 'Backend\Behaviors\ListController' ]; + public $implement = ['Backend\Behaviors\ListController','Backend\Behaviors\FormController' ]; public $listConfig = 'config_list.yaml'; + public $formConfig = 'config_form.yaml'; public function __construct() { diff --git a/plugins/tps/birzha/controllers/transactions/config_filter.yaml b/plugins/tps/birzha/controllers/transactions/config_filter.yaml new file mode 100644 index 000000000..a75e7ae46 --- /dev/null +++ b/plugins/tps/birzha/controllers/transactions/config_filter.yaml @@ -0,0 +1,10 @@ +scopes: + created_at: + label: Date + type: daterange + conditions: created_at >= ':after' AND created_at <= ':before' + user: + label: Seller + modelClass: RainLab\User\Models\User + nameFrom: name + conditions: user_id in (:filtered) diff --git a/plugins/tps/birzha/controllers/transactions/config_form.yaml b/plugins/tps/birzha/controllers/transactions/config_form.yaml new file mode 100644 index 000000000..2002f009b --- /dev/null +++ b/plugins/tps/birzha/controllers/transactions/config_form.yaml @@ -0,0 +1,10 @@ +name: Payments +form: $/tps/birzha/models/transaction/fields.yaml +modelClass: TPS\Birzha\Models\Transaction +defaultRedirect: tps/birzha/transactions +create: + redirect: 'tps/birzha/transactions/update/:id' + redirectClose: tps/birzha/transactions +update: + redirect: tps/birzha/transactions + redirectClose: tps/birzha/transactions diff --git a/plugins/tps/birzha/controllers/transactions/config_list.yaml b/plugins/tps/birzha/controllers/transactions/config_list.yaml index c03e64622..2bcf01615 100644 --- a/plugins/tps/birzha/controllers/transactions/config_list.yaml +++ b/plugins/tps/birzha/controllers/transactions/config_list.yaml @@ -9,3 +9,5 @@ toolbar: buttons: list_toolbar search: prompt: 'backend::lang.list.search_prompt' +recordUrl: 'tps/birzha/transactions/update/:id' +filter: config_filter.yaml diff --git a/plugins/tps/birzha/controllers/transactions/update.htm b/plugins/tps/birzha/controllers/transactions/update.htm new file mode 100644 index 000000000..bee4156fb --- /dev/null +++ b/plugins/tps/birzha/controllers/transactions/update.htm @@ -0,0 +1,54 @@ + + + + +fatalError): ?> + + 'layout']) ?> + +
+ formRender() ?> +
+ +
+
+ + + + + + + +
+
+ + + +

fatalError)) ?>

+

+ diff --git a/plugins/tps/birzha/models/Payment.php b/plugins/tps/birzha/models/Payment.php index 5e1ecf688..d19dec4f4 100644 --- a/plugins/tps/birzha/models/Payment.php +++ b/plugins/tps/birzha/models/Payment.php @@ -43,7 +43,7 @@ class Payment extends Model if($this->status == 'approved' || $this->payment_type == 'gift' ) { if(!$transaction = $this->transaction) { - $this->createTransaction(); + $this->createTransaction($this->payment_type != 'gift'? $this->patment_type:'sowgat'); } else{ $transaction->amount = $this->amount; @@ -86,10 +86,11 @@ class Payment extends Model } } - private function createTransaction(){ + private function createTransaction($desc='sowgat'){ $transaction = new Transaction([ 'user_id' => $this->user_id, - 'amount' => $this->amount + 'amount' => $this->amount, + 'description' => "Balansyn doldurulmagy {$desc} {$this->amount} manat" ]); $this->transaction()->save($transaction); } diff --git a/plugins/tps/birzha/models/Product.php b/plugins/tps/birzha/models/Product.php index ad4374e37..e050c202a 100644 --- a/plugins/tps/birzha/models/Product.php +++ b/plugins/tps/birzha/models/Product.php @@ -58,7 +58,7 @@ class Product extends Model ]; public $morphOne = [ - 'transaction' => [Transaction::class, 'name' => 'transactable','delete' => true] + 'transaction' => [Transaction::class, 'name' => 'transactable'] ]; public $attachMany = [ @@ -113,7 +113,8 @@ class Product extends Model private function createTransaction(){ $transaction = new Transaction([ 'user_id' => $this->vendor_id, - 'amount' => 0 - $this->payed_fee_for_publ + 'amount' => 0 - $this->payed_fee_for_publ, + 'description' => "Lot #{$this->id} {$this->name} haryt ucin tutym." ]); $this->transaction()->save($transaction); } @@ -132,12 +133,8 @@ class Product extends Model // $createdAt = Carbon::parse($this->created_at); $this->ends_at = \Carbon\Carbon::now()->addDays(Settings::getValue('duration')); } - elseif($this->status == 'denied') { - // give fee back to the user, because his post has been denied - $user = $this->vendor; - //todo delete associated transaction - $user->balance = $user->balance + $this->payed_fee_for_publ; - $user->save(); + elseif($this->status == 'denied' && $this->transaction) { + $this->transaction()->delete(); } } diff --git a/plugins/tps/birzha/models/transaction/columns.yaml b/plugins/tps/birzha/models/transaction/columns.yaml index 9eacc3308..0c742a8a9 100644 --- a/plugins/tps/birzha/models/transaction/columns.yaml +++ b/plugins/tps/birzha/models/transaction/columns.yaml @@ -13,6 +13,10 @@ columns: type: datetime user_id: label: User - type: text + type: user relation: user valueFrom: email + sortable: false + description: + label: Description + type: text diff --git a/plugins/tps/birzha/models/transaction/fields.yaml b/plugins/tps/birzha/models/transaction/fields.yaml index 29cc793dd..9b0dec046 100644 --- a/plugins/tps/birzha/models/transaction/fields.yaml +++ b/plugins/tps/birzha/models/transaction/fields.yaml @@ -3,14 +3,22 @@ fields: label: Number span: auto type: number + disabled: true user: label: User nameFrom: email descriptionFrom: name span: auto type: relation + disabled: true created_at: label: 'Created date' mode: datetime span: auto type: datepicker + disabled: true + description: + label: Description + span: auto + type: text + disabled: true diff --git a/plugins/tps/birzha/updates/builder_table_update_tps_birzha_transactions_2.php b/plugins/tps/birzha/updates/builder_table_update_tps_birzha_transactions_2.php new file mode 100644 index 000000000..0d3a871dd --- /dev/null +++ b/plugins/tps/birzha/updates/builder_table_update_tps_birzha_transactions_2.php @@ -0,0 +1,23 @@ +text('description')->nullable(); + }); + } + + public function down() + { + Schema::table('tps_birzha_transactions', function($table) + { + $table->dropColumn('description'); + }); + } +} diff --git a/plugins/tps/birzha/updates/builder_table_update_tps_birzha_transactions_3.php b/plugins/tps/birzha/updates/builder_table_update_tps_birzha_transactions_3.php new file mode 100644 index 000000000..e8700def9 --- /dev/null +++ b/plugins/tps/birzha/updates/builder_table_update_tps_birzha_transactions_3.php @@ -0,0 +1,23 @@ +decimal('amount', 10, 2)->change(); + }); + } + + public function down() + { + Schema::table('tps_birzha_transactions', function($table) + { + $table->decimal('amount', 10, 0)->change(); + }); + } +} diff --git a/plugins/tps/birzha/updates/version.yaml b/plugins/tps/birzha/updates/version.yaml index e52693b13..97be1f448 100644 --- a/plugins/tps/birzha/updates/version.yaml +++ b/plugins/tps/birzha/updates/version.yaml @@ -236,3 +236,9 @@ 1.0.82: - 'Updated table tps_birzha_transactions' - builder_table_update_tps_birzha_transactions.php +1.0.83: + - 'Updated table tps_birzha_transactions' + - builder_table_update_tps_birzha_transactions_2.php +1.0.84: + - 'Updated decimal table tps_birzha_transactions' + - builder_table_update_tps_birzha_transactions_3.php diff --git a/themes/birzha/pages/kabinet/transactions.htm b/themes/birzha/pages/kabinet/transactions.htm new file mode 100644 index 000000000..3096d1cb1 --- /dev/null +++ b/themes/birzha/pages/kabinet/transactions.htm @@ -0,0 +1,62 @@ +title = "Balans taryhy" +url = "/balans-taryhy" +layout = "default" +is_hidden = 0 +== +
+
+
+
+ История Balansa +
+ +
+ + + + + + + + + + + + {% for transaction in user.transactions%} + + + + + + + + {% else %} + + {% endfor %} + +
Дата пополненияDescriptionСуммаType
{{transaction.id}}{{transaction.created_at|date('H:i - d.m.Y')}}{{transaction.description}}{{transaction.amount}} TMT + {% if transaction.amount > 0%} +

{{'popolnenie'|_}}

+ {% else %} +

{{'oplata'|_}}

+ {% endif %} +
{{'no_balance_history'|_}}
+
+ + + + + + + + + + + + + + + +
+
+
diff --git a/themes/birzha/partials/header.htm b/themes/birzha/partials/header.htm index 0b1356e53..6944ad626 100644 --- a/themes/birzha/partials/header.htm +++ b/themes/birzha/partials/header.htm @@ -102,7 +102,7 @@ code = "main-top" {% else %} - +
@@ -114,14 +114,14 @@ code = "main-top"
-
+
{{user.getBalance}} TMT
-
+
@@ -305,7 +305,7 @@ code = "main-top"
- + {% endif %}