public virtual void DeleteBillItem(DevExpress.Xpo.Session session, Guid billItemId) { try { NAS.DAL.Invoice.BillItem billItem = session.GetObjectByKey <NAS.DAL.Invoice.BillItem>(billItemId); Bill bill = billItem.BillId; if (billItem == null) { return; } billItem.Delete(); //Update totalprice bill.SumOfItemPrice = bill.BillItems.Sum(r => r.TotalPrice); bill.Save(); if (bill.PromotionCalculationType.Equals(Utility.Constant.CALCULATION_TYPE_ON_ITEMS)) { UpdatePromotionOnItems(session, bill.BillId); } UpdateSumOfTax(session, bill); #region Update bill Total bill.Total = bill.SumOfItemPrice - bill.SumOfPromotion + bill.SumOfTax; bill.Save(); #endregion Update bill Total } catch (Exception) { throw; } }
public virtual void UpdateBillItem( DevExpress.Xpo.Session session, Guid billItemId, Guid itemId, Guid unitId, double quantity, double price, double promotionInPercentage, string comment) { try { NAS.DAL.Invoice.BillItem billItem = session.GetObjectByKey <NAS.DAL.Invoice.BillItem>(billItemId); if (billItem == null) { throw new Exception("Could not found specific bill item"); } //Get ItemUnit Item item = session.GetObjectByKey <Item>(itemId); Unit unit = session.GetObjectByKey <Unit>(unitId); ItemUnit itemUnit = session.FindObject <ItemUnit>( CriteriaOperator.And( new BinaryOperator("ItemId", item), new BinaryOperator("UnitId", unit), CriteriaOperator.Or( new BinaryOperator("RowStatus", Utility.Constant.ROWSTATUS_ACTIVE), new BinaryOperator("RowStatus", Utility.Constant.ROWSTATUS_DEFAULT) ) )); if (itemUnit == null) { throw new Exception("Could not found item unit"); } billItem.Comment = comment; //Currency billItem.ItemUnitId = itemUnit; billItem.Price = price; billItem.PromotionInNumber = promotionInPercentage != -1 ? (price * quantity * promotionInPercentage) / 100 : 0; billItem.PromotionInPercentage = promotionInPercentage; billItem.Quantity = quantity; billItem.TotalPrice = price * quantity; session.Delete(billItem.BillItemTaxs); billItem.Save(); //update SumOfItemPrice Bill bill = billItem.BillId; bill.SumOfItemPrice = bill.BillItems.Sum(r => r.TotalPrice); bill.Save(); if (billItem.BillId.PromotionCalculationType.Equals(Utility.Constant.CALCULATION_TYPE_ON_ITEMS)) { UpdatePromotionOnItems(session, billItem.BillId.BillId); } //Insert into BillItemTax... //Get VAT TaxType of Item ItemBO itemBO = new ItemBO(); ItemTax itemTax = itemBO.GetCurrentVATOfItem(session, itemId); if (itemTax != null) { BillItemTax billItemTax = new BillItemTax(session) { BillItemId = billItem, ItemTaxId = itemTax, TaxInNumber = itemTax.TaxId.Amount, TaxInPercentage = itemTax.TaxId.Percentage }; billItemTax.Save(); } UpdateSumOfTax(session, bill); #region Update bill Total bill.Total = bill.SumOfItemPrice - bill.SumOfPromotion + bill.SumOfTax; bill.Save(); #endregion Update bill Total } catch (Exception ex) { throw; } }