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))); } } }