示例#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->aCajachica !== null) {
             if ($this->aCajachica->isModified() || $this->aCajachica->isNew()) {
                 $affectedRows += $this->aCajachica->save($con);
             }
             $this->setCajachica($this->aCajachica);
         }
         if ($this->aGasto !== null) {
             if ($this->aGasto->isModified() || $this->aGasto->isNew()) {
                 $affectedRows += $this->aGasto->save($con);
             }
             $this->setGasto($this->aGasto);
         }
         if ($this->isNew() || $this->isModified()) {
             // persist changes
             if ($this->isNew()) {
                 $this->doInsert($con);
             } else {
                 $this->doUpdate($con);
             }
             $affectedRows += 1;
             $this->resetModified();
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
示例#2
0
 public function nuevomovimientoAction()
 {
     $request = $this->request;
     if ($request->isPost()) {
         $post_data = $request->getPost();
         $fecha = \DateTime::createFromFormat('d/m/Y', $post_data['cajachica_fecha']);
         //Creamos nuestro movimiento
         $cajachica = new \Cajachica();
         $cajachica->setCajachicaFecha($fecha->format('Y-m-d'))->setIdconceptocajachica($post_data['idconcepto'])->setCajachicaTipomovimiento($post_data['cajachica_tipomoviento'])->setCajachicaCantidad($post_data['cajachica_cantidad'])->setCajachicaComprobante($post_data['cajachica_comprobante'])->setCajachicaPacientedoctor($post_data['cajachica_pacientedoctor'])->setCajachicaNota($post_data['cajachica_nota']);
         //Ya existe un movimiento?
         if (\CajachicaQuery::create()->exists()) {
             //Modificamos el balance de nuestra caja
             $first_row = \CajachicaQuery::create()->orderByIdcajachica('asc')->findOne();
             $current_balance = $first_row->getCajachicaBalance();
             if ($post_data['cajachica_tipomoviento'] == 'cargo') {
                 $new_balance = $current_balance + $post_data['cajachica_cantidad'];
             } else {
                 $new_balance = $current_balance - $post_data['cajachica_cantidad'];
             }
             $first_row->setCajachicaBalance($new_balance);
             $first_row->save();
         } else {
             if ($post_data['cajachica_tipomoviento'] == 'cargo') {
                 $new_balance = 0 + $post_data['cajachica_cantidad'];
                 $cajachica->setCajachicaBalance($new_balance);
             } else {
                 $new_balance = 0 - $post_data['cajachica_cantidad'];
                 $cajachica->setCajachicaBalance($new_balance);
             }
         }
         $cajachica->save();
         if (!$cajachica->isPrimaryKeyNull()) {
             return $this->getResponse()->setContent(\Zend\Json\Json::encode(array('response' => true, 'data' => array('idconceptocajachica' => $cajachica->getIdconceptocajachica(), 'id' => $cajachica->getIdcajachica(), 'fecha' => $cajachica->getCajachicaFecha('d-m-Y'), 'fecha_js' => $cajachica->getCajachicaFecha('m/d/Y')))));
         } else {
             return $this->getResponse()->setContent(\Zend\Json\Json::encode(array('response' => false)));
         }
     }
 }