示例#1
0
 function valorizarPorCliente($year = null, $paraGraf = false)
 {
     $data = "";
     $sql = "SELECT *\n\t\t\t\tFROM\n\t\t\t\t(\n\t\t\t\t  SELECT t2.id_cliente, t2.razon_social_cliente, SUM(t1.total_venta) total_por_cliente\n\t\t\t\t  FROM ventas t1\n\t\t\t\t  INNER JOIN clientes t2 ON t2.id_cliente=t1.id_cliente\n\t\t\t\t  WHERE t1.id_registro_estado=1\n\t\t\t\t  AND EXTRACT(YEAR FROM t1.fecha_venta) = {$year}\n\t\t\t\t  GROUP BY t2.id_cliente\n\t\t\t\t) rs1\n\t\t\t\tORDER BY total_por_cliente DESC";
     $rs = getRS($sql);
     $sql = "SELECT SUM(t1.total_venta) total_por_anio\n\t\t\t\t  FROM ventas t1\n\t\t\t\t  WHERE t1.id_registro_estado=1\n\t\t\t\t  AND EXTRACT(YEAR FROM t1.fecha_venta) = {$year}";
     $rsTotalPorAnio = getRS($sql);
     $rowTotalPorAnio = getRow($rsTotalPorAnio);
     $totalPorAnio = $rowTotalPorAnio["total_por_anio"];
     $porc_cte = 0;
     $total_acum = 0;
     $porc_fact = 0;
     $porc_acum = 0;
     $nroDeClientes = getNrosRows($rs);
     if ($nroDeClientes) {
         $nro = 1;
         while ($row = getRow($rs)) {
             $porc_cte = round($nro * 100 / $nroDeClientes, 2);
             $porc_fact = round($row["total_por_cliente"] * 100 / $totalPorAnio, 4);
             $porc_acum += $row["total_por_cliente"] * 100 / $totalPorAnio;
             $total_acum += $row["total_por_cliente"];
             $porc_item = round($porc_acum, 4);
             if ($porc_item >= 0 && $porc_item <= 80) {
                 $clase = "A";
             } else {
                 if ($porc_item > 80 && $porc_item <= 90) {
                     $clase = "B";
                 } else {
                     $clase = "C";
                 }
             }
             if (!$paraGraf) {
                 $data .= "<row id='" . $row["id_cliente"] . "'>" . "<cell><![CDATA[" . $nro . "]]></cell>" . "<cell><![CDATA[" . $row["razon_social_cliente"] . "]]></cell>" . "<cell><![CDATA[" . $porc_cte . "]]></cell>" . "<cell><![CDATA[" . round($row["total_por_cliente"], 2) . "]]></cell>" . "<cell><![CDATA[" . $porc_fact . "]]></cell>" . "<cell><![CDATA[" . round($total_acum, 2) . "]]></cell>" . "<cell><![CDATA[" . $porc_item . "]]></cell>" . "<cell><![CDATA[" . $clase . "]]></cell></row>";
             } else {
                 if ($nro == 11) {
                     break;
                 }
                 $data .= "<item id='{$nro}'><cliente>" . $row["razon_social_cliente"] . "</cliente><monto>" . round($row["total_por_cliente"], 2) . "</monto></item>";
             }
             $nro++;
         }
     }
     if (!$paraGraf) {
         $fin = "</rows>";
         $cab = "<?xml version='1.0' encoding='iso-8859-1'?><rows>";
     } else {
         $fin = "</data>";
         $cab = "<data>";
     }
     return $cab . $data . $fin;
 }
示例#2
0
 function delete($id)
 {
     $sql = "SELECT id_repartidor FROM repartos WHERE id_repartidor={$id}";
     $rs = mysql_query($sql);
     $cantReg = getNrosRows($rs);
     if ($cantReg != 0) {
         return false;
     }
     $sql = "DELETE FROM repartidores WHERE id_repartidor={$id}";
     if (!mysql_query($sql)) {
         die('Error: ' . mysql_error() . $sql);
     } else {
         return true;
     }
 }
 function delete($id)
 {
     $sql = "SELECT id_tipo_producto FROM productos WHERE id_tipo_producto={$id}";
     $rs = mysql_query($sql);
     $cantReg = getNrosRows($rs);
     if ($cantReg != 0) {
         return false;
     }
     $sql = "DELETE FROM tipo_producto WHERE id_tipo_producto={$id}";
     if (!mysql_query($sql)) {
         die('Error: ' . mysql_error() . $sql);
     } else {
         return true;
     }
 }
