package com.example.waoperations.Picking;

import java.sql.Date;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class OrderQuarantineDatabaseHelper {

        private static final int DATABASE_VERSION =  1;
        private static final String DATABASE_NAME = "WMSOrderQuarantine.db";
        private static final String TABLE_NAME = "OQuarantineList_Table";
        private static final String ORDER_QUARANTINE_ID = "_id";
        private static final String ITEMID = "articulo";
        private static final String QTY = "cantidad";
        private static final String TRANSTYPE = "tipo";
        private static final String STATUSRECEIPT = "estadorecepcion";
        private static final String DATAAREAID = "empresa";

        
        private ContactOpenHelper openHelper;
        private SQLiteDatabase database;

        public OrderQuarantineDatabaseHelper(Context context) {
                openHelper = new ContactOpenHelper(context);
                database = openHelper.getWritableDatabase();
        }
        
        public void saveQuarantineLine(String itemid,String qty,String transtype,String statusreceipt,String dataareaid) {
        	    ContentValues contentValues = new ContentValues();
                contentValues.put(ITEMID, itemid);
                contentValues.put(QTY, qty);
                contentValues.put(TRANSTYPE, transtype);
                contentValues.put(STATUSRECEIPT, statusreceipt);
                contentValues.put(DATAAREAID, dataareaid);
                database.insert(TABLE_NAME, null, contentValues);
                
        }
        public void deleteAllData()
        {
                 database.delete(TABLE_NAME, null, null);
        }
     
        public Cursor getAllQuarantineLines() {
            return database.rawQuery(
                            "SELECT * FROM " + TABLE_NAME+"", 
                            null);
    } 
        
        public Cursor getAllQuarantineLines(String ponumber) {
                return database.rawQuery(
                                "SELECT * FROM " + TABLE_NAME+"", 
                                null);
        } 
   
        /*public Cursor getQuarantineLines(String ponumber) {
            return database.rawQuery(
                            "SELECT * FROM " + TABLE_NAME+" WHERE " +PONUMBER+ " ='"
                            	     +ponumber+"'",
                            null);
        }  */
   
     /*   public void UpdateScannedItem(String amountpicked,String id) {
    	    ContentValues contentValues = new ContentValues();
            contentValues.put(AMOUNTPICKED , amountpicked);
            contentValues.put(SCANNED , "1");
            String strFilter = "_id=" + id;
            database.update(TABLE_NAME, contentValues, strFilter, null);    
        }  
        
        public void UpdateReplenishmentPending(String id) {
    	    ContentValues contentValues = new ContentValues();
            contentValues.put(REPLENISHMENTPENDING , "1");
            String strFilter = "_id=" + id;
            database.update(TABLE_NAME, contentValues, strFilter, null);    
        }  */
   
        /*public Cursor getCountItemBarcode(String ponumber,String barcode) {
            return database.rawQuery(
                 "SELECT * FROM " + TABLE_NAME+" WHERE " +PONUMBER+ " ='"
                 +ponumber+"'"
                 +" AND "+ITEMBARCODE+" ='"+barcode+"'",
                 null);
        }
        
        public Cursor getPOItemLocation(String po,String idim) {
          //  String query= "SELECT * FROM "+TABLE_NAME+" where "+ PONUMBER+"='"+PO+"' and "+ SKU+"='"+PSKU+"'and "+ LOCATION+"='"+LOC+"' LIMIT 1";
        	String query= "SELECT * FROM "+TABLE_NAME+" where "+ INVENTDIMID+"='"+idim+"'and "+ PONUMBER+"='"+po+"' LIMIT 1";
            return database.rawQuery(query,null);
            }*/
   
        public Cursor getItemByID(String ID) {
            String query= "SELECT * FROM "+TABLE_NAME+" where "+ ORDER_QUARANTINE_ID+"='"+ID+"'";
            return database.rawQuery(query,null);
            }
        public Cursor getItemDetail2(String sku) {
            String query= "SELECT * FROM "+TABLE_NAME+" where  "+ ITEMID+"='"+sku+"' ";
            return database.rawQuery(query,null);
            }
     
        /*public Cursor getItemDetail(String ponumber,String inventdim,String sku,String orderid) {
            String query= "SELECT * FROM "+TABLE_NAME+" where "+ PONUMBER+"='"+ponumber+"' AND "+ INVENTDIMID+"='"+inventdim+"' AND "+ SKU+"='"+sku+"' AND "+ ORDERID+"='"+orderid+"'";
            return database.rawQuery(query,null);
            }*/
        
        /*public Cursor getItemPosition(String ponumber,String sku,String location) {
            String query= "SELECT * FROM "+TABLE_NAME+" where "+ PONUMBER+"='"+ponumber+"' AND "+  SKU+"='"+sku+"' AND "+ LOCATION+"='"+location+"'";
            return database.rawQuery(query,null);
            }*/
        
        /*public Cursor getNonScannedItemsPerPO(String PO) {
             String query= "SELECT * FROM "+TABLE_NAME+" where "+SCANNED+"='"+0+"' and "+ PONUMBER+"='"+PO+"' LIMIT 1";
        	//  String query= "SELECT * FROM "+TABLE_NAME+" where "+SCANNED+"='"+0+"' LIMIT 1";
            return database.rawQuery(query,null);
            }*/
        
        /*public Cursor getPickingItemBarcode(String PO,String barcode) {
            return database.rawQuery(
                "SELECT * FROM " + TABLE_NAME+" WHERE " +PONUMBER+ " ='"
                +PO+"' AND "+ITEMBARCODE+" ='"+barcode+"'",
         //       "SELECT * FROM " + TABLE_NAME+" WHERE "+
        //        ITEMBARCODE+" ='"+barcode+"'",
                 null);
        }*/
        
        private class ContactOpenHelper extends SQLiteOpenHelper {

                public ContactOpenHelper(Context context) {
                        super(context, DATABASE_NAME, null, DATABASE_VERSION);
                }
                
                @Override
                public void onCreate(SQLiteDatabase database) {
                        database.execSQL("CREATE TABLE " + TABLE_NAME + "("
                                        + ORDER_QUARANTINE_ID + " INTEGER PRIMARY KEY, "
                                        + ITEMID + " TEXT, "
                                        + QTY + " TEXT, "
                                        + TRANSTYPE + " TEXT, "
                                        + STATUSRECEIPT + " TEXT, "
                                        + DATAAREAID + " TEXT)");    

                }
                @Override
                public void onUpgrade(SQLiteDatabase database, int oldVersion, int newVersion) {
                        database.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME + "");
                        onCreate(database);
                }

        }

}

