/** * Crear Detalle * @param \Zend\ServiceManager\ServiceLocatorInterface $serviceLocator * @param \Tesoreria\Models\Registracion $objRegistracion * @param \Tesoreria\Models\ERequest $request * @return boolean * @throws Exception */ public static function crearDetalle($serviceLocator, $objRegistracion, $request) { self::init($serviceLocator); if (array_key_exists("item", $request->param_da)) { $param_da = $request->param_da->item; } else { $param_da = $request->param_da; } $allDetallesRegistracion = array(); foreach ($param_da as $key_pa => $param) { $objMaestro = new MaestroBase(); $objMaestro->setId($param->maestro_base->id); if (array_key_exists("item", $param->lista_configuraciones)) { $listaConfiguracion = $param->lista_configuraciones->item; } else { $listaConfiguracion = $param->lista_configuraciones; } if (!is_array($listaConfiguracion)) { $listaConfiguracion = array($listaConfiguracion); } $tipo = $param->tipo; $valorParam = $param->valor; $condicion = ""; if (!is_null($valorParam)) { foreach ($listaConfiguracion as $key => $listConf) { $valorConf = $listConf->valor; $nombre = $listConf->configuracion->nombre; $tipo_dato = $listConf->configuracion->tipo_dato; if ($tipo_dato != Constants::CONF_DA_SERIALIZACION) { continue; } if ($key > 0) { $condicion .= " AND "; } if (is_string($valorConf)) { $condicion .= " " . $nombre . "= '" . $valorConf . "'"; } else { $condicion .= " " . $nombre . "=" . $valorConf; } } $resultSetItem = ExpStoresProcedures::findItems($serviceLocator, $param->maestro_base->id, $condicion); if ($tipo == Constants::MO_SALIDA_CORTO && count($resultSetItem) == 0) { throw new Exception("Error: no existe el item para hacer un movimiento de salida"); } else { if ($tipo == Constants::MO_ENTRADA_CORTO && count($resultSetItem) == 0) { $item = new Item(); $item->setMaestro($objMaestro); $item->setCantidad($valorParam); $objItem = self::$itemDao->save($item); if (!$objItem) { throw new Exception("Error: no se pudo crear el item para hacer el movimiento de entrada"); } #creacion de los usos de datos adicionales foreach ($listaConfiguracion as $listConf) { $valorConf = $listConf->valor; $confDA = new ConfDatosAdicionales(); $confDA->setId($listConf->configuracion->id); $usoDAItem = new UsoDAItem(); $usoDAItem->setItem($objItem); $usoDAItem->setValor($valorConf); $usoDAItem->setConfDatosAdicionales($confDA); $objUsoDAItem = self::$usoDAItemDao->save($usoDAItem); if (!$objUsoDAItem) { throw new Exception("Error: no se pudo crear el item para hacer el movimiento de entrada"); } } } else { $objItem = self::$itemDao->getOneObject(array('it_id' => $resultSetItem[0]->it_id)); if ($valorParam > 0) { #actualiza cantidad en item $cantidad = $objItem->getCantidad(); $nuevaCantidad = 0; if ($tipo == Constants::MO_SALIDA_CORTO) { $nuevaCantidad = $cantidad - $valorParam; } else { if ($tipo == Constants::MO_ENTRADA_CORTO) { $nuevaCantidad = $cantidad + $valorParam; } else { throw new Exception("Error: el item no posee el tipo de movimiento"); } } $objItem->setCantidad($nuevaCantidad); if (!self::$itemDao->save($objItem)) { throw new Exception("Error: el item no pudo ser actualizado - " . $objItem->id); } } } } $tipoMovimiento = Constants::MO_ENTRADA; if ($tipo == Constants::MO_SALIDA_CORTO) { $tipoMovimiento = Constants::MO_SALIDA; } $detalleRegistracion = new DetalleRegistracion(); $detalleRegistracion->setRegistracion($objRegistracion); $detalleRegistracion->setMaestro($objMaestro); $detalleRegistracion->setItem($objItem); $detalleRegistracion->setTipoMovimiento($tipoMovimiento); $detalleRegistracion->setValor($valorParam); $allDetallesRegistracion[] = $detalleRegistracion; $objDetalleRegistracion = self::$detalleRegistracionDao->save($detalleRegistracion); if (!$objDetalleRegistracion) { throw new Exception("Error: no se pudo crear el detalle de la registracion"); } } } # HASH DE LA REGISTRACION $generator = new ExpStringGenerator(); $tokenLength = 20; $hash = $generator->generate($tokenLength); $objRegistracion->setHashControl($hash); $objRegistracionUpdated = self::$registracionDao->save($objRegistracion); if (!$objRegistracionUpdated) { throw new Exception("Error: no se pudo actualizar el objeto registracion"); } return true; }
/** * Get Ticket Cierre Unificado * @param \Zend\ServiceManager\ServiceLocatorInterface $serviceLocator * @param \Tesoreria\Models\Registracion $objRegistracion * @param \Siris\Models\Ticket[] $ticketCierreSiris * @param boolean $forzado * @return \Siris\Models\Ticket[] */ public static function getTicketCierreUnificado($serviceLocator, $objRegistracion = null, $ticketCierreSiris = null, $forzado) { self::init($serviceLocator); $hash = chunk_split($objRegistracion->getHashControl(), 5, ' '); $terminal = $objRegistracion->getEntidad($serviceLocator); $cajaDetalle = ExpStoresProcedures::getCajaDetalle($serviceLocator, $terminal->getId(), date('Y-m-d'), date('Y-m-d')); $resultCierres = from('$detalle')->in($cajaDetalle)->where('$detalle => $detalle->id_operacion == ' . Constants::PA_SIS_CIERRE_CAJA . ' && $detalle->entidad == "' . $terminal->getNombre() . '"')->orderBy('$detalle => $detalle->fecha_registracion')->select('$detalle'); $condicionFechaRegistracion = ""; if (count($resultCierres) > 1) { $ultimoCierre = $resultCierres[count($resultCierres) - 1]->fecha_registracion; $condicionFechaRegistracion = ' && $detalle->fecha_registracion > "' . $ultimoCierre . '" '; } ######## EXTRACCIONES DE EFECTIVO ######### $extraccionesEfectivo = from('$detalle')->in($cajaDetalle)->where('$detalle => $detalle->id_operacion == ' . Constants::PA_SIS_EGRESO_EFECTIVO . ' && $detalle->id_concepto == ' . Constants::MA_BA_RETIRO_EFECTIVO . ' && $detalle->entidad == "' . $terminal->nombre . '"' . $condicionFechaRegistracion)->select('$detalle'); $texto = $ticketCierreSiris[0]->texto; $texto[] = ""; $texto[] = "----------------------------------------"; $texto[] = ""; $texto[] = " EXTRACCIONES DE EFECTIVO "; $texto[] = ""; $totalExtraccion = 0; foreach ($extraccionesEfectivo as $ext) { $totalExtraccion += $ext->valor; $montoExtraccion = number_format($ext->monto_operacion, 2, ",", "."); $texto[] = "Monto: " . $montoExtraccion; } if ($totalExtraccion > 0) { $texto[] = ""; $texto[] = "Total Extracciones: " . number_format($totalExtraccion, 2, ",", "."); } ######## RECAUDACIONES EXTERNAS (CONCILIACION) ######### $recaudacionesExternas = from('$detalle')->in($cajaDetalle)->where('$detalle => $detalle->id_operacion == ' . Constants::PA_SIS_RECAUDACION_EXTERNA . ' && $detalle->id_concepto == ' . Constants::MA_BA_RECAUDACION_EXTERNA . ' && $detalle->entidad == "' . $terminal->nombre . '"' . $condicionFechaRegistracion)->select('$detalle'); $texto[] = ""; $texto[] = "----------------------------------------"; $texto[] = ""; $texto[] = " RECAUDACIONES EXTERNAS "; $texto[] = ""; $totalRecaudaciones = 0; foreach ($recaudacionesExternas as $rec) { $usosDAItem = self::$usoDAItemDao->getAllObjects(array("item_id" => $rec->id_item)); $entidad = "XXXXXX"; foreach ($usosDAItem as $uso) { if ($uso->getConfDatosAdicionales($serviceLocator)->getId() == Constants::CONF_DA_ENTES_RECAUDADORES) { $objEntidad = self::$maestroBaseDao->getById($uso->getValor()); $entidad = $objEntidad->getNombre(); } } $totalRecaudaciones += $rec->valor; $montoRecaudacion = number_format($rec->valor, 2, ",", "."); $texto[] = "Entidad: " . $entidad; $texto[] = "Monto: " . $montoRecaudacion; $texto[] = ""; } if ($totalRecaudaciones > 0) { $texto[] = ""; $texto[] = "Total Recaudacion Ext.: " . number_format($totalRecaudaciones, 2, ",", "."); } ######## CORTES DE CAJA ######### $cortesCaja = from('$detalle')->in($cajaDetalle)->where('$detalle => $detalle->id_operacion == ' . Constants::PA_SIS_CORTE_CAJA . ' && $detalle->id_concepto == ' . Constants::MA_BA_PESOS . ' && $detalle->tipo_movimiento == "' . Constants::MO_SALIDA . '" && $detalle->entidad == "' . $terminal->nombre . '"' . $condicionFechaRegistracion)->select('$detalle'); $texto[] = ""; $texto[] = "----------------------------------------"; $texto[] = ""; $texto[] = " CORTES DE CAJA "; $texto[] = ""; $totalCortes = 0; foreach ($cortesCaja as $cor) { $totalCortes += $cor->valor; $montoCorte = number_format($cor->valor, 2, ",", "."); $texto[] = "Monto: " . $montoCorte; } if ($totalCortes > 0) { $texto[] = ""; $texto[] = "Total Cortes Caja: " . number_format($totalCortes, 2, ",", "."); } if ($forzado) { $texto[] = ""; $texto[] = "CONCEPTO: CIERRE FORZADO"; } $ticketCierre = new Ticket(); $ticketCierre->texto = $texto; $ticketFinalCierre = self::getTicketCajaNoCuadrada($serviceLocator, "CIERRE", $objRegistracion, array($ticketCierre)); return $ticketFinalCierre; }