yii2tech / balance Goto Github PK
View Code? Open in Web Editor NEWBalance accounting (bookkeeping) system based on debit and credit principle
License: Other
Balance accounting (bookkeeping) system based on debit and credit principle
License: Other
Hi,
I would love to use the module for creating a minimized warehouse application.
What I would love to understand is:
Thanks in advance Philipp
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(),
]);
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
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;
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, ...)
in /var/www/advanced/vendor/yiisoft/yii2/db/ColumnSchema.php at line 104 – yii\db\ColumnSchema::typecast(common\models\Account)
in /var/www/advanced/vendor/yiisoft/yii2/db/mysql/QueryBuilder.php at line 208 – yii\db\ColumnSchema::dbTypecast(common\models\Account)
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, ...])
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}
Does this plugin allows to
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.
For the more flexibility of the Manager
and events triggering should be added.
List of events:
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
]);
I can't make it works unless set the db to ISAM.
Any idea why it doesn't works with InnoDb?
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
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!
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.
When we call ManagerDbTransaction::transfer
\yii2tech\balance\ManagerDbTransaction::beginDbTransaction
called multiple times (in transfer, increase and decrease methods).
First time it's work normally and begins transaction, but in next times it's returns null, so we lost transaction object and cant' commit them
Hello!
I have created a tables from tests:
BalanceAccount
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)
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.