public function actionProcess() { $model = new Inventory(); if ($model->load(Yii::$app->request->post())) { $model->bill_no = $model->bill_no; $model->inventory = 'i'; $model->save(); $cart = new Cart(); foreach ($cart->contents() as $items) { $detail = new \app\models\Inventorydetail(); $detail->load(Yii::$app->request->post()); $detail->inventory_id = $model->id; $detail->product_id = $items['id']; $detail->qty = $items['qty']; $detail->price = $items['price']; $product = Products::findOne($items['id']); echo $product->qty = $items['qty']; $product->save(); $detail->save(); } $cart->destroy(); return $this->redirect(['inventory/index']); } }
</div> <table cellpadding="6" cellspacing="1" style="width:100%" border="0" class="table table-bordered"> <tr> <th>#</th> <th width="700">รายการวัสดุ</th> <th>ราคา/หน่วย</th> <th>จำนวน</th> <th style="text-align:right">รวม</th> <th colspan="2"></th> </tr> <?php $i = 1; ?> <?php foreach ($cart->contents() as $items) { ?> <?php echo Html::hiddenInput($i . '[rowid]', $items['rowid']); ?> <tr> <td><?php echo $i; ?> </td> <td><?php echo Products::find()->where(['id' => $items['name']])->one()->name; ?> </td> <td style="text-align:right"><?php echo $cart->format_number($items['price']);