protected function processForm(sfWebRequest $request, sfForm $form) { $requestparam = $request->getParameter('stockentry'); $stock = StockTable::fetchById($requestparam['stock_id']); $qty = $requestparam['qty']; $date = $requestparam['date']['year'] . "-" . $requestparam['date']['month'] . "-" . $requestparam['date']['day']; //$ref_class=$requestparam['ref_class']; //$ref_id=$requestparam['ref_id']; $type = $requestparam['type'] != "" ? $requestparam['type'] : 'Adjustment'; //$priority=0; $description = $requestparam['description']; if ($qty == 0) { $this->redirect('home/error?msg="Invalid Qty"'); } $stockentry = $stock->addEntry($date, $qty, null, null, $type, $description); $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName())); if ($form->isValid()) { $notice = $form->getObject()->isNew() ? 'The item was created successfully.' : 'The item was updated successfully.'; $this->dispatcher->notify(new sfEvent($this, 'admin.save_object', array('object' => $stockentry))); $this->getUser()->setFlash('notice', $notice); $this->redirect('stock/view?id=' . $stockentry->getstockId()); } else { if ($form['qty']->getError()) { $this->redirect('home/error?msg="Invalid Qty: ' . $qty . '"'); } if ($form['date']->getError()) { $this->redirect('home/error?msg="Invalid Date: ' . $date . '"'); } //$this->getUser()->setFlash('error', 'The item has not been saved due to some errors.', false); } }
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 static function generate($array) { $event = new Event(); $event->setType($array["type"]); $event->setParentClass(get_class($array["parent"])); $event->setParentId($array["parent"]->getId()); //$event->setParentName($array["parent_name"]); switch ($array["type"]) { case "Inventory": $parent = $event->getParent(); //create stockentry if (get_class($parent) == "Invoicedetail") { $stockentry = StockTable::createStockOut(SettingsTable::fetch("default_warehouse_id"), $parent->getProductId(), $parent->getQty(), $parent->getInvoice()->getDate(), $parent); } else { if (get_class($parent) == "Purchasedetail") { $stockentry = StockTable::createStockIn(SettingsTable::fetch("default_warehouse_id"), $parent->getProductId(), $parent->getQty(), $parent->getPurchase()->getDate(), $parent); } } $event->setChildClass("Stockentry"); $event->setChildrenId($stockentry->getId()); break; } $event->save(); }
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; } }
function getCurrentQty() { //return $this->getStock(SettingsTable::get("default_warehouse_id"))->getCurrentQty(); $stock = StockTable::fetch(SettingsTable::fetch("default_warehouse_id"), $this->getId()); return $stock->getCurrentQty(); }
<?php foreach ($products as $index => $product) { ?> <h1><?php echo link_to($product->getName(), "product/edit?id=" . $product->getId()); ?> </h1> <table border=1> <tr> <td>Warehouse</td> <td>Qty</td> <td>View</td> </tr> <?php foreach (WarehouseTable::fetchAll() as $warehouse) { $stock = StockTable::fetch($warehouse->getId(), $product->getId()); ?> <tr> <td><?php echo $warehouse->getName(); ?> </td> <td><?php echo $stock->getCurrentQty(); ?> </td> <td><?php echo link_to("View", "stock/view?id=" . $stock->getId()); ?> </td> </tr>
<?php if ($form->getObject()->getId()) { foreach (WarehouseTable::fetchAll() as $warehouse) { $stock = StockTable::fetch($warehouse->getId(), $form->getObject()->getId()); //$this->redirect("stock/view?id=".$stock->getId()); echo link_to("Go to " . $warehouse . " stock", "stock/view?id=" . $stock->getId()) . "<br>"; } } ?>
public function getStockDisponible() { $res = StockTable::getInstance()->getDispoForMateriel($this->getId())->fetchOne(); return $res['stock'] != NULL ? $res['stock'] : '0'; }
public function getStock() { if ($this->stock == null or $force) { $this->stock = StockTable::fetch(SettingsTable::fetch("default_warehouse_id"), $this->getProductId()); } return $this->stock; //return StockTable::fetch($this->getWarehouseId(), $this->getProductId()); }