/** * Resets all references to other model objects or collections of model objects. * * This method is a user-space workaround for PHP's inability to garbage collect * objects with circular references (even in PHP 5.3). This is currently necessary * when using Propel in certain daemon or large-volume/high-memory operations. * * @param boolean $deep Whether to also clear the references on all referrer objects. */ public function clearAllReferences($deep = false) { if ($deep && !$this->alreadyInClearAllReferencesDeep) { $this->alreadyInClearAllReferencesDeep = true; if ($this->aLugarinventario instanceof Persistent) { $this->aLugarinventario->clearAllReferences($deep); } if ($this->aTraspaso instanceof Persistent) { $this->aTraspaso->clearAllReferences($deep); } $this->alreadyInClearAllReferencesDeep = false; } // if ($deep) $this->aLugarinventario = null; $this->aTraspaso = null; }
/** * @param Traspaso $traspaso The traspaso object to add. */ protected function doAddTraspaso($traspaso) { $this->collTraspasos[] = $traspaso; $traspaso->setOrdencompra($this); }
public function editarAction() { //Cachamos el valor desde nuestro params $id = (int) $this->params()->fromRoute('id'); //Verificamos que el Id articulo que se quiere modificar exista if (!\TraspasoQuery::create()->filterByIdinventariolugar($id)->exists()) { $id = 0; } //Si es incorrecto redireccionavos al action nuevo if (!$id) { return $this->redirect()->toRoute('almacen-transferencias', array('action' => 'nuevo')); } $request = $this->getRequest(); $entity = \TraspasoQuery::create()->findOneByIdinventariolugar($id); $entity_array = $entity->toArray(); $entity_array['detalles'] = array(); $traspaso_detalles = $entity->getTraspasodetalless(); foreach ($traspaso_detalles as $detalle) { $tmp['costo'] = $detalle->getLugarinventario()->getOrdencompradetalle()->getArticulovariante()->getArticulovarianteCosto(); $tmp['idarticulovariante'] = $detalle->getLugarinventario()->getOrdencompradetalle()->getIdarticulovariante(); $tmp['idlugarinventario'] = $detalle->getIdlugarinventario(); $tmp['cantidad'] = (int) $detalle->getTraspasoCantidad(); $tmp['descripcion'] = ''; $idarticulovariante = $detalle->getLugarinventario()->getOrdencompradetalle()->getIdarticulovariante(); $articulovariante = \ArticulovarianteQuery::create()->findPk($idarticulovariante); $articulovariantevalor = \ArticulovariantevalorQuery::create()->filterByIdarticulovariante($idarticulovariante)->find(); $tmp['descripcion'] .= $articulovariante->getArticulo()->getArticuloNombre() . ' '; $propiedadCount = 0; foreach ($articulovariantevalor as $key => $value) { $propiedadCount++; $tmp['descripcion'] .= \PropiedadQuery::create()->findOneByIdpropiedad($value->getIdpropiedad())->getPropiedadNombre(); //Propiedad $tmp['descripcion'] .= ':' . \PropiedadvalorQuery::create()->findOneByIdpropiedadvalor($value->getIdpropiedadvalor())->getPropiedadvalorNombre(); //PropiedadValor if ($propiedadCount < $articulovariantevalor->count()) { $tmp['descripcion'] .= ' - '; } } $tmp['caducidad'] = !is_null($detalle->getLugarinventario()->getOrdencompradetalle()->getOrdencompradetalleCaducidad('m/Y')) ? $detalle->getLugarinventario()->getOrdencompradetalle()->getOrdencompradetalleCaducidad('m/Y') : 'N/D'; array_push($entity_array['detalles'], $tmp); } //Instanciamos nuestro lugares $lugaresCollection = \LugarQuery::create()->find(); $lugarArray = array(); foreach ($lugaresCollection as $lugar) { $lugarArray[] = array('value' => $lugar->getIdLugar(), 'name' => $lugar->getLugarNombre()); } if ($request->isPost()) { //Si hicieron POST $post_data = $request->getPost(); //echo '<pre>';var_dump($entity_array); echo '<pre>';exit(); //Eliminamos nuestra anterior transferencia $traspaso = \TraspasoQuery::create()->findOneByIdinventariolugar($id); $traspaso_idorden = $traspaso->getIdOrdencompra(); $traspaso_detalles = $traspaso->getTraspasodetalless(); //Eliminamos los detalles y los regresamos a almacen general foreach ($traspaso_detalles as $detalle) { //Instanciamos nuestro el lugar inventario del detalle $lugar_inventario = $detalle->getLugarinventario(); $current_stock = $lugar_inventario->getLugarinventarioCantidad(); $new_stock = $current_stock + $detalle->getTraspasoCantidad(); $lugar_inventario->setLugarinventarioCantidad($new_stock); $lugar_inventario->save(); } //Eliminamos el traspaso y la orden $traspaso->delete(); \OrdencompraQuery::create()->findPk($traspaso_idorden)->delete(); /* * Creamos la nueva */ $traspaso_fecha = \DateTime::createFromFormat('d/m/Y', $post_data['traspaso_fecha']); //Si existen items en el traspaso if (isset($post_data["traspaso_detalles"])) { //Creamos una nueva orden donde vamos a registrar el traspaso $orden = new \Ordencompra(); $orden->setIdproveedor(1)->setOrdencompraNofactura($traspaso_fecha->getTimestamp())->setOrdencompraFecha($traspaso_fecha->format('Y-m-d h:m:s'))->setOrdencompraImporte(0.0)->setOrdencompraStatus('inventario')->setOrdencompraFechaapagar($traspaso_fecha->format('Y-m-d'))->save(); //Generamos el traspaso $traspaso = new \Traspaso(); $traspaso->setIdinventariolugar($entity_array['Idinventariolugar']); $traspaso_fecha = \DateTime::createFromFormat('d/m/Y', $post_data['traspaso_fecha']); $traspaso->setTraspasoFecha($traspaso_fecha->format('Y-m-d h:m:s')); $traspaso->setIdordencompra($orden->getIdordencompra()); $traspaso->setTraspasoStatus('recibido'); $traspaso->setIdlugarremitente($post_data['traspaso_idlugarorigen']); $traspaso->setIdlugardestinatario($post_data["traspaso_idlugardestinatario"]); $traspaso->save(); $idtraspaso = $traspaso->getIdinventariolugar(); //Se guardo con exito la orden if (!$orden->isPrimaryKeyNull()) { $idorden = $orden->getIdordencompra(); //Modificamos el idorden de nuestro traspaso //Insertamos los orden items foreach ($post_data["traspaso_detalles"] as $detalle) { //Agregamos los detalles del traspaso $traspaso_detalle = new \Traspasodetalles(); $traspaso_detalle->setIdtraspaso($idtraspaso)->setIdlugarinventario($detalle["idlugarinventario"])->setTraspasoCantidad($detalle["traspaso_cantidad"])->save(); //Agregamos el order item a la orden $orden_detalle = new \Ordencompradetalle(); $orden_detalle->setIdordencompra($idorden)->setIdarticulovariante($detalle["idarticulovariante"])->setOrdencompradetalleCantidad($detalle["traspaso_cantidad"])->setOrdencompradetalleCosto(0.0)->setOrdencompradetallePrecio(0.0)->setOrdencompradetalleImporte(0.0); if ($detalle['caducidad'] != 'N/D') { $caducidad = \DateTime::createFromFormat('m/Y', $detalle['caducidad']); $orden_detalle->setOrdencompradetalleCaducidad($caducidad->format('Y-m-d')); } $orden_detalle->save(); //Insertamos en nuestro almacen destinatario $lugar_inventario = new \Lugarinventario(); $lugar_inventario->setIdlugar($post_data["traspaso_idlugardestinatario"])->setIdordencompradetalle($orden_detalle->getIdordencompradetalle())->setLugarinventarioCantidad($orden_detalle->getOrdencompradetalleCantidad())->save(); //Restamos del lugarinventario remitente (almacen general) $lugar_inventario = \LugarinventarioQuery::create()->findPk($detalle["idlugarinventario"]); $current_stock = $lugar_inventario->getLugarinventarioCantidad(); $new_stock = $current_stock - $orden_detalle->getOrdencompradetalleCantidad(); $lugar_inventario->setLugarinventarioCantidad($new_stock)->save(); } } } //Agregamos un mensaje $this->flashMessenger()->addMessage('Transferencia modificada exitosamente!'); return $this->getResponse()->setContent(\Zend\Json\Json::encode(array('response' => true))); } return new ViewModel(array('id' => $id, 'transferencia' => $entity_array, 'lugares' => $lugarArray)); }
/** * Adds an object to the instance pool. * * Propel keeps cached copies of objects in an instance pool when they are retrieved * from the database. In some cases -- especially when you override doSelect*() * methods in your stub classes -- you may need to explicitly add objects * to the cache in order to ensure that the same objects are always returned by doSelect*() * and retrieveByPK*() calls. * * @param Traspaso $obj A Traspaso object. * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally). */ public static function addInstanceToPool($obj, $key = null) { if (Propel::isInstancePoolingEnabled()) { if ($key === null) { $key = serialize(array((string) $obj->getIdinventariolugar(), (string) $obj->getIdlugarremitente(), (string) $obj->getIdlugardestinatario())); } // if key === null TraspasoPeer::$instances[$key] = $obj; } }
/** * Exclude object from result * * @param Traspaso $traspaso Object to remove from the list of results * * @return TraspasoQuery The current query, for fluid interface */ public function prune($traspaso = null) { if ($traspaso) { $this->addCond('pruneCond0', $this->getAliasedColName(TraspasoPeer::IDINVENTARIOLUGAR), $traspaso->getIdinventariolugar(), Criteria::NOT_EQUAL); $this->addCond('pruneCond1', $this->getAliasedColName(TraspasoPeer::IDLUGARREMITENTE), $traspaso->getIdlugarremitente(), Criteria::NOT_EQUAL); $this->addCond('pruneCond2', $this->getAliasedColName(TraspasoPeer::IDLUGARDESTINATARIO), $traspaso->getIdlugardestinatario(), Criteria::NOT_EQUAL); $this->combine(array('pruneCond0', 'pruneCond1', 'pruneCond2'), Criteria::LOGICAL_OR); } return $this; }
/** * Filter the query by a related Traspaso object * * @param Traspaso|PropelObjectCollection $traspaso the related object to use as filter * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * * @return LugarQuery The current query, for fluid interface * @throws PropelException - if the provided filter is invalid. */ public function filterByTraspasoRelatedByIdlugarremitente($traspaso, $comparison = null) { if ($traspaso instanceof Traspaso) { return $this->addUsingAlias(LugarPeer::IDLUGAR, $traspaso->getIdlugarremitente(), $comparison); } elseif ($traspaso instanceof PropelObjectCollection) { return $this->useTraspasoRelatedByIdlugarremitenteQuery()->filterByPrimaryKeys($traspaso->getPrimaryKeys())->endUse(); } else { throw new PropelException('filterByTraspasoRelatedByIdlugarremitente() only accepts arguments of type Traspaso or PropelCollection'); } }
/** * Filter the query by a related Traspaso object * * @param Traspaso|PropelObjectCollection $traspaso the related object to use as filter * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * * @return OrdencompraQuery The current query, for fluid interface * @throws PropelException - if the provided filter is invalid. */ public function filterByTraspaso($traspaso, $comparison = null) { if ($traspaso instanceof Traspaso) { return $this->addUsingAlias(OrdencompraPeer::IDORDENCOMPRA, $traspaso->getIdordencompra(), $comparison); } elseif ($traspaso instanceof PropelObjectCollection) { return $this->useTraspasoQuery()->filterByPrimaryKeys($traspaso->getPrimaryKeys())->endUse(); } else { throw new PropelException('filterByTraspaso() only accepts arguments of type Traspaso or PropelCollection'); } }
/** * Filter the query by a related Traspaso object * * @param Traspaso|PropelObjectCollection $traspaso The related object(s) to use as filter * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * * @return TraspasodetallesQuery The current query, for fluid interface * @throws PropelException - if the provided filter is invalid. */ public function filterByTraspaso($traspaso, $comparison = null) { if ($traspaso instanceof Traspaso) { return $this->addUsingAlias(TraspasodetallesPeer::IDTRASPASO, $traspaso->getIdinventariolugar(), $comparison); } elseif ($traspaso instanceof PropelObjectCollection) { if (null === $comparison) { $comparison = Criteria::IN; } return $this->addUsingAlias(TraspasodetallesPeer::IDTRASPASO, $traspaso->toKeyValue('Idinventariolugar', 'Idinventariolugar'), $comparison); } else { throw new PropelException('filterByTraspaso() only accepts arguments of type Traspaso or PropelCollection'); } }