public function executeAjout(sfWebRequest $request) { $this->materiel = $this->getRoute()->getObject(); if (!$this->getUser()->isAuthenticated() || !$this->getUser()->getGuardUser()->hasAccess($this->materiel->getAsso()->getLogin(), 0x40)) { $this->getUser()->setFlash('error', 'Vous n\'avez pas le droit d\'effectuer cette action.'); $this->redirect('asso/show?login='******'q')->andWhere('materiel_id = ?', $this->materiel->getId())->andWhere('etat_id = ?', 1)->fetchOne(); $this->form = new StockForm($stock); $this->form->setDefault('materiel_id', $this->materiel->getId()); }
public function emprunter($form) { $materiel_id = $form->getValue('materiel_id'); $nombre = $form->getValue('nombre'); $dispo = StockTable::getInstance()->findOneByMaterielIdAndEtatId($materiel_id, 1); if ($dispo && $dispo->getNombre() >= $nombre) { $form->save(); $dispo->addNombre(-$nombre); $dispo->save(); $emprunte = StockTable::getInstance()->findOneByMaterielIdAndEtatId($materiel_id, 2); if (!$emprunte) { $emprunte = new Stock(); $emprunte->setNombre($nombre); $emprunte->setMaterielId($materiel_id); $emprunte->setEtatId(2); } else { $emprunte->addNombre($nombre); } $emprunte->save(); return true; } else { return false; } }
public function getStockDisponible() { $res = StockTable::getInstance()->getDispoForMateriel($this->getId())->fetchOne(); return $res['stock'] != NULL ? $res['stock'] : '0'; }