// delete selling bill public int deletesllingBill(int id, string s) { if (s == "no") { try { Selling_Bill c = db.Selling_Bill.Find(id); db.Selling_Bill.Remove(c); db.SaveChanges(); return(1); } catch (Exception e) { Console.Write(e.StackTrace); return(0); } } else if (s == "yes") { try { Selling_Bill c = db.Selling_Bill.Find(id); Customer cu = db.Customers.Find(c.cust_id); List <Dead_Products> dp = db.Dead_Products.Where(a => a.bill_id == c.bill_id).ToList(); if (dp.Count == 0) { cu.cust_balance -= c.total - c.bill_paid; cust.updateCutomer(cu); var li = db.Selling_Bill_Details.Where(a => a.bill_id == c.bill_id).ToList(); foreach (var i in li) { Product p = db.Products.Find(i.product_id); p.product_quantity += i.product_quantity; } db.Selling_Bill.Remove(c); db.SaveChanges(); return(1); } else { MessageBox.Show("هذه الفاتوره عليها مرتجعات ولا يمكن حذفها"); return(0); } } catch (Exception e) { Console.Write(e.StackTrace); return(0); } } else { return(0); } }
public int updateSellingBil(Selling_Bill sb) { try { Selling_Bill b = db.Selling_Bill.Find(sb.bill_id); b.total = sb.total; db.SaveChanges(); return(1); } catch { return(0); } }
//create dead product public int createDeadProduct(DeadProductDto dead) { Dead_Products d = new Dead_Products(); d.bill_id = dead.sillingBillId; d.note = dead.note; d.quantity = dead.quntity; d.user_id = user.getUserIdByName(dead.user_name.Trim()); d.product_id = pdal.getProductIdByName(dead.name.Trim()); d.process_date = dead.processDate; Selling_Bill_Details billDetails = sdal.getBillDetailsByBillId(dead.sillingBillId, d.product_id); Selling_Bill bil = sdal.getSellingBillByid(dead.sillingBillId); Customer cu = cdal.getCustomerById(bil.cust_id); //to do edit bill and client balance try { // MessageBox.Show(bil.cust_id + " " + cu.cust_id); if (d.quantity <= billDetails.product_quantity) { Product p = pdal.getProductById(dead.name.Trim()); p.product_quantity += dead.quntity; billDetails.product_quantity -= dead.quntity; // billDetails.product_price -= dead.quntity * p.product_price; bil.total -= dead.quntity * (billDetails.product_price - billDetails.profuct_discount); cu.cust_balance -= dead.quntity * (billDetails.product_price - billDetails.profuct_discount); cdal.updateCutomer(cu); sdal.updateSellingBil(bil); sdal.updateSellingBillDetails(billDetails); pdal.updateProduct(p); db.Dead_Products.Add(d); db.SaveChanges(); return(1); } else { return(0); } } catch { return(0); } }
public int createSillingBill(List <Util.SillBillDetails> l, Selling_Bill s) { List <Selling_Bill_Details> li = new List <Selling_Bill_Details>(); foreach (var i in l) { Selling_Bill_Details sbd = new Selling_Bill_Details(); sbd.bill_id = s.bill_id; sbd.product_id = pdal.getProductIdByName(i.Product_name); sbd.product_quantity = i.Product_quent; sbd.profuct_discount = i.Product_dicound; sbd.product_price = i.Product_price; li.Add(sbd); } return(sdal.createSillingBill(s, li));; }
//create new bill public int createSillingBill(Selling_Bill s, List <Selling_Bill_Details> li) { try { db.Selling_Bill.Add(s); var cu = db.Customers.Find(s.cust_id); cu.cust_balance += s.total - s.bill_paid; foreach (var i in li) { db.Selling_Bill_Details.Add(i); var pro = db.Products.First(a => a.product_id == i.product_id); pro.product_quantity -= i.product_quantity; } db.SaveChanges(); return(1); } catch (Exception e) { Console.Write(e.StackTrace); return(0); } }