protected override void CloneBillItemData(Session session, Guid billId, ref Bill ret) { NAS.DAL.Invoice.SalesInvoice source = session.GetObjectByKey <NAS.DAL.Invoice.SalesInvoice>(billId); var sourceBillItemList = source.BillItems.Where(r => r.RowStatus == Utility.Constant.ROWSTATUS_ACTIVE); if (sourceBillItemList == null) { return; } foreach (var sourceBillItem in sourceBillItemList) { //Clone BillItem BillItem billItem = new BillItem(session) { BillId = ret, Comment = sourceBillItem.Comment, Currency = sourceBillItem.Currency, ItemId = sourceBillItem.ItemId, ItemUnitId = sourceBillItem.ItemUnitId, LotId = sourceBillItem.LotId, Price = sourceBillItem.Price, PromotionInNumber = sourceBillItem.PromotionInNumber, PromotionInPercentage = sourceBillItem.PromotionInPercentage, Quantity = sourceBillItem.Quantity, RowStatus = sourceBillItem.RowStatus, TotalPrice = sourceBillItem.TotalPrice, UnitId = sourceBillItem.UnitId }; billItem.Save(); //Clone BillItemTax foreach (var sourceBillItemTax in sourceBillItem.BillItemTaxs) { BillItemTax billItemTax = new BillItemTax(session) { BillItemId = billItem, ItemTaxId = sourceBillItemTax.ItemTaxId, TaxInNumber = sourceBillItemTax.TaxInNumber, TaxInPercentage = sourceBillItemTax.TaxInPercentage }; billItemTax.Save(); } } }
public BillItemTax BillItemTaxInit(Session session, BillItem BillItemId, Guid BillItemTaxId, ItemTax ItemTaxId, double TaxInPercentage, double TaxInNumber ) { BillItemTax billItemTax = session.GetObjectByKey <BillItemTax>(BillItemTaxId); if (billItemTax == null) { billItemTax = new BillItemTax(session); billItemTax.BillItemTaxId = BillItemTaxId; } billItemTax.BillItemId = BillItemId; billItemTax.TaxInNumber = TaxInNumber; billItemTax.TaxInPercentage = TaxInPercentage; billItemTax.ItemTaxId = ItemTaxId; return(billItemTax); }
protected void gridviewBillItem_CustomColumnDisplayText(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewColumnDisplayTextEventArgs e) { if (e.Column.FieldName.Equals("UnitId!Key")) { if (e.Value == null || e.Value == DBNull.Value) { return; } NAS.DAL.Nomenclature.Item.Unit unit = session.GetObjectByKey <NAS.DAL.Nomenclature.Item.Unit>(e.Value); e.DisplayText = String.Format("{0} - {1}", unit.Code, unit.Name); } else if (e.Column.FieldName.Equals("PromotionInPercentage")) { var billId = gridviewBillItem.GetRowValues(e.VisibleRowIndex, "BillId!Key"); if (billId == null) { return; } Bill bill = session.GetObjectByKey <Bill>(billId); if (bill.PromotionCalculationType.Equals(Utility.Constant.CALCULATION_TYPE_ON_ITEMS)) { if (e.Value == null || e.Value == DBNull.Value) { return; } double promotionInPercentage = (double)e.Value; if (promotionInPercentage == -1) { e.DisplayText = "N/A"; } else { e.DisplayText = promotionInPercentage.ToString(); } } else if (bill.PromotionCalculationType.Equals(Utility.Constant.CALCULATION_TYPE_ON_BILL_BY_AMOUNT) || bill.PromotionCalculationType.Equals(Utility.Constant.CALCULATION_TYPE_ON_BILL_BY_PERCENTAGE)) { e.DisplayText = "N/A"; e.Column.CellStyle.BackColor = System.Drawing.ColorTranslator.FromHtml("#EFEFEF"); } } else if (e.Column.Name.Equals("VATInPercentage")) { var val = gridviewBillItem.GetRowValues(e.VisibleRowIndex, "BillItemId"); if (val == null) { return; } BillItem billItem = session.GetObjectByKey <BillItem>(val); BillItemTax billItemTax = billItem.BillItemTaxs.FirstOrDefault(); if (billItemTax != null) { e.DisplayText = billItemTax.TaxInPercentage.ToString(); } else { e.DisplayText = "N/A"; } } }
protected void grdPurchase_CustomCallback(object sender, ASPxGridViewCustomCallbackEventArgs e) { string[] p = e.Parameters.Split('|'); switch (p[0]) { case "copy": Guid id = Guid.Parse(p[1].ToString()); Bill bill = session.GetObjectByKey <Bill>(id); if (bill != null) { ArtifactCodeRuleBO artifactCodeRuleBO = new ArtifactCodeRuleBO(); Bill billCopy = new Bill(session); billCopy.BillId = new Guid(); billCopy.Code = bill.Code + "_copy"; billCopy.RowStatus = 1; billCopy.TargetOrganizationId = bill.TargetOrganizationId; billCopy.SourceOrganizationId = bill.SourceOrganizationId; CriteriaOperator filter = new BinaryOperator("Code", billCopy.Code, BinaryOperatorType.Equal); Bill billTest = session.FindObject <Bill>(filter); if (billTest == null) { billCopy.Save(); } else { grdPurchase.JSProperties.Add("cpCopyFailed", billCopy.Code); return; } filter = new BinaryOperator("BillId", id, BinaryOperatorType.Equal); XPCollection <BillActor> collectBillActor = new XPCollection <BillActor>(session, filter); foreach (BillActor ba in collectBillActor) { BillActor billActor = new BillActor(session); billActor.BillId = billCopy; billActor.BillActorId = Guid.NewGuid(); billActor.BillActorTypeId = ba.BillActorTypeId; billActor.OrganizationId = ba.OrganizationId; billActor.PersonId = ba.PersonId; billActor.Save(); } filter = new BinaryOperator("BillId", id, BinaryOperatorType.Equal); XPCollection <BillItem> collectBillItem = new XPCollection <BillItem>(session, filter); foreach (BillItem bi in collectBillItem) { BillItem billItem = new BillItem(session); billItem.BillId = billCopy; billItem.RowStatus = 1; billItem.BillItemId = bi.BillItemId; billItem.LotId = bi.LotId; billItem.Price = bi.Price; billItem.PromotionInNumber = bi.PromotionInNumber; billItem.PromotionInPercentage = bi.PromotionInPercentage; billItem.Quantity = bi.Quantity; billItem.TotalPrice = bi.TotalPrice; billItem.Save(); filter = new BinaryOperator("BillItemId", id, BinaryOperatorType.Equal); XPCollection <BillItemTax> collectBillItemTax = new XPCollection <BillItemTax>(session, filter); foreach (BillItemTax bit in collectBillItemTax) { BillItemTax billItemTax = new BillItemTax(session); billItemTax.BillItemId = billItem; billItemTax.BillItemTaxId = Guid.NewGuid(); billItemTax.ItemTaxId = bit.ItemTaxId; billItemTax.TaxInNumber = bit.TaxInNumber; billItemTax.TaxInPercentage = bit.TaxInPercentage; billItemTax.Save(); } } grdPurchase.JSProperties.Add("cpRefresh", billCopy.Code); } break; default: break; } }
public virtual void CreateBillItem( DevExpress.Xpo.Session session, Guid billId, Guid itemId, Guid unitId, double quantity, double price, double promotionInPercentage, string comment) { try { NAS.DAL.Invoice.Bill bill = session.GetObjectByKey <NAS.DAL.Invoice.Bill>(billId); if (bill == null) { throw new Exception("Could not found specific bill"); } //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 billItem = new BillItem(session) { BillId = bill, Comment = comment, //Currency ItemUnitId = itemUnit, Price = price, PromotionInNumber = promotionInPercentage != -1 ? (price * quantity * promotionInPercentage) / 100 : 0, PromotionInPercentage = promotionInPercentage, Quantity = quantity, RowStatus = Utility.Constant.ROWSTATUS_ACTIVE, TotalPrice = price * quantity }; billItem.Save(); //update SumOfItemPrice bill.SumOfItemPrice = bill.BillItems.Sum(r => r.TotalPrice); bill.Save(); if (bill.PromotionCalculationType.Equals(Utility.Constant.CALCULATION_TYPE_ON_ITEMS)) { UpdatePromotionOnItems(session, 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; } }