示例#4
0
 function delete($id)
 {
     $sql = "SELECT id_cliente FROM ventas WHERE id_cliente={$id}\r\n\t\t\t\tUNION ALL\r\n\t\t\t\tSELECT id_cliente FROM saldo_deudor WHERE id_cliente={$id}";
     $rs = mysql_query($sql);
     $cantReg = getNrosRows($rs);
     if ($cantReg != 0) {
         return false;
     }
     $sql = "DELETE FROM clientes WHERE id_cliente={$id}";
     if (!mysql_query($sql)) {
         die('Error: ' . mysql_error() . $sql);
     } else {
         return true;
     }
 }
示例#5
0
 function delete($id)
 {
     $sql = "SELECT id_zona FROM clientes WHERE id_zona={$id}\n                UNION ALL\n                SELECT id_zona FROM repartos WHERE id_zona={$id}";
     $rs = mysql_query($sql);
     $cantReg = getNrosRows($rs);
     if ($cantReg != 0) {
         return false;
     }
     $sql = "DELETE FROM zonas WHERE id_zona={$id}";
     if (!mysql_query($sql)) {
         die('Error: ' . mysql_error() . $sql);
     } else {
         return true;
     }
 }
示例#6
0
 function getSinConfirmar()
 {
     $sql = "SELECT *\r\n\t\t\t\tFROM ordenes_compra oc\r\n\t\t\t\tWHERE oc.generada = 0";
     $rs = getRS($sql);
     if (!getNrosRows($rs)) {
         return false;
     } else {
         return true;
     }
 }
示例#7
0
 function graficarDemandaPronosticoError($oData)
 {
     $sql = "select\r\n\t\t\t\tdate_format(c1.fecha_fin, '%d/%m/%Y') fecha_fin, \r\n\t\t\t\tcantidad_demandada, \r\n\t\t\t\tprediccion, \r\n\t\t\t\terror,\r\n\t\t\t\tsenial \r\n\t\t\t\tfrom (\r\n\t\t\t\t\tselect\r\n\t\t\t\t\tfecha_fin, \r\n\t\t\t\t\tcantidad_demandada, \r\n\t\t\t\t\tprediccion, \r\n\t\t\t\t\terror, \r\n\t\t\t\t\tsenial \r\n\t\t\t\t\tfrom predicciones t1 \r\n\t\t\t\t\tinner join periodos t2 on t1.id_periodo = t2.id_periodo \r\n\t\t\t\t\twhere id_producto= " . $oData["id_producto"] . " \r\n\t\t\t\t\torder by fecha_fin asc) c1";
     $rs = getRS($sql);
     $data = array();
     $nro = getNrosRows($rs);
     $flag = 1;
     if ($nro) {
         while ($row = getRow($rs)) {
             if ($flag) {
                 $inicio = $row['fecha_fin'];
                 $flag = 0;
             }
             $nro--;
             if ($nro == 0) {
                 $fin = $row['fecha_fin'];
             }
             $data[] = array('', $row['cantidad_demandada'], $row['prediccion'], $row['error'], $row['senial']);
         }
     }
     $plot = new PHPlot(800, 465);
     //$plot->SetImageBorderType('plain');
     $plot->SetPlotType('lines');
     //tipo de gráfico
     $plot->SetDataType('text-data');
     $plot->SetDataValues($data);
     $plot->SetTitle('Demanda real, predicción, error y señal de rastreo. Periodo ' . $inicio . ' al ' . $fin);
     //Título
     $plot->SetLegend(array('Demanda real', 'Pronóstico', 'Error', 'Señal de rastreo'));
     //Referencia
     $plot->SetLineWidths(2);
     //ancho de la linea
     $plot->SetLineStyles("solid");
     //estilo de la linea
     $plot->SetDataColors(array('green', 'blue', 'red', 'purple'));
     $plot->SetXTickLabelPos('none');
     $plot->SetXTickPos('none');
     # Draw both grids:
     $plot->SetDrawXGrid(True);
     $plot->SetDrawYGrid(True);
     $plot->DrawGraph();
 }
示例#8
0
 function getSubproducto($idProducto)
 {
     $sql = "SELECT * FROM productos WHERE id_subproducto=" . $idProducto;
     $resultSet = getRS($sql);
     $numsRows = getNrosRows($resultSet);
     if ($numsRows > 0) {
         return getRow($resultSet);
     } else {
         return false;
     }
 }
