Merge branch 'feature/inventory' into develop
This commit is contained in:
commit
6ca4e14c97
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,6 +3,7 @@
|
||||
|
||||
# phpstorm project files
|
||||
.idea
|
||||
*.iml
|
||||
|
||||
# netbeans project files
|
||||
nbproject
|
||||
|
||||
@ -81,7 +81,11 @@ class InventoryItemController extends Controller
|
||||
['item_count_sold', 'Eladott mennyiség (db)'],
|
||||
['item_count_in', 'Beszerzett mennyiség (db)'],
|
||||
['item_count', 'Leltározott mennyiség (db)'],
|
||||
['item_difference', 'Különbség (db)'],
|
||||
['item_purchase_price_net', 'Nettó beszerezési ár (Ft)'],
|
||||
['item_net_stock_money', 'Nettó készlet érték (Ft)'],
|
||||
['item_stock_missing_count', 'Különbség (db)'],
|
||||
['item_price_brutto', 'Bruttó eladási ár (Ft)'],
|
||||
['item_stock_missing_money', 'Leltár hiány (Ft)'],
|
||||
['item_count_system', 'Rendszer szerinti mennyiség (db)'],
|
||||
];
|
||||
$cols = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P'];
|
||||
@ -121,11 +125,13 @@ class InventoryItemController extends Controller
|
||||
// 'name' => 'Verdana'
|
||||
|
||||
|
||||
foreach (range('A', 'I') as $columnID) {
|
||||
foreach (range('A', 'N') as $columnID) {
|
||||
$sheet->getColumnDimension($columnID)->setAutoSize(true);
|
||||
$sheet->getStyle($columnID . '1')->applyFromArray($styleArray);
|
||||
}
|
||||
|
||||
$sheet->freezePane( "N2" );
|
||||
|
||||
// Redirect output to a client’s web browser (Excel5)
|
||||
header('Content-Type: application/vnd.ms-excel');
|
||||
header('Content-Disposition: attachment;filename="leltar.xls"');
|
||||
@ -191,32 +197,18 @@ class InventoryItemController extends Controller
|
||||
{
|
||||
$model = $this->findModel($id);
|
||||
$inventory = Inventory::findOne($model->id_inventory);
|
||||
|
||||
if (!$inventory->isOpen()) {
|
||||
throw new NotAcceptableHttpException("A leltár elem nem található");
|
||||
}
|
||||
|
||||
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
|
||||
|
||||
$model->recalculateTotalPriceBrutto();
|
||||
|
||||
$model->save(false);
|
||||
|
||||
\Yii::$app->session->setFlash('success', "Mennyiség elmentve: " . $model->productName . ' - ' .$model->count . ' db');
|
||||
|
||||
// $prev = Url::previous("inventory-item-index");
|
||||
|
||||
|
||||
|
||||
|
||||
$next = InventoryItem::findNextItemAlphabetical($model->id_inventory_item);
|
||||
if ( isset($_POST['_next']) && isset($next)){
|
||||
return $this->redirect(['inventory-item/update', 'id' => $next]);
|
||||
}else{
|
||||
return $this->redirect(['index', 'id' => $inventory->id_inventory]);
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
return $this->render('update', [
|
||||
'model' => $model,
|
||||
@ -226,11 +218,11 @@ class InventoryItemController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null $idInventory the id of the inventory
|
||||
* @param integer $id the inventory item id
|
||||
* @return string
|
||||
* @throws Exception
|
||||
* @throws NotAcceptableHttpException
|
||||
* @throws NotFoundHttpException
|
||||
*/
|
||||
public function actionUpdateItem($idInventory = null,$id = null)
|
||||
{
|
||||
@ -269,7 +261,6 @@ class InventoryItemController extends Controller
|
||||
|
||||
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
|
||||
|
||||
$model->recalculateTotalPriceBrutto();
|
||||
|
||||
if ( $model->save(false) ){
|
||||
\Yii::$app->session->setFlash('success', "Mennyiség elmentve: " . $model->productName . ' - ' .$model->count . ' db');
|
||||
|
||||
@ -123,16 +123,14 @@ class InventoryItemForm extends Model{
|
||||
$item->price_brutto = $this->product->sale_price;
|
||||
$item->type = InventoryItem::$TYPE_PRODUCT;
|
||||
$item->id_product = $this->product->id_product;
|
||||
$item->tax = $this->product->tax;
|
||||
$item->purchase_price_net = $this->product->purchase_net_price;
|
||||
}else{
|
||||
$item->id_inventory_group = $this->inventoryGroup->id_inventory_group;
|
||||
$item->type = InventoryItem::$TYPE_INVENTORY_GROUP;
|
||||
}
|
||||
$item->id_inventory = $this->inventory->id_inventory;
|
||||
|
||||
|
||||
$item->recalculateTotalPriceBrutto();
|
||||
|
||||
|
||||
if ( !$item->save(false) ){
|
||||
throw new \Exception("Nem sikerült a leltár végrehajtása");
|
||||
}
|
||||
|
||||
@ -2,7 +2,6 @@
|
||||
|
||||
namespace backend\models;
|
||||
|
||||
use Yii;
|
||||
use yii\base\Model;
|
||||
use yii\data\ActiveDataProvider;
|
||||
use common\models\InventoryItem;
|
||||
@ -72,8 +71,10 @@ class InventoryItemSearch extends InventoryItem
|
||||
'inventory_prev.id_inventory as inventory_prev_id_inventory',
|
||||
'inventory_prev.name as inventory_prev_name',
|
||||
'inventory_item.price_brutto as item_price_brutto',
|
||||
'inventory_item.total_price_brutto as item_total_price_brutto',
|
||||
new Expression('(coalesce(inventory_item.count,0) - ( coalesce(inventory_item.count_prev,0) + coalesce(inventory_item.count_in,0) - coalesce(inventory_item.count_sold,0) )) as item_difference'),
|
||||
'inventory_item.purchase_price_net as item_purchase_price_net',
|
||||
'inventory_item.net_stock_money as item_net_stock_money',
|
||||
'inventory_item.stock_missing_count as item_stock_missing_count',
|
||||
'inventory_item.stock_missing_money as item_stock_missing_money'
|
||||
]);
|
||||
|
||||
$query->from(InventoryItem::tableName());
|
||||
@ -91,11 +92,7 @@ class InventoryItemSearch extends InventoryItem
|
||||
|
||||
$this->load($params);
|
||||
|
||||
if (!$this->validate()) {
|
||||
// uncomment the following line if you do not want to return any records when validation fails
|
||||
// $query->where('0=1');
|
||||
return $dataProvider;
|
||||
}
|
||||
|
||||
|
||||
$dataProvider = new ActiveDataProvider(
|
||||
['query' => $query ,
|
||||
@ -117,13 +114,21 @@ class InventoryItemSearch extends InventoryItem
|
||||
['inventory.name', 'inventory_name'],
|
||||
['inventory_prev_name', 'inventory_prev_name'],
|
||||
['item_price_brutto', 'item_price_brutto'],
|
||||
['item_total_price_brutto', 'item_total_price_brutto'],
|
||||
['item_purchase_price_net', 'item_purchase_price_net'],
|
||||
['item_stock_missing_count', 'item_stock_missing_count'],
|
||||
['item_stock_missing_money', 'item_stock_missing_money'],
|
||||
])
|
||||
,
|
||||
]
|
||||
]
|
||||
);
|
||||
|
||||
if (!$this->validate()) {
|
||||
// uncomment the following line if you do not want to return any records when validation fails
|
||||
$query->where('0=1');
|
||||
return $dataProvider;
|
||||
}
|
||||
|
||||
|
||||
if ( !empty($this->item_type) && is_numeric($this->item_id) ){
|
||||
if ( $this->item_type == 'product'){
|
||||
|
||||
@ -115,18 +115,24 @@ $this->registerJs('inventoryItemIndex.init( ' . json_encode($options) . ' );');
|
||||
[
|
||||
'attribute' => 'inventory_prev_name',
|
||||
'label' => 'Utolsó leltár',
|
||||
'contentOptions' => ['class' => 'col-b']
|
||||
'contentOptions' => ['class' => '']
|
||||
],
|
||||
[
|
||||
'attribute' => 'item_count_system',
|
||||
'label' => 'Rendszer szerinti mennyiség (db)',
|
||||
'contentOptions' => ['class' => 'numeric']
|
||||
|
||||
],
|
||||
[
|
||||
'attribute' => 'item_purchase_price_net',
|
||||
'label' => 'Nettó beszerezési ár',
|
||||
'contentOptions' => ['class' => 'numeric']
|
||||
|
||||
],
|
||||
[
|
||||
'attribute' => 'item_count',
|
||||
'label' => 'Leltározott mennyiség (db)',
|
||||
'contentOptions' => ['class' => 'numeric col-b']
|
||||
'contentOptions' => ['class' => 'numeric ']
|
||||
|
||||
],
|
||||
[
|
||||
@ -138,7 +144,7 @@ $this->registerJs('inventoryItemIndex.init( ' . json_encode($options) . ' );');
|
||||
[
|
||||
'attribute' => 'item_count_in',
|
||||
'label' => 'Beszerzett mennyiség (db)',
|
||||
'contentOptions' => ['class' => 'numeric col-b' ]
|
||||
'contentOptions' => ['class' => 'numeric ' ]
|
||||
|
||||
],
|
||||
[
|
||||
@ -148,9 +154,9 @@ $this->registerJs('inventoryItemIndex.init( ' . json_encode($options) . ' );');
|
||||
|
||||
],
|
||||
[
|
||||
'attribute' => 'item_difference',
|
||||
'attribute' => 'item_stock_missing_count',
|
||||
'label' => 'Különbség (db)',
|
||||
'contentOptions' => ['class' => 'numeric col-b']
|
||||
'contentOptions' => ['class' => 'numeric ']
|
||||
|
||||
],
|
||||
[
|
||||
@ -159,13 +165,12 @@ $this->registerJs('inventoryItemIndex.init( ' . json_encode($options) . ' );');
|
||||
'contentOptions' => ['class' => 'numeric']
|
||||
],
|
||||
[
|
||||
'attribute' => 'item_total_price_brutto',
|
||||
'label' => 'Összeg (Ft)',
|
||||
'contentOptions' => ['class' => 'numeric col-b']
|
||||
],
|
||||
|
||||
|
||||
'attribute' => 'item_stock_missing_money',
|
||||
'label' => 'Leltár hiány (Ft)',
|
||||
'contentOptions' => ['class' => 'numeric ']
|
||||
]
|
||||
];
|
||||
|
||||
if ($model->isOpen()) {
|
||||
$columns[] = ['class' => 'yii\grid\ActionColumn',
|
||||
'template' => '{update}',
|
||||
@ -187,6 +192,28 @@ $this->registerJs('inventoryItemIndex.init( ' . json_encode($options) . ' );');
|
||||
];
|
||||
}
|
||||
|
||||
$i = 0;
|
||||
foreach ($columns as $col){
|
||||
$value = "";
|
||||
if ( !isset($col["contentOptions"])){
|
||||
$col["contentOptions"] = [];
|
||||
}
|
||||
|
||||
if ( isset($col["contentOptions"]["class"])){
|
||||
$value = $col["contentOptions"]["class"];
|
||||
}
|
||||
|
||||
if ( $i % 2 == 1){
|
||||
$columns[$i]["contentOptions"]["class"] = $value . " col-b";
|
||||
}else{
|
||||
$columns[$i]["contentOptions"]["class"] = $value . " col-a";
|
||||
}
|
||||
|
||||
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
echo GridView::widget([
|
||||
'dataProvider' => $dataProvider,
|
||||
'columns' => $columns
|
||||
|
||||
@ -40,6 +40,8 @@ $inventory_groups = ['' => ''] + ArrayHelper::map($inventory_groups, "id_invent
|
||||
|
||||
<?= $form->field($model, 'profit_margins')->textInput() ?>
|
||||
|
||||
<?= $form->field($model, 'tax')->textInput() ?>
|
||||
|
||||
<?= $form->field($model, 'status')->checkbox( ['value' => 10, 'label' => Yii::t('common/product', "Active") ]) ?>
|
||||
|
||||
<?= $form->field($model, 'description')->textarea(['maxlength' => true])->hint( Yii::t( 'common/product', "Max 255 character")) ?>
|
||||
|
||||
@ -37,6 +37,7 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
'product_number',
|
||||
'barcode',
|
||||
'sale_price',
|
||||
'tax',
|
||||
[
|
||||
'attribute' => 'status',
|
||||
'value' => 'statusHuman',
|
||||
|
||||
@ -29,6 +29,7 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
'purchase_price',
|
||||
'sale_price',
|
||||
'profit_margins',
|
||||
'tax',
|
||||
'statusHuman',
|
||||
'stock',
|
||||
[
|
||||
|
||||
@ -26,11 +26,16 @@ use common\components\ProductAwareBehavior;
|
||||
* @property integer $id_user
|
||||
* @property integer $id_inventory_item_prev
|
||||
* @property integer $price_brutto
|
||||
* @property integer $total_price_brutto
|
||||
* @property string $created_at
|
||||
* @property string $updated_at
|
||||
* @property mixed productName
|
||||
* @property mixed product
|
||||
* @property integer tax
|
||||
* @property integer purchase_price_net
|
||||
* @property integer net_stock_money
|
||||
* @property integer stock_missing_count
|
||||
* @property integer stock_missing_money
|
||||
* @property \common\models\InventoryGroup inventoryGroup
|
||||
*/
|
||||
class InventoryItem extends BaseFitnessActiveRecord
|
||||
{
|
||||
@ -133,6 +138,7 @@ class InventoryItem extends BaseFitnessActiveRecord
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getInventoryGroupName(){
|
||||
$result = "";
|
||||
|
||||
@ -159,32 +165,6 @@ class InventoryItem extends BaseFitnessActiveRecord
|
||||
return $name;
|
||||
}
|
||||
|
||||
|
||||
public function getDifference(){
|
||||
$diff = $this->count - ( $this->count_prev + $this->count_in - $this->count_sold );
|
||||
return $diff;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function recalculateTotalPriceBrutto(){
|
||||
$diff = $this->difference;
|
||||
if (!isset($diff) || !is_numeric($diff)){
|
||||
$diff = 0;
|
||||
}
|
||||
|
||||
$price = $this->price_brutto;
|
||||
if (!isset($price) || !is_numeric($price)){
|
||||
$price = 0;
|
||||
}
|
||||
|
||||
$this->total_price_brutto = $price * $diff;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static function findNextItemAlphabetical($id_inventory_item){
|
||||
|
||||
$inventoryItem = InventoryItem::findOne($id_inventory_item);
|
||||
@ -227,6 +207,65 @@ class InventoryItem extends BaseFitnessActiveRecord
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recalculate the next values:
|
||||
*
|
||||
netto készlet érték
|
||||
leltárhiány db
|
||||
leltárhiány összeg
|
||||
*
|
||||
* @param boolean $insert whether this method called while inserting a record.
|
||||
* If false, it means the method is called while updating a record.
|
||||
* @return boolean whether the insertion or updating should continue.
|
||||
* If false, the insertion or updating will be cancelled.
|
||||
*/
|
||||
public function beforeSave($insert)
|
||||
{
|
||||
$result = parent::beforeSave($insert);
|
||||
if ( $result ){
|
||||
if ( !isset($this->id_inventory_group) ){
|
||||
$count = 0;
|
||||
$purchase_price_net = 0;
|
||||
$count_prev = 0;
|
||||
$count_in = 0;
|
||||
$count_sold = 0;
|
||||
|
||||
$price = 0;
|
||||
if (isset($price) && is_numeric($price)){
|
||||
$price = $this->price_brutto;
|
||||
}
|
||||
|
||||
if ( isset($this->count)){
|
||||
$count = $this->count;
|
||||
}
|
||||
|
||||
if ( isset($this->purchase_price_net)){
|
||||
$purchase_price_net = $this->purchase_price_net;
|
||||
}
|
||||
|
||||
if ( isset($this->count_prev) ){
|
||||
$count_prev = $this->count_prev;
|
||||
}
|
||||
|
||||
if ( isset($this->count_in)){
|
||||
$count_in = $this->count_in;
|
||||
}
|
||||
|
||||
if ( isset($this->count_sold)){
|
||||
$count_sold = $this->count_sold;
|
||||
}
|
||||
|
||||
//netto készlet érték
|
||||
$this->net_stock_money = $count * $purchase_price_net;
|
||||
//leltárhiány db
|
||||
$this->stock_missing_count = $this->count - ($count_prev + $count_in - $count_sold) ;
|
||||
//leltárhiány összeg
|
||||
$this->stock_missing_money = $price * $this->stock_missing_count;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
public function afterSave($insert, $changedAttributes){
|
||||
if ( !$insert ){
|
||||
|
||||
@ -2,9 +2,9 @@
|
||||
|
||||
namespace common\models;
|
||||
|
||||
use common\components\Helper;
|
||||
use Yii;
|
||||
use yii\helpers\ArrayHelper;
|
||||
use common\components\Helper;
|
||||
|
||||
/**
|
||||
* This is the model class for table "product".
|
||||
@ -18,13 +18,16 @@ use common\components\Helper;
|
||||
* @property integer $purchase_price
|
||||
* @property integer $sale_price
|
||||
* @property integer $profit_margins
|
||||
* @property integer $tax
|
||||
* @property integer $purchase_net_price
|
||||
* @property integer $status
|
||||
* @property integer $stock
|
||||
* @property string $description
|
||||
* @property string $created_at
|
||||
* @property string $updated_at
|
||||
*/
|
||||
class Product extends \common\models\BaseFitnessActiveRecord {
|
||||
class Product extends \common\models\BaseFitnessActiveRecord
|
||||
{
|
||||
|
||||
const STATUS_DELETED = 0;
|
||||
const STATUS_ACTIVE = 10;
|
||||
@ -46,7 +49,7 @@ class Product extends \common\models\BaseFitnessActiveRecord {
|
||||
{
|
||||
return [
|
||||
[['id_product_category', 'id_account', 'name'], 'required'],
|
||||
[['id_inventory_group', 'id_product_category', 'id_account', 'purchase_price', 'sale_price', 'profit_margins', 'status'], 'integer'],
|
||||
[['id_inventory_group', 'id_product_category', 'id_account', 'purchase_price', 'sale_price', 'profit_margins', 'status', 'tax'], 'integer'],
|
||||
[['product_number', 'barcode'], 'string', 'max' => 20],
|
||||
[['product_number', 'barcode'], 'filter', 'filter' => 'trim', 'skipOnArray' => true],
|
||||
[['name'], 'string', 'max' => 128],
|
||||
@ -55,15 +58,18 @@ class Product extends \common\models\BaseFitnessActiveRecord {
|
||||
// [['barcode'], 'unique' ],
|
||||
// a1 and a2 need to be unique together, only a1 will receive error message
|
||||
// ['a1', 'unique', 'targetAttribute' => ['a1', 'a2']]
|
||||
[['barcode','product_number'], 'filter', 'filter' => function($value){return Helper::fixAsciiChars($value);}],
|
||||
[['barcode', 'product_number'], 'filter', 'filter' => function ($value) {
|
||||
return Helper::fixAsciiChars($value);
|
||||
}],
|
||||
['barcode', 'unique', 'targetAttribute' => ['id_account', 'barcode']],
|
||||
['product_number', 'unique', 'targetAttribute' => ['id_account', 'product_number']],
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
public function validateAscii($attribute,$params){
|
||||
if ( !$this->hasErrors($this->$attribute)){
|
||||
public function validateAscii($attribute, $params)
|
||||
{
|
||||
if (!$this->hasErrors($this->$attribute)) {
|
||||
$this->attribute = Helper::fixAsciiChars($this->attributes);
|
||||
}
|
||||
}
|
||||
@ -84,6 +90,8 @@ class Product extends \common\models\BaseFitnessActiveRecord {
|
||||
'profit_margins' => Yii::t('common/product', 'Profit Margins'),
|
||||
'status' => Yii::t('common/product', 'Status'),
|
||||
'name' => Yii::t('common/product', 'Name'),
|
||||
'tax' => Yii::t('common/product', 'Adó(%)'),
|
||||
'stock' => Yii::t('common/product', 'Raktáron'),
|
||||
'description' => Yii::t('common/product', 'Description'),
|
||||
'created_at' => Yii::t('common/product', 'Created At'),
|
||||
'updated_at' => Yii::t('common/product', 'Updated At'),
|
||||
@ -92,51 +100,63 @@ class Product extends \common\models\BaseFitnessActiveRecord {
|
||||
}
|
||||
|
||||
|
||||
public function getAccount() {
|
||||
return $this->hasOne ( Account::className (), [
|
||||
public function getAccount()
|
||||
{
|
||||
return $this->hasOne(Account::className(), [
|
||||
'id_account' => 'id_account'
|
||||
] );
|
||||
]);
|
||||
}
|
||||
public function getAccountName() {
|
||||
|
||||
public function getAccountName()
|
||||
{
|
||||
return $this->account->name;
|
||||
}
|
||||
|
||||
public function getInventoryGroup() {
|
||||
return $this->hasOne ( InventoryGroup::className (), [
|
||||
public function getInventoryGroup()
|
||||
{
|
||||
return $this->hasOne(InventoryGroup::className(), [
|
||||
'id_inventory_group' => 'id_inventory_group'
|
||||
] );
|
||||
]);
|
||||
}
|
||||
public function getInventoryGroupName() {
|
||||
|
||||
public function getInventoryGroupName()
|
||||
{
|
||||
$result = "";
|
||||
$inventoryGroup = $this->inventoryGroup;
|
||||
if ( isset($inventoryGroup)){
|
||||
if (isset($inventoryGroup)) {
|
||||
$result = $inventoryGroup->name;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getProductCategory() {
|
||||
return $this->hasOne ( ProductCategory::className (), [
|
||||
public function getProductCategory()
|
||||
{
|
||||
return $this->hasOne(ProductCategory::className(), [
|
||||
'id_product_category' => 'id_product_category'
|
||||
] );
|
||||
]);
|
||||
}
|
||||
public function getProductCategoryName() {
|
||||
|
||||
public function getProductCategoryName()
|
||||
{
|
||||
return $this->productCategory->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @formatter:on
|
||||
*/
|
||||
static function statuses() {
|
||||
static function statuses()
|
||||
{
|
||||
return [
|
||||
self::STATUS_ACTIVE => Yii::t ( 'common/product', 'Active' ),
|
||||
self::STATUS_DELETED => Yii::t ( 'common/product', 'Inactive' )
|
||||
self::STATUS_ACTIVE => Yii::t('common/product', 'Active'),
|
||||
self::STATUS_DELETED => Yii::t('common/product', 'Inactive')
|
||||
];
|
||||
}
|
||||
public function getStatusHuman() {
|
||||
|
||||
public function getStatusHuman()
|
||||
{
|
||||
$result = null;
|
||||
$s = self::statuses ( );
|
||||
if (array_key_exists ( $this->status, $s )) {
|
||||
$s = self::statuses();
|
||||
if (array_key_exists($this->status, $s)) {
|
||||
$result = $s [$this->status];
|
||||
}
|
||||
return $result;
|
||||
@ -145,13 +165,14 @@ class Product extends \common\models\BaseFitnessActiveRecord {
|
||||
/**
|
||||
* $param int $forceIncludeAccount id warehouse, that should be included in list, even if it is inactive
|
||||
* */
|
||||
public static function read($forceIncludeObjectWithId = null){
|
||||
public static function read($forceIncludeObjectWithId = null)
|
||||
{
|
||||
$warehouses = null;
|
||||
|
||||
if ( $forceIncludeObjectWithId == null){
|
||||
if ($forceIncludeObjectWithId == null) {
|
||||
$warehouses = Product::find()->andWhere(['status' => Product::STATUS_ACTIVE])->orderBy(['product.name' => SORT_ASC])->all();
|
||||
}else{
|
||||
$warehouses = Product::find()->andWhere( ['or', ['status' => Product::STATUS_ACTIVE], ['id_product' => $forceIncludeObjectWithId ] ])->orderBy(['product.name' => SORT_ASC])->all();
|
||||
} else {
|
||||
$warehouses = Product::find()->andWhere(['or', ['status' => Product::STATUS_ACTIVE], ['id_product' => $forceIncludeObjectWithId]])->orderBy(['product.name' => SORT_ASC])->all();
|
||||
}
|
||||
|
||||
return $warehouses;
|
||||
@ -160,20 +181,21 @@ class Product extends \common\models\BaseFitnessActiveRecord {
|
||||
/**
|
||||
* $param int $forceIncludeAccount id warehouse, that should be included in list, even if it is inactive
|
||||
* */
|
||||
public static function readForDefaultAccount($forceIncludeObjectWithId = null){
|
||||
public static function readForDefaultAccount($forceIncludeObjectWithId = null)
|
||||
{
|
||||
$result = null;
|
||||
|
||||
$account = Account::readDefault();
|
||||
|
||||
if ( $forceIncludeObjectWithId == null){
|
||||
if ($forceIncludeObjectWithId == null) {
|
||||
$query = Product::find()->andWhere(['status' => Product::STATUS_ACTIVE])->orderBy(['product.name' => SORT_ASC]);
|
||||
if ( Helper::isProductVisibilityAccount() && $account )
|
||||
if (Helper::isProductVisibilityAccount() && $account)
|
||||
$query->andWhere(["product.id_account" => $account]);
|
||||
|
||||
$result = $query->all();
|
||||
}else{
|
||||
$query = Product::find()->andWhere( ['or', ['status' => Product::STATUS_ACTIVE], ['id_product' => $forceIncludeObjectWithId ] ])->orderBy(['product.name' => SORT_ASC]);
|
||||
if ( Helper::isProductVisibilityAccount() && $account )
|
||||
} else {
|
||||
$query = Product::find()->andWhere(['or', ['status' => Product::STATUS_ACTIVE], ['id_product' => $forceIncludeObjectWithId]])->orderBy(['product.name' => SORT_ASC]);
|
||||
if (Helper::isProductVisibilityAccount() && $account)
|
||||
$query->andWhere(["product.id_account" => $account]);
|
||||
|
||||
$result = $query->all();
|
||||
@ -183,34 +205,35 @@ class Product extends \common\models\BaseFitnessActiveRecord {
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function findProduct($query, $account = null){
|
||||
$result = [];
|
||||
public static function findProduct($query, $account = null)
|
||||
{
|
||||
$product = null;
|
||||
|
||||
$query = Product::find()
|
||||
->andWhere(
|
||||
['or',
|
||||
['product_number' => $query ],
|
||||
['barcode' => $query ],
|
||||
['product_number' => $query],
|
||||
['barcode' => $query],
|
||||
]
|
||||
)->andWhere(['status' =>Product::STATUS_ACTIVE]);
|
||||
)->andWhere(['status' => Product::STATUS_ACTIVE]);
|
||||
|
||||
if ( Helper::isProductVisibilityAccount() && $account ){
|
||||
if (Helper::isProductVisibilityAccount() && $account) {
|
||||
$query->andFilterWhere(['product.id_account' => $account]);
|
||||
}
|
||||
|
||||
|
||||
$products = $query->all();
|
||||
|
||||
if ( count($products) == 1 ){
|
||||
if (count($products) == 1) {
|
||||
$product = $products[0];
|
||||
}
|
||||
return $product;
|
||||
}
|
||||
|
||||
public static function modelToArray($product,$default = null){
|
||||
public static function modelToArray($product, $default = null)
|
||||
{
|
||||
|
||||
if ( $product == null ){
|
||||
if ($product == null) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
@ -230,9 +253,10 @@ class Product extends \common\models\BaseFitnessActiveRecord {
|
||||
]);
|
||||
}
|
||||
|
||||
public static function modelToMapIdName($product,$default = null){
|
||||
public static function modelToMapIdName($product, $default = null)
|
||||
{
|
||||
|
||||
if ( $product == null ){
|
||||
if ($product == null) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
@ -244,9 +268,10 @@ class Product extends \common\models\BaseFitnessActiveRecord {
|
||||
]);
|
||||
}
|
||||
|
||||
public static function modelToMapIdNameLong($product,$default = null){
|
||||
public static function modelToMapIdNameLong($product, $default = null)
|
||||
{
|
||||
|
||||
if ( $product == null ){
|
||||
if ($product == null) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
@ -254,46 +279,73 @@ class Product extends \common\models\BaseFitnessActiveRecord {
|
||||
'common\models\Product' => [
|
||||
'id_product',
|
||||
'name' => function ($product) {
|
||||
return $product->name . " - " .$product->productCategoryName . " (" . $product->accountName . ")";
|
||||
return $product->name . " - " . $product->productCategoryName . " (" . $product->accountName . ")";
|
||||
},
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public static function sellProduct($product,$count){
|
||||
public static function sellProduct($product, $count)
|
||||
{
|
||||
$product->stock = $product->stock - $count;
|
||||
}
|
||||
|
||||
|
||||
public static function readProductsNotPartOfInventoryGroup( $id_account = null ){
|
||||
public static function readProductsNotPartOfInventoryGroup($id_account = null)
|
||||
{
|
||||
$query = Product::find();
|
||||
$query->andWhere("id_inventory_group is null");
|
||||
$query->andWhere(['status' => Product::STATUS_ACTIVE]);
|
||||
return $query->all();
|
||||
}
|
||||
|
||||
public static function readInventoryGroups(){
|
||||
public static function readInventoryGroups()
|
||||
{
|
||||
$query = InventoryGroup::find();
|
||||
$query->andWhere(['status' => Product::STATUS_ACTIVE]);
|
||||
return $query->all();
|
||||
}
|
||||
|
||||
public static function buildProductAndInventoryGroupList($id_account = null){
|
||||
public static function buildProductAndInventoryGroupList($id_account = null)
|
||||
{
|
||||
$productOptions = [];
|
||||
|
||||
$products = Product::readProductsNotPartOfInventoryGroup($id_account);
|
||||
$inventoryGroups = Product::readInventoryGroups();
|
||||
|
||||
foreach ($products as $product ){
|
||||
$productOptions[]= [ 'type' =>'product', 'id' => $product->id_product ,'name' => $product->name . " (Termék/" .$product->productCategoryName ."/" . $product->accountName .")" ];
|
||||
foreach ($products as $product) {
|
||||
$productOptions[] = ['type' => 'product', 'id' => $product->id_product, 'name' => $product->name . " (Termék/" . $product->productCategoryName . "/" . $product->accountName . ")"];
|
||||
}
|
||||
|
||||
foreach ($inventoryGroups as $inventoryGroup ){
|
||||
$productOptions[] = ['type' =>'group', 'id' =>$inventoryGroup->id_inventory_group ,'name' =>$inventoryGroup->name ."/Termékcsoport" ];
|
||||
foreach ($inventoryGroups as $inventoryGroup) {
|
||||
$productOptions[] = ['type' => 'group', 'id' => $inventoryGroup->id_inventory_group, 'name' => $inventoryGroup->name . "/Termékcsoport"];
|
||||
|
||||
}
|
||||
return $productOptions;
|
||||
}
|
||||
|
||||
public function beforeSave($insert)
|
||||
{
|
||||
$result = parent::beforeSave($insert);
|
||||
if ($result) {
|
||||
|
||||
//automatically set net price
|
||||
//net price = purchase_price -(purchase_price * tax /100)
|
||||
$purchase_price_brutto = 0;
|
||||
$tax = 0;
|
||||
if (isset($this->purchase_price)) {
|
||||
$purchase_price_brutto = $this->purchase_price;
|
||||
}
|
||||
|
||||
if (isset($this->tax)) {
|
||||
$tax = $this->tax;
|
||||
}
|
||||
|
||||
$this->purchase_net_price = $purchase_price_brutto - ($purchase_price_brutto * $tax / 100);
|
||||
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -40,6 +40,7 @@ use yii\web\NotAcceptableHttpException;
|
||||
* @property integer $id_customer
|
||||
* @property int|string paid_by
|
||||
* @property int payment_method
|
||||
* @property \common\models\Ticket ticket
|
||||
*/
|
||||
class Transfer extends \common\models\BaseFitnessActiveRecord {
|
||||
const TYPE_PRODUCT = 10;
|
||||
@ -597,7 +598,6 @@ class Transfer extends \common\models\BaseFitnessActiveRecord {
|
||||
public function beforeDelete() {
|
||||
parent::beforeDelete ();
|
||||
if ($this->type == Transfer::TYPE_TICKET) {
|
||||
/** @noinspection PhpUndefinedFieldInspection */
|
||||
$ticket = $this->ticket;
|
||||
if ($ticket != null) {
|
||||
$ticket->delete ();
|
||||
|
||||
@ -54,7 +54,6 @@ class InventoryConsoleController extends Controller{
|
||||
|
||||
$item->count_sold = $products;
|
||||
|
||||
$item->recalculateTotalPriceBrutto();
|
||||
|
||||
echo $item->price_brutto . " - ". $item->productName ."\n";
|
||||
|
||||
|
||||
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
use yii\db\Schema;
|
||||
use yii\db\Migration;
|
||||
|
||||
class m170103_172147_alter__product__add__column__tax extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
$this->addColumn("product", "tax", "int default 27");
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
echo "m170103_172147_alter__product__add__column__tax cannot be reverted.\n";
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
// Use safeUp/safeDown to run migration code within a transaction
|
||||
public function safeUp()
|
||||
{
|
||||
}
|
||||
|
||||
public function safeDown()
|
||||
{
|
||||
}
|
||||
*/
|
||||
}
|
||||
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
use yii\db\Schema;
|
||||
use yii\db\Migration;
|
||||
|
||||
class m170103_175608_alter__product__add__column__purchase_net_price extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
$this->addColumn("product", "purchase_net_price", "int default 0");
|
||||
$this->execute("update product set purchase_net_price = purchase_price - FLOOR( purchase_price * tax / 100 )");
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
echo "m170103_175608_alter__product__add__column__purchase_net_price cannot be reverted.\n";
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
// Use safeUp/safeDown to run migration code within a transaction
|
||||
public function safeUp()
|
||||
{
|
||||
}
|
||||
|
||||
public function safeDown()
|
||||
{
|
||||
}
|
||||
*/
|
||||
}
|
||||
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use yii\db\Schema;
|
||||
use yii\db\Migration;
|
||||
|
||||
class m170104_054306_alter__table__product__set_products__tax__18 extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
$this->execute("update product set tax = 18 where name = 'Zabcsók';");
|
||||
$this->execute("update product set tax = 18 where name = 'Mabaker zabszelet';");
|
||||
$this->execute("update product set purchase_net_price = purchase_price - FLOOR( purchase_price * tax / 100 )");
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
echo "m170104_054306_alter__table__product__set_products__tax__18 cannot be reverted.\n";
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
// Use safeUp/safeDown to run migration code within a transaction
|
||||
public function safeUp()
|
||||
{
|
||||
}
|
||||
|
||||
public function safeDown()
|
||||
{
|
||||
}
|
||||
*/
|
||||
}
|
||||
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
use yii\db\Schema;
|
||||
use yii\db\Migration;
|
||||
|
||||
class m170104_063931_alter__table__inventory__item__add__tax__net_stock_valu__sotck_missing extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
$this->addColumn("inventory_item", "tax", "int default 0");
|
||||
$this->addColumn("inventory_item", "net_stock_money", "int default 0");
|
||||
$this->addColumn("inventory_item", "purchase_price_net", "int default 0");
|
||||
$this->addColumn("inventory_item", "stock_missing_money", "int default 0");
|
||||
$this->addColumn("inventory_item", "stock_missing_count", "int default 0");
|
||||
|
||||
|
||||
$sql = "UPDATE inventory_item AS i
|
||||
INNER JOIN product AS p ON p.id_product = i.id_product
|
||||
SET
|
||||
i.tax = p.tax,
|
||||
i.purchase_price_net = p.purchase_net_price,
|
||||
i.net_stock_money = i.count * p.purchase_net_price,
|
||||
i.stock_missing_count = (coalesce(i.count,0) - ( coalesce(i.count_prev,0) + coalesce(i.count_in,0) - coalesce(i.count_sold,0) )),
|
||||
i.stock_missing_money = i.price_brutto * (coalesce(i.count,0) - ( coalesce(i.count_prev,0) + coalesce(i.count_in,0) - coalesce(i.count_sold,0) ))
|
||||
WHERE i.id_inventory_group is null ";
|
||||
|
||||
|
||||
$this->execute($sql);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
echo "m170104_063931_alter__table__inventory__item__add__tax__net_stock_valu__sotck_missing cannot be reverted.\n";
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
// Use safeUp/safeDown to run migration code within a transaction
|
||||
public function safeUp()
|
||||
{
|
||||
}
|
||||
|
||||
public function safeDown()
|
||||
{
|
||||
}
|
||||
*/
|
||||
}
|
||||
@ -161,6 +161,8 @@ class TicketController extends FrontendController
|
||||
public function actionDelete($id)
|
||||
{
|
||||
$ticket = $this->findModel($id);
|
||||
|
||||
/** @var \common\models\Transfer $transfer */
|
||||
$transfer = Transfer::find()->andWhere(['transfer.type' => Transfer::TYPE_TICKET])
|
||||
->andWhere(['transfer.id_object' => $ticket->id_ticket])
|
||||
->one();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user