/** * GENERA UN RECIBO BANCARIO POR CADA RECIBO DE CLIENTE */ static function RecibosIndividuales($filtro) { $fecha = new Fecha(self::$parametros['fechaCobro']); $fCargo = $fecha->getaaaammdd(); unset($fecha); $recibos = new RecibosClientes(); $clientes = new Clientes(); $facturas = new FemitidasCab(); $tablaRecibos = $recibos->getDataBaseName() . "." . $recibos->getTableName(); $tablaClientes = $clientes->getDataBaseName() . "." . $clientes->getTableName(); $tablaFacturas = $facturas->getDataBaseName() . "." . $facturas->getTableName(); $em = new EntityManager($recibos->getConectionName()); if ($em->getDbLink()) { $filtro .= " and (Remesar='1') and (CHAR_LENGTH(r.Iban)>23) and (r.Iban<>'ES8200000000000000000000') and (r.Importe>0)"; $query = "select r.*,c.RazonSocial,f.NumeroFactura from {$tablaRecibos} as r\n left join {$tablaClientes} as c on r.IDCliente=c.IDCliente\n left join {$tablaFacturas} as f on r.IDFactura=f.IDFactura\n where {$filtro}\n order by c.RazonSocial,r.Vencimiento ASC"; $em->query($query); //echo $query; $rows = $em->fetchResult(); } unset($em); unset($clientes); unset($facturas); 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("Factura " . $recibo['NumeroFactura'] . "/" . $recibo['Recibo'], 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 el recibo con el ID de la remesa y el Vencimiento con la fecha de Cargo de la Remesa $recibos->queryUpdate(array('IDRemesa' => self::$idRemesa, 'Vencimiento' => $fCargo, 'IDEstado' => self::$parametros['idEstado']), "IDRecibo='{$recibo['IDRecibo']}'"); } }
static function getTopNComerciales($n = 10, $diasAtras = 365) { $femi = new FemitidasCab(); $tablaFacturas = $femi->getDataBaseName() . "." . $femi->getTableName(); $idRol = $_SESSION['usuarioPortal']['IdRol']; if ($idRol != '0' and $idRol != '9') { $filtro = "(f.IDComercial='{$_SESSION['usuarioPortal']['Id']}')"; } else { $filtro = "(1)"; } $hoy = new Fecha(); $desde = $hoy->sumaDias(-$diasAtras); $filtro .= " AND (Fecha>='{$desde}')"; $em = new EntityManager($femi->getConectionName()); if ($em->getDbLink()) { $query = "select IDComercial,sum(TotalBases) as Total \n from {$tablaFacturas}\n where {$filtro}\n group by IDComercial\n order by sum(TotalBases) DESC\n limit 0,{$n}"; $em->query($query); $rows = $em->fetchResult(); } foreach ($rows as $key => $row) { $comercial = new Agentes($row['IDComercial']); $rows[$key]['Nombre'] = $comercial->getNombreApellidos(); } unset($comercial); unset($em); unset($femi); return $rows; }