示例#9
0
 function getSaldoDeudor($id_reparto, $id_cliente)
 {
     $sql = "SELECT * FROM saldo_deudor WHERE id_reparto={$id_reparto} AND id_cliente={$id_cliente}";
     $rs = getRS($sql);
     $numsRows = getNrosRows($rs);
     if ($numsRows > 0) {
         $row = getRow($rs);
         return $row["monto_deudor"];
     }
     return 0;
 }
 function executePolitica_SR()
 {
     $sql = "SELECT *\r\n\t\t\t\tFROM productos p\r\n\t\t\t\t  INNER JOIN agotamientos_permitidos ap\r\n\t\t\t\t\tON ap.id_agotamiento = p.id_agotamiento\r\n\t\t\t\tWHERE id_politica = 2";
     $rs = getRS($sql);
     if (getNrosRows($rs)) {
         $flag = false;
         while ($row = getRow($rs)) {
             $sql = "SELECT *\r\n\t\t\t\t\t\tFROM ordenes_compra oc\r\n\t\t\t\t\t\t  INNER JOIN detalle_ordenes_compra doc\r\n\t\t\t\t\t\t\tON doc.id_orden_compra = oc.id_orden_compra\r\n\t\t\t\t\t\t\t  AND id_producto = " . $row["id_producto"] . "\r\n\t\t\t\t\t\tORDER BY fecha_orden_compra DESC LIMIT 1";
             $rsOC = getRS($sql);
             $rowOC = getRow($rsOC);
             $fechaOC = $rowOC["fecha_orden_compra"];
             $fechaActual = date("Y-m-d");
             $diferencia = getDiferenciaEntreFechas($fechaOC, $fechaActual);
             $R = $row["tpo_de_reaprovisionamiento_producto"];
             if ($diferencia >= $R) {
                 $R = $R / 7;
                 // lo convierto a semanas
                 $A = $row["costo_de_emision_producto"];
                 $oData = array();
                 $oData["id_producto"] = $row["id_producto"];
                 $D = $this->getDemandaAnual($oData);
                 $H = $row["tasa_de_almacenamiento_producto"] * $row["precio_unitario_producto"];
                 $Q = number_format(sqrt(2 * $A * $D / $H));
                 $agotamiento = $row["agotamientos_perm_x_anio"];
                 $N = number_format($D / $Q);
                 $nivel_de_serv = 1 - $agotamiento / $N;
                 $k = $this->getFactorDeSeguridad($nivel_de_serv);
                 $data = $this->getMinTpoDeEntregaAndProv($oData);
                 $te = $data["tpo_de_entrega"];
                 $te_sobre_durEnSem = $te / $this->getDuracionPeriodoEnSemanas();
                 $days = number_format($te * 7 + $R);
                 $desv_std = $this->getDesvStd($oData, $days) * $te_sobre_durEnSem;
                 $SS = $k * $desv_std;
                 $mu_e = $this->getDemanda($oData, $days) * $te_sobre_durEnSem;
                 $S = number_format($mu_e + $SS);
                 if ($row["stock_actual_producto"] < $S) {
                     begin();
                     $sql = "UPDATE productos SET nivel_s_producto={$S}, stock_seguridad_producto={$SS} WHERE id_producto=" . $oData["id_producto"];
                     if (!getRS($sql)) {
                         rollback();
                         return false;
                     } else {
                         $exp = new ExpertoOrdenes();
                         $nro_orden = $exp->getNroOrdenCompra();
                         $sql = "INSERT INTO  ordenes_compra (fecha_orden_compra, nro_orden_compra, generada, id_proveedor)\r\n\t\t\t\t\t\t\t\t\tVALUES ('" . date("Y-m-d") . "', " . $nro_orden . ", 0, " . $data["id_proveedor"] . ")";
                         if (!getRS($sql)) {
                             rollback();
                             return false;
                         } else {
                             $id = mysql_insert_id();
                             $cant = $S - $row["stock_actual_producto"];
                             $sql = "INSERT INTO detalle_ordenes_compra (id_orden_compra, id_producto, cantidad_detalle_orden_compra) VALUES  (" . $id . ", " . $oData["id_producto"] . ", " . $cant . ")";
                             if (!getRS($sql)) {
                                 rollback();
                                 return false;
                             } else {
                                 $nro_orden += 1;
                                 $sql = "UPDATE parametros SET valor_parametro = " . $nro_orden . " WHERE nombre_parametro='nro_orden_compra'";
                                 if (!mysql_query($sql)) {
                                     die('Error: ' . mysql_error());
                                     rollback();
                                     return false;
                                 } else {
                                     commit();
                                     $flag = true;
                                 }
                             }
                         }
                     }
                 }
             }
         }
         return $flag;
     }
     return false;
 }