/** * Genera una listado por pantalla en base al filtro. * Puede recibir un filtro adicional * * @param string $aditionalFilter * @return array con el template y valores a renderizar */ public function listAction($aditionalFilter = '') { $clientes = new Clientes(); $recibos = new RecibosClientes(); $idComercial = $this->request['filter']['valuesSelected']['5']; if ($this->values['permisos']['permisosModulo']['CO']) { if ($idComercial) { $this->listado->makeQuery($aditionalFilter); $this->listado->arrayQuery['FROM'] = str_replace(", {$clientes->getDataBaseName()}.{$clientes->getTableName()}", "", $this->listado->arrayQuery['FROM']); $this->listado->arrayQuery['FROM'] .= ", {$clientes->getDataBaseName()}.{$clientes->getTableName()}"; $this->listado->arrayQuery['WHERE'] .= " AND {$recibos->getDataBaseName()}.{$recibos->getTableName()}.IDCliente={$clientes->getDataBaseName()}.{$clientes->getTableName()}.IDCliente "; $this->listado->arrayQuery['WHERE'] .= "AND {$clientes->getDataBaseName()}.{$clientes->getTableName()}.IDComercial='{$idComercial}'"; $this->listado->buildQuery(); } $this->values['listado'] = $this->listado->getAll($aditionalFilter); $this->values['filtroRemesa'] = $this->values['listado']['filter']['valuesSelected'][11]; // Obtener total recibos y total a remesar $em = new EntityManager($recibos->getConectionName()); if ($em->getDbLink()) { $query = "select sum(Importe) as Importe from {$this->listado->arrayQuery['FROM']} where {$this->listado->arrayQuery['WHERE']}"; $em->query($query); $total = $em->fetchResult(); $query1 = "select sum(Importe) as Importe from {$this->listado->arrayQuery['FROM']} where {$this->listado->arrayQuery['WHERE']} and Remesar='1'"; $em->query($query1); $remesa = $em->fetchResult(); $em->desConecta(); } unset($em); $this->values['listado']['importeRecibos'] = $total[0]['Importe']; $this->values['listado']['importeRemesa'] = $remesa[0]['Importe']; $template = $this->entity . '/list.html.twig'; } else { $template = "_global/forbiden.html.twig"; } unset($clientes); unset($recibos); return array('template' => $template, 'values' => $this->values); }
public function RecibosAgrupados($filtro) { //$aux = substr(self::$parametros['fechaCobro'], 0, 4) . '20' . substr(self::$parametros['fechaCobro'], -2); $fecha = new Fecha(self::$parametros['fechaCobro']); $fCargo = $fecha->getaaaammdd(); unset($fecha); $recibos = new RecibosClientes(); $clientes = new Clientes(); $tablaRecibos = $recibos->getDataBaseName() . "." . $recibos->getTableName(); $tablaClientes = $clientes->getDataBaseName() . "." . $clientes->getTableName(); $em = new EntityManager($recibos->getConectionName()); if ($em->getDbLink()) { $filtro .= " and (Remesar='1') and (CHAR_LENGTH(r.Iban)>23) and (r.Iban<>'ES8200000000000000000000')"; $query = "select r.IDCliente,sum(r.Importe) as Importe,r.Iban,c.RazonSocial from {$tablaRecibos} as r\n left join {$tablaClientes} as c on r.IDCliente=c.IDCliente\n where {$filtro}\n group by r.IDCliente,r.Iban,c.RazonSocial \n having sum(r.Importe)>0\n order by c.RazonSocial,r.Vencimiento ASC"; $em->query($query); $rows = $em->fetchResult(); echo $query; } unset($em); unset($clientes); foreach ($rows as $recibo) { $codclie = self::Rellena($recibo['IDCliente'], 12); $titular = self::Rellena($recibo['RazonSocial'], 40); $importe = self::Ceros(str_replace(".", "", $recibo['Importe']), 10); $concepto = self::Rellena("Facturas", 40); $reg = "5680" . self::$ordenante['Cif'] . self::$ordenante['SufijoRemesas'] . $codclie . $titular . substr($recibo['Iban'], 4, strlen($recibo['Iban'])) . $importe . self::Vacio(16) . $concepto . self::Vacio(8); self::Escribe(self::$fp, $reg); self::$nRegistrosOrdenante += 1; self::$totalOrdenante += $recibo['Importe']; self::$nDomiciliacionesOrdenante += 1; //Marcar los recibos con el ID de la remesa $filtro = str_replace("r.", "", $filtro); $recibos->queryUpdate(array('IDRemesa' => self::$idRemesa, 'Vencimiento' => $fCargo, 'IDEstado' => self::$parametros['idEstado']), "IDCliente='{$recibo['IDCliente']}' and {$filtro}"); } }
static function RecibosAgrupados($filtro) { $recibos = new RecibosClientes(); $clientes = new Clientes(); $tablaRecibos = $recibos->getDataBaseName() . "." . $recibos->getTableName(); $tablaClientes = $clientes->getDataBaseName() . "." . $clientes->getTableName(); $em = new EntityManager($recibos->getConectionName()); if ($em->getDbLink()) { $filtro .= " and (Remesar='1') and (CHAR_LENGTH(r.Iban)>23) and (r.Iban<>'ES8200000000000000000000')"; $query = "select r.IDCliente," . "sum(r.Importe) importe," . "r.Iban iban, " . "r.Bic bic, " . "r.Mandato idMandato, " . "r.FechaMandato fechaMandato " . "from {$tablaRecibos} as r " . "left join {$tablaClientes} as c on r.IDCliente=c.IDCliente " . "where {$filtro} " . "group by r.IDCliente,r.Iban " . "having sum(r.Importe)>0 " . "order by c.RazonSocial,r.Vencimiento ASC"; $em->query($query); $rows = $em->fetchResult(); } unset($em); unset($recibos); unset($clientes); $total = 0; foreach ($rows as $row) { $cliente = new Clientes($row['IDCliente']); $total += $row['importe']; $recibos[] = array('numeroFactura' => 'Varias', 'importe' => $row['importe'], 'idMandato' => $row['idMandato'], 'fechaMandato' => $row['fechaMandato'], 'bic' => $row['bic'] == '' ? "BBBBESPP" : $row['bic'], 'iban' => $row['iban'], 'razonSocial' => $cliente->getRazonSocial(), 'direccion1' => $cliente->getDireccion(), 'direccion2' => $cliente->getIDPoblacion()->getMunicipio() . " " . $cliente->getCodigoPostal() . " " . $cliente->getIDProvincia()->getProvincia(), 'pais' => $cliente->getIDPais()->getCodigo(), 'texto' => "Varias Facturas"); } unset($cliente); return array('nRecibos' => count($rows), 'importeTotal' => $total, 'recibos' => $recibos); }
/** * Trasvasa los cobros */ private function Cobros($idSucursal, $idEstado) { $filtro = ""; if ($idSucursal != "") { $filtro = "IDSucursal='{$idSucursal}' and"; } if ($idEstado != "") { $filtro .= " IDEstado='{$idEstado}' and"; } $filtro .= " Vencimiento>='{$this->desdeFecha}' and Vencimiento<='{$this->hastaFecha}'"; $recibos = new RecibosClientes(); $tabla = $recibos->getDataBaseName() . "." . $recibos->getTableName(); $em = new EntityManager($recibos->getConectionName()); if ($em->getDbLink()) { $query = "\n SELECT IDCliente, Vencimiento, IDRemesa, CContable as CuentaPago, sum(Importe) as Importe , count(IDRecibo) as NRecibos, IDEstado\n FROM {$tabla}\n WHERE {$filtro}\n GROUP BY IDCliente, IDRemesa, CuentaPago\n ORDER BY Vencimiento ASC, IDRemesa ASC;"; $em->query($query); $recibos = $em->fetchResult(); $em->desConecta(); foreach ($recibos as $recibo) { $this->nAsiento++; $this->nCobros++; $asiento = array(); $cliente = new Clientes($recibo['IDCliente']); $fecha = str_replace("-", "", $recibo['Vencimiento']); // Apunte de Cobro $asiento[] = $this->ApunteCobro($this->nAsiento, $fecha, $recibo, $cliente); // Apunte(s) de detalle cobros $apuntes = $this->ApunteDetalleCobro($this->nAsiento, $fecha, $recibo); foreach ($apuntes as $apunte) { $asiento[] = $apunte; } // Escribir en el fichero el asiento foreach ($asiento as $apunte) { fwrite($this->fpDiario, $apunte); } // Guardar la subcuenta del cliente if (!isset($this->arraySubcuentas[$recibo['IDCliente']])) { $this->arraySubcuentas[$recibo['IDCliente']] = $this->SubcuentaCliente($cliente); } } } unset($em); unset($recibos); }