/// <summary> /// Calling this method automatically opened the indicated form as a Mdi child form in the main form tabs. /// Exposes a way to open the Catalogue Form from a Project outside of CDS.Client.Desktop.Catalogue /// </summary> /// <param name="form">The form control to be displayed in the tabs.</param> /// <remarks>Created: Theo Crous 14/11/2011</remarks> public void ShowCatalogueForm(DB.VW_Company entity, CDS.Client.BusinessLayer.ORG.ORG_Type type, CDS.Client.Desktop.Essential.BaseForm form) { CDS.Client.Desktop.Catalogue.CAT.CatalogueForm childForm = new Catalogue.CAT.CatalogueForm(); childForm.Entity = entity; childForm.Type = type; childForm.Tag = form; ShowForm(childForm); }
/// <summary> /// This method is called to show a form in the MainForm as a MDIChildform /// http://www.codeproject.com/Articles/9162/Invoking-methods-Runtime-on-method-name /// </summary> /// <remarks>Created: Werner Scheffer 06/11/2014</remarks> /// <param name="form">DevExpress Form to show</param> public void ShowCatalogueForm(DB.VW_Company entity, CDS.Client.BusinessLayer.ORG.ORG_Type type, BaseForm form) { var mainform = Application.OpenForms["MainForm"]; Type typExternal = mainform.GetType(); MethodInfo methodInf = typExternal.GetMethod("ShowCatalogueForm"); methodInf.Invoke(mainform, new object[] { entity, type, form }); }
protected override void Archive() { base.Archive(); DB.SYS_Entity sysEntity = (DB.SYS_Entity)BindingSourceORGEntitySYSEntity.DataSource; if (sysEntity.Archived) { sysEntity.Archived = !sysEntity.Archived; } else { DB.VW_Company vwCompany = DataContext.ReadonlyContext.VW_Company.FirstOrDefault(n => n.EntityId == sysEntity.Id); if (DataContext.EntityAccountingContext.GLX_History.Any(n => n.EntityId == sysEntity.Id && n.Amount != 0)) { Essential.BaseAlert.ShowAlert("Archive", "This company can not be archive." + Environment.NewLine + "\t• Account has outstanding balances.", Essential.BaseAlert.Buttons.Ok, Essential.BaseAlert.Icons.Information); } } btnArchive.Caption = sysEntity.Archived ? "Un-Archive" : "Archive"; try { using (TransactionScope transaction = DataContext.GetTransactionScope()) { DataContext.SaveChangesEntitySystemContext(); DataContext.CompleteTransaction(transaction); } DataContext.EntitySystemContext.AcceptAllChanges(); } catch (Exception ex) { DataContext.EntitySystemContext.RejectChanges(); HasErrors = true; if (CDS.Shared.Exception.UserInterfaceExceptionHandler.HandleException(ref ex)) { throw ex; } } }
/// <summary> /// Creates Quote from Job /// </summary> /// <param name="entity"></param> /// <returns></returns> public static DB.SYS_DOC_Header CreateSalesOrderFromJob(DB.SYS_DOC_Header entity, DataContext dataContext) { DB.SYS_DOC_Header docHeader = CopyDocument(entity, dataContext); docHeader.TypeId = (byte)SYS.SYS_DOC_Type.SalesOrder; docHeader.ORG_TRX_Header = ORG.ORG_TRX_Header.New; docHeader.ORG_TRX_Header.CompanyId = docHeader.JOB_Header.CompanyId; docHeader.ORG_TRX_Header.Telephone = docHeader.JOB_Header.Telephone; docHeader.ORG_TRX_Header.ContactPerson = docHeader.JOB_Header.ContactPerson; docHeader.ORG_TRX_Header.ContactTelephone = docHeader.JOB_Header.ContactTelephone; docHeader.ORG_TRX_Header.ReferenceShort1 = docHeader.JOB_Header.ReferenceShort1; docHeader.ORG_TRX_Header.ReferenceShort2 = docHeader.JOB_Header.ReferenceShort2; docHeader.ORG_TRX_Header.ReferenceShort3 = docHeader.JOB_Header.ReferenceShort3; docHeader.ORG_TRX_Header.ReferenceShort4 = docHeader.JOB_Header.ReferenceShort4; docHeader.ORG_TRX_Header.ReferenceShort5 = docHeader.JOB_Header.ReferenceShort5; docHeader.ORG_TRX_Header.ReferenceLong1 = docHeader.JOB_Header.ReferenceLong1; docHeader.ORG_TRX_Header.ReferenceLong2 = docHeader.JOB_Header.ReferenceLong2; docHeader.ORG_TRX_Header.ReferenceLong3 = docHeader.JOB_Header.ReferenceLong3; docHeader.ORG_TRX_Header.ReferenceLong4 = docHeader.JOB_Header.ReferenceLong4; docHeader.ORG_TRX_Header.ReferenceLong5 = docHeader.JOB_Header.ReferenceLong5; docHeader.ORG_TRX_Header.ShippingAddressLine1 = docHeader.JOB_Header.ShippingAddressLine1; docHeader.ORG_TRX_Header.ShippingAddressLine2 = docHeader.JOB_Header.ShippingAddressLine2; docHeader.ORG_TRX_Header.ShippingAddressLine3 = docHeader.JOB_Header.ShippingAddressLine3; docHeader.ORG_TRX_Header.ShippingAddressLine4 = docHeader.JOB_Header.ShippingAddressLine4; docHeader.ORG_TRX_Header.ShippingAddressCode = docHeader.JOB_Header.ShippingAddressCode; docHeader.ORG_TRX_Header.BillingAddressLine1 = docHeader.JOB_Header.BillingAddressLine1; docHeader.ORG_TRX_Header.BillingAddressLine2 = docHeader.JOB_Header.BillingAddressLine2; docHeader.ORG_TRX_Header.BillingAddressLine3 = docHeader.JOB_Header.BillingAddressLine3; docHeader.ORG_TRX_Header.BillingAddressLine4 = docHeader.JOB_Header.BillingAddressLine4; docHeader.ORG_TRX_Header.BillingAddressCode = docHeader.JOB_Header.BillingAddressCode; DB.VW_Company company = dataContext.ReadonlyContext.VW_Company.FirstOrDefault(n => n.Id == docHeader.ORG_TRX_Header.CompanyId); foreach (DB.SYS_DOC_Line line in docHeader.SYS_DOC_Line) { decimal sellPrice = 0, discountPrice = 0, discountPercentage = 0; if ((new byte[] { (byte)SYS.SYS_Type.Inventory, (byte)SYS.SYS_Type.BuyOut }).Contains(line.LineItem.TypeId)) { ORG.ORG_TRX_PriceHelper.GetSellPrice(line, company, line.Quantity, true, out sellPrice, out discountPrice, out discountPercentage, dataContext); line.Amount = discountPrice; line.DiscountPercentage = discountPercentage; } line.Total = Math.Round(line.Amount * (line.LineItem.TypeId == (byte)SYS.SYS_Type.Account ? 1 : line.Quantity), 2, MidpointRounding.AwayFromZero); //line.ProfitPercentage = (line.Amount > 0) ? (line.Amount - line.UnitAverage) / line.Amount : 0M; switch (company.CostCategoryId) { case (byte)ORG.ORG_CostCategory.SellingPriceIncludingSalesTax: line.TotalTax = line.Total * ApplicationDataContext.Instance.CompanySite.VatPercentage / 100; break; case (byte)ORG.ORG_CostCategory.SellingPriceExcludingSalesTax: line.TotalTax = 0; break; case (byte)ORG.ORG_CostCategory.CostIncludingSalesTax: line.TotalTax = line.Total * ApplicationDataContext.Instance.CompanySite.VatPercentage / 100; break; case (byte)ORG.ORG_CostCategory.CostExcludingSalesTax: line.TotalTax = 0; break; case (byte)ORG.ORG_CostCategory.AverageCostExcludingSalesTax: line.TotalTax = 0; break; } line.TotalTax = Math.Round(line.TotalTax, 2, MidpointRounding.AwayFromZero); line.FromJob = true; } docHeader.Generated = true; return(docHeader); }
public static void GetSellPrice(DB.SYS_DOC_Line line, DB.VW_Company entity, decimal amount, bool useWarehouseDiscount, out decimal sellPrice, out decimal discountPrice, out decimal discountPercentage, DataContext dataContext) { if (line == null || line.LineItem == null || (line.LineItem as DB.VW_LineItem).InventoryId == null) { sellPrice = line.Amount; discountPrice = line.Amount; discountPercentage = 0M; return; } sellPrice = line.Amount; discountPrice = 0M; discountPercentage = 0M; if ((entity == null)) { // NO entity SELECTED //sellPrice = inventoryItem.UnitPrice; return; } DB.VW_LineItem inventory = line.LineItem as DB.VW_LineItem; var discounts = dataContext.ReadonlyContext.VW_Discount.Where(n => (n.CompanyDiscountCode == entity.DiscountCode || n.EntityId == entity.OrgEntityId) && (n.InventoryDiscountCode == inventory.DiscountCode || n.InventoryId == inventory.InventoryId)).ToList(); //If any of the discounts are fixed price discounts if (discounts.Any(n => n.DiscountAmountTypeId == (byte)BL.ITM.ITM_DIS_AmountType.FixedPriceDiscount)) { if (!useWarehouseDiscount) { sellPrice = discounts.Min(n => n.CompanyDiscount).Value; } else { sellPrice = discounts.Min(n => n.WorkshopDiscount).Value; } discountPrice = sellPrice; discountPercentage = 0; return; } else { //Henko: I am pretty sure if anything this should be MIN not MAX? But either way this is really badly done... if (!useWarehouseDiscount) { discountPercentage = discounts.Count() > 0 ? discounts.Max(n => n.CompanyDiscount).Value : 0; } else { discountPercentage = discounts.Count() > 0 ? discounts.Max(n => n.WorkshopDiscount).Value : 0; } } if ((entity.CostCategoryId == (byte)BL.ORG.ORG_CostCategory.CostExcludingSalesTax) || (entity.CostCategoryId == (byte)BL.ORG.ORG_CostCategory.CostIncludingSalesTax)) { // COST INCLUDING or COST EXCLUDING if (discountPercentage < 0) { discountPrice = inventory.UnitCost - (inventory.UnitCost * discountPercentage / 100); sellPrice = inventory.UnitCost; } else { discountPrice = (inventory.UnitCost * (100 - discountPercentage)) / 100; sellPrice = inventory.UnitCost; } //sellPrice = line.UnitCost; return; } else if (entity.CostCategoryId == (byte)BL.ORG.ORG_CostCategory.AverageCostExcludingSalesTax) { // AVG COST EXCLUDING if (discountPercentage < 0) { discountPrice = inventory.UnitAverage - (line.UnitAverage * discountPercentage / 100); sellPrice = inventory.UnitAverage; } else { discountPrice = (inventory.UnitAverage * (100 - discountPercentage)) / 100; sellPrice = inventory.UnitAverage; } //sellPrice = line.UnitAverage; return; } else if ((entity.CostCategoryId == (byte)BL.ORG.ORG_CostCategory.SellingPriceExcludingSalesTax) || (entity.CostCategoryId == (byte)BL.ORG.ORG_CostCategory.SellingPriceIncludingSalesTax)) { // SELLING PRICE INCLUDING or SELLING PRICE EXCLUDING if (discountPercentage < 0) { discountPrice = inventory.UnitPrice - (inventory.UnitPrice * discountPercentage / 100); sellPrice = inventory.UnitPrice; } else { discountPrice = (inventory.UnitPrice * (100 - discountPercentage)) / 100; sellPrice = inventory.UnitPrice; } //sellPrice = line.UnitAverage; return; } }