//Get DocumentFinanceYearSerieTerminal for Terminal public static FIN_DocumentFinanceYearSerieTerminal GetDocumentFinanceYearSerieTerminal(Session pSession, Guid pDocumentType, Guid pLoggedTerminal) { DateTime currentDateTime = FrameworkUtils.CurrentDateTimeAtomic(); FIN_DocumentFinanceYearSerieTerminal documentFinanceYearSerieTerminal = null; FIN_DocumentFinanceType documentFinanceType = (FIN_DocumentFinanceType)FrameworkUtils.GetXPGuidObject(pSession, typeof(FIN_DocumentFinanceType), pDocumentType); //If DocumentTypeInvoiceWayBill Replace/Override Helper Document Type InvoiceWayBill with InvoiceWay to get Invoice Serie, //this way we have Invoice Serie but DocumentMaster keeps DocumentFinanceType has DocumentFinanceTypeInvoiceWayBill //Usefull for Future Documents WayBill distinct code, ex have WayBill, ex Re-Print Documents in WayBillMode etc Guid documentFinanceTypeSerieGuid = (documentFinanceType.Oid == SettingsApp.XpoOidDocumentFinanceTypeInvoiceWayBill) ? SettingsApp.XpoOidDocumentFinanceTypeInvoice : documentFinanceType.Oid ; //Get Document Serie SortingCollection sortCollection = new SortingCollection(); sortCollection.Add(new SortProperty("FiscalYear", DevExpress.Xpo.DB.SortingDirection.Ascending)); CriteriaOperator criteria = CriteriaOperator.Parse(string.Format("(Disabled = 0 OR Disabled IS NULL) AND DocumentType == '{0}'", documentFinanceTypeSerieGuid.ToString())); ICollection collectionDocumentFinanceSeries = pSession.GetObjects(pSession.GetClassInfo(typeof(FIN_DocumentFinanceYearSerieTerminal)), criteria, sortCollection, int.MaxValue, false, true); foreach (FIN_DocumentFinanceYearSerieTerminal item in collectionDocumentFinanceSeries) { if (currentDateTime.Year >= item.FiscalYear.FiscalYear) { if (item.Terminal.Oid == pLoggedTerminal) { documentFinanceYearSerieTerminal = item; } } } return(documentFinanceYearSerieTerminal); }
//XpoMode public TreeViewDocumentFinanceYearSerieTerminal(Window pSourceWindow, XPGuidObject pDefaultValue, CriteriaOperator pXpoCriteria, Type pDialogType, GenericTreeViewMode pGenericTreeViewMode = GenericTreeViewMode.Default, GenericTreeViewNavigatorMode pGenericTreeViewNavigatorMode = GenericTreeViewNavigatorMode.Default) { //Init Vars Type xpoGuidObjectType = typeof(FIN_DocumentFinanceYearSerieTerminal); //Override Default Value with Parameter Default Value, this way we can have diferent Default Values for GenericTreeView FIN_DocumentFinanceYearSerieTerminal defaultValue = (pDefaultValue != null) ? pDefaultValue as FIN_DocumentFinanceYearSerieTerminal : null; //Override Default DialogType with Parameter Dialog Type, this way we can have diferent DialogTypes for GenericTreeView Type typeDialogClass = (pDialogType != null) ? pDialogType : typeof(DialogDocumentFinanceYearSerieTerminal); //Configure columnProperties List <GenericTreeViewColumnProperty> columnProperties = new List <GenericTreeViewColumnProperty>(); columnProperties.Add(new GenericTreeViewColumnProperty("FiscalYear") { Title = Resx.global_fiscal_year, ChildName = "Designation" }); //columnProperties.Add(new GenericTreeViewColumnProperty("DocumentType") { Title = Resx.global_documentfinanceseries_documenttype, ChildName = "Designation" }); //columnProperties.Add(new GenericTreeViewColumnProperty("Serie") { Title = Resx.global_documentfinance_series, ChildName = "Designation" }); columnProperties.Add(new GenericTreeViewColumnProperty("Designation") { Title = Resx.global_designation, Expand = true }); columnProperties.Add(new GenericTreeViewColumnProperty("Terminal") { Title = Resx.global_configurationplaceterminal, ChildName = "Designation" }); columnProperties.Add(new GenericTreeViewColumnProperty("UpdatedAt") { Title = Resx.global_record_date_updated, MinWidth = 150, MaxWidth = 150 }); //Configure Criteria/XPCollection/Model : Use Default Filter CriteriaOperator criteria = (ReferenceEquals(pXpoCriteria, null)) ? CriteriaOperator.Parse("(Disabled = 0 OR Disabled IS NULL)") : pXpoCriteria; //Init Collection XPCollection xpoCollection = new XPCollection(GlobalFramework.SessionXpo, xpoGuidObjectType, criteria); //Override default Sorting SortingCollection sortingCollection = new SortingCollection(); sortingCollection.Add(new SortProperty("Terminal", DevExpress.Xpo.DB.SortingDirection.Ascending)); sortingCollection.Add(new SortProperty("Ord", DevExpress.Xpo.DB.SortingDirection.Ascending)); xpoCollection.Sorting = sortingCollection; //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 ); }
public static bool PrintFinanceDocument(Session pSession, FIN_DocumentFinanceMaster pDocumentFinanceMaster, List <int> pCopyNames, bool pSecondCopy, string pMotive) { bool result = false; try { //Finish Payment with Print Job + Open Drawer (If Not TableConsult) FIN_DocumentFinanceYearSerieTerminal xDocumentFinanceYearSerieTerminal = ProcessFinanceDocumentSeries.GetDocumentFinanceYearSerieTerminal(pSession, pDocumentFinanceMaster.DocumentType.Oid); PrintFinanceDocument(GlobalFramework.LoggedTerminal.Printer, pDocumentFinanceMaster, pCopyNames, pSecondCopy, pMotive); //Open Door if Has Valid Payment if (pDocumentFinanceMaster.PaymentMethod != null) { OpenDoor(GlobalFramework.LoggedTerminal.Printer); } result = true; } catch (Exception ex) { _log.Warn(ex.Message, ex); throw new Exception(ex.Message); } return(result); }
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: //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(Resx.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); }