protected void ASPxGridView1_CustomColumnDisplayText(object sender, ASPxGridViewColumnDisplayTextEventArgs e) { if (e.VisibleRowIndex >= 0) { AccountingPeriod CurrentDataRow = ASPxGridView1.GetRow(e.VisibleRowIndex) as AccountingPeriod; if (e.Column.FieldName == "AccountingPeriodTypeId!Key") { if (CurrentDataRow.AccountingPeriodTypeId == null) { return; } e.DisplayText = CurrentDataRow.AccountingPeriodTypeId.Name; } if (e.Column.Caption == "Chu kì trực thuộc") { string displayText = ""; CriteriaOperator criteria_0 = new BinaryOperator("AccountingPeriodId", CurrentDataRow, BinaryOperatorType.Equal); CriteriaOperator criteria_1 = new BinaryOperator("RowStatus", Constant.ROWSTATUS_ACTIVE, BinaryOperatorType.GreaterOrEqual); CriteriaOperator criteria = new GroupOperator(GroupOperatorType.And, criteria_0, criteria_1); XPCollection <AccountingPeriodComposite> collection = new XPCollection <AccountingPeriodComposite>(session, criteria); foreach (AccountingPeriodComposite cp in collection) { displayText = displayText + cp.ChildrenAccountingPeriodId.Code + "; "; } e.DisplayText = displayText; } } }
public Task closing_an_open_period(YearMonth openedOn, EquityAccount retainedEarnings, GeneralLedgerEntryIdentifier[] generalLedgerEntryIdentifiers, GeneralLedgerEntryIdentifier closingGeneralLedgerEntryIdentifier) => new Scenario() .Given(ChartOfAccounts.Identifier, new AccountDefined { AccountNumber = retainedEarnings.AccountNumber.ToInt32(), AccountName = retainedEarnings.AccountName.ToString() }) .Given(GeneralLedger.Identifier, new GeneralLedgerOpened { OpenedOn = Time.Format.LocalDate(openedOn.OnDayOfMonth(1)) }) .When(new BeginClosingAccountingPeriod { GeneralLedgerEntryIds = ImmutableArray <Guid> .Empty.AddRange(Array.ConvertAll(generalLedgerEntryIdentifiers, x => x.ToGuid())), ClosingOn = openedOn.OnDayOfMonth(2).AtMidnight().ToDateTimeUnspecified(), RetainedEarningsAccountNumber = retainedEarnings.AccountNumber.ToInt32(), ClosingGeneralLedgerEntryId = closingGeneralLedgerEntryIdentifier.ToGuid() }) .Then(GeneralLedger.Identifier, new AccountingPeriodClosing { Period = AccountingPeriod.Open(openedOn.OnDayOfMonth(1)).ToString(), GeneralLedgerEntryIds = Array.ConvertAll(generalLedgerEntryIdentifiers, x => x.ToGuid()), ClosingOn = Time.Format.LocalDateTime(openedOn.OnDayOfMonth(2).AtMidnight()), RetainedEarningsAccountNumber = retainedEarnings.AccountNumber.ToInt32(), ClosingGeneralLedgerEntryId = closingGeneralLedgerEntryIdentifier.ToGuid() }) .Assert(_handler, _facts);
public async Task <AccountingPeriod> FetchOrCreateQuarterlyAccountingPeriodAsync( int tenantId, int year, byte quarter) { var existingAccountingPeriod = await _db.AccountingPeriod .FirstOrDefaultAsync(ap => ap.TenantId == tenantId && ap.PeriodType == AccountingPeriodType.Quarter && ap.Year == year && ap.Quarter == quarter); if (existingAccountingPeriod != null) { return(existingAccountingPeriod); } var newAccountingPeriod = new AccountingPeriod( tenantId, AccountingPeriodType.Quarter, year, (byte)(quarter * 3)); await _db.AccountingPeriod.AddAsync(newAccountingPeriod); await _db.SaveChangesAsync(); return(newAccountingPeriod); }
public SaleInvoiceTransaction SaleInvoiceTransactionInit(Session session, DateTime CreateDate, string Code, string Description, Guid BillId) { SalesInvoice salesInvoice = session.GetObjectByKey <SalesInvoice>(BillId); SaleInvoiceTransaction saleInvoiceTransaction; if (salesInvoice.SaleInvoiceTransactions.Count > 0) { saleInvoiceTransaction = session.GetObjectByKey <SaleInvoiceTransaction>(salesInvoice.SaleInvoiceTransactions[0].TransactionId); } else { saleInvoiceTransaction = new SaleInvoiceTransaction(session); saleInvoiceTransaction.CreateDate = CreateDate; } AccountingPeriod accountingPeriod = session.GetObjectByKey <AccountingPeriod>(Guid.Parse("305cf651-19ba-43b5-a159-eddb28e35308")); saleInvoiceTransaction.SalesInvoiceId = salesInvoice; saleInvoiceTransaction.AccountingPeriodId = accountingPeriod; saleInvoiceTransaction.Code = Code; saleInvoiceTransaction.Description = Description; return(saleInvoiceTransaction); }
public bool changeIsActiveAccountingPeriod(UnitOfWork uow) { try { AccountingPeriod apIsActive = uow.FindObject <AccountingPeriod>(new BinaryOperator("Code", "NAAN_DEFAULT", BinaryOperatorType.Equal)); XPCollection <AccountingPeriod> DBAccountingPeriod = new XPCollection <AccountingPeriod>(uow); DBAccountingPeriod.Criteria = CriteriaOperator.And( new BinaryOperator("IsActive", true, BinaryOperatorType.Equal), new BinaryOperator("RowStatus", Utility.Constant.ROWSTATUS_ACTIVE, BinaryOperatorType.GreaterOrEqual) ); if (apIsActive == null) { throw new Exception("AccountingPeriod is not NAAN_DEFAULT"); } if (DBAccountingPeriod == null) { throw new Exception("AccountingPeriod is not in system"); } foreach (AccountingPeriod ap in DBAccountingPeriod) { if (!ap.Code.Equals(apIsActive.Code)) { ap.IsActive = false; uow.FlushChanges(); } } return(true); } catch (Exception) { return(false); throw; } }
public async ValueTask Handle(AccountingPeriodClosing @event, CancellationToken cancellationToken) { var generalLedgerEntryIdentifiers = Array.ConvertAll(@event.GeneralLedgerEntryIds, id => new GeneralLedgerEntryIdentifier(id)); var chartOfAccounts = await _chartOfAccounts.Get(cancellationToken); var accountingPeriodClosingProcess = new AccountingPeriodClosingProcess( chartOfAccounts, AccountingPeriod.Parse(@event.Period), Time.Parse.LocalDateTime(@event.ClosingOn), generalLedgerEntryIdentifiers, new GeneralLedgerEntryIdentifier(@event.ClosingGeneralLedgerEntryId), (EquityAccount)chartOfAccounts[new AccountNumber(@event.RetainedEarningsAccountNumber)], _accountIsDeactivated); foreach (var id in @event.GeneralLedgerEntryIds) { var generalLedgerEntry = await _generalLedgerEntries.Get(new GeneralLedgerEntryIdentifier(id), cancellationToken); accountingPeriodClosingProcess.TransferEntry(generalLedgerEntry); } var generalLedger = await _generalLedger.Get(cancellationToken); generalLedger.CompleteClosingPeriod(generalLedgerEntryIdentifiers, accountingPeriodClosingProcess.Complete(), accountingPeriodClosingProcess.TrialBalance); }
public Task entry_not_in_balance_throws(GeneralLedgerEntryIdentifier generalLedgerEntryIdentifier, int sequenceNumber, LocalDate openedOn, AccountName accountName, AccountNumber accountNumber) { var scenario = new Scenario() .Given(GeneralLedger.Identifier, new GeneralLedgerOpened { OpenedOn = Time.Format.LocalDate(openedOn) }) .Given(ChartOfAccounts.Identifier, new AccountDefined { AccountName = accountName.ToString(), AccountNumber = accountNumber.ToInt32() }) .When(new PostGeneralLedgerEntry { Period = AccountingPeriod.Open(openedOn).ToString(), BusinessTransaction = new BadTransaction { Account = accountNumber, ReferenceNumber = sequenceNumber }, CreatedOn = openedOn.ToDateTimeUnspecified(), GeneralLedgerEntryId = generalLedgerEntryIdentifier.ToGuid() }) .Throws(new GeneralLedgerEntryNotInBalanceException(generalLedgerEntryIdentifier)); _writer.Write(scenario.Build()); return(scenario.Assert(new GeneralLedgerEntryHandlers(new GeneralLedgerTestRepository(_facts), new GeneralLedgerEntryTestRepository(_facts), _ => false), _facts)); }
protected void ASPxGridView1_StartRowEditing(object sender, DevExpress.Web.Data.ASPxStartRowEditingEventArgs e) { AccountingPeriod currentEdit = session.GetObjectByKey <AccountingPeriod>(Guid.Parse(e.EditingKeyValue.ToString())); Guid accountingPeriodId = Guid.Parse(e.EditingKeyValue.ToString()); if (AccountingPeriodBO.IsChildOfAnother(session, accountingPeriodId)) { e.Cancel = true; (sender as ASPxGridView).CancelEdit(); throw new Exception("Chu kì kế toán này đang là chu kì trực thuộc của một chu kì khác! Không thể chỉnh sửa"); } Session["AccountingPeriodId_cr"] = currentEdit.AccountingPeriodId; ASPxGridLookup grid = ASPxGridView1.FindEditRowCellTemplateControl(ASPxGridView1.Columns[5] as GridViewDataColumn, "cp_Grid1").FindControl("GridUnderPeriod") as ASPxGridLookup; if (currentEdit.AccountingPeriodTypeId.IsDefault == true) { XPOAccountingPeriodLookup.Criteria = "[RowStatus] > 0s And [IsActive] = True And [IsActive] <> True And [Code] <> 'NAAN_DEFAULT' And [AccountingPeriodTypeId.IsDefault] = True"; grid.Enabled = false; } else { XPOAccountingPeriodLookup.Criteria = "[RowStatus] > 0s And [IsActive] = True And [Code] <> 'NAAN_DEFAULT' And [AccountingPeriodTypeId.IsDefault] = True"; grid.Enabled = true; } }
public AccountingPeriod Add(AccountingPeriod AP, string userid) { var sqlQuery = @"INSERT INTO ACCOUNTINGPERIOD (ACCOUNTINGYEAR, PERIODSEQUENT, STARTDATE, ENDDATE, ISSTATUS, COMPANYSITE, INPUTBY, INPUTDATE, UPDATEBY, UPDATEDATE) VALUES('" + AP.ACCOUNTINGYEAR + "', '" + AP.PERIODSEQUENT + "', '" + AP.STARTDATE + "', '" + AP.ENDDATE + "', '" + AP.ISSTATUS + "', '" + AP.COMPANYSITE + "','" + userid + "', '" + DateTime.Now + "', '" + userid + "', '" + DateTime.Now + "'); " + "SELECT CAST(SCOPE_IDENTITY() as int)"; var SID = _db.Query <int>(sqlQuery, AP).Single(); AP.SID = SID; return(AP); }
public static AccountingPeriodLiteViewModel FromModel(AccountingPeriod model) { if (model == null) { return(null); } return(Fill(new AccountingPeriodViewModel(), model)); }
protected void cboAccountPeriod_ItemRequestedByValue(object source, DevExpress.Web.ASPxEditors.ListEditItemRequestedByValueEventArgs e) { AccountingPeriod obj = session.GetObjectByKey <AccountingPeriod>(e.Value); if (obj != null) { cboAccountPeriod.DataSource = new AccountingPeriod[] { obj }; cboAccountPeriod.DataBindItems(); } }
protected void grdBalanceLine_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e) { if (cboBalanceInitAccount.Value == null) { grdBalanceLine.JSProperties.Add("cpAccountInvalid", "invalid"); e.Cancel = true; return; } if (cboBalanceInitCurrency.Value == null) { grdBalanceLine.JSProperties.Add("cpCurrencyInvalid", "invalid"); e.Cancel = true; return; } BalanceForwardTransaction balanceForwardTransaction = new BalanceForwardTransaction(session); balanceForwardTransaction.TransactionId = Guid.NewGuid(); balanceForwardTransaction.Code = e.NewValues["TransactionId.Code"] as string; balanceForwardTransaction.Description = e.NewValues["TransactionId.Description"] as string; balanceForwardTransaction.RowStatus = 1; balanceForwardTransaction.IssueDate = balanceForwardTransaction.CreateDate = DateTime.Now; if (cboAccountPeriod.Value == null) { throw new Exception("Chưa chọn kỳ kế toán !"); } AccountingPeriod _accountingPeriod = session.GetObjectByKey <AccountingPeriod>(Guid.Parse(cboAccountPeriod.Value.ToString())); if (_accountingPeriod == null) { throw new Exception("Chưa chọn kỳ kế toán !"); } balanceForwardTransaction.AccountingPeriodId = _accountingPeriod; balanceForwardTransaction.Save(); e.NewValues["GeneralJournalId"] = Guid.NewGuid().ToString(); ASPxSpinEdit c = (ASPxSpinEdit)grdBalanceLine.FindEditRowCellTemplateControl((GridViewDataColumn)grdBalanceLine.Columns["Debit"], "colBalanceInitDebit"); e.NewValues["Debit"] = c.Value.ToString(); c = (ASPxSpinEdit)grdBalanceLine.FindEditRowCellTemplateControl((GridViewDataColumn)grdBalanceLine.Columns["Credit"], "colBalanceInitCredit"); e.NewValues["Credit"] = c.Value.ToString(); e.NewValues["RowStatus"] = "1"; e.NewValues["AccountId!Key"] = cboBalanceInitAccount.Value.ToString(); e.NewValues["CurrencyId!Key"] = cboBalanceInitCurrency.Value.ToString(); e.NewValues["TransactionId!Key"] = balanceForwardTransaction.TransactionId.ToString(); BalanceLineSetData(); }
public static AccountingPeriodLiteViewModel Fill( AccountingPeriodLiteViewModel viewModel, AccountingPeriod model) { viewModel.Id = model.Id; viewModel.PeriodType = model.PeriodType; viewModel.Year = model.Year; viewModel.Month = model.Month; viewModel.Quarter = model.Quarter; viewModel.Name = model.Name; viewModel.Closed = model.Closed; return(viewModel); }
public bool checkIsAccountingPeriodTypeIdInCurrency(UnitOfWork session, string AccountingPeriodTypeId) { AccountingPeriod dbAccountingPeriodeId = session.FindObject <AccountingPeriod>( CriteriaOperator.And( new BinaryOperator("AccountingPeriodTypeId", AccountingPeriodTypeId, BinaryOperatorType.Equal), new BinaryOperator("RowStatus", Utility.Constant.ROWSTATUS_ACTIVE, BinaryOperatorType.Equal) )); if (dbAccountingPeriodeId != null) { return(true); } return(false); }
public static void CreatAccountingPeriodComposite(Session session, Guid accountingPeriodId, Guid childAccountingPeriodId) { AccountingPeriod parentAccountingPeriod = session.GetObjectByKey <AccountingPeriod>(accountingPeriodId); AccountingPeriod childAccountingPeriod = session.GetObjectByKey <AccountingPeriod>(childAccountingPeriodId); if ((parentAccountingPeriod != null) && (childAccountingPeriod != null)) { AccountingPeriodComposite composite = new AccountingPeriodComposite(session); composite.AccountingPeriodId = parentAccountingPeriod; composite.ChildrenAccountingPeriodId = childAccountingPeriod; composite.RowStatus = Constant.ROWSTATUS_ACTIVE; composite.Save(); } }
public bool checkAccountingPeriod_Code(UnitOfWork uow, string code, string AccPeriodTypeId) { AccountingPeriod AccountingPeriod_Code = uow.FindObject <AccountingPeriod>( CriteriaOperator.And( new BinaryOperator("Code", code, BinaryOperatorType.Equal), new BinaryOperator("RowStatus", Utility.Constant.ROWSTATUS_ACTIVE, BinaryOperatorType.Equal), new BinaryOperator("AccountingPeriodTypeId", Guid.Parse(AccPeriodTypeId.ToString()), BinaryOperatorType.Equal) )); if (AccountingPeriod_Code != null) { return(true); } return(false); }
public async Task when_an_entry_is_posted( GeneralLedgerEntryIdentifier generalLedgerEntryIdentifier, LocalDateTime createdOn, Money[] amounts) { var period = AccountingPeriod.Open(createdOn.Date); var thru = createdOn.Date.PlusDays(1).AtMidnight(); var accounts = await OpenBooks(createdOn).ToArrayAsync(); var debits = Array.ConvertAll(amounts, amount => new Debit(accounts.OrderBy(_ => Guid.NewGuid()).First().accountNumber, amount)); var credits = Array.ConvertAll(amounts, amount => new Credit(accounts.OrderBy(_ => Guid.NewGuid()).First().accountNumber, amount)); var journalEntry = new JournalEntry { ReferenceNumber = 1, Credits = Array.ConvertAll(credits, credit => new JournalEntry.Item { Amount = credit.Amount.ToDecimal(), AccountNumber = credit.AccountNumber.Value }), Debits = Array.ConvertAll(debits, debit => new JournalEntry.Item { Amount = debit.Amount.ToDecimal(), AccountNumber = debit.AccountNumber.ToInt32() }) }; var command = new PostGeneralLedgerEntry { GeneralLedgerEntryId = generalLedgerEntryIdentifier.ToGuid(), CreatedOn = createdOn.ToDateTimeUnspecified(), BusinessTransaction = journalEntry, Period = period.ToString() }; var expected = new BalanceSheetReport { Thru = thru.ToDateTimeUnspecified(), LineItems = journalEntry.Debits.Concat(journalEntry.Credits.Select(c => new JournalEntry.Item() { Amount = -c.Amount, AccountNumber = c.AccountNumber })).Aggregate(ImmutableDictionary <int, LineItem> .Empty, (items, item) => items.SetItem( item.AccountNumber, new LineItem { AccountNumber = item.AccountNumber, Name = accounts.Single(x => x.accountNumber.ToInt32() == item.AccountNumber).accountName .ToString(), Balance = items.TryGetValue(item.AccountNumber, out var existing) ? existing.Balance + item.Amount : new () { DecimalValue = item.Amount } })).Values.OrderBy(x => x.AccountNumber).ToImmutableArray(),
public async Task Somewthing() { var now = DateTime.UtcNow; var period = AccountingPeriod.Open(LocalDate.FromDateTime(now)); var transactionId = Guid.NewGuid(); await HttpClient.SendCommand("/transactions", new PostGeneralLedgerEntry { BusinessTransaction = new BusinessTransaction { TransactionId = transactionId, ReferenceNumber = 1, Version = 1 }, Period = period.ToString(), CreatedOn = now, GeneralLedgerEntryId = transactionId }, TransactoSerializerOptions.BusinessTransactions(typeof(BusinessTransaction))); }
public XPCollection <InventoryLedger> getTransactionInventoryLedgers(Session session, Guid InventoryId, Guid ItemUnitId) { try { AccountingPeriod currentAP = AccountingPeriodBO.getCurrentAccountingPeriod(session); //if (currentAP == null) // return null; XPCollection <InventoryTransaction> ITLst = new XPCollection <InventoryTransaction>(session); //ITLst.Criteria = CriteriaOperator.And( // new BinaryOperator("AccountingPeriodId", currentAP, BinaryOperatorType.Equal), // new BinaryOperator("RowStatus", 0, BinaryOperatorType.Greater) // ); ITLst.Criteria = new BinaryOperator("RowStatus", 1, BinaryOperatorType.GreaterOrEqual); if (ITLst == null || ITLst.Count == 0) { return(null); } if (ITLst == null || ITLst.Count == 0) { return(null); } CriteriaOperator criteriaIN = new InOperator("InventoryTransactionId", ITLst); XPCollection <InventoryLedger> ILLst = new XPCollection <InventoryLedger>(session); ILLst.Criteria = CriteriaOperator.And( new InOperator("InventoryTransactionId", ITLst), new BinaryOperator("ItemUnitId!Key", ItemUnitId, BinaryOperatorType.Equal), new BinaryOperator("InventoryId!Key", InventoryId, BinaryOperatorType.Equal), new BinaryOperator("RowStatus", 1, BinaryOperatorType.GreaterOrEqual) ); SortingCollection sortCollection = new SortingCollection(); sortCollection.Add(new SortProperty("IssueDate", DevExpress.Xpo.DB.SortingDirection.Descending)); sortCollection.Add(new SortProperty("CreateDate", DevExpress.Xpo.DB.SortingDirection.Descending)); sortCollection.Add(new SortProperty("UpdateDate", DevExpress.Xpo.DB.SortingDirection.Descending)); ILLst.Sorting = sortCollection; return(ILLst); } catch (Exception e) { return(null); } }
public AccountingPeriod Update(AccountingPeriod AP, string userid) { var sqlQuery = "UPDATE ACCOUNTINGPERIOD " + "SET ACCOUNTINGYEAR = '" + AP.ACCOUNTINGYEAR + "', " + " PERIODSEQUENT = '" + AP.PERIODSEQUENT + "', " + " STARTDATE = '" + AP.STARTDATE + "', " + " ENDDATE = '" + AP.ENDDATE + "', " + " ISSTATUS = '" + AP.ISSTATUS + "', " + " COMPANYSITE = '" + AP.COMPANYSITE + "', " + " UPDATEBY = '" + Convert.ToInt32(userid) + "', " + " UPDATEDATE = '" + DateTime.Now + "' " + "WHERE SID = " + AP.SID + ""; this._db.Execute(sqlQuery, AP); return(AP); }
public Task applying_credit_to_non_existing_account_throws( GeneralLedgerEntryIdentifier generalLedgerEntryIdentifier, int sequenceNumber, LocalDate openedOn, AccountNumber accountNumber) => new Scenario() .Given(GeneralLedger.Identifier, new GeneralLedgerOpened { OpenedOn = Time.Format.LocalDate(openedOn) }) .When(new PostGeneralLedgerEntry { GeneralLedgerEntryId = generalLedgerEntryIdentifier.ToGuid(), Period = AccountingPeriod.Open(openedOn).ToString(), BusinessTransaction = new TestTransaction(new GeneralLedgerEntryNumber("t", sequenceNumber), credits: new[] { new Credit(accountNumber, Money.Zero) }), CreatedOn = openedOn.ToDateTimeUnspecified() }) .Throws(new AccountDeactivatedException(accountNumber)) .Assert(new GeneralLedgerEntryHandlers(new GeneralLedgerTestRepository(_facts), new GeneralLedgerEntryTestRepository(_facts), _ => true), _facts);
public Task closing_the_period_before_the_period_has_started(LocalDate openedOn, EquityAccount retainedEarnings, GeneralLedgerEntryIdentifier closingGeneralLedgerEntryIdentifier) => new Scenario() .Given(ChartOfAccounts.Identifier, new AccountDefined { AccountNumber = retainedEarnings.AccountNumber.ToInt32(), AccountName = retainedEarnings.AccountName.ToString() }) .Given(GeneralLedger.Identifier, new GeneralLedgerOpened { OpenedOn = Time.Format.LocalDate(openedOn) }) .When(new BeginClosingAccountingPeriod { ClosingOn = openedOn.PlusMonths(-1).ToDateTimeUnspecified(), RetainedEarningsAccountNumber = retainedEarnings.AccountNumber.ToInt32(), ClosingGeneralLedgerEntryId = closingGeneralLedgerEntryIdentifier.ToGuid() }) .Throws(new ClosingDateBeforePeriodException(AccountingPeriod.Open(openedOn), openedOn.PlusMonths(-1))) .Assert(_handler, _facts);
protected void cboAccountPeriod_ItemRequestedByValue(object source, ListEditItemRequestedByValueEventArgs e) { try { ASPxComboBox combo = source as ASPxComboBox; AccountingPeriod obj = session.GetObjectByKey <AccountingPeriod>(e.Value); if (obj != null) { combo.DataSource = new AccountingPeriod[] { obj }; combo.DataBindItems(); } } catch { } }
protected void ASPxGridView1_CustomButtonInitialize(object sender, ASPxGridViewCustomButtonEventArgs e) { if (e.VisibleIndex >= 0) { AccountingPeriod CurrentDataRow = ASPxGridView1.GetRow(e.VisibleIndex) as AccountingPeriod; if (e.ButtonID == "btUnder") { if (CurrentDataRow.AccountingPeriodTypeId == null) { return; } if (CurrentDataRow.AccountingPeriodTypeId.IsDefault == true) { e.Enabled = false; } } } }
protected void ASPxGridView1_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e) { if (e.NewValues["IsActive"] == null) { e.NewValues["IsActive"] = false; } if (Util.isExistXpoObject <AccountingPeriod>("Code", (string)e.NewValues["Code"])) { e.Cancel = true; throw (new Exception("Trùng mã chu kì")); return; } if (e.NewValues["AccountingPeriodTypeId!Key"] == null) { e.Cancel = true; throw (new Exception("Chưa chọn thể loại")); return; } AccountingPeriod accountingPeriod = new AccountingPeriod(session); accountingPeriod.Description = (string)e.NewValues["Description"]; accountingPeriod.Code = (string)e.NewValues["Code"]; accountingPeriod.AccountingPeriodTypeId = session.GetObjectByKey <AccountingPeriodType>(Guid.Parse(e.NewValues["AccountingPeriodTypeId!Key"].ToString())); accountingPeriod.FromDateTime = (DateTime)e.NewValues["FromDateTime"]; accountingPeriod.ToDateTime = (DateTime)e.NewValues["ToDateTime"]; accountingPeriod.RowStatus = Constant.ROWSTATUS_ACTIVE; accountingPeriod.IsActive = (bool)e.NewValues["IsActive"]; if (accountingPeriod.Code != null) { accountingPeriod.Save(); } ASPxGridLookup grid = ASPxGridView1.FindEditRowCellTemplateControl(ASPxGridView1.Columns[5] as GridViewDataColumn, "cp_Grid1").FindControl("GridUnderPeriod") as ASPxGridLookup; List <object> selectedRows = grid.GridView.GetSelectedFieldValues("AccountingPeriodId"); if (!accountingPeriod.AccountingPeriodTypeId.IsDefault) { foreach (var o in selectedRows) { AccountingPeriodBO.CreatAccountingPeriodComposite(session, accountingPeriod.AccountingPeriodId, Guid.Parse(o.ToString())); } } e.Cancel = true; ASPxGridView1.CancelEdit(); }
protected void ASPxGridView1_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e) { try { AccountingPeriod currentAP = session.GetObjectByKey <AccountingPeriod>((Guid)e.Keys[0]); if (Util.isExistXpoObject <AccountingPeriod>("Code", e.NewValues["Code"].ToString())) { CriteriaOperator criteria0 = new BinaryOperator("Code", e.NewValues["Code"].ToString(), BinaryOperatorType.Equal); CriteriaOperator criteria1 = new BinaryOperator("AccountingPeriodId", e.Keys[0], BinaryOperatorType.NotEqual); CriteriaOperator criteria2 = new BinaryOperator("RowStatus", Constant.ROWSTATUS_ACTIVE, BinaryOperatorType.GreaterOrEqual); CriteriaOperator cr = new GroupOperator(GroupOperatorType.And, criteria0, criteria1, criteria2); AccountingPeriod ap = session.FindObject <AccountingPeriod>(cr); if (ap != null) { e.Cancel = true; throw (new Exception("Trùng mã chu kì")); return; } } ASPxGridLookup grid = ASPxGridView1.FindEditRowCellTemplateControl(ASPxGridView1.Columns[5] as GridViewDataColumn, "cp_Grid1").FindControl("GridUnderPeriod") as ASPxGridLookup; CriteriaOperator criteria_0 = new BinaryOperator("AccountingPeriodId", currentAP, BinaryOperatorType.Equal); CriteriaOperator criteria_1 = new BinaryOperator("RowStatus", Constant.ROWSTATUS_ACTIVE, BinaryOperatorType.GreaterOrEqual); CriteriaOperator criteria = new GroupOperator(GroupOperatorType.And, criteria_0, criteria_1); XPCollection <AccountingPeriodComposite> collection = new XPCollection <AccountingPeriodComposite>(session, criteria); foreach (AccountingPeriodComposite cp in collection) { cp.RowStatus = Constant.ROWSTATUS_DELETED; cp.Save(); } List <object> selectedRows = grid.GridView.GetSelectedFieldValues("AccountingPeriodId"); if (!currentAP.AccountingPeriodTypeId.IsDefault) { foreach (var o in selectedRows) { AccountingPeriodBO.CreatAccountingPeriodComposite(session, currentAP.AccountingPeriodId, Guid.Parse(o.ToString())); } } } catch (Exception) { throw (new Exception("Trùng mã chu kì")); } }
protected void cpHeader_Callback(object sender, DevExpress.Web.ASPxClasses.CallbackEventArgsBase e) { string[] p = e.Parameter.Split('|'); switch (p[0]) { case "cboAccountingPeriodChanged": AccountingPeriod ap = session.GetObjectByKey <AccountingPeriod>(Guid.Parse(cboAccountPeriod.Value.ToString())); if (ap != null) { txtFromDate.Value = ap.FromDateTime; txtToDate.Value = ap.ToDateTime; } break; default: break; } }
protected void Page_Init(object sender, EventArgs e) { session = XpoHelper.GetNewSession(); CriteriaOperator filter = new BinaryOperator("IsActive", 1, BinaryOperatorType.Equal); AccountingPeriod ap = session.FindObject <AccountingPeriod>(filter); if (ap != null) { cboAccountPeriod.Value = ap.AccountingPeriodId; txtFromDate.Value = new DateTime(2014, 1, 1); txtToDate.Value = new DateTime(2014, 1, 31); } else { txtFromDate.Value = DateTime.Now; txtToDate.Value = DateTime.Now; } }
public static bool IsChildOfAnother(Session session, Guid accountingPeriodId) { bool result = false; try { CriteriaOperator criteria_RowStatus = new BinaryOperator("RowStatus", Constant.ROWSTATUS_ACTIVE, BinaryOperatorType.GreaterOrEqual); AccountingPeriod accountingPeriod = session.GetObjectByKey <AccountingPeriod>(accountingPeriodId); if (accountingPeriodId == null) { return(false); } if (accountingPeriod.AccountingPeriodComposites == null) { result = false; } else { XPCollection <AccountingPeriodComposite> AccountingPeriodCompositeCol = new XPCollection <AccountingPeriodComposite>(accountingPeriod.AccountingPeriodComposites, criteria_RowStatus); if (AccountingPeriodCompositeCol == null) { result = false; } else { if (AccountingPeriodCompositeCol.Count == 0) { result = false; } else { result = true; } } } } catch (Exception) { return(false); } return(result); }
protected void treelistACCPeriod_NodeDeleting(object sender, DevExpress.Web.Data.ASPxDataDeletingEventArgs e) { try { e.Cancel = true; uow.BeginTransaction(); Guid a = Guid.Parse(e.Keys[0].ToString()); AccountingPeriod accp = uow.GetObjectByKey <AccountingPeriod>(a); accp.RowStatus = Utility.Constant.ROWSTATUS_DELETED; accp.Save(); uow.CommitTransaction(); } catch (Exception) { uow.RollbackTransaction(); e.Cancel = true; throw; } }