Finish version/v.0.0.55

This commit is contained in:
Roland Schneider 2016-03-25 20:12:33 +01:00
commit 120ce58e0b
58 changed files with 2247 additions and 171 deletions

View File

@ -0,0 +1,31 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace backend\assets;
use yii\web\AssetBundle;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class InventoryItemIndexAsset extends AssetBundle
{
public $basePath = '@webroot';
public $baseUrl = '@web';
public $css = [
];
public $js = [
'js/app.js',
'js/inventory.item.index.js',
];
public $depends = [
'backend\assets\AppAsset',
'yii\jui\JuiAsset',
'common\assets\TypeAheadAsset',
];
}

View File

@ -106,6 +106,7 @@ class AdminMenuStructure{
// $items[] = ['label' => 'Bevétel', 'url' => ['/transfer/summary' , 'TransferSummarySearch[start]' =>$today,'TransferSummarySearch[end]' => $tomorrow ] ]; // $items[] = ['label' => 'Bevétel', 'url' => ['/transfer/summary' , 'TransferSummarySearch[start]' =>$today,'TransferSummarySearch[end]' => $tomorrow ] ];
$items[] = ['label' => 'Napi bevételek', 'url' => ['/transfer/list', 'TransferListSearch[start]' =>$todayDatetime,'TransferListSearch[end]' => $tomorrowDatetime ] ]; $items[] = ['label' => 'Napi bevételek', 'url' => ['/transfer/list', 'TransferListSearch[start]' =>$todayDatetime,'TransferListSearch[end]' => $tomorrowDatetime ] ];
$items[] = ['label' => 'Kassza müveletek', 'url' => ['/account-state/index'] ]; $items[] = ['label' => 'Kassza müveletek', 'url' => ['/account-state/index'] ];
$items[] = ['label' => 'Későbbi utalások', 'url' => ['/transfer/payment-later','TransferLaterSearch[start]' =>$todayDatetime,'TransferLaterSearch[end]' => $tomorrowDatetime ] ];
//$items[] = ['label' => 'Zárások', 'url' => ['/collection/index' , 'CollectionSearch[start]' =>$todayDatetime,'CollectionSearch[end]' => $tomorrowDatetime ] ]; //$items[] = ['label' => 'Zárások', 'url' => ['/collection/index' , 'CollectionSearch[start]' =>$todayDatetime,'CollectionSearch[end]' => $tomorrowDatetime ] ];
$this->menuItems[] = ['label' => 'Pénzügy', 'url' => $this->emptyUrl, $this->menuItems[] = ['label' => 'Pénzügy', 'url' => $this->emptyUrl,
'items' => $items 'items' => $items

View File

@ -69,7 +69,6 @@ class AccountStateController extends \backend\controllers\BackendController
* @return mixed * @return mixed
*/ */
public function actionView($id) { public function actionView($id) {
echo "view";
$accountState = $this->findModel ( $id ); $accountState = $this->findModel ( $id );
$output = Yii::$app->getRequest ()->getQueryParam ( 'output' ); $output = Yii::$app->getRequest ()->getQueryParam ( 'output' );
$details = null; $details = null;

View File

@ -8,13 +8,7 @@ use backend\models\InventorySearch;
use yii\web\Controller; use yii\web\Controller;
use yii\web\NotFoundHttpException; use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter; use yii\filters\VerbFilter;
use common\models\InventoryItem;
use yii\data\ActiveDataProvider;
use common\components\Helper;
use common\models\User; use common\models\User;
use common\models\Product;
use common\models\InventoryGroup;
use yii\db\Expression;
use yii\db\Query; use yii\db\Query;
use backend\models\InventoryItemSearch; use backend\models\InventoryItemSearch;
@ -50,26 +44,6 @@ class InventoryController extends Controller
]); ]);
} }
/**
* Displays a single Inventory model.
* @param integer $id
* @return mixed
*/
public function actionView($id)
{
$inventory = $this->findModel($id);
$searchModel = new InventoryItemSearch(['inventory' => $inventory]);
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$query = new Query();
return $this->render('view', [
'model' => $inventory,
'dataProvider' => $dataProvider
]);
}
/** /**
* Creates a new Inventory model. * Creates a new Inventory model.
@ -88,43 +62,13 @@ class InventoryController extends Controller
if ($model->load(Yii::$app->request->post()) && $model->save()) { if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id_inventory]); return $this->redirect(['view', 'id' => $model->id_inventory]);
} else { } else {
}
return $this->render('create', [ return $this->render('create', [
'model' => $model, 'model' => $model,
]); ]);
} }
}
/**
* Updates an existing Inventory model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id_inventory]);
} else {
return $this->render('update', [
'model' => $model,
]);
}
}
/**
* Deletes an existing Inventory model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
*/
public function actionDelete($id)
{
$this->findModel($id)->delete();
return $this->redirect(['index']);
}
/** /**
* Finds the Inventory model based on its primary key value. * Finds the Inventory model based on its primary key value.

View File

@ -10,6 +10,8 @@ use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter; use yii\filters\VerbFilter;
use backend\models\InventoryItemForm; use backend\models\InventoryItemForm;
use common\models\Inventory; use common\models\Inventory;
use yii\helpers\Url;
use common\models\Product;
/** /**
* InventoryItemController implements the CRUD actions for InventoryItem model. * InventoryItemController implements the CRUD actions for InventoryItem model.
@ -43,13 +45,94 @@ class InventoryItemController extends Controller
$searchModel = new InventoryItemSearch(['inventory' => $inventory]); $searchModel = new InventoryItemSearch(['inventory' => $inventory]);
$dataProvider = $searchModel->search(Yii::$app->request->queryParams); $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$productOptions = Product::buildProductAndInventoryGroupList();
if ($searchModel->output == 'xls') {
$this->downloadIndexXls($dataProvider);
}else{
Url::remember(Url::current(),"inventory-item-index");
}
return $this->render('index', [ return $this->render('index', [
'model' => $inventory, 'model' => $inventory,
'searchModel' => $searchModel, 'searchModel' => $searchModel,
'dataProvider' => $dataProvider, 'dataProvider' => $dataProvider,
'productOptions' =>$productOptions
]); ]);
} }
protected function downloadIndexXls($dataProvider){
$defs = [['item_created_at', 'Létrehozva'],
['item_name', 'Termék/Termék csoport'],
['user_username', 'Felhasználó'],
['item_count_prev', 'Előző leltár (db)'],
['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_count_system', 'Rendszer szerinti mennyiség (db)'],
];
$cols = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P'];
$models = $dataProvider->getModels ();
$objPHPExcel = new \PHPExcel ();
$sheet = $objPHPExcel->setActiveSheetIndex ( 0 );
/**
* Termék azonosító Termék neve Termék szám Termék vonalkód Termék raktáron Termék eladva
*/
$row = 1;
$col = 0;
foreach ( $defs as $def ) {
$sheet->setCellValue ( $cols [$col] . $row, $def [1] );
$col ++;
}
foreach ( $models as $model ) {
$row ++;
$col = 0;
foreach ( $defs as $def ) {
$sheet->setCellValue ( $cols [$col] . $row, $model[$def [0]] );
$col ++;
}
}
$styleArray = array (
'font' => array (
'bold' => true
)
);
// 'color' => array('rgb' => 'FF0000'),
// 'size' => 15,
// 'name' => 'Verdana'
foreach ( range ( 'A', 'I' ) as $columnID ) {
$sheet->getColumnDimension ( $columnID )->setAutoSize ( true );
$sheet->getStyle ( $columnID . '1' )->applyFromArray ( $styleArray );
}
// Redirect output to a clients web browser (Excel5)
header ( 'Content-Type: application/vnd.ms-excel' );
header ( 'Content-Disposition: attachment;filename="leltar.xls"' );
header ( 'Cache-Control: max-age=0' );
// If you're serving to IE 9, then the following may be needed
header ( 'Cache-Control: max-age=1' );
// If you're serving to IE over SSL, then the following may be needed
header ( 'Expires: Mon, 26 Jul 1997 05:00:00 GMT' ); // Date in the past
header ( 'Last-Modified: ' . gmdate ( 'D, d M Y H:i:s' ) . ' GMT' ); // always modified
header ( 'Cache-Control: cache, must-revalidate' ); // HTTP/1.1
header ( 'Pragma: public' ); // HTTP/1.0
$objWriter = \PHPExcel_IOFactory::createWriter ( $objPHPExcel, 'Excel5' );
$objWriter->save ( 'php://output' );
exit ();
}
/** /**
* Displays a single InventoryItem model. * Displays a single InventoryItem model.
* @param integer $id * @param integer $id
@ -93,12 +176,21 @@ class InventoryItemController extends Controller
public function actionUpdate($id) public function actionUpdate($id)
{ {
$model = $this->findModel($id); $model = $this->findModel($id);
$inventory = Inventory::findOne($model->id_inventory);
if ($model->load(Yii::$app->request->post()) && $model->save()) { if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id_inventory_item]);
$prev = Url::previous("inventory-item-index");
if ( isset($prev)){
return $this->redirect($prev);
}else{
return $this->redirect([ 'index', 'id' => $inventory->id_inventory ]);
}
} else { } else {
return $this->render('update', [ return $this->render('update', [
'model' => $model, 'model' => $model,
'inventory' => $inventory,
]); ]);
} }
} }

View File

@ -15,6 +15,8 @@ use backend\models\TransferSaleSearch;
use common\models\ProductCategory; use common\models\ProductCategory;
use common\models\Product; use common\models\Product;
use backend\models\TransferListUserGroupedSearch; use backend\models\TransferListUserGroupedSearch;
use backend\models\TransferLaterSearch;
use yii\helpers\Url;
/** /**
* TransferController implements the CRUD actions for Transfer model. * TransferController implements the CRUD actions for Transfer model.
@ -29,7 +31,14 @@ class TransferController extends \backend\controllers\BackendController
'rules' => [ 'rules' => [
// allow authenticated users // allow authenticated users
[ [
'actions' => [ 'index','view','summary','list',"sale","sale-pdf" ,'list-user-grouped'], 'actions' => [ 'index',
'view',
'summary',
'list',
"sale",
"sale-pdf" ,
'list-user-grouped',
'payment-later'],
'allow' => true, 'allow' => true,
'roles' => ['admin','employee','reception'], 'roles' => ['admin','employee','reception'],
], ],
@ -40,6 +49,34 @@ class TransferController extends \backend\controllers\BackendController
} }
public function actionPaymentLater(){
$searchModel = new TransferLaterSearch();
if ( \Yii::$app->request->isPost){
$searchModel->load(Yii::$app->request->post());
if ( $searchModel->doPayout()) {
return $this->redirect(['transfer/payment-later' ]);
}
}
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$accounts = Account::read();
$users = User::read();
Url::remember("payment_later",Url::current());
return $this->render('payment_later', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
'accounts' => $accounts,
'users' => $users,
]);
}
/** /**
* Lists all Transfer models. * Lists all Transfer models.
* @return mixed * @return mixed

View File

@ -89,7 +89,6 @@ class InventoryItemForm extends Model{
} }
public function save(){ public function save(){
if ( $this->validate()) {
$this->loadLastInventory(); $this->loadLastInventory();
@ -109,10 +108,14 @@ class InventoryItemForm extends Model{
if ( isset( $this->last_inventory_item ) ){ if ( isset( $this->last_inventory_item ) ){
$item->id_inventory_item_prev = $this->last_inventory_item->id_inventory_item; $item->id_inventory_item_prev = $this->last_inventory_item->id_inventory_item;
$item->count_prev = $this->last_inventory_item->count; $item->count_prev = $this->last_inventory_item->count;
if ( !isset($item->count_prev)){
$item->count_prev = 0;
}
}else{ }else{
$item->count_prev = 0; $item->count_prev = 0;
} }
$item->id_user = \Yii::$app->user->id; $item->id_user = \Yii::$app->user->id;
if ( $this->type == 'product'){ if ( $this->type == 'product'){
@ -122,19 +125,18 @@ class InventoryItemForm extends Model{
} }
$item->id_inventory = $this->inventory->id_inventory; $item->id_inventory = $this->inventory->id_inventory;
if ( !$item->save() ){ if ( !$item->save(false) ){
throw new \Exception("Nem sikerült a leltár végrehajtása"); throw new \Exception("Nem sikerült a leltár végrehajtása");
} }
$this->inventory_item = $item; $this->inventory_item = $item;
return true; return true;
} }
return false;
}
protected function loadProductIn(){ protected function loadProductIn(){
$query = new Query(); $query = new Query();
$query->select(['sum(procurement.count) as total_in']); $query->select(['coalesce(sum(procurement.count),0) as total_in']);
$query->from(Procurement::tableName()); $query->from(Procurement::tableName());
$query->innerJoin(Product::tableName(),"product.id_product = procurement.id_product"); $query->innerJoin(Product::tableName(),"product.id_product = procurement.id_product");
@ -155,7 +157,7 @@ class InventoryItemForm extends Model{
protected function loadProductSold(){ protected function loadProductSold(){
$query = new Query(); $query = new Query();
$query->select(['sum(transfer.count) as total_sold']); $query->select(['coalesce(sum(transfer.count),0) as total_sold']);
$query->from(Transfer::tableName()); $query->from(Transfer::tableName());
$query->innerJoin(Sale::tableName(),"sale.id_sale = transfer.id_object and transfer.type = " .Transfer::TYPE_PRODUCT); $query->innerJoin(Sale::tableName(),"sale.id_sale = transfer.id_object and transfer.type = " .Transfer::TYPE_PRODUCT);
$query->innerJoin(Product::tableName(),"product.id_product = sale.id_product "); $query->innerJoin(Product::tableName(),"product.id_product = sale.id_product ");
@ -174,7 +176,7 @@ class InventoryItemForm extends Model{
protected function loadProductStock(){ protected function loadProductStock(){
$query = new Query(); $query = new Query();
$query->select(['sum(product.stock) as total_stock']); $query->select(['coalesce(sum(product.stock),0) as total_stock']);
$query->from(Product::tableName()); $query->from(Product::tableName());
if ( $this->type == 'product') { if ( $this->type == 'product') {

View File

@ -20,7 +20,10 @@ use common\models\Inventory;
class InventoryItemSearch extends InventoryItem class InventoryItemSearch extends InventoryItem
{ {
public $inventory; public $inventory;
public $output;
public $item_name;
public $item_type;
public $item_id;
/** /**
* @inheritdoc * @inheritdoc
*/ */
@ -28,6 +31,10 @@ class InventoryItemSearch extends InventoryItem
{ {
return [ return [
[['id_inventory_item', 'id_inventory', 'count_in', 'count_sold', 'count', 'type', 'id_product', 'id_inventory_group', 'id_user'], 'integer'], [['id_inventory_item', 'id_inventory', 'count_in', 'count_sold', 'count', 'type', 'id_product', 'id_inventory_group', 'id_user'], 'integer'],
['output', 'string'],
['item_name', 'string'],
['item_type', 'string'],
['item_id', 'integer'],
]; ];
} }
@ -50,6 +57,7 @@ class InventoryItemSearch extends InventoryItem
public function search($params) public function search($params)
{ {
$query = new Query(); $query = new Query();
$query->select([ $query->select([
'inventory_item.id_inventory_item as item_id_inventory_item', 'inventory_item.id_inventory_item as item_id_inventory_item',
'inventory_item.created_at as item_created_at', 'inventory_item.created_at as item_created_at',
@ -63,8 +71,9 @@ class InventoryItemSearch extends InventoryItem
'inventory.created_at as inventory_created_at', 'inventory.created_at as inventory_created_at',
'inventory_prev.id_inventory as inventory_prev_id_inventory', 'inventory_prev.id_inventory as inventory_prev_id_inventory',
'inventory_prev.name as inventory_prev_name', 'inventory_prev.name as inventory_prev_name',
new Expression('(inventory_item.count - ( inventory_item.count_prev + inventory_item.count_in - inventory_item.count_sold )) as item_difference'), 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'),
]); ]);
$query->from(InventoryItem::tableName()); $query->from(InventoryItem::tableName());
@ -78,9 +87,19 @@ class InventoryItemSearch extends InventoryItem
$query->andWhere( ['inventory_item.id_inventory' => $this->inventory->id_inventory] ); $query->andWhere( ['inventory_item.id_inventory' => $this->inventory->id_inventory] );
$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( $dataProvider = new ActiveDataProvider(
['query' => $query , ['query' => $query ,
'pagination' => ( empty($this->output) ? [] : false ),
'sort' => [ 'sort' => [
'defaultOrder' => ['item_name' => SORT_ASC],
'attributes' => Helper::mkYiiSortItems([ 'attributes' => Helper::mkYiiSortItems([
['item_created_at', 'item_created_at'], ['item_created_at', 'item_created_at'],
['item_name', 'item_name'], ['item_name', 'item_name'],
@ -100,22 +119,16 @@ 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 if ( !empty($this->item_type) && is_numeric($this->item_id) ){
// $query->where('0=1'); if ( $this->item_type == 'product'){
return $dataProvider; $query->andFilterWhere(['product.id_product' => $this->item_id]);
}else if ( $this->item_type == 'group' ){
$query->andFilterWhere(['inventory_group.id_inventory_group' => $this->item_id]);
}
} }
$query->andFilterWhere([
'inventory_item.id_inventory_item' => $this->id_inventory_item,
'inventory_item.type' => $this->type,
'inventory_item.id_product' => $this->id_product,
'inventory_item.id_inventory_group' => $this->id_inventory_group,
'inventory_item.id_user' => $this->id_user,
'inventory_item.created_at' => $this->created_at,
]);
return $dataProvider; return $dataProvider;
} }

View File

@ -45,6 +45,9 @@ class InventorySearch extends Inventory
$dataProvider = new ActiveDataProvider([ $dataProvider = new ActiveDataProvider([
'query' => $query, 'query' => $query,
'sort' => [
'defaultOrder' => ['created_at' => SORT_DESC]
]
]); ]);
$this->load($params); $this->load($params);

View File

@ -0,0 +1,195 @@
<?php
namespace backend\models;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\Transfer;
use yii\db\Expression;
use yii\base\Object;
use yii\db\Query;
use yii\helpers\ArrayHelper;
use common\models\Account;
use common\components\Helper;
use common\components\RoleDefinition;
/**
* TransferSearch represents the model behind the search form about `common\models\Transfer`.
*/
class TransferLaterSearch extends Transfer
{
public $start;
public $end;
public $timestampStart;
public $timestampEnd;
public $id_ticket_type;
public $ticket_type;
public $selected = [];
public $total_money;
/**
* @inheritdoc
*/
public function rules()
{
return [
[[ 'id_ticket_type','id_user'], 'integer'],
[[ 'start', ], 'date', 'format' =>Yii::$app->formatter->datetimeFormat , 'timestampAttribute' => 'timestampStart' ,'timestampAttributeFormat' => 'yyyy-MM-dd HH:mm' ,'timeZone' => 'UTC' ],
[[ 'end' , ], 'date' ,'format' =>Yii::$app->formatter->datetimeFormat , 'timestampAttribute' => 'timestampEnd' ,'timestampAttributeFormat' => 'yyyy-MM-dd HH:mm' ,'timeZone' => 'UTC' ],
['selected', 'each', 'rule' => ['integer']],
];
}
/**
* @inheritdoc
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = new Query();
$query->select([
'transfer.id_transfer as transfer_id_transfer',
'transfer.created_at as transfer_created_at',
'transfer.money as transfer_money',
'transfer.status as transfer_status',
'user.username as user_username',
'customer.name as customer_name',
'ticket_type.name as ticket_type_name',
'product.name as product_name',
'ticket.start as ticket_start',
'ticket.end as ticket_end',
]);
$query->from("transfer");
$query->innerJoin('user', " user.id = transfer.id_user");
$query->leftJoin('customer', " transfer.id_customer = customer.id_customer");
$query->leftJoin('ticket', " transfer.type = ".Transfer::TYPE_TICKET." and transfer.id_object = ticket.id_ticket");
$query->leftJoin('ticket_type', " ticket.id_ticket_type = ticket_type.id_ticket_type");
$query->leftJoin('sale', " transfer.type = ".Transfer::TYPE_PRODUCT." and transfer.id_object = sale.id_sale");
$query->leftJoin('product', " product.id_product = sale.id_product");
$query->andWhere(["transfer.payment_method" => Transfer::PAYMENT_METHOD_TRANSFER_LATER ]);
$query->andWhere(['transfer.status' => Transfer::STATUS_NOT_PAID]);
$dataProvider = new ActiveDataProvider([
'query' => $query,
'sort' =>[
'defaultOrder' =>[
'transfer_created_at' => SORT_DESC
],
'attributes' => Helper::mkYiiSortItems([
['transfer_created_at'],
['transfer_money'],
['transfer_status'],
['user_username'],
['customer_name'],
['ticket_type_name'],
['product_name'],
['ticket_start'],
['ticket_end'],
])
]
]);
// $query->addSelect( ['*' ]);
$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;
}
$query->andFilterWhere([
'ticket_type.id_ticket_type' => $this->id_ticket_type,
'transfer.id_user' => $this->id_user,
]);
$created_condition = ['and',[ '>=', 'transfer.created_at', $this->timestampStart ] ,[ '<', 'transfer.created_at', $this->timestampEnd ] ];
$paid_condition = ['and',[ '>=', 'transfer.paid_at', $this->timestampStart ] ,[ '<', 'transfer.paid_at', $this->timestampEnd ] ];
$query->andFilterWhere(['or' , $created_condition , $paid_condition]);
$qtotal = Query::create($query);
$qtotal->select([ new Expression("coalesce(sum(transfer.money),0) as transfer_money" )]);
$this->total_money = $qtotal->scalar();
return $dataProvider;
}
public function totalsTransfers( ){
}
public function doPayout(){
if ( !isset($this->selected) || count($this->selected) == 0){
Helper::flash("error", "Nincs kiválasztott tranzakció");
return false;
}
$transfers = Transfer::find()
->andWhere(['status' => Transfer::STATUS_NOT_PAID ])
->andWhere(['payment_method' => Transfer::PAYMENT_METHOD_TRANSFER_LATER])
->andWhere(['in','transfer.id_transfer',$this->selected])
->all();
if ( count($transfers) != count($this->selected)){
Helper::flash("warning", "A kiválasztott tranzakciókban időközben változás történt");
return false;
}
$db = \Yii::$app->db;
$tx = $db->beginTransaction();
try{
foreach ($transfers as $transfer){
if ( !$transfer->payout($transfer->id_account) ){
\Yii::error("Failed to payout transaction: " .$transfer->id_transfer);
throw new \Exception("Nem sikerült mententi a tranzakciókat");
}
}
$tx->commit();
Helper::flash("success", "Tranzakciók fizetettnek jelölve: " .count($transfers) . " db");
}catch (\Exception $e){
$tx->rollBack();
Helper::flash("error", "Hiba történt a művelet közben");
return false;
}
return true;
}
}

View File

@ -143,7 +143,6 @@ class TransferSearch extends Transfer
return $dataProvider; return $dataProvider;
} }
echo "start date:" .$this->timestampStart;
$query->andFilterWhere([ $query->andFilterWhere([
'transfer.id_account' => $this->id_account, 'transfer.id_account' => $this->id_account,

View File

@ -7,6 +7,7 @@ use yii\base\Widget;
<?php <?php
echo AccountStateBanknoteCountWidget::widget([ echo AccountStateBanknoteCountWidget::widget([
'model' => $model, 'model' => $model,
'showDailyDownload' =>false
]); ]);
?> ?>

View File

@ -12,8 +12,6 @@ use yii\widgets\ActiveForm;
<?php $form = ActiveForm::begin(); ?> <?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'name')->textInput(['autocomplete' => 'off']) ?>
<?= $form->field($model, 'id_product')->hiddenInput()->label(false) ?>
<?= $form->field($model, 'type')->hiddenInput()->label(false) ?> <?= $form->field($model, 'type')->hiddenInput()->label(false) ?>
<?= $form->field($model, 'count')->textInput() ?> <?= $form->field($model, 'count')->textInput() ?>

View File

@ -11,36 +11,22 @@ use yii\widgets\ActiveForm;
<div class="inventory-item-search"> <div class="inventory-item-search">
<?php $form = ActiveForm::begin([ <?php $form = ActiveForm::begin([
'action' => ['index'], 'action' => ['index','id' => $model->inventory->id_inventory],
'method' => 'get', 'method' => 'get',
]); ?> ]); ?>
<?= $form->field($model, 'id_inventory_item') ?> <?= $form->field($model, 'item_type')->hiddenInput()->label(false) ?>
<?= $form->field($model, 'item_id')->hiddenInput()->label(false) ?>
<?= $form->field($model, 'id_inventory') ?> <div class="row">
<div class="col-md-4">
<?= $form->field($model, 'count_in') ?> <?= $form->field($model, 'item_name')->label("Termék/Termék csoport neve") ?>
</div>
<?= $form->field($model, 'count_sold') ?> </div>
<?= $form->field($model, 'count') ?>
<?php // echo $form->field($model, 'type') ?>
<?php // echo $form->field($model, 'id_product') ?>
<?php // echo $form->field($model, 'id_inventory_group') ?>
<?php // echo $form->field($model, 'id_user') ?>
<?php // echo $form->field($model, 'created_at') ?>
<?php // echo $form->field($model, 'updated_at') ?>
<div class="form-group"> <div class="form-group">
<?= Html::submitButton(Yii::t('common/inventory-item', 'Search'), ['class' => 'btn btn-primary']) ?> <?= Html::submitButton(Yii::t('common/inventory-item', 'Keresés'), ['class' => 'btn btn-primary']) ?>
<?= Html::resetButton(Yii::t('common/inventory-item', 'Reset'), ['class' => 'btn btn-default']) ?>
</div> </div>
<?php ActiveForm::end(); ?> <?php ActiveForm::end(); ?>

View File

@ -4,6 +4,7 @@ use yii\helpers\Html;
use yii\grid\GridView; use yii\grid\GridView;
use yii\widgets\DetailView; use yii\widgets\DetailView;
use yii\helpers\Url; use yii\helpers\Url;
use backend\assets\InventoryItemIndexAsset;
/* @var $this yii\web\View */ /* @var $this yii\web\View */
/* @var $searchModel backend\models\InventoryItemSearch */ /* @var $searchModel backend\models\InventoryItemSearch */
@ -11,6 +12,15 @@ use yii\helpers\Url;
$this->title = Yii::t('common/inventory-item', 'Leltár részletei'); $this->title = Yii::t('common/inventory-item', 'Leltár részletei');
$this->params['breadcrumbs'][] = $this->title; $this->params['breadcrumbs'][] = $this->title;
InventoryItemIndexAsset::register($this);
$options = [];
$options['products'] = $productOptions;
$this->registerJs('inventoryItemIndex.init( '. json_encode($options) .' );');
?> ?>
<div class="inventory-item-index"> <div class="inventory-item-index">
@ -23,17 +33,17 @@ $this->params['breadcrumbs'][] = $this->title;
'name', 'name',
['attribute'=>'id_user', ['attribute'=>'id_user',
'value'=>$model->userName 'value'=>$model->userName
],
['attribute'=>'id_account',
'value'=>$model->accountName
], ],
'created_at:datetime', 'created_at:datetime',
], ],
]) ?> ]) ?>
<?php // echo $this->render('_search', ['model' => $searchModel]); ?> <?php echo $this->render('_search', ['model' => $searchModel]); ?>
<p>
<?= Html::a(Yii::t('common/inventory', 'Új termék felvétele a leltárba'), ['inventory-item/create','id' =>$model->id_inventory], ['class' => 'btn btn-success']) ?>
</p>
<p> <p>
Magyarázat: Magyarázat:
@ -59,6 +69,10 @@ $this->params['breadcrumbs'][] = $this->title;
</ul> </ul>
</p> </p>
<p>
<?php echo Html::a("XLS letöltése", Url::current(['InventoryItemSearch[output]' =>'xls']),['class' =>'btn btn-primary'])?>
</p>
<?php <?php
echo GridView::widget( [ echo GridView::widget( [
'dataProvider' => $dataProvider, 'dataProvider' => $dataProvider,
@ -114,16 +128,14 @@ $this->params['breadcrumbs'][] = $this->title;
], ],
['class' => 'yii\grid\ActionColumn', ['class' => 'yii\grid\ActionColumn',
'template' => '{delete}', 'template' => '',
'urlCreator' => function ($action, $model, $key, $index){ 'urlCreator' => function ($action, $model, $key, $index){
return Url::to(['inventory-item/delete', 'id' => $model['item_id_inventory_item' ] ]) ; return Url::to(['inventory-item/update', 'id' => $model['item_id_inventory_item' ] ]) ;
}, },
'buttons' =>[ 'buttons' =>[
'delete' =>function ($url, $model, $key) { 'update' =>function ($url, $model, $key) {
return Html::a('Törlés', $url,['class' => 'btn btn-xs btn-danger', return Html::a('Módosítás', $url,['class' => 'btn btn-xs btn-success',
'data' => [ 'data' => [
'confirm' => Yii::t('common/inventory-item', 'Biztosan törlöd ezt az elemet?'),
'method' => 'post',
], ],
]) ; ]) ;
} }

View File

@ -1,13 +1,12 @@
<?php <?php
use yii\helpers\Html; use yii\helpers\Html;
use yii\widgets\DetailView;
/* @var $this yii\web\View */ /* @var $this yii\web\View */
/* @var $model common\models\InventoryItem */ /* @var $model common\models\InventoryItem */
$this->title = Yii::t('common/inventory-item', 'Update {modelClass}: ', [ $this->title = Yii::t('common/inventory-item', 'Leltár termék');
'modelClass' => 'Inventory Item',
]) . ' ' . $model->id_inventory_item;
$this->params['breadcrumbs'][] = ['label' => Yii::t('common/inventory-item', 'Inventory Items'), 'url' => ['index']]; $this->params['breadcrumbs'][] = ['label' => Yii::t('common/inventory-item', 'Inventory Items'), 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => $model->id_inventory_item, 'url' => ['view', 'id' => $model->id_inventory_item]]; $this->params['breadcrumbs'][] = ['label' => $model->id_inventory_item, 'url' => ['view', 'id' => $model->id_inventory_item]];
$this->params['breadcrumbs'][] = Yii::t('common/inventory-item', 'Update'); $this->params['breadcrumbs'][] = Yii::t('common/inventory-item', 'Update');
@ -16,6 +15,37 @@ $this->params['breadcrumbs'][] = Yii::t('common/inventory-item', 'Update');
<h1><?= Html::encode($this->title) ?></h1> <h1><?= Html::encode($this->title) ?></h1>
<h2>Leltár</h2>
<?= DetailView::widget([
'model' => $inventory,
'attributes' => [
'id_inventory',
'name',
['attribute'=>'id_user',
'value'=>$inventory->userName
],
['attribute'=>'id_account',
'value'=>$inventory->accountName
],
'created_at:datetime',
],
]) ?>
<h2>Termék</h2>
<?= DetailView::widget([
'model' => $model,
'attributes' => [
[
'value' => $model->name,
'label' =>"Név"
],
],
]) ?>
<?= $this->render('_form', [ <?= $this->render('_form', [
'model' => $model, 'model' => $model,
]) ?> ]) ?>

View File

@ -2,18 +2,27 @@
use yii\helpers\Html; use yii\helpers\Html;
use yii\widgets\ActiveForm; use yii\widgets\ActiveForm;
use common\models\Account;
use common\components\Helper;
use frontend\components\HtmlHelper;
/* @var $this yii\web\View */ /* @var $this yii\web\View */
/* @var $model common\models\Inventory */ /* @var $model common\models\Inventory */
/* @var $form yii\widgets\ActiveForm */ /* @var $form yii\widgets\ActiveForm */
?> ?>
<?php
$accounts = ['' =>'Mind'] + HtmlHelper::mkAccountOptions( Account::readAccounts() );
?>
<div class="inventory-form"> <div class="inventory-form">
<?php $form = ActiveForm::begin(); ?> <?php $form = ActiveForm::begin(); ?>
<div class="form-group"> <div class="form-group">
<?php echo $form->field($model, "id_account")->dropDownList($accounts)?>
<?php echo $form->field($model, "name")->textInput()?> <?php echo $form->field($model, "name")->textInput()?>
<?= Html::submitButton($model->isNewRecord ? Yii::t('common/inventory', 'Létrehoz') : Yii::t('common/inventory', 'Módosít'), [ 'name'=>'Inventory[submit]' ,'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> <?= Html::submitButton($model->isNewRecord ? Yii::t('common/inventory', 'Létrehoz') : Yii::t('common/inventory', 'Módosít'), [ 'name'=>'Inventory[submit]' ,'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div> </div>

View File

@ -17,7 +17,7 @@ $this->params['breadcrumbs'][] = $this->title;
<?php // echo $this->render('_search', ['model' => $searchModel]); ?> <?php // echo $this->render('_search', ['model' => $searchModel]); ?>
<p> <p>
<?= Html::a(Yii::t('common/inventory', 'Új leltár'), ['create'], ['class' => 'btn btn-success']) ?> <?php //echo Html::a(Yii::t('common/inventory', 'Új leltár'), ['create'], ['class' => 'btn btn-success']) ?>
</p> </p>
<?= GridView::widget([ <?= GridView::widget([

View File

@ -0,0 +1,65 @@
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use kartik\widgets\DatePicker;
use frontend\components\HtmlHelper;
use common\models\Transfer;
use kartik\widgets\DateTimePicker;
use common\models\TicketType;
use common\models\User;
/* @var $this yii\web\View */
/* @var $model common\models\TransferSearch */
/* @var $form yii\widgets\ActiveForm */
?>
<?php
$userOptions = ['' => 'Mind'] + HtmlHelper::mkOptions(User::find()->all(),'id','username');
$ticketTypeOptions = ['' => 'Mind'] + HtmlHelper::mkTicketTypeOptions(TicketType::find()->all());
?>
<div class="transfer-search">
<?php $form = ActiveForm::begin([
// 'action' => ['list'],
'method' => 'get',
]); ?>
<div class="row">
<div class="col-md-4">
<?= $form->field($model, 'start')->widget(DateTimePicker::classname(), [
'pluginOptions' => [
'autoclose'=>true,
'format' => 'yyyy.mm.dd hh:ii'
]
]) ?>
</div>
<div class="col-md-4">
<?= $form->field($model, 'end') ->widget(DateTimePicker::classname(), [
'pluginOptions' => [
'autoclose'=>true,
'format' => 'yyyy.mm.dd hh:ii'
]
]) ?>
</div>
</div>
<div class="row">
<div class="col-md-4">
<?= $form->field($model, 'id_ticket_type')->dropDownList($ticketTypeOptions)->label("Bérlet típus") ?>
</div>
<div class="col-md-4">
<?= $form->field($model, 'id_user')->dropDownList($userOptions) ?>
</div>
</div>
<div class="form-group">
<?= Html::submitButton(Yii::t('frontend/transfer', 'Search'), ['class' => 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>

View File

@ -0,0 +1,129 @@
<?php
use yii\helpers\Html;
use yii\grid\GridView;
use yii\widgets\DetailView;
use yii\base\Widget;
use yii\base\Object;
use yii\data\ArrayDataProvider;
use common\components\AccountStatisticWidget;
use common\components\DataProviderTotal;
use common\components\Helper;
use common\models\Transfer;
use yii\helpers\VarDumper;
use yii\widgets\ActiveForm;
use yii\helpers\Url;
/* @var $this yii\web\View */
/* @var $searchModel backend\models\TransferSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = "Tranzakciók későbbi utalás fizetés típussal";
$this->params['breadcrumbs'][] = $this->title;
?>
<style>
.table-transfer .money,
.table-transfer .count,
.table-transfer .item-price
{
text-align: right;
}
</style>
<div class="transfer-index">
<h1><?= Html::encode($this->title) ?></h1>
<?php echo $this->render('_search_payment_later', ['model' => $searchModel, ]); ?>
<div style="margin-bottom: 6px;">
<?php
echo Html::a("Összes kiválasztása",null, ['class' => 'btn btn-primary select-all' ,'style' => 'margin-right: 6px;',
'onclick' => "$('.table-transfer').find(\"input[type='checkbox']\").prop('checked',true);"
]);
echo Html::a("Egyiket sem",null, ['class' => 'btn btn-primary deselect-all',
'onclick' => "$('.table-transfer').find(\"input[type='checkbox']\").prop('checked',false);"
]);
?>
</div>
<div class="transfer-form">
<?php $form = ActiveForm::begin(
[ 'action' => Url::current() ]
); ?>
<p>
Összesen: <?php echo $searchModel->total_money;?> Ft
</p>
<?= GridView::widget([
'tableOptions' => ['class' => 'table table-striped table-bordered table-transfer'],
'dataProvider' => $dataProvider,
'showFooter'=>TRUE,
'columns' => [
[
'label' => '',
'value' => function ($model, $key, $index, $column) use ( &$searchModel){
return Html::checkbox(Html::getInputName($searchModel, 'selected[]') , in_array($model['transfer_id_transfer'], $searchModel->selected) , [ 'class' => 'cart-item', 'value' => $model['transfer_id_transfer']] );
},
'format' => 'raw'
],
[
'attribute' => 'user_username',
'label' => 'Felhasználó'
],
[
'attribute' => 'customer_name',
'label' => 'Vendég'
],
[
'attribute' => 'ticket_type_name',
'label' => 'Bérlet típus'
],
[
'attribute' => 'ticket_start',
'label' => 'Érvényes -tól',
'format' => 'date'
],
[
'attribute' => 'ticket_end',
'label' => 'Érvényes -ig',
'format' => 'date'
],
[
'attribute' => 'product_name',
'label' => 'Termék'
],
[
'attribute' => 'transfer_created_at',
'label' => 'Kiadva',
'format' => 'datetime'
],
[
'attribute' => 'transfer_money',
'label' => 'Összeg'
],
[
'attribute' => 'transfer_status',
'label' => 'Státusz',
'value' => function ($model, $key, $index, $column){
return Helper::getArrayValue(Transfer::statuses(), $model['transfer_status'],'');
},
],
],
]); ?>
<div class="form-group">
<?= Html::submitButton( 'Fizetettnek jelöl', [ 'class' => 'btn btn-success' ] ) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
</div>

View File

@ -0,0 +1,58 @@
var inventoryItemIndex = {
defaults : {
products: [],
selector_type : '#inventoryitemsearch-item_type',
selector_name : '#inventoryitemsearch-item_name',
selector_id : '#inventoryitemsearch-item_id',
},
product: null,
init: function(o){
this.defaults = $.extend( this.defaults, o );
this.initAutocomplete();
},
initAutocomplete : function (){
var self = this;
var $input = $(self.defaults.selector_name);
$input.typeahead({source : self.defaults.products,
autoSelect: true,
items: 20,
minLength: 3,
});
$input.change(function() {
var current = $input.typeahead("getActive");
$("#filter_text").val('');
if (current) {
// Some item from your model is active!
if (current.name == $input.val()) {
self.product = current;
} else {
self.product = null;
}
} else {
self.product = null;
}
self.productChange();
});
},
productChange: function( ){
this.clearProductData();
this.setProductData();
},
clearProductData: function(){
$(this.defaults.selector_type).val('');
$(this.defaults.selector_id).val('');
},
setProductData: function(){
if ( this.product ){
$(this.defaults.selector_type).val( this.product.type);
$(this.defaults.selector_id ).val( this.product.id);
}
}
}

View File

@ -1,3 +1,5 @@
-0.0.55
- new type transfer later
-0.0.54 -0.0.54
- add ticket usage count increment trigger - add ticket usage count increment trigger
- add log - add log

View File

@ -4,7 +4,7 @@ return [
'supportEmail' => 'rocho02@gmail.com', 'supportEmail' => 'rocho02@gmail.com',
'infoEmail' => 'info@rocho-net.hu', 'infoEmail' => 'info@rocho-net.hu',
'user.passwordResetTokenExpire' => 3600, 'user.passwordResetTokenExpire' => 3600,
'version' => 'v0.0.54', 'version' => 'v0.0.55',
'company' => 'movar',//gyor 'company' => 'movar',//gyor
'company_name' => "Freimann Kft.", 'company_name' => "Freimann Kft.",
'product_visiblity' => 'account',// on reception which products to display. account or global 'product_visiblity' => 'account',// on reception which products to display. account or global

View File

@ -5,7 +5,7 @@
<b>Felhasználó:</b> <?php echo $model->username ;?><br> <b>Felhasználó:</b> <?php echo $model->username ;?><br>
<b>Idő:</b> <?php echo \Yii::$app->formatter->asDatetime(time());?><br> <b>Idő:</b> <?php echo \Yii::$app->formatter->asDatetime(time());?><br>
<?php <?php
if ( isset($geoip->city)){ if ( isset($geoip) && isset($geoip->city)){
?> ?>
<b>Ip cím:</b> <?php echo $geoip->ip?><br> <b>Ip cím:</b> <?php echo $geoip->ip?><br>
<b>Város:</b> <?php echo $geoip->city?><br> <b>Város:</b> <?php echo $geoip->city?><br>

View File

@ -5,12 +5,16 @@ namespace common\models;
use Yii; use Yii;
use common\components\UserAwareBehavior; use common\components\UserAwareBehavior;
use yii\helpers\ArrayHelper; use yii\helpers\ArrayHelper;
use yii\db\Query;
use backend\models\InventoryItemForm;
use common\components\AccountAwareBehavior;
/** /**
* This is the model class for table "inventory". * This is the model class for table "inventory".
* *
* @property integer $id_inventory * @property integer $id_inventory
* @property integer $id_user * @property integer $id_user
* @property integer $id_account
* @property string $name * @property string $name
* @property string $created_at * @property string $created_at
* @property string $updated_at * @property string $updated_at
@ -27,13 +31,15 @@ class Inventory extends \common\models\BaseFitnessActiveRecord
return 'inventory'; return 'inventory';
} }
/** /**
* @inheritdoc * @inheritdoc
*/ */
public function rules() public function rules()
{ {
return [ return [
[['name'], 'string'] [['name'], 'string'],
[['id_account'], 'integer'],
]; ];
} }
@ -46,6 +52,7 @@ class Inventory extends \common\models\BaseFitnessActiveRecord
'id_inventory' => Yii::t('common/inventory', 'Leltár azonosító'), 'id_inventory' => Yii::t('common/inventory', 'Leltár azonosító'),
'name' => Yii::t('common/inventory', 'Megnevezés'), 'name' => Yii::t('common/inventory', 'Megnevezés'),
'id_user' => Yii::t('common/inventory', 'Felhasználó'), 'id_user' => Yii::t('common/inventory', 'Felhasználó'),
'id_account' => Yii::t('common/inventory', 'Kassza'),
'created_at' => Yii::t('common/inventory', 'Létrehozás'), 'created_at' => Yii::t('common/inventory', 'Létrehozás'),
'updated_at' => Yii::t('common/inventory', 'Módosítás'), 'updated_at' => Yii::t('common/inventory', 'Módosítás'),
]; ];
@ -59,7 +66,59 @@ class Inventory extends \common\models\BaseFitnessActiveRecord
return ArrayHelper::merge( [ return ArrayHelper::merge( [
[ [
'class' => UserAwareBehavior::className(), 'class' => UserAwareBehavior::className(),
],
[
'class' => AccountAwareBehavior::className()
] ]
], parent::behaviors()); ], parent::behaviors());
} }
public function afterSave($insert, $changedAttributes){
if ( $insert ){
$query = Product::find();
if ( isset($this->id_account) && is_numeric($this->id_account)){
$query->andWhere(['id_account' => $this->id_account]);
}
// $query->andWhere("product.id_inventory_group is null");
$products = $query->all();
echo "Products found: " . count($products);
$inventoryGroups = InventoryGroup::find()->all();
foreach ($products as $product){
$form = new InventoryItemForm(
[
'inventory' => $this,
'id_product' => $product->id_product,
'product' => $product,
'type' => 'product'
]
);
$form->save();
}
foreach ($inventoryGroups as $group){
$form = new InventoryItemForm(
[
'inventory' => $this,
'id_product' => $group->id_inventory_group,
'inventoryGroup' => $group,
'type' => 'group'
]
);
$form->save();
}
}
}
} }

View File

@ -6,6 +6,7 @@ use Yii;
use yii\helpers\ArrayHelper; use yii\helpers\ArrayHelper;
use common\components\UserAwareBehavior; use common\components\UserAwareBehavior;
use common\components\Helper; use common\components\Helper;
use common\components\ProductAwareBehavior;
/** /**
* This is the model class for table "inventory_item". * This is the model class for table "inventory_item".
@ -45,6 +46,8 @@ class InventoryItem extends BaseFitnessActiveRecord
public function rules() public function rules()
{ {
return [ return [
[['count'],'integer'] ,
[['count'],'required'] ,
]; ];
} }
@ -58,7 +61,7 @@ class InventoryItem extends BaseFitnessActiveRecord
'id_inventory' => Yii::t('common/inventory_item', 'Id Inventory'), 'id_inventory' => Yii::t('common/inventory_item', 'Id Inventory'),
'count_in' => Yii::t('common/inventory_item', 'Count In'), 'count_in' => Yii::t('common/inventory_item', 'Count In'),
'count_sold' => Yii::t('common/inventory_item', 'Count Sold'), 'count_sold' => Yii::t('common/inventory_item', 'Count Sold'),
'count' => Yii::t('common/inventory_item', 'Count'), 'count' => Yii::t('common/inventory_item', 'Leltározott mennyiség'),
'type' => Yii::t('common/inventory_item', 'Type'), 'type' => Yii::t('common/inventory_item', 'Type'),
'id_product' => Yii::t('common/inventory_item', 'Id Product'), 'id_product' => Yii::t('common/inventory_item', 'Id Product'),
'id_inventory_group' => Yii::t('common/inventory_item', 'Id Inventory Group'), 'id_inventory_group' => Yii::t('common/inventory_item', 'Id Inventory Group'),
@ -72,6 +75,9 @@ class InventoryItem extends BaseFitnessActiveRecord
return ArrayHelper::merge( [ return ArrayHelper::merge( [
[ [
'class' => UserAwareBehavior::className(), 'class' => UserAwareBehavior::className(),
],
[
'class' => ProductAwareBehavior::className(),
] ]
], parent::behaviors()); ], parent::behaviors());
} }
@ -133,4 +139,18 @@ class InventoryItem extends BaseFitnessActiveRecord
} }
public function afterSave($insert, $changedAttributes){
if ( !$insert ){
if ( $this->type == 'product'){
$product = $this->product;
$product->stock = $this->count;
if ( !$product->save(false) ){
\Yii::error("Failed to save product stock");
throw new \Exception("A leltár elem mentése nem sikerült");
}
}
}
}
} }

View File

@ -264,4 +264,36 @@ class Product extends \common\models\BaseFitnessActiveRecord {
$product->stock = $product->stock - $count; $product->stock = $product->stock - $count;
} }
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(){
$query = InventoryGroup::find();
$query->andWhere(['status' => Product::STATUS_ACTIVE]);
return $query->all();
}
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 ($inventoryGroups as $inventoryGroup ){
$productOptions[] = ['type' =>'group', 'id' =>$inventoryGroup->id_inventory_group ,'name' =>$inventoryGroup->name ."/Termékcsoport" ];
}
return $productOptions;
}
} }

View File

@ -53,6 +53,7 @@ class Transfer extends \common\models\BaseFitnessActiveRecord {
const PAYMENT_METHOD_CAFETERY = 40; // SZÉCHENYI KÁRTYA const PAYMENT_METHOD_CAFETERY = 40; // SZÉCHENYI KÁRTYA
// const PAYMENT_METHOD_DEBIT_MANDATE = 50;//CSOPORTOS BESZEDÉSI MEGBÍZÁS // const PAYMENT_METHOD_DEBIT_MANDATE = 50;//CSOPORTOS BESZEDÉSI MEGBÍZÁS
const PAYMENT_METHOD_TRANSFER_LATER = 50;
/** /**
* @inheritdoc * @inheritdoc
*/ */
@ -526,11 +527,24 @@ class Transfer extends \common\models\BaseFitnessActiveRecord {
self::PAYMENT_METHOD_CASH => Yii::t ( 'common/transfer', 'Készpénz' ), self::PAYMENT_METHOD_CASH => Yii::t ( 'common/transfer', 'Készpénz' ),
self::PAYMENT_METHOD_BANCCARD => Yii::t ( 'common/transfer', 'Bankkártyás fizetés' ), self::PAYMENT_METHOD_BANCCARD => Yii::t ( 'common/transfer', 'Bankkártyás fizetés' ),
self::PAYMENT_METHOD_TRANSFER => Yii::t ( 'common/transfer', 'Átutalás' ), self::PAYMENT_METHOD_TRANSFER => Yii::t ( 'common/transfer', 'Átutalás' ),
self::PAYMENT_METHOD_CAFETERY => Yii::t ( 'common/transfer', 'Széchenyi kártya' ) self::PAYMENT_METHOD_CAFETERY => Yii::t ( 'common/transfer', 'Széchenyi kártya' ),
self::PAYMENT_METHOD_TRANSFER_LATER => Yii::t ( 'common/transfer', 'Átutalás később' )
] ]
// self::PAYMENT_METHOD_DEBIT_MANDATE => Yii::t('common/transfer','Csoportos beszedési megbízás'), // self::PAYMENT_METHOD_DEBIT_MANDATE => Yii::t('common/transfer','Csoportos beszedési megbízás'),
; ;
} }
public static function paymentMethodsForProduct() {
return [
self::PAYMENT_METHOD_CASH => Yii::t ( 'common/transfer', 'Készpénz' ),
self::PAYMENT_METHOD_BANCCARD => Yii::t ( 'common/transfer', 'Bankkártyás fizetés' ),
self::PAYMENT_METHOD_TRANSFER => Yii::t ( 'common/transfer', 'Átutalás' ),
self::PAYMENT_METHOD_CAFETERY => Yii::t ( 'common/transfer', 'Széchenyi kártya' ),
]
// self::PAYMENT_METHOD_DEBIT_MANDATE => Yii::t('common/transfer','Csoportos beszedési megbízás'),
;
}
public static function statuses() { public static function statuses() {
return [ return [
self::STATUS_NOT_PAID => Yii::t ( 'common/transfer', 'Nincs fizetve' ), self::STATUS_NOT_PAID => Yii::t ( 'common/transfer', 'Nincs fizetve' ),
@ -946,7 +960,7 @@ class Transfer extends \common\models\BaseFitnessActiveRecord {
ShoppingCart::deleteAll(['id_transfer' => $this->id_transfer]); ShoppingCart::deleteAll(['id_transfer' => $this->id_transfer]);
UserSoldItem::deleteAll(['id_transfer' => $this->id_transfer]); UserSoldItem::deleteAll(['id_transfer' => $this->id_transfer]);
} }
public function payout() { public function payout($id_account = null) {
if ($this->status != Transfer::STATUS_NOT_PAID) { if ($this->status != Transfer::STATUS_NOT_PAID) {
return false; return false;
@ -956,14 +970,18 @@ class Transfer extends \common\models\BaseFitnessActiveRecord {
$this->paid_at = Helper::getDateTimeString (); $this->paid_at = Helper::getDateTimeString ();
$this->paid_by = \Yii::$app->user->id; $this->paid_by = \Yii::$app->user->id;
if ( isset($id_account)){
$this->id_account = $id_account;
}else{
if( Helper::isUserCartVisibilityAll() ){ if( Helper::isUserCartVisibilityAll() ){
$this->id_account = Account::readDefault(); $this->id_account = Account::readDefault();
} }
}
ShoppingCart::deleteAll ( [ 'id_transfer' => $this->id_transfer ] ); ShoppingCart::deleteAll ( [ 'id_transfer' => $this->id_transfer ] );
UserSoldItem::deleteAll ( [ 'id_transfer' => $this->id_transfer UserSoldItem::deleteAll ( [ 'id_transfer' => $this->id_transfer
] ); ] );
return $this->save (); return $this->save (false);
} }
@ -1067,4 +1085,19 @@ class Transfer extends \common\models\BaseFitnessActiveRecord {
return [$transfer,$ticket]; return [$transfer,$ticket];
} }
public static function canBeAddedToCart($payment_method) {
if ( $payment_method == Transfer::PAYMENT_METHOD_TRANSFER_LATER){
return false;
}
return true;
}
public static function canMarkPaidByReception($payment_method) {
if ( $payment_method == Transfer::PAYMENT_METHOD_TRANSFER_LATER){
return false;
}
return true;
}
} }

View File

@ -23,18 +23,24 @@
</tr> </tr>
<?php } ?> <?php } ?>
</tbody>
</table>
<?php if ( count($model->moneyMovements ) == 0 ) { <?php if ( count($model->moneyMovements ) == 0 ) {
?> ?>
<tr>
<td colspan="7" style="text-align: right; padding: 3px;">
Nincs találat Nincs találat
</td>
</tr>
<?php <?php
}else{?> }?>
</tbody>
</table>
<?php if ( count($model->moneyMovements ) > 0 ) {
?>
<div class="row"> <div class="row">
<div class="col-md-12 text-right" style="text-decoration: underline;"> <div class="col-md-12 text-right" style="text-decoration: underline;">
Összesen: <?php echo \Yii::$app->formatter->asInteger( $model->moneyMovementMoneis); ?> Ft Összesen: <?php echo \Yii::$app->formatter->asInteger( $model->moneyMovementMoneis); ?> Ft
</div> </div>
</div> </div>
<?php <?php

View File

@ -0,0 +1,30 @@
<?php
use yii\db\Schema;
use yii\db\Migration;
class m160321_082725_alter__inventory__add__column__id_account extends Migration
{
public function up()
{
$this->addColumn("inventory", "id_account", "int");
}
public function down()
{
echo "m160321_082725_alter__inventory__add__column__id_account cannot be reverted.\n";
return false;
}
/*
// Use safeUp/safeDown to run migration code within a transaction
public function safeUp()
{
}
public function safeDown()
{
}
*/
}

View File

@ -0,0 +1,39 @@
<?php
use yii\db\Schema;
use yii\db\Migration;
class m160324_203543_devlog extends Migration
{
public function up()
{
$tableOptions = null;
if ($this->db->driverName === 'mysql') {
// http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
}
$this->createTable( '{{%devlog}}', [
'id_devlog' => $this->primaryKey(),
'msg' => $this->string(),
], $tableOptions );
}
public function down()
{
echo "m160324_203543_devlog cannot be reverted.\n";
return false;
}
/*
// Use safeUp/safeDown to run migration code within a transaction
public function safeUp()
{
}
public function safeDown()
{
}
*/
}

View File

@ -0,0 +1,30 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace frontend\assets;
use yii\web\AssetBundle;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class InventoryItemIndexAsset extends AssetBundle
{
public $basePath = '@webroot';
public $baseUrl = '@web';
public $css = [
];
public $js = [
'js/inventory.item.index.js',
];
public $depends = [
'frontend\assets\AppAsset',
'yii\jui\JuiAsset',
'common\assets\TypeAheadAsset',
];
}

View File

@ -22,6 +22,7 @@ class AccountStateBanknoteCountWidget extends Widget{
public $model; public $model;
public $layout; public $layout;
public $index; public $index;
public $showDailyDownload = true;
public function run(){ public function run(){
@ -60,12 +61,14 @@ class AccountStateBanknoteCountWidget extends Widget{
$s .= Html::a( Html::tag("span","",['class' =>'glyphicon glyphicon-download-alt']) ."&nbsp;Pdf", Url::to([ 'view', 'id' =>$this->model->id_account_state, 'output' =>'pdf']) ,['class' => 'btn btn-primary btn-pdf','style' =>'margin-bottom: 12px; margin-right: 6px;']); $s .= Html::a( Html::tag("span","",['class' =>'glyphicon glyphicon-download-alt']) ."&nbsp;Pdf", Url::to([ 'view', 'id' =>$this->model->id_account_state, 'output' =>'pdf']) ,['class' => 'btn btn-primary btn-pdf','style' =>'margin-bottom: 12px; margin-right: 6px;']);
if ( $this->model->isTypeClose() ){ if ( $this->model->isTypeClose() ){
if ( $this->showDailyDownload ){
$s .= Html::a('<span class="glyphicon glyphicon-eye-open"></span>&nbsp;Napi összefoglaló', Url::toRoute(['mixed','id' =>$this->model->id_account_state]), [ $s .= Html::a('<span class="glyphicon glyphicon-eye-open"></span>&nbsp;Napi összefoglaló', Url::toRoute(['mixed','id' =>$this->model->id_account_state]), [
'title' => 'Napi összefoglaló', 'title' => 'Napi összefoglaló',
'class' => 'btn btn-success', 'class' => 'btn btn-success',
'style' =>'margin-bottom: 12px; margin-right: 6px;' 'style' =>'margin-bottom: 12px; margin-right: 6px;'
]); ]);
} }
}
$s .= Html::a('<span class="glyphicon glyphicon-eye-open"></span>&nbsp;Részletek', Url::toRoute(['view','id' =>$this->model->id_account_state]), [ $s .= Html::a('<span class="glyphicon glyphicon-eye-open"></span>&nbsp;Részletek', Url::toRoute(['view','id' =>$this->model->id_account_state]), [
'title' => 'Részletek', 'title' => 'Részletek',

View File

@ -88,7 +88,8 @@ class FrontendMenuStructure{
// } // }
$items[] = ['label' => Yii::t('frontend/card','Vendégek'), 'url' => [ '/card/index' ] ]; $items[] = ['label' => Yii::t('frontend/card','Vendégek'), 'url' => [ '/card/index' ] ];
$items[] = ['label' => Yii::t('frontend/card','Leltár'), 'url' => [ '/product/inventory' ] ]; // $items[] = ['label' => Yii::t('frontend/card','Leltár'), 'url' => [ '/product/inventory' ] ];
$items[] = ['label' => Yii::t('frontend/card','Leltár'), 'url' => [ '/inventory/index' ] ];
$this->menuItems[] = ['label' => Yii::t('frontend/account', 'Account'), $this->menuItems[] = ['label' => Yii::t('frontend/account', 'Account'),

View File

@ -0,0 +1,86 @@
<?php
namespace frontend\controllers;
use Yii;
use common\models\Inventory;
use frontend\models\InventorySearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use common\models\User;
/**
* InventoryController implements the CRUD actions for Inventory model.
*/
class InventoryController extends Controller
{
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['post'],
],
],
];
}
/**
* Lists all Inventory models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new InventorySearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
* Creates a new Inventory model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Inventory();
$user = User::findOne(\Yii::$app->user->id);
$model->name = 'Leltár_'.date('Ymd_His') .'_' . $user->username;
$model->id_user = \Yii::$app->user->id;
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['inventory-item/index', 'id' => $model->id_inventory]);
} else {
}
return $this->render('create', [
'model' => $model,
]);
}
/**
* Finds the Inventory model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return Inventory the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = Inventory::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}

View File

@ -0,0 +1,228 @@
<?php
namespace frontend\controllers;
use Yii;
use common\models\InventoryItem;
use frontend\models\InventoryItemSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use backend\models\InventoryItemForm;
use common\models\Inventory;
use yii\helpers\Url;
use common\models\Product;
/**
* InventoryItemController implements the CRUD actions for InventoryItem model.
*/
class InventoryItemController extends Controller
{
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['post'],
],
],
];
}
/**
* Lists all InventoryItem models.
* @return mixed
*/
public function actionIndex($id)
{
$inventory = Inventory::findOne($id);
if ( !isset($inventory)){
throw new NotFoundHttpException("Leltár nem található");
}
$searchModel = new InventoryItemSearch(['inventory' => $inventory]);
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$productOptions = Product::buildProductAndInventoryGroupList();
if ($searchModel->output == 'xls') {
$this->downloadIndexXls($dataProvider);
}else{
Url::remember(Url::current(),"inventory-item-index");
}
return $this->render('index', [
'model' => $inventory,
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
'productOptions' =>$productOptions
]);
}
protected function downloadIndexXls($dataProvider){
$defs = [['item_created_at', 'Létrehozva'],
['item_name', 'Termék/Termék csoport'],
['user_username', 'Felhasználó'],
['item_count_prev', 'Előző leltár (db)'],
['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_count_system', 'Rendszer szerinti mennyiség (db)'],
];
$cols = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P'];
$models = $dataProvider->getModels ();
$objPHPExcel = new \PHPExcel ();
$sheet = $objPHPExcel->setActiveSheetIndex ( 0 );
/**
* Termék azonosító Termék neve Termék szám Termék vonalkód Termék raktáron Termék eladva
*/
$row = 1;
$col = 0;
foreach ( $defs as $def ) {
$sheet->setCellValue ( $cols [$col] . $row, $def [1] );
$col ++;
}
foreach ( $models as $model ) {
$row ++;
$col = 0;
foreach ( $defs as $def ) {
$sheet->setCellValue ( $cols [$col] . $row, $model[$def [0]] );
$col ++;
}
}
$styleArray = array (
'font' => array (
'bold' => true
)
);
// 'color' => array('rgb' => 'FF0000'),
// 'size' => 15,
// 'name' => 'Verdana'
foreach ( range ( 'A', 'I' ) as $columnID ) {
$sheet->getColumnDimension ( $columnID )->setAutoSize ( true );
$sheet->getStyle ( $columnID . '1' )->applyFromArray ( $styleArray );
}
// Redirect output to a clients web browser (Excel5)
header ( 'Content-Type: application/vnd.ms-excel' );
header ( 'Content-Disposition: attachment;filename="leltar.xls"' );
header ( 'Cache-Control: max-age=0' );
// If you're serving to IE 9, then the following may be needed
header ( 'Cache-Control: max-age=1' );
// If you're serving to IE over SSL, then the following may be needed
header ( 'Expires: Mon, 26 Jul 1997 05:00:00 GMT' ); // Date in the past
header ( 'Last-Modified: ' . gmdate ( 'D, d M Y H:i:s' ) . ' GMT' ); // always modified
header ( 'Cache-Control: cache, must-revalidate' ); // HTTP/1.1
header ( 'Pragma: public' ); // HTTP/1.0
$objWriter = \PHPExcel_IOFactory::createWriter ( $objPHPExcel, 'Excel5' );
$objWriter->save ( 'php://output' );
exit ();
}
/**
* Displays a single InventoryItem model.
* @param integer $id
* @return mixed
*/
public function actionView($id)
{
return $this->render('view', [
'model' => $this->findModel($id),
]);
}
/**
* Creates a new InventoryItem model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate($id)
{
$model = new InventoryItemForm([
'id_inventory' => $id
]);
$model->read();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['inventory-item/index', 'id' => $model->inventory->id_inventory]);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
/**
* Updates an existing InventoryItem model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
$inventory = Inventory::findOne($model->id_inventory);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
$prev = Url::previous("inventory-item-index");
if ( isset($prev)){
return $this->redirect($prev);
}else{
return $this->redirect([ 'index', 'id' => $inventory->id_inventory ]);
}
} else {
return $this->render('update', [
'model' => $model,
'inventory' => $inventory,
]);
}
}
/**
* Deletes an existing InventoryItem model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
*/
public function actionDelete($id)
{
$item = $this->findModel($id);
$id_inventory = $item->id_inventory;
$item->delete();
return $this->redirect(['index', 'id' => $id_inventory]);
}
/**
* Finds the InventoryItem model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return InventoryItem the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = InventoryItem::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}

View File

@ -94,8 +94,11 @@ class SiteController extends Controller
$geoip = Helper::getGeoIp(); $geoip = Helper::getGeoIp();
$message = "";
$user = User::findOne(\Yii::$app->user->id); $user = User::findOne(\Yii::$app->user->id);
if ( isset($geoip)){
$message = "Bejelentkezés: " .$user->username. " Ip cím:". $geoip->ip . " Város: " . $geoip->city; $message = "Bejelentkezés: " .$user->username. " Ip cím:". $geoip->ip . " Város: " . $geoip->city;
}
Log::log([ Log::log([
'type' =>Log::$TYPE_LOGIN, 'type' =>Log::$TYPE_LOGIN,

View File

@ -0,0 +1,135 @@
<?php
namespace frontend\models;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\InventoryItem;
use yii\db\Query;
use yii\db\Expression;
use common\models\User;
use common\models\Product;
use common\models\InventoryGroup;
use common\components\Helper;
use common\models\Inventory;
/**
* InventoryItemSearch represents the model behind the search form about `common\models\InventoryItem`.
*/
class InventoryItemSearch extends InventoryItem
{
public $inventory;
public $output;
public $item_name;
public $item_type;
public $item_id;
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id_inventory_item', 'id_inventory', 'count_in', 'count_sold', 'count', 'type', 'id_product', 'id_inventory_group', 'id_user'], 'integer'],
['output', 'string'],
['item_name', 'string'],
['item_type', 'string'],
['item_id', 'integer'],
];
}
/**
* @inheritdoc
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = new Query();
$query->select([
'inventory_item.id_inventory_item as item_id_inventory_item',
'inventory_item.created_at as item_created_at',
new Expression('case when inventory_item.id_product is null then inventory_group.name else product.name end as item_name'),
'user.username as user_username',
'coalesce(inventory_item.count_prev ,0)as item_count_prev',
'coalesce(inventory_item.count_in,0) as item_count_in',
'coalesce(inventory_item.count_sold,0) as item_count_sold',
'coalesce(inventory_item.count,0) as item_count',
'coalesce(inventory_item.count_system,0) as item_count_system',
'inventory.created_at as inventory_created_at',
'inventory_prev.id_inventory as inventory_prev_id_inventory',
'inventory_prev.name as inventory_prev_name',
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'),
]);
$query->from(InventoryItem::tableName());
$query->innerJoin(User::tableName(), "user.id = inventory_item.id_user");
$query->leftJoin(Product::tableName(), "product.id_product = inventory_item.id_product");
$query->leftJoin(InventoryGroup::tableName(), "inventory_group.id_inventory_group = inventory_item.id_inventory_group");
$query->leftJoin(Inventory::tableName(), "inventory.id_inventory = inventory_item.id_inventory");
$query->leftJoin( "inventory_item as item_prev", "item_prev.id_inventory_item = inventory_item.id_inventory_item_prev" );
$query->leftJoin( "inventory as inventory_prev", "inventory_prev.id_inventory = item_prev.id_inventory" );
$query->andWhere( ['inventory_item.id_inventory' => $this->inventory->id_inventory] );
$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 ,
'pagination' => ( empty($this->output) ? [] : false ),
'sort' => [
'defaultOrder' => ['item_name' => SORT_ASC],
'attributes' => Helper::mkYiiSortItems([
['item_created_at', 'item_created_at'],
['item_name', 'item_name'],
['user_username', 'user_username'],
['item_count_prev', 'item_count_prev'],
['item_count_sold', 'item_count_sold'],
['item_count_in', 'item_count_in'],
['item_count', 'item_count'],
['item_count', 'item_count'],
['item_difference', 'item_difference'],
['item_count_system', 'item_count_system'],
['inventory.id_inventory', 'inventory_id_inventory'],
['inventory.name', 'inventory_name'],
['inventory_prev_name', 'inventory_prev_name'],
])
,
]
]
);
if ( !empty($this->item_type) && is_numeric($this->item_id) ){
if ( $this->item_type == 'product'){
$query->andFilterWhere(['product.id_product' => $this->item_id]);
}else if ( $this->item_type == 'group' ){
$query->andFilterWhere(['inventory_group.id_inventory_group' => $this->item_id]);
}
}
return $dataProvider;
}
}

View File

@ -0,0 +1,70 @@
<?php
namespace frontend\models;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\Inventory;
/**
* InventorySearch represents the model behind the search form about `common\models\Inventory`.
*/
class InventorySearch extends Inventory
{
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id_inventory', 'id_user'], 'integer'],
[['created_at', 'updated_at'], 'safe'],
];
}
/**
* @inheritdoc
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Inventory::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,
'sort' =>[
'defaultOrder' => [ 'created_at' => SORT_DESC ]
]
]);
$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;
}
$query->andFilterWhere([
'id_inventory' => $this->id_inventory,
'id_user' => $this->id_user,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
]);
return $dataProvider;
}
}

View File

@ -192,7 +192,9 @@ class ProductSaleForm extends Model
$customer = null; $customer = null;
$paid_at; $paid_at;
$status = Transfer::STATUS_PAID; $status = Transfer::STATUS_PAID;
if ( $this->isAppendToUserCart() ){ if ( !Transfer::canMarkPaidByReception($this->payment_method)){
$status = Transfer::STATUS_NOT_PAID;
}else if ( $this->isAppendToUserCart() ){
$status = Transfer::STATUS_NOT_PAID; $status = Transfer::STATUS_NOT_PAID;
}else if ( $this->isAppendToCustomerCart() ){ }else if ( $this->isAppendToCustomerCart() ){
$status = Transfer::STATUS_NOT_PAID; $status = Transfer::STATUS_NOT_PAID;
@ -237,12 +239,14 @@ class ProductSaleForm extends Model
public function appendToUserCart(){ public function appendToUserCart(){
if ( $this->isAppendToUserCart() ){ if ( $this->isAppendToUserCart() ){
if ( Transfer::canBeAddedToCart($this->payment_method)){
$item = new UserSoldItem(); $item = new UserSoldItem();
$item->id_transfer = $this->transfer->id_transfer; $item->id_transfer = $this->transfer->id_transfer;
$item->id_user = Yii::$app->user->id; $item->id_user = Yii::$app->user->id;
$item->save(false); $item->save(false);
} }
} }
}
public function isAppendToCustomerCart(){ public function isAppendToCustomerCart(){
$result = false; $result = false;
if ( isset( $this->cart ) && $this->cart == 'customer' ){ if ( isset( $this->cart ) && $this->cart == 'customer' ){
@ -253,10 +257,12 @@ class ProductSaleForm extends Model
public function appendToCustomerCart(){ public function appendToCustomerCart(){
if ( $this->isAppendToCustomerCart() && isset($this->customer) ){ if ( $this->isAppendToCustomerCart() && isset($this->customer) ){
if ( Transfer::canBeAddedToCart($this->payment_method)){
$item = new ShoppingCart(); $item = new ShoppingCart();
$item->id_customer = $this->customer->id_customer; $item->id_customer = $this->customer->id_customer;
$item->id_transfer = $this->transfer->id_transfer; $item->id_transfer = $this->transfer->id_transfer;
$item->save(false); $item->save(false);
} }
} }
}
} }

View File

@ -217,7 +217,10 @@ class TicketCreate extends Ticket{
$transfer->id_account = $this->_account->id_account; $transfer->id_account = $this->_account->id_account;
$status = Transfer::STATUS_PAID; $status = Transfer::STATUS_PAID;
if ( $this->isAppendToUserCart() ){
if ( !Transfer::canMarkPaidByReception( $this->payment_method ) ){
$status = Transfer::STATUS_NOT_PAID;
}else if ( $this->isAppendToUserCart() ){
$status = Transfer::STATUS_NOT_PAID; $status = Transfer::STATUS_NOT_PAID;
}else if ( $this->isAppendToCustomerCart() ){ }else if ( $this->isAppendToCustomerCart() ){
$status = Transfer::STATUS_NOT_PAID; $status = Transfer::STATUS_NOT_PAID;
@ -284,6 +287,7 @@ class TicketCreate extends Ticket{
} }
public function appendToCustomerCart(){ public function appendToCustomerCart(){
if ( Transfer::canBeAddedToCart($this->payment_method)){
if ( $this->isAppendToCustomerCart() && isset($this->customer) ){ if ( $this->isAppendToCustomerCart() && isset($this->customer) ){
$item = new ShoppingCart(); $item = new ShoppingCart();
$item->id_customer = $this->customer->id_customer; $item->id_customer = $this->customer->id_customer;
@ -295,6 +299,7 @@ class TicketCreate extends Ticket{
} }
} }
}

View File

@ -4,6 +4,8 @@ use common\components\total\TotalDetailedMoneyMovementWidget;
?> ?>
<p>Bérletek típus szerint</p> <p>Bérletek típus szerint</p>
<?php echo TotalMediumTicketsWidget::widget(['dailyListing' => $details]);?> <?php echo TotalMediumTicketsWidget::widget(['dailyListing' => $details]);?>
<p>Termékek kategória szerint</p> <p>Termékek kategória szerint</p>

View File

@ -3,7 +3,14 @@ use common\components\accountstate\AccountStateWidget;
use common\components\total\TotalDifferenceWidget; use common\components\total\TotalDifferenceWidget;
?> ?>
<style>
.table td{
padding: 2px;
}
.table th{
padding: 2px;
}
</style>
<div class="account-state-view "> <div class="account-state-view ">
<table class="table-top"> <table class="table-top">

View File

@ -45,11 +45,14 @@ $this->params['breadcrumbs'][] = $this->title;
['class' => 'yii\grid\ActionColumn', ['class' => 'yii\grid\ActionColumn',
'template' => '{ticket} {ticket_history} {keys} {contract}', 'template' => '{ticket} {product} {ticket_history} {keys} {contract}',
'buttons' => [ 'buttons' => [
'ticket' => function ($url, $model, $key) { 'ticket' => function ($url, $model, $key) {
return Html::a('Új bérlet', $url, ['class'=> 'btn btn-xs btn-success' ]) ; return Html::a('Új bérlet', $url, ['class'=> 'btn btn-xs btn-success' ]) ;
}, },
'product' => function ($url, $model, $key) {
return Html::a('Új termék', $url, ['class'=> 'btn btn-xs btn-success' ]) ;
},
'ticket_history' => function ($url, $model, $key) { 'ticket_history' => function ($url, $model, $key) {
return Html::a('Befizetések', $url, ['class'=> 'btn btn-xs btn-success' ]) ; return Html::a('Befizetések', $url, ['class'=> 'btn btn-xs btn-success' ]) ;
}, },
@ -64,6 +67,8 @@ $this->params['breadcrumbs'][] = $this->title;
$url = ""; $url = "";
if ( 'ticket' == $action ){ if ( 'ticket' == $action ){
$url = Url::to(['ticket/create','number' => $model['card_number']]); $url = Url::to(['ticket/create','number' => $model['card_number']]);
}else if ( 'product' == $action ){
$url = Url::to(['product/sale','number' => $model['card_number']]);
}else if ( 'ticket_history' == $action ){ }else if ( 'ticket_history' == $action ){
$url = Url::to(['ticket/index','number' => $model['card_number']]); $url = Url::to(['ticket/index','number' => $model['card_number']]);
}else if ( 'keys' == $action ){ }else if ( 'keys' == $action ){

View File

@ -0,0 +1,25 @@
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
/* @var $model common\models\InventoryItem */
/* @var $form yii\widgets\ActiveForm */
?>
<div class="inventory-item-form">
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'type')->hiddenInput()->label(false) ?>
<?= $form->field($model, 'count')->textInput() ?>
<div class="form-group">
<?= Html::submitButton( Yii::t('common/inventory-item', 'Mentés') , ['class' => 'btn btn-success' ]) ?>
</div>
<?php ActiveForm::end(); ?>
</div>

View File

@ -0,0 +1,34 @@
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
/* @var $model backend\models\InventoryItemSearch */
/* @var $form yii\widgets\ActiveForm */
?>
<div class="inventory-item-search">
<?php $form = ActiveForm::begin([
'action' => ['index','id' => $model->inventory->id_inventory],
'method' => 'get',
]); ?>
<?= $form->field($model, 'item_type')->hiddenInput()->label(false) ?>
<?= $form->field($model, 'item_id')->hiddenInput()->label(false) ?>
<div class="row">
<div class="col-md-4">
<?= $form->field($model, 'item_name')->label("Termék/Termék csoport neve") ?>
</div>
</div>
<div class="form-group">
<?= Html::submitButton(Yii::t('common/inventory-item', 'Keresés'), ['class' => 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>

View File

@ -0,0 +1,33 @@
<?php
use yii\helpers\Html;
use backend\assets\InventoryItemCreateAsset;
use yii\helpers\Url;
/* @var $this yii\web\View */
/* @var $model common\models\InventoryItem */
$this->title = Yii::t('common/inventory-item', 'Új leltár elem');
$this->params['breadcrumbs'][] = ['label' => 'Leltár' , 'url' => ['inventory/view', 'id' => $model->inventory->id_inventory]];
$this->params['breadcrumbs'][] = $this->title;
InventoryItemCreateAsset::register($this);
$options = [];
$options['products'] = $model->productOptions;
$options['url_product_find'] = Url::toRoute(['product/find']);
$this->registerJs('inventoryItemCreate.init( '. json_encode($options) .' );');
?>
<div class="inventory-item-create">
<h1><?= Html::encode($this->title) ?></h1>
<?= $this->render('_form', [
'model' => $model,
]) ?>
</div>

View File

@ -0,0 +1,146 @@
<?php
use yii\helpers\Html;
use yii\grid\GridView;
use yii\widgets\DetailView;
use yii\helpers\Url;
use backend\assets\InventoryItemIndexAsset;
/* @var $this yii\web\View */
/* @var $searchModel backend\models\InventoryItemSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = Yii::t('common/inventory-item', 'Leltár részletei');
$this->params['breadcrumbs'][] = ['label' => 'Leltár lista' , 'url' => ['inventory/index']];;
$this->params['breadcrumbs'][] = $this->title;
InventoryItemIndexAsset::register($this);
$options = [];
$options['products'] = $productOptions;
$this->registerJs('inventoryItemIndex.init( '. json_encode($options) .' );');
?>
<style>
.table thead th{
white-space: normal;
}
</style>
<div class="inventory-item-index">
<h1><?= Html::encode($this->title) ?></h1>
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'id_inventory',
'name',
['attribute'=>'id_user',
'value'=>$model->userName
],
['attribute'=>'id_account',
'value'=>$model->accountName
],
'created_at:datetime',
],
]) ?>
<?php echo $this->render('_search', ['model' => $searchModel]); ?>
<p>
Magyarázat:
<ul>
<li>
Előző leltár (db): az előző leltárban összeszámolt mennyiség. Ha ez a termék első leltározása akkor 0.
</li>
<li>
Beszerzett mennyiség: Az előző leltár óta történt beszerzett mennyiségek összege
</li>
<li>
Eladott mennyiség: Az előző leltár óta eladott darabszám összege
</li>
<li>
Leltározott mennyiség: A felhasználó által összeszámolt és leltár létrehozásakor beírt mennyiség
</li>
<li>
Rendszer szerinti mennyiség: a rendszer által számolt és aktuális látott mennyiség
</li>
<li>
Különbség: = "Leltározott mennyiség - ( "Előző leltár" + "Beszerzett mennyiség" - "Eladott mennyiség" )
</li>
</ul>
</p>
<p>
<?php echo Html::a("XLS letöltése", Url::current(['InventoryItemSearch[output]' =>'xls']),['class' =>'btn btn-primary'])?>
</p>
<?php
echo GridView::widget( [
'dataProvider' => $dataProvider,
'columns' =>[
[
'attribute' => 'item_name',
'label' => 'Név',
],
[
'attribute' => 'item_count_system',
'label' => 'Rendszer szerinti mennyiség (db)',
],
[
'attribute' => 'item_count',
'label' => 'Leltározott mennyiség (db)',
],
[
'attribute' => 'item_count_prev',
'label' => 'Előzö leltár (db)'
],
[
'attribute' => 'item_count_in',
'label' => 'Beszerzett mennyiség (db)'
],
[
'attribute' => 'item_count_sold',
'label' => 'Eladott mennyiség (db)',
],
[
'attribute' => 'item_difference',
'label' => 'Különbség (db)',
],
['class' => 'yii\grid\ActionColumn',
'template' => '{update}',
'urlCreator' => function ($action, $model, $key, $index){
return Url::to(['inventory-item/update', 'id' => $model['item_id_inventory_item' ] ]) ;
},
'buttons' =>[
'update' =>function ($url, $model, $key) {
return Html::a('Módosítás', $url,['class' => 'btn btn-xs btn-success',
'data' => [
],
]) ;
}
]
]
]
]);
?>
</div>

View File

@ -0,0 +1,81 @@
<?php
use yii\helpers\Html;
use yii\widgets\DetailView;
/* @var $this yii\web\View */
/* @var $model common\models\InventoryItem */
$this->title = Yii::t('common/inventory-item', 'Leltár termék');
$this->params['breadcrumbs'][] = ['label' => 'Leltár lista', 'url' => ['inventory/index']];
$this->params['breadcrumbs'][] = ['label' => 'Leltár', 'url' => ['inventory-item/index', 'id' => $model->id_inventory ]];
$this->params['breadcrumbs'][] = Yii::t('common/inventory-item', 'Update');
?>
<div class="inventory-item-update">
<h1><?= Html::encode($this->title) ?></h1>
<h2>Leltár</h2>
<?= DetailView::widget([
'model' => $inventory,
'attributes' => [
'id_inventory',
'name',
['attribute'=>'id_user',
'value'=>$inventory->userName
],
['attribute'=>'id_account',
'value'=>$inventory->accountName
],
'created_at:datetime',
],
]) ?>
<h2>Termék</h2>
<?= DetailView::widget([
'model' => $model,
'attributes' => [
[
'value' => $model->name,
'label' =>"Név"
],
[
'value' => $model->count_system,
'label' => 'Rendszer szerinti mennyiség (db)',
],
[
'value' => $model->count,
'label' => 'Leltározott mennyiség (db)',
],
[
'value' => $model->count_prev,
'label' => 'Előző leltár (db)',
],
[
'value' => $model->count_in,
'label' => 'Beszerzett mennyiség (db)',
],
[
'value' => $model->count_sold,
'label' => 'Eladott mennyiség (db)',
],
[
'value' => $model->getDifference(),
'label' => 'Különbség',
],
[
'value' => '',
'label' => '',
],
],
]) ?>
<?= $this->render('_form', [
'model' => $model,
]) ?>
</div>

View File

@ -0,0 +1,45 @@
<?php
use yii\helpers\Html;
use yii\widgets\DetailView;
/* @var $this yii\web\View */
/* @var $model common\models\InventoryItem */
$this->title = $model->id_inventory_item;
$this->params['breadcrumbs'][] = ['label' => Yii::t('common/inventory-item', 'Inventory Items'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="inventory-item-view">
<h1><?= Html::encode($this->title) ?></h1>
<p>
<?= Html::a(Yii::t('common/inventory-item', 'Update'), ['update', 'id' => $model->id_inventory_item], ['class' => 'btn btn-primary']) ?>
<?= Html::a(Yii::t('common/inventory-item', 'Delete'), ['delete', 'id' => $model->id_inventory_item], [
'class' => 'btn btn-danger',
'data' => [
'confirm' => Yii::t('common/inventory-item', 'Are you sure you want to delete this item?'),
'method' => 'post',
],
]) ?>
</p>
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'id_inventory_item',
'id_inventory',
'count_in',
'count_sold',
'count',
'type',
'id_product',
'id_inventory_group',
'id_user',
'created_at',
'updated_at',
],
]) ?>
</div>

View File

@ -0,0 +1,32 @@
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use common\models\Account;
use common\components\Helper;
use frontend\components\HtmlHelper;
/* @var $this yii\web\View */
/* @var $model common\models\Inventory */
/* @var $form yii\widgets\ActiveForm */
?>
<?php
$accounts = ['' =>'Mind'] + HtmlHelper::mkAccountOptions( Account::readAccounts() );
?>
<div class="inventory-form">
<?php $form = ActiveForm::begin(); ?>
<div class="form-group">
<?php echo $form->field($model, "id_account")->dropDownList($accounts)?>
<?php echo $form->field($model, "name")->textInput()?>
<?= Html::submitButton($model->isNewRecord ? Yii::t('common/inventory', 'Létrehoz') : Yii::t('common/inventory', 'Módosít'), [ 'name'=>'Inventory[submit]' ,'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>

View File

@ -0,0 +1,33 @@
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
/* @var $model backend\models\InventorySearch */
/* @var $form yii\widgets\ActiveForm */
?>
<div class="inventory-search">
<?php $form = ActiveForm::begin([
'action' => ['index'],
'method' => 'get',
]); ?>
<?= $form->field($model, 'id_inventory') ?>
<?= $form->field($model, 'id_user') ?>
<?= $form->field($model, 'created_at') ?>
<?= $form->field($model, 'updated_at') ?>
<div class="form-group">
<?= Html::submitButton(Yii::t('common/inventory', 'Search'), ['class' => 'btn btn-primary']) ?>
<?= Html::resetButton(Yii::t('common/inventory', 'Reset'), ['class' => 'btn btn-default']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>

View File

@ -0,0 +1,21 @@
<?php
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $model common\models\Inventory */
$this->title = Yii::t('common/inventory', 'Új leltár');
$this->params['breadcrumbs'][] = ['label' => Yii::t('common/inventory', 'Leltár lista'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="inventory-create">
<h1><?= Html::encode($this->title) ?></h1>
<?= $this->render('_form', [
'model' => $model,
]) ?>
</div>

View File

@ -0,0 +1,50 @@
<?php
use yii\helpers\Html;
use yii\grid\GridView;
use yii\helpers\Url;
/* @var $this yii\web\View */
/* @var $searchModel backend\models\InventorySearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = Yii::t('common/inventory', 'Leltár lista');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="inventory-index">
<h1><?= Html::encode($this->title) ?></h1>
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>
<p>
<?= Html::a(Yii::t('common/inventory', 'Új leltár'), ['create'], ['class' => 'btn btn-success']) ?>
</p>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
'id_inventory',
'name',
[ 'attribute' => 'id_user', "value" =>"userName" ],
'created_at:datetime',
['class' => 'yii\grid\ActionColumn',
'template' => '{view}',
'urlCreator' => function( $action, $model, $key, $index ){
if ( $action == 'view' ){
return Url::to(['inventory-item/index' , 'id'=> $model->id_inventory]);
}
},
'buttons' =>[
'view' =>function ($url, $model, $key) {
return Html::a('Részletek', $url,['class' => 'btn btn-xs btn-primary',
]) ;
}
]
],
],
]); ?>
</div>

View File

@ -0,0 +1,23 @@
<?php
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $model common\models\Inventory */
$this->title = Yii::t('common/inventory', 'Update {modelClass}: ', [
'modelClass' => 'Inventory',
]) . ' ' . $model->id_inventory;
$this->params['breadcrumbs'][] = ['label' => Yii::t('common/inventory', 'Inventories'), 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => $model->id_inventory, 'url' => ['view', 'id' => $model->id_inventory]];
$this->params['breadcrumbs'][] = Yii::t('common/inventory', 'Update');
?>
<div class="inventory-update">
<h1><?= Html::encode($this->title) ?></h1>
<?= $this->render('_form', [
'model' => $model,
]) ?>
</div>

View File

@ -0,0 +1,89 @@
<?php
use yii\helpers\Html;
use yii\widgets\DetailView;
use yii\grid\GridView;
use yii\base\Widget;
/* @var $this yii\web\View */
/* @var $model common\models\Inventory */
$this->title = $model->id_inventory;
$this->params['breadcrumbs'][] = ['label' => Yii::t('common/inventory', 'Leltár lista'), 'url' => ['index']];
$this->params['breadcrumbs'][] = "Leltár";
?>
<div class="inventory-view">
<h1><?= Html::encode("Leltár") ?></h1>
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'id_inventory',
'name',
['attribute'=>'id_user',
'value'=>$model->userName
],
'created_at:datetime',
],
]) ?>
</div>
<p>
<?= Html::a(Yii::t('common/inventory', 'Új termék'), ['inventory-item/create','id' =>$model->id_inventory], ['class' => 'btn btn-success']) ?>
</p>
<?php
echo GridView::widget( [
'dataProvider' => $dataProvider,
'columns' =>[
[
'attribute' => 'item_created_at',
'label' => 'Létrehozva',
'format' => 'datetime'
],
[
'attribute' => 'item_name',
'label' => 'Név',
],
[
'attribute' => 'user_username',
'label' => 'Felhasználó',
],
[
'attribute' => 'item_count_prev',
'label' => 'Előzö leltár (db)'
],
[
'attribute' => 'item_count_in',
'label' => 'Beszerzett mennyiség (db)'
],
[
'attribute' => 'item_count_sold',
'label' => 'Eladott mennyiség (db)',
],
[
'attribute' => 'item_count',
'label' => 'Leltározott mennyiség (db)',
],
[
'attribute' => 'item_difference',
'label' => 'Különbség (db)',
],
]
]);
?>

View File

@ -98,7 +98,7 @@ $discountOptions = mkOptions( ArrayHelper::map($discounts, 'id_discount', 'name'
</div> </div>
<div class="row"> <div class="row">
<div class='col-md-12'> <div class='col-md-12'>
<?php echo $form->field($model,'payment_method')->dropDownList(Transfer::paymentMethods()) ?> <?php echo $form->field($model,'payment_method')->dropDownList(Transfer::paymentMethodsForProduct()) ?>
</div> </div>
</div> </div>
<div class="row"> <div class="row">

View File

@ -0,0 +1,58 @@
var inventoryItemIndex = {
defaults : {
products: [],
selector_type : '#inventoryitemsearch-item_type',
selector_name : '#inventoryitemsearch-item_name',
selector_id : '#inventoryitemsearch-item_id',
},
product: null,
init: function(o){
this.defaults = $.extend( this.defaults, o );
this.initAutocomplete();
},
initAutocomplete : function (){
var self = this;
var $input = $(self.defaults.selector_name);
$input.typeahead({source : self.defaults.products,
autoSelect: true,
items: 20,
minLength: 3,
});
$input.change(function() {
var current = $input.typeahead("getActive");
$("#filter_text").val('');
if (current) {
// Some item from your model is active!
if (current.name == $input.val()) {
self.product = current;
} else {
self.product = null;
}
} else {
self.product = null;
}
self.productChange();
});
},
productChange: function( ){
this.clearProductData();
this.setProductData();
},
clearProductData: function(){
$(this.defaults.selector_type).val('');
$(this.defaults.selector_id).val('');
},
setProductData: function(){
if ( this.product ){
$(this.defaults.selector_type).val( this.product.type);
$(this.defaults.selector_id ).val( this.product.id);
}
}
}