1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
public Invoice getInvoice(SQLiteDatabase db, Long inid){
Cursor cursor = db.rawQuery("SELECT * FROM invoice WHERE _id = ?", new String[]{inid.toString()});
if (cursor != null){
cursor.moveToFirst();
long rowcount = cursor.getCount();
if (rowcount > 0 && cursor.getColumnCount()>0) {
Invoice ret = new Invoice();
ret.setId(cursor.getLong(0));
ret.setInvoiceNumber(cursor.getLong(1));
ret.setCustomerId(cursor.getLong(2));
ret.setPayerId(cursor.getLong(3));
ret.setCustomerName(cursor.getString(4));
ret.setWorkDescription(cursor.getString(5));
ret.setDate(cursor.getLong(6));
ret.setDateAccessed(cursor.getLong(7));
ret.setDateModified(cursor.getLong(8));
ret.setDateScheduled(cursor.getLong(9));
ret.setAutoPartPrice(cursor.getDouble(10));
ret.setAutoLaborPrice(cursor.getDouble(11));
ret.setAutoOtherPrice(cursor.getDouble(12));
ret.setAutoTotalPrice(cursor.getDouble(13));
ret.setAutoTaxA(cursor.getDouble(14));
ret.setAutoTaxB(cursor.getDouble(15));
ret.setUserPartPrice(cursor.getDouble(16));
ret.setUserLaborPrice(cursor.getDouble(17));
ret.setUserOtherPrice(cursor.getDouble(18));
ret.setUserTotalPrice(cursor.getDouble(19));
ret.setUserTaxA(cursor.getDouble(20));
ret.setUserTaxB(cursor.getDouble(21));
ret.setStatusId(cursor.getLong(22));
return ret;
}
}
return null;
}
public void saveInvoice(SQLiteDatabase db, Invoice item, boolean forceInsert){
ContentValues values = new ContentValues();
values.put(DbContract.InvoiceEntry.COLUMN_NAME_ID.toString(),item.getId());
values.put(DbContract.InvoiceEntry.COLUMN_NAME_INVOICE_NUMBER.toString(),item.getInvoiceNumber());
values.put(DbContract.InvoiceEntry.COLUMN_NAME_CUSTOMER_ID.toString(),item.getCustomerId());
values.put(DbContract.InvoiceEntry.COLUMN_NAME_PAYER_ID.toString(),item.getPayerId());
values.put(DbContract.InvoiceEntry.COLUMN_NAME_CUSTOMER_NAME.toString(),item.getCustomerName());
values.put(DbContract.InvoiceEntry.COLUMN_NAME_WORK_DESCRIPTION.toString(),item.getWorkDescription());
values.put(DbContract.InvoiceEntry.COLUMN_NAME_DATE.toString(),item.getDate());
values.put(DbContract.InvoiceEntry.COLUMN_NAME_DATE_ACCESSED.toString(),item.getDateAccessed());
values.put(DbContract.InvoiceEntry.COLUMN_NAME_DATE_MODIFIED.toString(),item.getDateModified());
values.put(DbContract.InvoiceEntry.COLUMN_NAME_DATE_SCHEDULED.toString(),item.getDateScheduled());
values.put(DbContract.InvoiceEntry.COLUMN_NAME_AUTO_PART_PRICE.toString(),item.getAutoPartPrice());
values.put(DbContract.InvoiceEntry.COLUMN_NAME_AUTO_LABOR_PRICE.toString(),item.getAutoLaborPrice());
values.put(DbContract.InvoiceEntry.COLUMN_NAME_AUTO_OTHER_PRICE.toString(),item.getAutoOtherPrice());
values.put(DbContract.InvoiceEntry.COLUMN_NAME_AUTO_TOTAL_PRICE.toString(),item.getAutoTotalPrice());
values.put(DbContract.InvoiceEntry.COLUMN_NAME_AUTO_TAX_A.toString(),item.getAutoTaxA());
values.put(DbContract.InvoiceEntry.COLUMN_NAME_AUTO_TAX_B.toString(),item.getAutoTaxB());
values.put(DbContract.InvoiceEntry.COLUMN_NAME_USER_PART_PRICE.toString(),item.getUserPartPrice());
values.put(DbContract.InvoiceEntry.COLUMN_NAME_USER_LABOR_PRICE.toString(),item.getUserLaborPrice());
values.put(DbContract.InvoiceEntry.COLUMN_NAME_USER_OTHER_PRICE.toString(),item.getUserOtherPrice());
values.put(DbContract.InvoiceEntry.COLUMN_NAME_USER_TOTAL_PRICE.toString(),item.getUserTotalPrice());
values.put(DbContract.InvoiceEntry.COLUMN_NAME_USER_TAX_A.toString(),item.getUserTaxA());
values.put(DbContract.InvoiceEntry.COLUMN_NAME_USER_TAX_B.toString(),item.getUserTaxB());
values.put(DbContract.InvoiceEntry.COLUMN_NAME_STATUS_ID.toString(),item.getStatusId());
if (item.getId()==null||forceInsert){
long nid = db.insert(DbContract.InvoiceEntry.TABLE_NAME,null,values);
item.setId(nid);
}
else{
db.update(DbContract.InvoiceEntry.TABLE_NAME,values,"_id=?",new String[]{item.getId().toString()});
}
}
public void saveInvoice(SQLiteDatabase db, Invoice item){
saveInvoice(db,item,false);
}
|