Giter Site home page Giter Site logo

balance's People

Contributors

klimov-paul avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

balance's Issues

Sample for Warehouse

Hi,

I would love to use the module for creating a minimized warehouse application.

What I would love to understand is:

  1. Is each good an extra account or will this be stored within the transaction as an id?
  2. What will be the counter account if I call the increase without a transfer account?
  3. If i put the good id within the transaction can I recieve a balance by good by a predefined method?

Thanks in advance Philipp

Migration

How to properly create all db tables ?

I created migration with code

$this->createTable('BalanceAccount', [
    'id' => $this->primaryKey(),
    'balance' => $this->integer()->notNull()->defaultValue(0),
]);

$this->createTable('BalanceTransaction', [
    'id' => $this->primaryKey(),
    'date' => $this->integer()->notNull(),
    'accountId' => $this->integer()->notNull(),
    'extraAccountId' => $this->integer()->notNull(),
    'amount' => $this->integer()->notNull()->defaultValue(0),
    'data' => $this->text(),
]);

Object of class common\models\Account could not be converted to int

Hi @klimov-paul ,

Since today I have been getting this error, not sure why because this worked last week and I haven't changed anything in my Configuration.
Does anything in this log make sense to you?
Could you point me in the right direction to debug this?

Thanks


  1. in /var/www/advanced/vendor/yiisoft/yii2/db/ColumnSchema.php at line 134
    125126127128129130131132133134135136137138139140141142143 if (is_resource($value)) {
    return $value;
    }
    if (is_float($value)) {
    // ensure type cast always has . as decimal separator in all locales
    return str_replace(',', '.', (string) $value);
    }
    return (string) $value;
    case 'integer':
    return (int) $value;
    case 'boolean':
    // treating a 0 bit value as false too
    // yiisoft/yii2#9006
    return (bool) $value && $value !== "\0";
    case 'double':
    return (double) $value;
    }

    return $value;
    
  2. in /var/www/advanced/vendor/yiisoft/yii2/db/ColumnSchema.php at line 134 – yii\base\ErrorHandler::handleError(8, 'Object of class common\models\Ac...', '/var/www/advanced/vendor/yiisoft...', 134, ...)

  3. in /var/www/advanced/vendor/yiisoft/yii2/db/ColumnSchema.php at line 104 – yii\db\ColumnSchema::typecast(common\models\Account)

  4. in /var/www/advanced/vendor/yiisoft/yii2/db/mysql/QueryBuilder.php at line 208 – yii\db\ColumnSchema::dbTypecast(common\models\Account)

  5. in /var/www/advanced/vendor/yiisoft/yii2/db/Command.php at line 430 – yii\db\mysql\QueryBuilder::insert('{{%ftransaction}}', ['description' => '7165-6729-2589-8850 sent to 0902...', 'type_id' => 3, 'product_id' => 0, 'payment_method_id' => 5, ...], [':qp0' => '7165-6729-2589-8850 sent to 0902...', ':qp1' => 3, ':qp2' => 0, ':qp3' => 5, ...])

  6. in /var/www/advanced/vendor/yiisoft/yii2/db/Schema.php at line 450 – yii\db\Command::insert('{{%ftransaction}}', ['description' => '7165-6729-2589-8850 sent to 0902...', 'type_id' => 3, 'product_id' => 0, 'payment_method_id' => 5, ...])

system_log entry


exception 'yii\base\ErrorException' with message 'Object of class common\models\Account could not be converted to int' in /var/www/advanced/vendor/yiisoft/yii2/db/ColumnSchema.php:134
Stack trace:
#0 /var/www/advanced/vendor/yiisoft/yii2/db/ColumnSchema.php(134): yii\base\ErrorHandler->handleError(8, 'Object of class...', '/var/www/advanc...', 134, Array)
#1 /var/www/advanced/vendor/yiisoft/yii2/db/ColumnSchema.php(104): yii\db\ColumnSchema->typecast(Object(common\models\Account))
#2 /var/www/advanced/vendor/yiisoft/yii2/db/mysql/QueryBuilder.php(208): yii\db\ColumnSchema->dbTypecast(Object(common\models\Account))
#3 /var/www/advanced/vendor/yiisoft/yii2/db/Command.php(430): yii\db\mysql\QueryBuilder->insert('{{%ftransaction...', Array, Array)
#4 /var/www/advanced/vendor/yiisoft/yii2/db/Schema.php(450): yii\db\Command->insert('{{%ftransaction...', Array)
#5 /var/www/advanced/vendor/yii2tech/balance/ManagerDb.php(192): yii\db\Schema->insert('{{%ftransaction...', Array)
#6 /var/www/advanced/vendor/yii2tech/balance/Manager.php(91): yii2tech\balance\ManagerDb->createTransaction(Array)
#7 /var/www/advanced/vendor/yii2tech/balance/ManagerDbTransaction.php(33): yii2tech\balance\Manager->increase(Object(common\models\Account), -5, Array)
#8 /var/www/advanced/vendor/yii2tech/balance/Manager.php(103): yii2tech\balance\ManagerDbTransaction->increase(Object(common\models\Account), -5, Array)
#9 /var/www/advanced/vendor/yii2tech/balance/Manager.php(128): yii2tech\balance\Manager->decrease(Object(common\models\Account), 5, Array)
#10 /var/www/advanced/vendor/yii2tech/balance/ManagerDbTransaction.php(49): yii2tech\balance\Manager->transfer(Object(common\models\Account), 6, 5, Array)
#11 /var/www/advanced/frontend/controllers/SmstextController.php(196): yii2tech\balance\ManagerDbTransaction->transfer(Object(common\models\Account), 6, 5, Array)
#12 [internal function]: frontend\controllers\SmstextController->actionVoucher()
#13 /var/www/advanced/vendor/yiisoft/yii2/base/InlineAction.php(55): call_user_func_array(Array, Array)
#14 /var/www/advanced/vendor/yiisoft/yii2/base/Controller.php(154): yii\base\InlineAction->runWithParams(Array)
#15 /var/www/advanced/vendor/yiisoft/yii2/base/Module.php(454): yii\base\Controller->runAction('voucher', Array)
#16 /var/www/advanced/vendor/yiisoft/yii2/web/Application.php(87): yii\base\Module->runAction('smstext/voucher', Array)
#17 /var/www/advanced/vendor/yiisoft/yii2/base/Application.php(375): yii\web\Application->handleRequest(Object(yii\web\Request))
#18 /var/www/advanced/frontend/web/index.php(28): yii\base\Application->run()
#19 {main}

