<?php
  /**
   * By Urie
   */
  require_once "conexion.php";
  class ModeloVentas{
    /*=============================================
        OBTENER TODAS LAS PARTIDAS DE MATERIALES CON STATUS DE APROBADO
    =============================================*/
    static public function mdlGetSalesByStore($tabla,$item,$valor){

      if ($item !== null) {
        if($valor["fecha"] !== "null"){
          $stmt = conexion::conectar()->prepare("SELECT _store.Id,_store.name, sum(ROUND(_ventas.total_venta,2)) as  Ventas,WEEK(fecha) AS Week,year(fecha) AS _year FROM $tabla as _store  JOIN pbakeryadmin_adminapp.ventas AS _ventas ON _store.Id = _ventas.idSucursal WHERE _store.status = '1' AND _ventas.fecha = '$valor[fecha]' GROUP BY _store.Id");
        }else{
          $stmt = conexion::conectar()->prepare("SELECT _store.Id,_store.name, sum(ROUND(_ventas.total_venta,2)) as  Ventas,WEEK(fecha) AS Week,year(fecha) AS _year FROM $tabla as _store  JOIN pbakeryadmin_adminapp.ventas AS _ventas ON _store.Id = _ventas.idSucursal WHERE _store.status = '1' AND WEEK(fecha)= '$valor[week]' AND year(fecha) = '$valor[year]' GROUP BY _store.Id");

        }      
        $stmt ->execute();
        return $stmt ->fetchall();
      }        
      $stmt->close();
      $stmt=null;
    }
    
    static public function mdlGetSalesByIdStore($tabla,$item,$valor){

      if ($item !== null) {
        if($valor["fecha"] !== "null"){
          $stmt = conexion::conectar()->prepare("SELECT _store.Id,_store.name, sum(ROUND(_ventas.total_venta,2)) as  Ventas,WEEK(fecha) AS Week,year(fecha) AS _year FROM $tabla as _store  JOIN pbakeryadmin_adminapp.ventas AS _ventas ON _store.Id = _ventas.idSucursal WHERE _store.status = '1' AND _ventas.fecha = '$valor[fecha]' AND _store.Id = '$valor[id_store]' GROUP BY _store.Id");
        }else{
          $stmt = conexion::conectar()->prepare("SELECT _store.Id,_store.name, sum(ROUND(_ventas.total_venta,2)) as  Ventas,WEEK(fecha) AS Week,year(fecha) AS _year FROM $tabla as _store  JOIN pbakeryadmin_adminapp.ventas AS _ventas ON _store.Id = _ventas.idSucursal WHERE _store.status = '1' AND WEEK(fecha)= '$valor[week]' AND year(fecha) = '$valor[year]' AND _store.Id = '$valor[id_store]' GROUP BY _store.Id");

        }      
        $stmt ->execute();
        return $stmt ->fetchall();
      }        
      $stmt->close();
      $stmt=null;
    }

  }

 ?>
