function rankingVendedor() { $fecha = $_REQUEST['fecha']; if (!empty($_REQUEST['txtFechaAprobadoInicio'])) { $txtFechaAprobadoInicio = date('Y-m-d', strtotime($_REQUEST['txtFechaAprobadoInicio'])); } if (!empty($_REQUEST['txtFechaAprobadoFinal'])) { $txtFechaAprobadoFinal = date('Y-m-d', strtotime($_REQUEST['txtFechaAprobadoFinal'])); } if (!empty($_REQUEST['txtFechaGuiadoInicio'])) { $txtFechaGuiadoInicio = date('Y-m-d', strtotime($_REQUEST['txtFechaGuiadoInicio'])); } if (!empty($_REQUEST['txtFechaGuiadoFin'])) { $txtFechaGuiadoFin = date('Y-m-d', strtotime($_REQUEST['txtFechaGuiadoFin'])); } if (!empty($_REQUEST['txtFechaDespachoInicio'])) { $txtFechaDespachoInicio = date('Y-m-d', strtotime($_REQUEST['txtFechaDespachoInicio'])); } if (!empty($_REQUEST['txtFechaDespachoFin'])) { $txtFechaDespachoFin = date('Y-m-d', strtotime($_REQUEST['txtFechaDespachoFin'])); } if (!empty($_REQUEST['txtFechaCanceladoInicio'])) { $txtFechaCanceladoInicio = date('Y-m-d', strtotime($_REQUEST['txtFechaCanceladoInicio'])); } if (!empty($_REQUEST['txtFechaCanceladoFin'])) { $txtFechaCanceladoFin = date('Y-m-d', strtotime($_REQUEST['txtFechaCanceladoFin'])); } $idOrdenVenta = $_REQUEST['idOrdenVenta']; $idCliente = $_REQUEST['idCliente']; $idVendedor = $_REQUEST['idVendedor']; $idpadre = $_REQUEST['idpadre']; $idcategoria = $_REQUEST['idcategoria']; $idzona = $_REQUEST['idzona']; $condicion = $_REQUEST['condicion']; $aprobados = $_REQUEST['aprobados']; $desaprobados = $_REQUEST['desaprobados']; $pendiente = $_REQUEST['pendiente']; $idmoneda = $_REQUEST['idmoneda']; $simbolomoneda = $idmoneda == 1 ? "S/." : "US \$"; $condicionVenta = ""; if ($condicion == 1) { $condicionVenta = " and ov.es_contado='1' and ov.es_credito!='1' and ov.es_letras!='1' "; } elseif ($condicion == 2) { $condicionVenta = " and ov.es_credito='1' and ov.es_letras!='1' "; } elseif ($condicion == 3) { $condicionVenta = " and ov.es_letras='1' and ov.tipo_letra=1"; } elseif ($condicion == 4) { $condicionVenta = " and ov.es_letras='1' and ov.tipo_letra=2"; } $reporte = $this->AutoLoadModel('reporte'); $categoria = $this->AutoLoadModel('zona'); $data = $reporte->rankingVendedor($txtFechaAprobadoInicio, $txtFechaAprobadoFinal, $txtFechaGuiadoInicio, $txtFechaGuiadoFin, $txtFechaDespachoInicio, $txtFechaDespachoFin, $txtFechaCanceladoInicio, $txtFechaCanceladoFin, $idOrdenVenta, $idCliente, $idVendedor, $idpadre, $idcategoria, $idzona, $condicionVenta, $aprobados, $desaprobados, $pendiente, $idmoneda); // echo "<pre>"; // print_r($data); // exit; if (!empty($idpadre)) { $dataCategoria = $categoria->buscaCategoria($idpadre); } $cantidad = count($data); $dataReporte = array(); $idVendedor = 0; $importeContado = 0; $totalContado = 0; $importeCredito = 0; $totalCredito = 0; $importeLetraB = 0; $totalLetraB = 0; $importeLetraC = 0; $totalLetraC = 0; $importePagado = 0; $subTotal = 0; $importeTotal = 0; $totalPagado = 0; $importeLima = 0; $importeAnulado = 0; $importeDevolucion = 0; $totalDevolucion = 0; $importeProvincia = 0; $cont = 0; $totalGuias = 0; $num = 0; //$tipoCambio=$this->configIni($this->configIni('Globals','Modo'),'TipoCambio'); for ($i = 0; $i < $cantidad + 1; $i++) { if ($data[$i]['idvendedor'] != $idVendedor || $i == $cantidad) { if ($i != $cantidad + 1) { if ($i != 0) { $dataReporte[$num]['idvendedor'] = $idVendedor; $dataReporte[$num]['importecontado'] = $importeContado; $dataReporte[$num]['importecredito'] = $importeCredito; $dataReporte[$num]['importeletrab'] = $importeLetraB; $dataReporte[$num]['importeletrac'] = $importeLetraC; $dataReporte[$num]['importepagado'] = $importePagado; $dataReporte[$num]['importedevolucion'] = $importeDevolucion; $dataReporte[$num]['subtotal'] = $subTotal; $dataReporte[$num]['cantidadguia'] = $cont; $dataReporte[$num]['vendedor'] = $nombres; $num++; $importeContado = 0; $importeCredito = 0; $importeLetraB = 0; $importeLetraC = 0; $importePagado = 0; $importeDevolucion = 0; $importePagado = 0; $subTotal = 0; $cont = 0; } $idVendedor = $data[$i]['idvendedor']; $nombres = $data[$i]['nombres'] . ' ' . $data[$i]['apellidopaterno'] . ' ' . $data[$i]['apellidomaterno']; } } if ($i != $cantidad + 1) { if ($data[$i]['es_letras'] == 1 && $data[$i]['tipo_letra'] == 1) { $importeLetraB += $data[$i]['importeov']; $totalLetraB += $data[$i]['importeov']; } else { if ($data[$i]['es_letras'] == 1 && $data[$i]['tipo_letra'] == 2) { $importeLetraC += $data[$i]['importeov']; $totalLetraC += $data[$i]['importeov']; } else { if ($data[$i]['es_credito'] == 1) { $importeCredito += $data[$i]['importeov']; $totalCredito += $data[$i]['importeov']; } else { if ($data[$i]['es_contado'] == 1) { $importeContado += $data[$i]['importeov']; $totalContado += $data[$i]['importeov']; } } } } if ($data[$i]['idpadrec'] == 1) { $importeProvincia += $data[$i]['importeov']; } else { if ($data[$i]['idpadrec'] == 2) { $importeLima += $data[$i]['importeov']; } } if ($data[$i]['esanulado'] == 1) { $importeAnulado += $data[$i]['importeov']; } $totalGuias++; $totalDevolucion += $data[$i]['importedevolucion']; $totalPagado += $data[$i]['importepagado'] > $data[$i]['importeov'] ? $data[$i]['importeov'] : $data[$i]['importepagado']; $importeDevolucion += $data[$i]['importedevolucion']; $importePagado += $data[$i]['importepagado'] > $data[$i]['importeov'] ? $data[$i]['importeov'] : $data[$i]['importepagado']; $subTotal += $data[$i]['importeov']; $importeTotal += $data[$i]['importeov']; $cont++; } } $cantidadReporte = count($dataReporte); $pdf = new PDF_Mc_Table("L", "mm", "A4"); $titulos = array(utf8_decode('Nº'), 'Vendedor', 'VTA. NETA', '%', 'CONTADO', '%', 'L.BANCO', '%', 'L.CARTERA', '%', 'CREDITO', '%', 'Devolucion', 'Pagado', 'Pendiente', 'Guias'); $ancho = array(7, 55, 20, 9, 20, 9, 20, 9, 20, 9, 20, 9, 20, 20, 20, 10); $orientacionTitulos = array('C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C'); $orientacion = array('', '', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'C'); $pdf->_titulo = "Ranking de Ventas " . $simbolomoneda; $pdf->_fecha = $dataCategoria[0]['nombrec'] . ' (' . $_REQUEST['txtFechaGuiadoInicio'] . ' - ' . $_REQUEST['txtFechaGuiadoFin'] . ') '; $pdf->AddPage(); $relleno = true; $pdf->SetFillColor(202, 232, 234); $pdf->SetTextColor(12, 78, 139); $pdf->SetDrawColor(12, 78, 139); $pdf->SetLineWidth(0.3); $pdf->SetFont('Helvetica', 'B', 7); $pdf->fill($relleno); //un arreglo con su medida a lo ancho $pdf->SetWidths($ancho); //un arreglo con alineacion de cada celda $pdf->SetAligns($orientacionTitulos); $fila = $titulos; $pdf->Row($fila); $relleno = !$relleno; $pdf->fill($relleno); $pdf->SetAligns($orientacion); $pdf->SetFillColor(224, 235, 255); $pdf->SetTextColor(0); $pdf->SetFont(''); $dataReporte = $this->ordernarArray($dataReporte, "subtotal", true); for ($i = 0; $i < $cantidadReporte; $i++) { $fila = array($i + 1, $dataReporte[$i]['vendedor'], number_format($dataReporte[$i]['subtotal'], 2), $importeTotal == 0 ? 0 : round($dataReporte[$i]['subtotal'] * 100 / $importeTotal, 2), number_format($dataReporte[$i]['importecontado'], 2), $totalContado == 0 ? 0 : round($dataReporte[$i]['importecontado'] * 100 / $totalContado, 2), number_format($dataReporte[$i]['importeletrab'], 2), $totalLetraB == 0 ? 0 : round($dataReporte[$i]['importeletrab'] * 100 / $totalLetraB, 2), number_format($dataReporte[$i]['importeletrac'], 2), $totalLetraC == 0 ? 0 : round($dataReporte[$i]['importeletrac'] * 100 / $totalLetraC, 2), number_format($dataReporte[$i]['importecredito'], 2), $totalCredito == 0 ? 0 : round($dataReporte[$i]['importecredito'] * 100 / $totalCredito, 2), number_format($dataReporte[$i]['importedevolucion'], 2), number_format($dataReporte[$i]['importepagado'], 2), number_format($dataReporte[$i]['subtotal'] - $dataReporte[$i]['importepagado'], 2), $dataReporte[$i]['cantidadguia']); $pdf->Row($fila); $relleno = !$relleno; $pdf->fill($relleno); } $pdf->ln(); $relleno = false; $pdf->fill($relleno); $fila = array("", "TOTALES EN " . $simbolomoneda . " ", number_format($importeTotal, 2), 100, number_format($totalContado, 2), 100, number_format($totalLetraB, 2), 100, number_format($totalLetraC, 2), 100, number_format($totalCredito, 2), 100, number_format($totalDevolucion, 2), number_format($totalPagado, 2), number_format($importeTotal - $totalPagado, 2), $totalGuias); $pdf->Row($fila); // $relleno=false; // $pdf->fill($relleno); // $fila=array("","TOTALES EN $.(".$tipoCambio.")",number_format($importeTotal/$tipoCambio,2),100,number_format($totalContado/$tipoCambio,2),100,number_format($totalLetraB/$tipoCambio,2),100,number_format($totalLetraC/$tipoCambio,2),100,number_format($totalCredito/$tipoCambio,2),100,number_format($totalDevolucion/$tipoCambio,2),number_format($totalPagado/$tipoCambio,2),number_format(($importeTotal-$totalPagado)/$tipoCambio,2),$totalGuias); // $pdf->Row($fila); $pdf->AliasNbPages(); $pdf->Output(); }
} return $nl; } } //Creación del objeto de la clase heredada //$pdf=new PDF(); $pdf = new PDF_Mc_Table('L'); //Creación del objeto de la clase heredada //$pdf=new PDF(); $pdf->AliasNbPages(); $pdf->AddPage(); /* $pdf->SetFont('Arial','B',10); $pdf->Cell(200,5,' ',0,1,'C'); $pdf->Cell(200,5,'CONCURSO ARTE JOVEN 2014',0,1,'C'); $pdf->ln(10); */ $pdf->SetFont('Arial', 'B', 10); $rs = mysql_query($ejec, $con); $tot = 0; $pdf->SetFont('Arial', '', 8); $espe = 'x'; /* $pdf->SetWidths(array(8,40,15,65,40,30,75)); $pdf->SetAligns(array('L','L','L','L','L','L','L')); $pdf->Row(array("Insc.","Nombre","DNI","Contacto","Titulo","Tamaño(alto-ancho)","Procedimiento"));*/ while ($row = mysql_fetch_assoc($rs)) { if ($espe != substr($row["especialidad"], 0, 1)) { if ($tot != 0) { $pdf->Cell(200, 5, ' ' . $tot, 0, 1); $tot = 0; } $pdf->Cell(200, 5, $row["especialidad"], 0, 1, 'C'); $pdf->SetFont('Arial', 'B', 8);