Introduce Serializer component

ManagerDataSerializeTrait::serializeMethod is not flexible enough and may lead to potential error in case of custom serializer usage.
It is better to introduce separated component Serializer with multiple inplementation.

Add Events

For the more flexibility of the Manager and events triggering should be added.
List of events:

  • beforeTransaction
  • afterTransaction

Integrity constraint violation

Error during transfer with message

Integrity constraint violation – yii\db\IntegrityException
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '8' for key 'PRIMARY'
The SQL being executed was: INSERT INTO stockTransaction (id, date, extraAccountId, amount, accountId, data) VALUES (8, 1501489193, 5, '5', 6, '{"task":"Stock adjustment","SKU":"SOGO","name":"Songoku","regular_price":"10000","sale_price":"0","voucher":"No"}')

Error Info:

Array
(
    [0] => 23000
    [1] => 1062
    [2] => Duplicate entry '8' for key 'PRIMARY'
)

========================

Duplicated entry '8' is for field 'userId', not sure why it goes to 'id' field though.

========================
CONFIG

'stockManager' => [
            'class' => 'yii2tech\balance\ManagerDb',
            'accountTable' => 'stockAccount',
            'transactionTable' => 'stockTransaction',
            'accountLinkAttribute' => 'accountId',
            'amountAttribute' => 'amount',
	    'extraAccountLinkAttribute' => 'extraAccountId',
            'dataAttribute' => 'data',
]

========================================
TRANSFER

Yii::$app->stockManager->transfer(
['userId' => 0, 'type' => 'VG-' . $model->id],
['userId' => $model->id, 'type' => 'VG'],
$stock_to_adjust,
[
   task' => 'Stock adjustment',
  'SKU' => $model->SKU,
  'id' => $model->id,
  'name' => $model->name,
  'regular_price' => $model->regular_price,
  'sale_price' => $model->sale_price,
  'voucher' => $model->voucher
]);						

Transaction

I can't make it works unless set the db to ISAM.
Any idea why it doesn't works with InnoDb?

Question (not an issue)

Hi,
What is the best way to store other data into table (additional column) instead of extraData to make it easier to query?
Example that kind of data, say Invoice Number.
Thx

Transaction date not properly formated

Hi @klimov-paul ,

In the config I had specified date attribute and datevalue expression as follows
// 'dateAttribute' => 'date',
// 'dateAttributeValue' => "date('Y-m-d H:i:s',time())",

But the date entries made in the transaction table is "0000-00-00 00:00:00", just to be sure the issue is not from the date expression, I commented out both attributes from the config so I can pass the date attributeValue as part of extra data in the transaction array

            // extra data associated with transaction :
                [
                    'date'=> date("Y-m-d H:i:s", $payment->date),
                ]

Could you take a look and advise why the transaction date entries are not showing up in the proper mysql TIMESTAMP format?

Thanks again!

`ManagerDbTransaction` may break nested transaction sequence

If ManagerDbTransaction::increase() is run inside already begun transaction, extranal transaction may fail.
yii\db\Connection saves transaction instance on beginTransaction(), thus inside ManagerDbTransaction uses same transaction as external one.

Balance modifying

Hello!
I have created a tables from tests:
BalanceAccount
image

and BalanceTransaction
image

In BalanceAccount a balance column increase only with

    $manager->accountBalanceAttribute = 'balance';

And transactions

 $manager->transfer(1,2,100);
 $manager->increase(1, 500);

As i right understand, the balance column (20 in one case) should be equal of transactions sum (10+10).
So therefore, without this "accountBalanceAttribute" this is everything no make sense, because transaction doesn't modify the balance column ( BalanceAccount table)

Account name not specified

Hi @klimov-paul ,

When an account is created on the fly, the account name is left blank. Your design provides every information needed to name the account when it is generated (for example, $userId . $accountType).
Did you make a decision not to name the account or is my configuration wrong somehow?

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.