here my solution. Pls, comments
In my _add.php
<?php
$itemsQuery = Inventory::find();
$itemsQuery->andFilterWhere(['inv_status' => 1, 'inv_condition' => 2]);
$dataProvider = new ActiveDataProvider([
'query' => $itemsQuery,
]);
echo GridView::widget([
'id' => 'griditems',
'dataProvider' => $dataProvider,
'columns' => [
['attribute' => 'inv_group', 'value' => 'invGroup.inv_group'],
['attribute' => 'inv_class', 'value' => 'invClass.inv_class'],
'brand',
'model',
'description',
['class' => 'yii\grid\CheckboxColumn', 'checkboxOptions' => ['onclick' => 'js:addItems(this.value, this.checked)']],
],
]);
?>
In javascript
function addItems(item_id, checked){
var pick_id = getUrlVars()["id"];
// alert(checked);
if(checked){
$.ajax({
url: 'index.php',
method: 'get',
dataType: 'text',
data: {r:'picked-items/add', item:item_id, pick:pick_id}
}).done(function(){alert('added')}).error(function(){alert('there was a problem...!')});
}
else{
$.ajax({
url: 'index.php',
method: 'get',
dataType: 'text',
data: {r:'picked-items/deselect', item:item_id, pick:pick_id}
}).done(function(){alert('deselected')}).error(function(){alert('there was a problem...!')});
}}
And in my controller
public function actionDeselect()
{
$picking_list = Yii::$app->request->get('pick');
$item_id = Yii::$app->request->get('item');
$deselectModel = PickedItems::find()->where(['item_id' => $item_id, 'picking_list' => $picking_list])->one();
$itemAdded = Inventory::find()->where(['inv_id' => $item_id])->one();
$itemAdded->inv_status = 1;
$itemAdded->current_ot = '0';
$deselectModel->delete();
$itemAdded->save();
}
public function actionAdd()
{
$picking_list = Yii::$app->request->get('pick');
$item_id = Yii::$app->request->get('item');
$itemAdded = Inventory::find()->where(['inv_id' => $item_id])->one();
$currentPicking = PickingList::find()->where(['pick_id' => $picking_list])->one();
$currentOt = Ot::find()->where(['ot_id' => $currentPicking->ot_id])->one();
if($itemAdded->composition === 2){
$parentGroup = $itemAdded->parent_code;
$otherItems = Inventory::find()->where(['parent_code' => $parentGroup])->all();
foreach($otherItems as $item){
$addModel = new PickedItems();
$addModel->picking_list = $picking_list;
$addModel->item_id = $item->inv_id;
$addModel->save();
$item->inv_status = 2;
$item->current_ot = $currentOt->ot_id;
$item->save();
}
}
else{
$addModel = new PickedItems();
$addModel->picking_list = $picking_list;
$addModel->item_id = $item_id;
$addModel->save();
$itemAdded->inv_status = 2;
$itemAdded->current_ot = $currentOt->ot_id;
$itemAdded->save();
}
}
Here an explanation: I need add items in batch when an items have his composition value to 2..., then, I find all items with te same parent_code and update.
However, I try to use POST method in javascript, but don't work...,
Form your help, THANKS!!!