Пример #1
0
        internal static String Save(DB.SYS_Tracking entry, DataContext dataContext)
        {
            try
            {
                if (dataContext.EntitySystemContext.GetEntityState(entry) == System.Data.Entity.EntityState.Detached)
                {
                    dataContext.EntitySystemContext.SYS_Tracking.Add(entry);
                }
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException ex)
            {
                return(dataContext.PackageValidationException());
            }

            return("Success");
        }
Пример #2
0
        protected override bool SaveSuccessful()
        {
            try
            {
                using (new CDS.Client.Desktop.Essential.UTL.WaitCursor())
                {
                    this.OnSaveRecord();
                    if (!IsValid)
                    {
                        CDS.Client.Desktop.Essential.BaseAlert.ShowAlert("Error", "Please ensure that all Periods, Contra Accounts and References have been filled in.", Essential.BaseAlert.Buttons.Ok, Essential.BaseAlert.Icons.Error);
                        return(false);
                    }

                    if (CDS.Client.Desktop.Essential.BaseAlert.ShowAlert("Process Bulk Entries", "You are about to create multiple entries.\nAre you certain you wish to continue?", CDS.Client.Desktop.Essential.BaseAlert.Buttons.OkCancel, CDS.Client.Desktop.Essential.BaseAlert.Icons.Warning) == System.Windows.Forms.DialogResult.OK)
                    {
                        try
                        {
                            using (TransactionScope transaction = DataContext.GetTransactionScope())
                            {
                                // Create Records for all entries...
                                foreach (BulkEntry entry in bulkentries)
                                {
                                    DB.GLX_Header glx_header = BL.GLX.GLX_Header.New;
                                    glx_header.Date              = entry.Date.Value;
                                    glx_header.Description       = entry.Description;
                                    glx_header.Reference         = entry.Reference;
                                    glx_header.PeriodId          = DataContext.ReadonlyContext.VW_Period.Where(n => glx_header.Date >= n.StartDate && glx_header.Date < n.EndDate).Select(n => n.Id).FirstOrDefault(); //entry.PeriodId.Value;
                                    glx_header.ReferencePeriodId = glx_header.PeriodId;
                                    glx_header.PostedDate        = BL.ApplicationDataContext.Instance.ServerDateTime.Date;
                                    glx_header.TrackId           = ((DataAccessLayer.DB.GLX_Header)BindingSourceHeader.DataSource).TrackId;
                                    glx_header.StatusId          = chkAutoPost.Checked ? (byte)BL.SYS.SYS_Status.Posted : (byte)BL.SYS.SYS_Status.Unposted;
                                    glx_header.JournalTypeId     = (byte)BL.GLX.GLX_JournalType.BulkJournal;

                                    // TOTAL
                                    DB.GLX_Line glx_line_total = BL.GLX.GLX_Line.New;
                                    glx_line_total.EntityId = (Int64)ddlAccount.EditValue;// DataAccessLayer.ApplicationContext.Instance.CompanySite.glx_Debtors;
                                    //CURRENT
                                    glx_line_total.AgingId  = Convert.ToByte(ddlAging.EditValue);
                                    glx_line_total.Amount   = -entry.Inclusive.Value;
                                    glx_line_total.CenterId = DataContext.ReadonlyContext.VW_Account.Where(n => n.Id == glx_line_total.EntityId).Select(n => n.CenterId).FirstOrDefault();

                                    // EXCL
                                    DB.GLX_Line glx_line_excl = BL.GLX.GLX_Line.New;
                                    glx_line_excl.EntityId = entry.AccountId.Value;// DataAccessLayer.ApplicationContext.Instance.CompanySite.glx_Debtors;
                                    //CURRENT
                                    glx_line_excl.AgingId  = entry.AgingId.Value;
                                    glx_line_excl.Amount   = entry.Exclusive.Value;
                                    glx_line_excl.CenterId = DataContext.ReadonlyContext.VW_Account.Where(n => n.Id == glx_line_excl.EntityId).Select(n => n.CenterId).FirstOrDefault();

                                    glx_header.GLX_Line.Add(glx_line_total);
                                    glx_header.GLX_Line.Add(glx_line_excl);

                                    if (entry.Inclusive != entry.Exclusive)
                                    {
                                        // TAX
                                        DB.GLX_Line glx_line_tax = BL.GLX.GLX_Line.New;
                                        glx_line_tax.EntityId = DataContext.EntityAccountingContext.GLX_Tax.Where(n => n.Id == entry.TaxId.Value).Select(n => n.EntityId.Value).FirstOrDefault(); //DataAccessLayer.ApplicationContext.Instance.CompanySite.glx_VatAccount;
                                        //CURRENT
                                        glx_line_tax.AgingId  = entry.AgingId.Value;
                                        glx_line_tax.Amount   = (entry.Inclusive.Value - entry.Exclusive.Value);
                                        glx_line_tax.CenterId = DataContext.ReadonlyContext.VW_Account.Where(n => n.Id == glx_line_tax.EntityId).Select(n => n.CenterId).FirstOrDefault();

                                        glx_header.GLX_Line.Add(glx_line_tax);
                                    }

                                    //TODO: Need to check that this works
                                    //DataContext.EntityAccountingContext.BeginTransaction();
                                    glx_header.JournalTypeId = (byte)BL.GLX.GLX_JournalType.Journal;

                                    if (!glx_header.IsYearendHeader)
                                    {
                                        BL.GLX.GLX_Header.InsertProfitDistributionEntries(glx_header, DataContext);
                                    }
                                    DB.SYS_Tracking tracking = BL.SYS.SYS_Tracking.New;
                                    BL.EntityController.SaveSYS_Tracking(tracking, DataContext);
                                    DataContext.SaveChangesEntitySystemContext();
                                    glx_header.TrackId = tracking.Id;
                                    BL.EntityController.SaveGLX_Header(glx_header, DataContext);
                                    DataContext.SaveChangesEntityAccountingContext();
                                    if (chkAutoPost.Checked)
                                    {
                                        BL.GLX.GLX_Header.UpdateLedgerAccountBalance(glx_header, DataContext);
                                    }
                                }
                                DataContext.CompleteTransaction(transaction);
                            }
                            DataContext.EntitySystemContext.AcceptAllChanges();
                            DataContext.EntityAccountingContext.AcceptAllChanges();
                            return(true);
                        }
                        catch (Exception ex)
                        {
                            DataContext.EntitySystemContext.RejectChanges();
                            DataContext.EntityAccountingContext.RejectChanges();
                            HasErrors = true;
                            if (CDS.Shared.Exception.UserInterfaceExceptionHandler.HandleException(ref ex))
                            {
                                throw ex;
                            }
                            return(false);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            catch (Exception ex)
            {
                HasErrors = true;
                if (CDS.Shared.Exception.UserInterfaceExceptionHandler.HandleException(ref ex))
                {
                    throw ex;
                }
                return(false);
            }
        }
Пример #3
0
        protected override bool SaveSuccessful()
        {
            try
            {
                using (new CDS.Client.Desktop.Essential.UTL.WaitCursor())
                {
                    this.OnSaveRecord();

                    Dictionary <string, BL.GLX.PaymentAccount> paymentAccounts = new Dictionary <string, BL.GLX.PaymentAccount>();

                    foreach (DevExpress.XtraGrid.Columns.GridColumn pa in PaymentGridView.Columns)
                    {
                        if (((DevExpress.XtraGrid.Columns.GridColumn)PaymentGridView.Columns[pa.FieldName]).Tag is CDS.Client.BusinessLayer.GLX.PaymentAccount)
                        {
                            paymentAccounts.Add(pa.FieldName, (BL.GLX.PaymentAccount)((DevExpress.XtraGrid.Columns.GridColumn)PaymentGridView.Columns[pa.FieldName]).Tag);
                        }
                    }

                    try
                    {
                        using (TransactionScope transaction = DataContext.GetTransactionScope())
                        {
                            foreach (DB.GLX_Header header in BL.GLX.GLX_Header.CreateReceipts(entriesDataSource.Select("colCheck=1"), accountsColumns, paymentAccounts, DataContext))
                            {
                                if (header.TrackId == -1)
                                {
                                    DB.SYS_Tracking sysTracking = BL.SYS.SYS_Tracking.New;
                                    BL.EntityController.SaveSYS_Tracking(sysTracking, DataContext);
                                    DataContext.SaveChangesEntitySystemContext();
                                    header.TrackId = sysTracking.Id;
                                }

                                BL.EntityController.SaveGLX_Header(header, DataContext);
                                BL.GLX.GLX_Header.UpdateLedgerAccountBalance(header, DataContext);
                                DataContext.SaveChangesEntitySystemContext();
                                DataContext.SaveChangesEntityAccountingContext();
                            }
                            DataContext.SaveChangesEntitySystemContext();
                            DataContext.SaveChangesEntityAccountingContext();
                            DataContext.CompleteTransaction(transaction);
                        }
                        DataContext.EntitySystemContext.AcceptAllChanges();
                        DataContext.EntityAccountingContext.AcceptAllChanges();
                        return(true);
                    }
                    catch (Exception ex)
                    {
                        DataContext.EntitySystemContext.RejectChanges();
                        DataContext.EntityAccountingContext.RejectChanges();
                        HasErrors = true;
                        if (CDS.Shared.Exception.UserInterfaceExceptionHandler.HandleException(ref ex))
                        {
                            throw ex;
                        }
                        return(false);
                    }
                }
            }
            catch (Exception ex)
            {
                HasErrors = true;
                if (CDS.Shared.Exception.UserInterfaceExceptionHandler.HandleException(ref ex))
                {
                    throw ex;
                }
                return(false);
            }
        }
Пример #4
0
        private void btnPostPeriod_Click(object sender, EventArgs e)
        {
            try
            {
                //TODO: Fix this

                if (!ValidateBeforeSave())
                {
                    return;
                }

                if (CDS.Client.Desktop.Essential.BaseAlert.ShowAlert("Create Entries", "You are about to Post Entries are you sure you want to continue", Essential.BaseAlert.Buttons.OkCancel, Essential.BaseAlert.Icons.Information) != System.Windows.Forms.DialogResult.OK)
                {
                    return;
                }

                DB.GLX_Header glxHeader = BL.GLX.GLX_Header.New;
                //glxHeader.Date = BL.ApplicationContext.Instance.ServerDateTime;
                //Changed so that it is the "1st" transacrtion of the following month
                glxHeader.Date        = period.EndDate.AddMinutes(1);
                glxHeader.Description = string.Format("Post Period Entries for {0}.", period.Title);
                glxHeader.Reference   = String.Format("Year-end {0}", period.Code);
                //TODO: Chekc that this works
                glxHeader.PeriodId          = BL.SYS.SYS_Period.GetNextItem(period, DataContext).Id;
                glxHeader.ReferencePeriodId = BL.SYS.SYS_Period.GetNextItem(period, DataContext).Id;
                glxHeader.PostedDate        = BL.ApplicationDataContext.Instance.ServerDateTime;
                glxHeader.JournalTypeId     = (byte)BL.GLX.GLX_JournalType.Posting;
                glxHeader.TrackId           = -1;
                glxHeader.IsYearendHeader   = true;
                //POASTED
                glxHeader.StatusId = (byte)BL.SYS.SYS_Status.Posted;

                decimal profitTotal = 0;

                foreach (DB.VW_PostPeriodFigures line in BindingSource)
                {
                    DB.GLX_Line glx_line = BL.GLX.GLX_Line.New;
                    glx_line.EntityId = line.EntityId;// BL.ApplicationContext.Instance.CompanySite.glx_Debtors;
                    //CURRENT
                    glx_line.AgingId  = 1;
                    glx_line.Amount   = line.Amount.Value;
                    glx_line.CenterId = BL.GLX.GLX_Account.LoadByEntityId(glx_line.EntityId, DataContext).CenterId;

                    //Total for profit entry
                    profitTotal += line.Amount.Value;
                    glxHeader.GLX_Line.Add(glx_line);
                }

                //PROFIT ENTRY
                DB.GLX_Line glx_line_profit = BL.GLX.GLX_Line.New;
                glx_line_profit.EntityId = (Int64)ddlAccount.EditValue;
                //CURRENT
                glx_line_profit.AgingId  = 1;
                glx_line_profit.Amount   = -profitTotal;
                glx_line_profit.CenterId = BL.GLX.GLX_Account.LoadByEntityId(glx_line_profit.EntityId, DataContext).CenterId;
                glxHeader.GLX_Line.Add(glx_line_profit);
                try
                {
                    using (TransactionScope transaction = DataContext.GetTransactionScope())
                    {
                        DB.SYS_Tracking sysTracking = BL.SYS.SYS_Tracking.New;
                        BL.EntityController.SaveSYS_Tracking(sysTracking, DataContext);
                        DataContext.SaveChangesEntitySystemContext();
                        glxHeader.TrackId = sysTracking.Id;
                        BL.EntityController.SaveGLX_Header(glxHeader, DataContext);
                        DataContext.SaveChangesEntityAccountingContext();
                        BL.GLX.GLX_Header.UpdateLedgerAccountBalance(glxHeader, DataContext);
                        DataContext.CompleteTransaction(transaction);
                    }
                    DataContext.EntitySystemContext.AcceptAllChanges();
                    DataContext.EntityAccountingContext.AcceptAllChanges();
                }
                catch (Exception ex)
                {
                    DataContext.EntitySystemContext.RejectChanges();
                    DataContext.EntityAccountingContext.RejectChanges();
                    if (CDS.Shared.Exception.UserInterfaceExceptionHandler.HandleException(ref ex))
                    {
                        throw ex;
                    }
                }
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
                this.Close();
            }
            catch (Exception ex)
            {
                if (CDS.Shared.Exception.UserInterfaceExceptionHandler.HandleException(ref ex))
                {
                    throw ex;
                }
            }
        }
Пример #5
0
        protected override bool SaveSuccessful()
        {
            try
            {
                using (new CDS.Client.Desktop.Essential.UTL.WaitCursor())
                {
                    this.OnSaveRecord();
                    if (!IsValid)
                    {
                        return(false);
                    }

                    (grdLines.MainView as DevExpress.XtraGrid.Views.Grid.GridView).PostEditor();
                    grdLines.EndUpdate();

                    //Gets Period Id from date
                    glxHeader.PeriodId          = DataContext.EntitySystemContext.SYS_Period.Where(n => datDate.DateTime >= n.StartDate && datDate.DateTime <= n.EndDate).Select(n => n.Id).FirstOrDefault();
                    glxHeader.ReferencePeriodId = glxHeader.PeriodId;
                    if (!glxHeader.JournalTypeId.HasValue)
                    {
                        glxHeader.JournalTypeId = (byte)BL.GLX.GLX_JournalType.Journal;
                    }

                    if (chkAutoPost.Checked)
                    {
                        glxHeader.StatusId   = (byte)BL.SYS.SYS_Status.Posted;
                        glxHeader.PostedDate = BL.ApplicationDataContext.Instance.ServerDateTime.Date;
                    }
                    else
                    {
                        glxHeader.StatusId   = (byte)BL.SYS.SYS_Status.Unposted;
                        glxHeader.PostedDate = null;
                    }

                    try
                    {
                        using (TransactionScope transaction = DataContext.GetTransactionScope())
                        {
                            if (!glxHeader.IsYearendHeader)
                            {
                                BL.GLX.GLX_Header.InsertProfitDistributionEntries(glxHeader, DataContext);
                            }

                            if (chkNewTrackNumber.Checked)
                            {
                                DB.SYS_Tracking tracking = BL.SYS.SYS_Tracking.New;
                                BL.EntityController.SaveSYS_Tracking(tracking, DataContext);
                                DataContext.SaveChangesEntitySystemContext();
                                glxHeader.TrackId = tracking.Id;
                            }
                            BL.EntityController.SaveGLX_Header(glxHeader, DataContext);
                            DataContext.SaveChangesEntityAccountingContext();
                            if (chkAutoPost.Checked)
                            {
                                BL.GLX.GLX_Header.UpdateLedgerAccountBalance(glxHeader, DataContext);
                            }
                            DataContext.CompleteTransaction(transaction);
                        }
                        DataContext.EntitySystemContext.AcceptAllChanges();
                        DataContext.EntityAccountingContext.AcceptAllChanges();
                        return(true);
                    }
                    catch (Exception ex)
                    {
                        DataContext.EntitySystemContext.RejectChanges();
                        DataContext.EntityAccountingContext.RejectChanges();
                        HasErrors = true;
                        if (CDS.Shared.Exception.UserInterfaceExceptionHandler.HandleException(ref ex))
                        {
                            throw ex;
                        }
                        return(false);
                    }
                }
            }
            catch (Exception ex)
            {
                //DataContext.EntityAccountingContext.RollBackTransaction();
                HasErrors = true; CurrentException = ex;
                if (CDS.Shared.Exception.UserInterfaceExceptionHandler.HandleException(ref ex))
                {
                    throw ex;
                }
                return(false);
            }
        }