Exemplo n.º 1
0
 /**
  * Performs the work of inserting or updating the row in the database.
  *
  * If the object is new, it inserts it; otherwise an update is performed.
  * All related objects are also updated in this method.
  *
  * @param PropelPDO $con
  * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
  * @throws PropelException
  * @see        save()
  */
 protected function doSave(PropelPDO $con)
 {
     $affectedRows = 0;
     // initialize var to track total num of affected rows
     if (!$this->alreadyInSave) {
         $this->alreadyInSave = true;
         // We call the save method on the following object(s) if they
         // were passed to this object by their corresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aLugarRelatedByIdlugardestinatario !== null) {
             if ($this->aLugarRelatedByIdlugardestinatario->isModified() || $this->aLugarRelatedByIdlugardestinatario->isNew()) {
                 $affectedRows += $this->aLugarRelatedByIdlugardestinatario->save($con);
             }
             $this->setLugarRelatedByIdlugardestinatario($this->aLugarRelatedByIdlugardestinatario);
         }
         if ($this->aLugarRelatedByIdlugarremitente !== null) {
             if ($this->aLugarRelatedByIdlugarremitente->isModified() || $this->aLugarRelatedByIdlugarremitente->isNew()) {
                 $affectedRows += $this->aLugarRelatedByIdlugarremitente->save($con);
             }
             $this->setLugarRelatedByIdlugarremitente($this->aLugarRelatedByIdlugarremitente);
         }
         if ($this->aOrdencompra !== null) {
             if ($this->aOrdencompra->isModified() || $this->aOrdencompra->isNew()) {
                 $affectedRows += $this->aOrdencompra->save($con);
             }
             $this->setOrdencompra($this->aOrdencompra);
         }
         if ($this->isNew() || $this->isModified()) {
             // persist changes
             if ($this->isNew()) {
                 $this->doInsert($con);
             } else {
                 $this->doUpdate($con);
             }
             $affectedRows += 1;
             $this->resetModified();
         }
         if ($this->traspasodetallessScheduledForDeletion !== null) {
             if (!$this->traspasodetallessScheduledForDeletion->isEmpty()) {
                 TraspasodetallesQuery::create()->filterByPrimaryKeys($this->traspasodetallessScheduledForDeletion->getPrimaryKeys(false))->delete($con);
                 $this->traspasodetallessScheduledForDeletion = null;
             }
         }
         if ($this->collTraspasodetalless !== null) {
             foreach ($this->collTraspasodetalless as $referrerFK) {
                 if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
Exemplo n.º 2
0
 public function guardarordenAction()
 {
     //Recibimos la orden como parametro
     $request = $this->request;
     $orden = $request->getPost('orden');
     //Cre un nuevo objeto de ordencompra
     $ordenCompra = new \Ordencompra();
     //Seteo los datos
     $ordencompra_fecha = new \DateTime();
     $ordencompra_fecha = $ordencompra_fecha->createFromFormat('d/m/Y', $orden['orden_fecha']);
     if (!empty($orden['orden_fechaapagar'])) {
         $ordencompra_fechapagar = new \DateTime();
         $ordencompra_fechapagar = $ordencompra_fechapagar->createFromFormat('d/m/Y', $orden['orden_fechaapagar']);
     }
     $ordencompra_importe = $orden['orden_importe'];
     $ordencompra_importe_split = explode('$ ', $ordencompra_importe);
     $ordencompra_importe = $ordencompra_importe_split[1];
     $ordencompra_importe = str_replace(',', '', $ordencompra_importe);
     //Guardamos nuestra compra
     $ordenCompra->setIdproveedor($orden['orden_proveedor'])->setOrdencompraStatus($orden['orden_status'])->setOrdencompraNofactura($orden['orden_folio'])->setOrdencompraFecha($ordencompra_fecha->format('Y-m-d'))->setOrdencompraImporte($ordencompra_importe);
     if (isset($ordencompra_fechapagar)) {
         $ordenCompra->setOrdencompraFechaapagar($ordencompra_fechapagar->format('Y-m-d'));
     }
     if (!is_null($orden['orden_facturapdf'])) {
         $ordenCompra->setOrdencompraFacturapdf($orden['orden_facturapdf']);
     }
     //echo '<pre>';var_dump($ordenCompra->toArray()); echo '<pre>';exit();
     $ordenCompra->save();
     //Itenaramos sobre los items
     foreach ($orden['orden_items'] as $item) {
         $item_importe = $item['ordencompradetalle_importe'];
         $item_importe_split = explode('$ ', $item_importe);
         $item_importe = $item_importe_split[1];
         $item_importe = str_replace(',', '', $item_importe);
         $ordenCompraDetalle = new \Ordencompradetalle();
         $ordenCompraDetalle->setIdordencompra($ordenCompra->getIdordencompra())->setIdarticulovariante($item['idarticulovariante'])->setOrdencompradetalleCantidad($item['ordencompradetalle_cantidad'])->setOrdencompradetalleCosto($item['ordencompradetalle_costo'])->setOrdencompradetallePrecio($item['ordencompradetalle_precio'])->setOrdencompradetalleImporte($item_importe);
         if (!empty($item['ordencompradetalle_caducidad'])) {
             $caducidad = \DateTime::createFromFormat('m/Y', $item['ordencompradetalle_caducidad']);
             $caducidad = $caducidad->format('Y-m-d');
             $ordenCompraDetalle->setOrdencompradetalleCaducidad($caducidad);
         }
         $ordenCompraDetalle->save();
         //Tambien actualizamos el precio del articulo variante
         $articulo_variante = \ArticulovarianteQuery::create()->findPk($item['idarticulovariante']);
         $articulo_variante->setArticulovariantePrecio($item['ordencompradetalle_precio']);
         $articulo_variante->setArticulovarianteCosto($item['ordencompradetalle_costo']);
         $articulo_variante->save();
         //Los insertamos en nuestro almacen general
         $lugarInventario = new \Lugarinventario();
         $lugarInventario->setIdlugar($orden['orden_lugar'])->setIdordencompradetalle($ordenCompraDetalle->getIdordencompradetalle())->setLugarinventarioCantidad($ordenCompraDetalle->getOrdencompradetalleCantidad())->save();
     }
     //Agregamos un mensaje
     $this->flashMessenger()->addMessage('Orden generada exitosamente!');
     return $this->getResponse()->setContent(\Zend\Json\Json::encode(array('response' => true)));
 }
Exemplo n.º 3
0
 public function caducidadbylugarAction()
 {
     $request = $this->request;
     if ($request->isPost()) {
         $post_data = $request->getPost();
         //Creamos una nueva Orden de compra, donde el proveedor va ser el mismo hospital
         $orden = new \Ordencompra();
         $orden->setIdproveedor(1);
         $fecha = new \DateTime();
         $orden->setOrdencompraNofactura($fecha->getTimestamp());
         $orden->setOrdencompraFecha($fecha->format('Y-m-d'));
         $orden->setOrdencompraImporte(0);
         $orden->setOrdencompraStatus('inventario');
         $orden->setOrdencompraFechaapagar($fecha->format('Y-m-d'));
         $post_data_array = array();
         foreach ($post_data as $post) {
             if (is_array($post)) {
                 $post_data_array[] = $post;
             }
         }
         //Comenzamos a itinerar sobre el post
         foreach ($post_data_array as $row) {
             //Si ya es una orden de compra detalle existente
             if (isset($row['id'])) {
                 //Creamos una instancia de la orden compra detalle
                 $ocd = \OrdencompradetalleQuery::create()->findPk($row['id']);
                 //Setiamos los valores
                 $newCaducidad = new \DateTime();
                 //Si nos envian la fecha, le damos formato
                 if (!empty($row['caducidad'])) {
                     $newCaducidad = $newCaducidad->createFromFormat('d/m/y', '01/' . $row['caducidad']);
                 } else {
                     $newCaducidad = null;
                 }
                 $ocd->setOrdencompradetalleCantidad($row['cantidad']);
                 if (!is_null($newCaducidad)) {
                     $ocd->setOrdencompradetalleCaducidad($newCaducidad->format('Y-m-d'));
                 }
                 $ocd->save();
                 //Ahora actualizamos en lugarInventario
                 $lugarInventario = \LugarinventarioQuery::create()->filterByIdlugar($post_data['idlugar'])->filterByIdordencompradetalle($ocd->getIdordencompradetalle())->findOne();
                 $lugarInventario->setLugarinventarioCantidad($row['cantidad']);
                 $lugarInventario->save();
             } else {
                 //En dado caso que no exista...
                 if (is_null($orden->getIdordencompra())) {
                     $orden->save();
                 }
                 //Nueva instancia de orden compra detalle
                 $ocd = new \Ordencompradetalle();
                 $newCaducidad = new \DateTime();
                 //Si nos envian la fecha, le damos formato
                 if (!empty($row['caducidad'])) {
                     $newCaducidad = $newCaducidad->createFromFormat('d/m/y', '01/' . $row['caducidad']);
                 } else {
                     $newCaducidad = null;
                 }
                 $ocd->setIdordencompra($orden->getIdordencompra())->setIdarticulovariante($post_data['idarticulovariante'])->setOrdencompradetalleCantidad($row['cantidad'])->setOrdencompradetalleCosto(0)->setOrdencompradetallePrecio(0)->setOrdencompradetalleImporte(0);
                 if (!is_null($newCaducidad)) {
                     $ocd->setOrdencompradetalleCaducidad($newCaducidad->format('Y-m-d'));
                 }
                 $ocd->save();
                 //Hacemos el insert en lugar inventario
                 $lugarInventario = new \Lugarinventario();
                 $lugarInventario->setIdlugar($post_data['idlugar'])->setIdordencompradetalle($ocd->getIdordencompradetalle())->setLugarinventarioCantidad($ocd->getOrdencompradetalleCantidad())->save();
             }
         }
         //Agregamos un mensaje
         $this->flashMessenger()->addMessage('Existencias guardadas exitosamente!');
         //Redireccionamos
         return $this->redirect()->toUrl('/productos/existencias');
     }
     //Cachamos los datos de la url
     $idarticulovariante = $this->params()->fromQuery('idarticulovariante');
     $idlugar = $this->params()->fromQuery('idlugar');
     $descripcion = $this->params()->fromQuery('descripcion');
     $existencias = $this->params()->fromQuery('existencias');
     $lugarNombre = $this->params()->fromQuery('lugarNombre');
     $modalName = 'modal-producto-' . $idarticulovariante . '-lugar-' . $idlugar;
     $modal = array('id' => $idarticulovariante, 'idlugar' => $idlugar, 'nombre' => \ArticulovarianteQuery::create()->findOneByIdarticulovariante($idarticulovariante)->getArticulo()->getArticuloNombre(), 'descripcion' => $descripcion, 'caducidad' => array(), 'existencias' => $existencias, 'lugar_nombre' => $lugarNombre);
     //Obtenemos todas las ordenes de compra por idarticulovariante
     $ordenCompraDetalleCollection = \OrdencompradetalleQuery::create()->findByIdarticulovariante($idarticulovariante);
     //Comenzamos a itinerar
     foreach ($ordenCompraDetalleCollection as $kocd => $vocd) {
         $tmp['idordendetallecompra'] = $vocd->getIdordencompradetalle();
         if (!is_null($vocd->getOrdencompradetalleCaducidad())) {
             $date = new \DateTime($vocd->getOrdencompradetalleCaducidad());
             $tmp['caducidad'] = $date->format('m/y');
         } else {
             $tmp['caducidad'] = '';
         }
         //Por cada item de articulovariante revisamos su lugar en el inventrario
         $idodencompreadetalle = $vocd->getIdordencompradetalle();
         $lugarinventarioCollection = \LugarinventarioQuery::create()->filterByIdlugar($idlugar)->filterByIdordencompradetalle($idodencompreadetalle)->find();
         //Itineramos en lugarInventario
         foreach ($lugarinventarioCollection as $kli => $vli) {
             $tmp['cantidad'] = $vli->getLugarinventarioCantidad();
             $modal['caducidad'][] = $tmp;
         }
     }
     $viewModel = new ViewModel();
     $viewModel->setTerminal(true);
     $viewModel->setVariables(array('modalName' => $modalName, 'modal' => $modal));
     return $viewModel;
 }