using System.Data;
using AsignadorKits_Almex_ML;
using MySqlConnector;

namespace CreateLabel_ML
{
   public class Cotizaciones
   {

      public DataTable GetKitItems(int product_id_master)
      {
         var cn = new clsConexion();
            var dt=cn.TraeDataTable("SELECT a.kit_id, a.product_id, a.kit_product_id, a.quantity, a.date_created, a.user_id, b.seller_sku, b.product_name, b.qty_available, b.qty_available_mkz, b.qty_available_almex, b.qty_available_vallejo, b.supplier_name, b.codebar  FROM product_kit AS a INNER JOIN mu_v_productinfo AS b ON a.kit_product_id = b.product_id  WHERE a.product_id = @product_id",new []
               {
                  new MySqlParameter("@product_id",product_id_master)
               },CommandType.Text);
         return dt;
      }
      
      public int GetInStock(int product_id, int warehouse_id, int quantity)
      {
         var cn = new clsConexion();
         var cont = 0;
            var dt=cn.TraeDataTable("SELECT count(a.location_id) as cont FROM mu_v_product_to_location AS a WHERE a.warehouse_id = @warehouse_id AND a.location_type_id IN ( 1, 6 ) AND a.quantity >= @quantity AND a.product_id = @product_id",new []
               {
                  new MySqlParameter("@product_id",product_id),
                  new MySqlParameter("@warehouse_id",warehouse_id),
                  new MySqlParameter("@quantity",quantity)
               },CommandType.Text);
            if (dt.Rows.Count > 0)
            {
               var dr = dt.Rows[0];
               if (!dr.IsNull("cont"))
                  cont = int.Parse(dr["cont"].ToString());
            }
            return cont;
      }
   }
}
