//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: //Helper for Create DocumentFinanceSeries & DocumentFinanceYearSerieTerminal //Used to generate Series Preview, or to Process Series in Database public static FrameworkCallsResult CreateDocumentFinanceYearSeriesTerminal(fin_documentfinanceyears pDocumentFinanceYears, DataTable pTerminals, string pAcronym, bool pPreviewMode) { FrameworkCallsResult result = new FrameworkCallsResult(); uint ordAndCode = 10; uint ordAndCodeInc = 10; int terminalInc = 1; string acronymPrefix = String.Empty, acronym, designation, output = String.Empty, acronymAudit; Dictionary <string, string> acronymPrefixCreatedSeries = new Dictionary <string, string>(); fin_documentfinanceseries documentFinanceSeries = null; //Used to add DocumentFinanceYearSerieTerminal to list to delete outside of Loop List <fin_documentfinanceyearserieterminal> listDeleteSerieTerminal = new List <fin_documentfinanceyearserieterminal>(); //Start UnitOfWork using (UnitOfWork uowSession = new UnitOfWork()) { try { //Get Object in UOW Session fin_documentfinanceyears documentFinanceYears = (fin_documentfinanceyears)FrameworkUtils.GetXPGuidObject(uowSession, typeof(fin_documentfinanceyears), pDocumentFinanceYears.Oid); //Initialize DocumentFinanceType Collection : Criteria/XPCollection/Model : Use Default Filter CriteriaOperator criteria = CriteriaOperator.Parse("(Disabled = 0 OR Disabled IS NULL)"); //Configure SortProperty SortProperty sortProperty = new SortProperty("Ord", DevExpress.Xpo.DB.SortingDirection.Ascending); //Init Collection XPCollection xpDocumentFinanceType = new XPCollection(uowSession, typeof(fin_documentfinancetype), criteria, sortProperty); //Loop Terminals foreach (DataRow terminal in pTerminals.Rows) { //Disable Series and Delete SerieTerminal for selected Terminal if (!pPreviewMode) { //Initialize DocumentFinanceYearSerieTerminal Collection : Criteria/XPCollection/Model : Use Default Filter + Terminal criteria = CriteriaOperator.Parse(string.Format("(Disabled = 0 OR Disabled IS NULL) AND (Terminal = '{0}')", terminal["Oid"])); //Init Collection XPCollection xpDocumentFinanceYearSerieTerminal = new XPCollection(uowSession, typeof(fin_documentfinanceyearserieterminal), criteria); //Loop DocumentFinanceYearSerieTerminal and Parent DocumentFinanceYearSerie and Delete foreach (fin_documentfinanceyearserieterminal documentFinanceYearSerieTerminal in xpDocumentFinanceYearSerieTerminal) { if (_debug) { _log.Debug(string.Format("Disabled documentFinanceYearSerie: [{0}]", documentFinanceYearSerieTerminal.Serie.Designation)); } documentFinanceYearSerieTerminal.Serie.Disabled = true; //documentFinanceYearSerieTerminal.Disabled = true; //Add to Post Loop Deletion listDeleteSerieTerminal.Add(documentFinanceYearSerieTerminal); } //Now we can delete, Outside of Loop foreach (fin_documentfinanceyearserieterminal deleteSerieTerminal in listDeleteSerieTerminal) { if (_debug) { _log.Debug(string.Format("Deleted documentFinanceYearSerieTerminal: [{0}]", deleteSerieTerminal.Designation)); } deleteSerieTerminal.Delete(); } } //Add to Output if (pPreviewMode) { output += string.Format("{0}{1}", terminal["Designation"], Environment.NewLine); } //Get Current Terminal Object pos_configurationplaceterminal configurationPlaceTerminal = (pos_configurationplaceterminal)uowSession.GetObjectByKey(typeof(pos_configurationplaceterminal), new Guid(terminal["Oid"].ToString())); //Create DocumentFinanceSeries Acronym From Date DateTime now = FrameworkUtils.CurrentDateTimeAtomic(); //AcronymPrefix ex FT[QN3T1U401]2016S001, works with Random and AcronymLastSerie modes if (SettingsApp.DocumentFinanceSeriesGenerationFactoryUseRandomAcronymPrefix) { acronymPrefix = DateToAcronymPrefix(new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second)); } //AcronymPrefix ex Fatura FT[0001]2016S001 else { //Get acronymPrefix in first DocumentFinanceType, not in every Document, this way we have uniform series acronymPrefix = (xpDocumentFinanceType[0] as fin_documentfinancetype).AcronymLastSerie.ToString(SettingsApp.DocumentFinanceSeriesGenerationFactoryAcronymLastSerieFormat); } //Add to Created List acronymPrefixCreatedSeries.Add(acronymPrefix, configurationPlaceTerminal.Designation); foreach (fin_documentfinancetype documentFinanceType in xpDocumentFinanceType) { //Ignored DocumentTypes (DocumentFinanceTypeInvoiceWayBill, this DocumentType use DocumentFinanceTypeInvoice Serie) if (documentFinanceType.Oid != SettingsApp.XpoOidDocumentFinanceTypeInvoiceWayBill) { //2018-05-08 : Old Format : [FT005012018S1] : Search GenDocumentNumber in ProcessFinanceDocument //acronym = string.Format("{0}{1}{2}{3}", documentFinanceType.Acronym, acronymPrefix, terminalInc.ToString("00"), pAcronym); //2018-05-08 : New Format //acronym = string.Format("{0} {1}{2}{3}", documentFinanceType.Acronym, pAcronym, acronymPrefix, terminalInc); acronym = string.Format("{0} {1}{2}", documentFinanceType.Acronym, pAcronym, acronymPrefix); designation = string.Format("{0} {1}", documentFinanceType.Designation, acronym); if (!pPreviewMode) { documentFinanceSeries = new fin_documentfinanceseries(uowSession) { Ord = ordAndCode, Code = ordAndCode, FiscalYear = documentFinanceYears, DocumentType = documentFinanceType, NextDocumentNumber = 1, DocumentNumberRangeBegin = 1, DocumentNumberRangeEnd = int.MaxValue, Acronym = acronym, Designation = designation }; } //Add to Output if (pPreviewMode) { output += string.Format(" {0} {1} - {2}{3}", documentFinanceType.Acronym, acronym, documentFinanceType.Designation, Environment.NewLine); } if (_debug) { _log.Debug(string.Format("DocumentFinanceSeries: [{0}], Designation: [{1}], Acronym: [{2}]", ordAndCode, designation, acronym)); } //Create DocumentFinanceYearSerieTerminal designation = string.Format("{0} {1}", designation, configurationPlaceTerminal.Designation); if (!pPreviewMode) { fin_documentfinanceyearserieterminal documentFinanceYearSerieTerminal = new fin_documentfinanceyearserieterminal(uowSession) { Ord = ordAndCode, Code = ordAndCode, FiscalYear = documentFinanceYears, DocumentType = documentFinanceSeries.DocumentType, Serie = documentFinanceSeries, Terminal = configurationPlaceTerminal, Printer = configurationPlaceTerminal.Printer, Template = documentFinanceSeries.DocumentType.Template, Designation = string.Format("{0} {1}", documentFinanceSeries.Designation, configurationPlaceTerminal.Designation) }; } if (_debug) { _log.Debug(string.Format("DocumentFinanceYearSerieTerminal: [{0}], Terminal: [{1}], Serie: [{2}]", ordAndCode, terminal["Designation"], designation)); } //Increment AcronymLastSerie and ordAndCodeInc documentFinanceType.AcronymLastSerie++; ordAndCode = ordAndCode + ordAndCodeInc; } } //Add Blank Line to Split Series/Terminal if (pPreviewMode && pTerminals.Rows.Count > terminalInc) { output += Environment.NewLine; } //Increment Terminal terminalInc++; } //Finnaly Commit Changes if (!pPreviewMode) { uowSession.CommitChanges(); } result.Result = true; if (pPreviewMode) { result.Output = output; } else { foreach (var item in acronymPrefixCreatedSeries) { //Audit FINANCE_SERIES_CREATED acronymAudit = string.Format("{0}{1}{2}{3}", "xx", item.Key, 0.ToString("00"), pAcronym); FrameworkUtils.Audit("FINANCE_SERIES_CREATED", string.Format(resources.CustomResources.GetCustomResources(GlobalFramework.Settings["customCultureResourceDefinition"], "audit_message_finance_series_created"), acronymAudit, item.Value, GlobalFramework.LoggedUser.Name)); } } } catch (Exception ex) { uowSession.RollbackTransaction(); result.Exception = ex; _log.Error(ex.Message, ex); } } return(result); }
//XpoMode public TreeViewDocumentFinanceSeries(Window pSourceWindow, XPGuidObject pDefaultValue, CriteriaOperator pXpoCriteria, Type pDialogType, GenericTreeViewMode pGenericTreeViewMode = GenericTreeViewMode.Default, GenericTreeViewNavigatorMode pGenericTreeViewNavigatorMode = GenericTreeViewNavigatorMode.Default) { //Assign Parameters to Members _sourceWindow = pSourceWindow; //Init Vars Type xpoGuidObjectType = typeof(fin_documentfinanceseries); //Override Default Value with Parameter Default Value, this way we can have diferent Default Values for GenericTreeView fin_documentfinanceseries defaultValue = (pDefaultValue != null) ? pDefaultValue as fin_documentfinanceseries : null; //Override Default DialogType with Parameter Dialog Type, this way we can have diferent DialogTypes for GenericTreeView Type typeDialogClass = (pDialogType != null) ? pDialogType : typeof(DialogDocumentFinanceSeries); //Configure columnProperties List <GenericTreeViewColumnProperty> columnProperties = new List <GenericTreeViewColumnProperty>(); columnProperties.Add(new GenericTreeViewColumnProperty("FiscalYear") { Title = resources.CustomResources.GetCustomResources(GlobalFramework.Settings["customCultureResourceDefinition"], "global_fiscal_year"), ChildName = "Designation", MinWidth = 160 }); columnProperties.Add(new GenericTreeViewColumnProperty("DocumentType") { Title = resources.CustomResources.GetCustomResources(GlobalFramework.Settings["customCultureResourceDefinition"], "global_documentfinanceseries_documenttype"), ChildName = "Designation", Expand = true }); columnProperties.Add(new GenericTreeViewColumnProperty("Designation") { Title = resources.CustomResources.GetCustomResources(GlobalFramework.Settings["customCultureResourceDefinition"], "global_designation"), Expand = true }); columnProperties.Add(new GenericTreeViewColumnProperty("UpdatedAt") { Title = resources.CustomResources.GetCustomResources(GlobalFramework.Settings["customCultureResourceDefinition"], "global_record_date_updated"), MinWidth = 150, MaxWidth = 150 }); //Configure Criteria/XPCollection/Model : Use Default Filter CriteriaOperator criteria = (ReferenceEquals(pXpoCriteria, null)) // Generate Default Criteria ? CriteriaOperator.Parse("(Disabled = 0 OR Disabled IS NULL)") // Add to Parameter Criteria : CriteriaOperator.Parse(string.Format("(Disabled = 0 OR Disabled IS NULL) AND ({0})", pXpoCriteria.ToString())) ; XPCollection xpoCollection = new XPCollection(GlobalFramework.SessionXpo, xpoGuidObjectType, criteria); //Call Base Initializer base.InitObject( pSourceWindow, //Pass parameter defaultValue, //Pass parameter pGenericTreeViewMode, //Pass parameter pGenericTreeViewNavigatorMode, //Pass parameter columnProperties, //Created Here xpoCollection, //Created Here typeDialogClass //Created Here ); //Add Extra Button to Navigator _buttonCreateDocumentFinanceSeries = Navigator.GetNewButton("touchButtonCreateDocumentFinanceSeries_DialogActionArea", resources.CustomResources.GetCustomResources(GlobalFramework.Settings["customCultureResourceDefinition"], "pos_button_create_series"), @"Icons/icon_pos_nav_new.png"); //_buttonCreateDocumentFinanceSeries.WidthRequest = 110; //Check if Has an Active Year Open before apply Permissions fin_documentfinanceyears currentDocumentFinanceYear = ProcessFinanceDocumentSeries.GetCurrentDocumentFinanceYear(); //Apply Permissions _buttonCreateDocumentFinanceSeries.Sensitive = (currentDocumentFinanceYear != null && FrameworkUtils.HasPermissionTo("BACKOFFICE_MAN_DOCUMENTFINANCESERIES_MANAGE_SERIES")); //Event _buttonCreateDocumentFinanceSeries.Clicked += buttonCreateDocumentFinanceSeries_Clicked; //Add to Extra Slot Navigator.ExtraSlot.PackStart(_buttonCreateDocumentFinanceSeries, false, false, 0); }