public function nuevomovimientoAction()
 {
     $request = $this->request;
     if ($request->isPost()) {
         $post_data = $request->getPost();
         $fecha = \DateTime::createFromFormat('d/m/Y', $post_data['banco_fecha']);
         //Creamos nuestro movimiento
         $banco = new \Banco();
         $banco->setBancoFecha($fecha->format('Y-m-d'))->setIdconceptobanco($post_data['idconcepto'])->setBancoTipomovimiento($post_data['banco_tipomoviento'])->setBancoCantidad($post_data['banco_cantidad'])->setBancoComprobante($post_data['banco_comprobante'])->setBancoNota($post_data['banco_nota']);
         //Ya existe un movimiento?
         if (\BancoQuery::create()->exists()) {
             //Modificamos el balance de nuestra caja
             $first_row = \BancoQuery::create()->orderByIdbanco('asc')->findOne();
             $current_balance = $first_row->getBancoBalance();
             if ($post_data['banco_tipomoviento'] == 'cargo') {
                 $new_balance = $current_balance + $post_data['banco_cantidad'];
             } else {
                 $new_balance = $current_balance - $post_data['banco_cantidad'];
             }
             $first_row->setBancoBalance($new_balance);
             $first_row->save();
         } else {
             if ($post_data['banco_tipomoviento'] == 'cargo') {
                 $new_balance = 0 + $post_data['banco_cantidad'];
                 $banco->setBancoBalance($new_balance);
             } else {
                 $new_balance = 0 - $post_data['banco_cantidad'];
                 $banco->setBancoBalance($new_balance);
             }
         }
         $banco->save();
         $fecha = new \DateTime($banco->getBancoFecha());
         $fechaJS = $fecha->format('m/d/Y');
         $fecha = $fecha->format('d-m-Y');
         if (!$banco->isPrimaryKeyNull()) {
             return $this->getResponse()->setContent(\Zend\Json\Json::encode(array('response' => true, 'data' => array('id' => $banco->getIdbanco(), 'fecha' => $fecha, 'fecha_js' => $fechaJS))));
         } else {
             return $this->getResponse()->setContent(\Zend\Json\Json::encode(array('response' => false)));
         }
     }
 }
 /**
  * Declares an association between this object and a Banco object.
  *
  * @param                  Banco $v
  * @return Bancotransaccion The current object (for fluent API support)
  * @throws PropelException
  */
 public function setBanco(Banco $v = null)
 {
     if ($v === null) {
         $this->setIdbanco(NULL);
     } else {
         $this->setIdbanco($v->getIdbanco());
     }
     $this->aBanco = $v;
     // Add binding for other direction of this n:n relationship.
     // If this object has already been added to the Banco object, it will not be re-added.
     if ($v !== null) {
         $v->addBancotransaccion($this);
     }
     return $this;
 }
 /**
  * Filter the query by a related Banco object
  *
  * @param   Banco|PropelObjectCollection $banco The related object(s) to use as filter
  * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return                 BancotransaccionQuery The current query, for fluid interface
  * @throws PropelException - if the provided filter is invalid.
  */
 public function filterByBanco($banco, $comparison = null)
 {
     if ($banco instanceof Banco) {
         return $this->addUsingAlias(BancotransaccionPeer::IDBANCO, $banco->getIdbanco(), $comparison);
     } elseif ($banco instanceof PropelObjectCollection) {
         if (null === $comparison) {
             $comparison = Criteria::IN;
         }
         return $this->addUsingAlias(BancotransaccionPeer::IDBANCO, $banco->toKeyValue('PrimaryKey', 'Idbanco'), $comparison);
     } else {
         throw new PropelException('filterByBanco() only accepts arguments of type Banco or PropelCollection');
     }
 }
Beispiel #4
0
 /**
  * Exclude object from result
  *
  * @param   Banco $banco Object to remove from the list of results
  *
  * @return BancoQuery The current query, for fluid interface
  */
 public function prune($banco = null)
 {
     if ($banco) {
         $this->addUsingAlias(BancoPeer::IDBANCO, $banco->getIdbanco(), Criteria::NOT_EQUAL);
     }
     return $this;
 }
Beispiel #5
0
 /**
  * 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 Banco $obj A Banco 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 = (string) $obj->getIdbanco();
         }
         // if key === null
         BancoPeer::$instances[$key] = $obj;
     }
 }