示例#1
0
文件: Item.php 项目: bangphe/klinik
 public static function updateStokItem($iditem, $permintaan)
 {
     $stok = self::getTotalStok($iditem);
     if ($stok >= $permintaan) {
         $criteria = new CDbCriteria();
         $criteria->condition = 'ID_ITEM=:iditem';
         $criteria->params = array(':iditem' => $iditem);
         $criteria->order = 'STOK DESC';
         $detilbarang = DetilItem::model()->findAll($criteria);
         $temp = $permintaan;
         foreach ($detilbarang as $databarang) {
             $databarang->scenario = 'updatestok';
             if ($databarang->STOK >= $temp) {
                 $databarang->STOK = $databarang->STOK - $temp;
                 $databarang->save();
                 break;
             } else {
                 $temp = $databarang->STOK - $temp;
                 //ini hasil pasti minus
                 if ($temp <= 0) {
                     $databarang->STOK = 0;
                 }
                 $temp = abs($temp);
                 $databarang->save();
             }
         }
     } else {
         //jelas ndak boleh
         return false;
     }
 }
示例#2
0
 public function actionStep($id)
 {
     DetilItem::model()->updateByPk($id, array('STATUS_PEMBAYARAN' => DetilItem::STATUS_LUNAS, 'TANGGAL_PEMBAYARAN' => date('Y-m-d')));
     $item = DetilItem::model()->findByPk($id);
     Yii::app()->user->setFlash('info', MyFormatter::alertSuccess('<strong>Sukses!</strong> Data telah berhasil disimpan.'));
     //$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('index'));
     $this->redirect(array('view', 'id' => $item->ID_ITEM));
 }