Beispiel #1
0
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param PropelPDO $con
  * @return void
  * @throws PropelException
  * @throws Exception
  * @see        BaseObject::setDeleted()
  * @see        BaseObject::isDeleted()
  */
 public function delete(PropelPDO $con = null)
 {
     if ($this->isDeleted()) {
         throw new PropelException("This object has already been deleted.");
     }
     if ($con === null) {
         $con = Propel::getConnection(OrdencompraPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = OrdencompraQuery::create()->filterByPrimaryKey($this->getPrimaryKey());
         $ret = $this->preDelete($con);
         if ($ret) {
             $deleteQuery->delete($con);
             $this->postDelete($con);
             $con->commit();
             $this->setDeleted(true);
         } else {
             $con->commit();
         }
     } catch (Exception $e) {
         $con->rollBack();
         throw $e;
     }
 }
 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));
 }
Beispiel #3
0
 public function removefacturapdfAction()
 {
     //Cachamos el valor desde nuestro params
     $id = (int) $this->params()->fromQuery('idorden');
     $html = $this->params()->fromQuery('html');
     if ($html) {
         $viewModel = new ViewModel();
         $viewModel->setTerminal(true);
         $viewModel->setVariable('id', $id);
         return $viewModel;
     }
     $request = $this->request;
     if ($request->isPost()) {
         $idorden = $request->getPost('id');
         //Elimnamos de la base de datos
         $orden = \OrdencompraQuery::create()->findPk($idorden);
         $facturapdf = $orden->getOrdencompraFacturapdf();
         $orden->setOrdencompraFacturapdf(NULL);
         $orden->save();
         //Eliminamos del servidor;
         if (file_exists($_SERVER["DOCUMENT_ROOT"] . $facturapdf)) {
             unlink($_SERVER["DOCUMENT_ROOT"] . $facturapdf);
             return $this->getResponse()->setContent(\Zend\Json\Json::encode(array('response' => true)));
         }
     }
 }
 /**
  * Get the associated Ordencompra object
  *
  * @param PropelPDO $con Optional Connection object.
  * @param $doQuery Executes a query to get the object if required
  * @return Ordencompra The associated Ordencompra object.
  * @throws PropelException
  */
 public function getOrdencompra(PropelPDO $con = null, $doQuery = true)
 {
     if ($this->aOrdencompra === null && $this->idordencompra !== null && $doQuery) {
         $this->aOrdencompra = OrdencompraQuery::create()->findPk($this->idordencompra, $con);
         /* The following can be used additionally to
               guarantee the related object contains a reference
               to this object.  This level of coupling may, however, be
               undesirable since it could result in an only partially populated collection
               in the referenced object.
               $this->aOrdencompra->addOrdencompradetalles($this);
            */
     }
     return $this->aOrdencompra;
 }
 /**
  * Returns a new OrdencompraQuery object.
  *
  * @param     string $modelAlias The alias of a model in the query
  * @param   OrdencompraQuery|Criteria $criteria Optional Criteria to build the query from
  *
  * @return OrdencompraQuery
  */
 public static function create($modelAlias = null, $criteria = null)
 {
     if ($criteria instanceof OrdencompraQuery) {
         return $criteria;
     }
     $query = new OrdencompraQuery(null, null, $modelAlias);
     if ($criteria instanceof Criteria) {
         $query->mergeWith($criteria);
     }
     return $query;
 }
Beispiel #6
0
 /**
  * Returns the number of related Ordencompra objects.
  *
  * @param Criteria $criteria
  * @param boolean $distinct
  * @param PropelPDO $con
  * @return int             Count of related Ordencompra objects.
  * @throws PropelException
  */
 public function countOrdencompras(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
 {
     $partial = $this->collOrdencomprasPartial && !$this->isNew();
     if (null === $this->collOrdencompras || null !== $criteria || $partial) {
         if ($this->isNew() && null === $this->collOrdencompras) {
             return 0;
         }
         if ($partial && !$criteria) {
             return count($this->getOrdencompras());
         }
         $query = OrdencompraQuery::create(null, $criteria);
         if ($distinct) {
             $query->distinct();
         }
         return $query->filterByProveedor($this)->count($con);
     }
     return count($this->collOrdencompras);
 }