public function copyEntireReceiving($receiving_id) { $this->clearAll(); $receiving = Receiving::model()->findbyPk($receiving_id); $receiving_item = ReceivingItem::model()->getReceivingItem($receiving_id); //$payments= ReceivSalePayment::model()->getPayment($sale_id); foreach ($receiving_item as $row) { $item_expire = ItemExpire::model()->findByAttributes(array('item_id' => $row->item_id, 'receiving_id' => $receiving_id)); $expire_date = null; if ($item_expire) { $expire_date = $item_expire->expire_date; } if ($row->discount_type == '$') { $discount_amount = $row->discount_type . $row->discount_amount; } else { $discount_amount = $row->discount_amount; } $this->addItem($row->item_id, $row->quantity, $discount_amount, $row->price, $row->description, $expire_date); } /* foreach($payments as $row) { $this->addPayment($row->payment_type,$row->payment_amount); } * */ $this->setSupplier($receiving->supplier_id); $this->setComment($receiving->remark); }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return ItemExpire the loaded model * @throws CHttpException */ public function loadModel($id) { $model = ItemExpire::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public function getItemExpDate($item_id) { $model = ItemExpire::model()->findAll('item_id=:item_id and quantity>0 order by expire_date', array(':item_id' => (int) $item_id)); $list = CHtml::listData($model, 'expire_date', 'ItemExpDateInfo'); return $list; }
protected function saveItemExpire($item_expire_date, $receiving_id, $item_id, $employee_id, $quantity, $trans_date, $remarks) { if (!empty($item_expire_date)) { $item_expire = ItemExpire::model()->find('item_id=:item_id and expire_date=:expire_date', array(':item_id' => (int) $item_id, ':expire_date' => $item_expire_date)); if (!$item_expire) { $item_expire = new ItemExpire(); $qty_in_stock = 0; } else { $qty_in_stock = $item_expire->quantity; } $stock_quantity = $this->stockQuantiy($qty_in_stock, $quantity); //Update Item expiry date & quantity $item_expire->item_id = $item_id; $item_expire->expire_date = $item_expire_date; $item_expire->quantity = $stock_quantity[0]; $item_expire->save(); $item_expire_dt = new ItemExpireDt(); $item_expire_dt->item_expire_id = $item_expire->id; $item_expire_dt->trans_id = $receiving_id; $item_expire_dt->trans_qty = $stock_quantity[0]; $item_expire_dt->trans_comment = $remarks; $item_expire_dt->modified_date = $trans_date; $item_expire_dt->employee_id = $employee_id; $item_expire_dt->save(); } }
public function updateStockExpire($item_id, $quantity, $sale_id) { $sql = "SELECT `id`,`item_id`,`expire_date`,`quantity`\n FROM `item_expire`\n WHERE item_id=:item_id\n AND quantity>0\n ORDER BY expire_date"; $result = Yii::app()->db->createCommand($sql)->queryAll(true, array(':item_id' => $item_id)); if ($result) { foreach ($result as $record) { $item_expire = ItemExpire::model()->find('id=:id', array(':id' => $record["id"])); if ($quantity <= $record["quantity"]) { $item_expire->quantity = $item_expire->quantity - $quantity; $item_expire->save(); $item_expire_dt = new ItemExpireDt(); $item_expire_dt->item_expire_id = $item_expire->id; $item_expire_dt->trans_id = $sale_id; $item_expire_dt->trans_qty = -$quantity; $item_expire_dt->trans_comment = 'POS ' . $sale_id; $item_expire_dt->modified_date = date('Y-m-d H:s:i'); $item_expire_dt->save(); break; } else { $deducted_qty = $item_expire->quantity; $item_expire->quantity = $item_expire->quantity - $deducted_qty; $item_expire->save(); $item_expire_dt = new ItemExpireDt(); $item_expire_dt->item_expire_id = $item_expire->id; $item_expire_dt->trans_id = $sale_id; $item_expire_dt->trans_qty = -$quantity; $item_expire_dt->trans_comment = 'POS ' . $sale_id; $item_expire_dt->modified_date = date('Y-m-d H:s:i'); $item_expire_dt->save(); $quantity = $quantity - $deducted_qty; } } } }