Ejemplo n.º 1
0
        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;
            }
        }
Ejemplo n.º 2
0
 protected void grdTransaction_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e)
 {
     e.NewValues["PaymentVouchesId!Key"]   = PrivateSession.Instance.VoucherId;
     e.NewValues["AccountingPeriodId!Key"] = AccountingPeriodBO.getCurrentAccountingPeriod(session).AccountingPeriodId;
     e.NewValues["RowStatus"]     = Constant.ROWSTATUS_ACTIVE;
     e.NewValues["CreateDate"]    = DateTime.Now;
     e.NewValues["UpdateDate"]    = DateTime.Now;
     e.NewValues["TransactionId"] = Guid.NewGuid();
 }
Ejemplo n.º 3
0
        protected void ASPxGridView1_RowDeleting(object sender, DevExpress.Web.Data.ASPxDataDeletingEventArgs e)
        {
            Guid accountingPeriodId = (Guid)e.Keys[0];

            if (AccountingPeriodBO.IsChildOfAnother(session, accountingPeriodId) == true)
            {
                e.Cancel = true;
                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ể xóa");
            }
        }
Ejemplo n.º 4
0
        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);
            }
        }
Ejemplo n.º 5
0
        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();
        }
Ejemplo n.º 6
0
 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ì"));
     }
 }
Ejemplo n.º 7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            AccountingBO accountBO = new AccountingBO();

            //try
            //{
            //    accountBO.InitBalanceForward(session, AccountingPeriodBO.getCurrentAccountingPeriod(session));

            //    lbAccountingPeriod.Text = AccountingPeriodBO.getCurrentAccountingPeriod(session).Code;
            //    lbAccountingPeriodStartdate.Text = AccountingPeriodBO.getCurrentAccountingPeriod(session).FromDateTime.ToShortDateString();
            //    lbAccountingPeriodEnddate.Text = AccountingPeriodBO.getCurrentAccountingPeriod(session).ToDateTime.Date.ToShortDateString();
            //}
            //catch
            //{
            //    cpMessageBox.JSProperties.Clear();
            //    MessageBox1.Message.Text = String.Format("Chưa tạo chu kỳ tháng {0} năm {1}", DateTime.Now.Month, DateTime.Now.Year);
            //    cpMessageBox.JSProperties.Add("cpWarning", "Chưa tạo chu kỳ tháng " + DateTime.Now.Month.ToString());
            //}

            List <NAS.BO.Accounting.AccountingBO.AccountingEntity> rs = accountBO.getInitBalanceForward(session, AccountingPeriodBO.getCurrentAccountingPeriod(session));

            AccountList.DataSource = rs;
            AccountList.DataBind();
            AccountList.Focus();

            NAS.DAL.Accounting.Currency.Currency currency;

            if (cboBalanceInitCurrency.Value == null)
            {
                CriteriaOperator _filter = new GroupOperator(GroupOperatorType.And,
                                                             new BinaryOperator("IsDefault", 1, BinaryOperatorType.Equal),
                                                             new BinaryOperator("CurrencyTypeId.IsMaster", 1, BinaryOperatorType.Equal));
                currency = session.FindObject <NAS.DAL.Accounting.Currency.Currency>(_filter);
                if (currency != null)
                {
                    cboBalanceInitCurrency.Value = currency.CurrencyId;
                }
            }

            currency = session.GetObjectByKey <NAS.DAL.Accounting.Currency.Currency>(Guid.Parse(cboBalanceInitCurrency.Value.ToString()));
            if (currency != null)
            {
                int    i  = 0;
                string _p = GetDecimals(currency.Coefficient, i).ToString();

                if (Int32.Parse(_p) <= 0)
                {
                    m_FormatNumber = m_FormatNumber.Replace('6', '0');
                }
                else
                {
                    m_FormatNumber = m_FormatNumber.Replace('6', char.Parse(_p));
                }
            }


            BalanceLineSetData();
            tgrdAccountBalance.ExpandToLevel(1);

            (tgrdAccountBalance.Columns["Debit"] as TreeListDataColumn).PropertiesEdit.DisplayFormatString  = m_FormatNumber;
            (tgrdAccountBalance.Columns["Credit"] as TreeListDataColumn).PropertiesEdit.DisplayFormatString = m_FormatNumber;

            if (!Page.IsPostBack)
            {
                refreshSummaryFooter();
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Ghi sổ tài chính phiếu kho
        /// </summary>
        /// <param name="_InventoryCommand"></param>
        public void BookFinancialEntriesOfInventoryCommand(Guid _InventoryCommand)
        {
            UnitOfWork uow = null;

            try
            {
                uow = XpoHelper.GetNewUnitOfWork();
                NAS.BO.Accounting.Journal.TransactionBOBase transactionBOBase = new TransactionBOBase();
                InventoryCommand command = uow.GetObjectByKey <InventoryCommand>(_InventoryCommand);
                if (command == null)
                {
                    throw new Exception("The InventoryCommand is not exist in system");
                }

                InventoryCommandBO CheckBO = new InventoryCommandBO();

                if (CheckBO.IsBookedEntriesForInventoryCommand(uow, _InventoryCommand))
                {
                    throw new Exception(string.Format("Không thể tiến hành vì Phiếu '{0}' đã hạch toán từ trước!", command.Code));
                }

                int  objectFinacialType = int.MinValue;
                int  objectItemType     = int.MinValue;
                Bill billArtifact       = GetSourceArtifactFromInventoryCommand(uow, command.InventoryCommandId);

                if (command.CommandType == INVENTORY_COMMAND_TYPE.IN)
                {
                    objectFinacialType = Utility.Constant.BusinessObjectType_InputInventoryCommandFinancialTransaction;
                    objectItemType     = Utility.Constant.BusinessObjectType_InputInventoryCommandItemTransaction;
                }
                else if (command.CommandType == INVENTORY_COMMAND_TYPE.OUT)
                {
                    objectFinacialType = Utility.Constant.BusinessObjectType_OutputInventoryCommandFinancialTransaction;
                    objectItemType     = Utility.Constant.BusinessObjectType_OutputInventoryCommandItemTransaction;
                }

                if (command.InventoryCommandFinancialTransactions != null && command.InventoryCommandFinancialTransactions.Count > 0)
                {
                    foreach (InventoryCommandFinancialTransaction t in command.InventoryCommandFinancialTransactions)
                    {
                        if (t.RowStatus != Utility.Constant.ROWSTATUS_BOOKED_ENTRY && t.RowStatus != Utility.Constant.ROWSTATUS_ACTIVE)
                        {
                            continue;
                        }

                        CanBookingEntryReturnValue rs = transactionBOBase.CanBookingEntry(t.TransactionId, true);
                        if (rs == CanBookingEntryReturnValue.DEBIT_CREDIT_ZERO)
                        {
                            throw new Exception(string.Format("Bút toán '{0}' không hợp lệ! Nợ = Có = 0", t.Code));
                        }
                        else if (rs == CanBookingEntryReturnValue.HAVE_NO_JOURNAL)
                        {
                            throw new Exception(string.Format("Bút toán '{0}' không chưa nhập định khoản", t.Code));
                        }
                        else if (rs == CanBookingEntryReturnValue.INVALID_TRANSACTION_STATUS)
                        {
                            throw new Exception(string.Format("Bút toán '{0}' có trạng thái không hợp lệ", t.Code));
                        }
                        else if (rs == CanBookingEntryReturnValue.MANY_SIDE)
                        {
                            throw new Exception(string.Format("Bút toán '{0}' không hợp lệ vì có nhiều tài khoản nợ và nhiều tài khoản có", t.Code));
                        }
                        else if (rs == CanBookingEntryReturnValue.NOT_BALANCED)
                        {
                            throw new Exception(string.Format("Bút toán '{0}' chưa cân bằng", t.Code));
                        }
                    }
                }

                foreach (InventoryCommandFinancialTransaction t in command.InventoryCommandFinancialTransactions)
                {
                    if (t.RowStatus != Utility.Constant.ROWSTATUS_BOOKED_ENTRY && t.RowStatus != Utility.Constant.ROWSTATUS_ACTIVE)
                    {
                        continue;
                    }

                    if (!transactionBOBase.BookEntry(uow, t.TransactionId))
                    {
                        throw new Exception("Xử lý ghi sổ phát sinh lỗi");
                    }
                    t.AccountingPeriodId = AccountingPeriodBO.GetAccountingPeriod(uow, t.IssueDate);
                    uow.FlushChanges();
                }

                foreach (InventoryTransaction t in command.InventoryCommandItemTransactions)
                {
                    if (t.RowStatus != Utility.Constant.ROWSTATUS_BOOKED_ENTRY && t.RowStatus != Utility.Constant.ROWSTATUS_ACTIVE)
                    {
                        continue;
                    }

                    if (billArtifact != null)
                    {
                        CurrencyBO      currencyBO             = new CurrencyBO();
                        COGSBO          CogsBO                 = new COGSBO();
                        COGSBussinessBO COGSInventoryCommandBO = new COGSBussinessBO();

                        foreach (InventoryJournal j in t.InventoryJournals)
                        {
                            #region setting COGS
                            if (command.CommandType == INVENTORY_COMMAND_TYPE.IN)
                            {
                                if (j.JournalType.Equals('A') && j.Debit > 0 && j.Credit == 0)
                                {
                                    BillItem billItem = billArtifact.BillItems.Where(
                                        i => i.RowStatus == Utility.Constant.ROWSTATUS_ACTIVE &&
                                        i.ItemUnitId == j.ItemUnitId).FirstOrDefault();

                                    if (billItem == null)
                                    {
                                        throw new Exception("The ItemUnit is not exist in Bill");
                                    }

                                    COGSInventoryCommandBO.CreateCOGS(
                                        uow,
                                        0,
                                        j.Debit,
                                        DateTime.Now,
                                        billItem.Price,
                                        t.IssueDate,
                                        t.InventoryTransactionId,
                                        command.RelevantInventoryId.InventoryId,
                                        j.ItemUnitId.ItemUnitId,
                                        currencyBO.GetDefaultCurrency(uow).CurrencyId);
                                }
                            }
                            else if (command.CommandType == INVENTORY_COMMAND_TYPE.OUT)
                            {
                                if (!j.JournalType.Equals('A') && j.Debit == 0 && j.Credit > 0)
                                {
                                    COGS LastCogs =
                                        CogsBO.GetLastCOGS(
                                            uow,
                                            j.ItemUnitId.ItemUnitId,
                                            currencyBO.GetDefaultCurrency(uow).CurrencyId,
                                            command.RelevantInventoryId.InventoryId);

                                    COGSInventoryCommandBO.CreateCOGS(
                                        uow,
                                        j.Credit,
                                        0,
                                        DateTime.Now,
                                        LastCogs == null ? 0 : LastCogs.COGSPrice,
                                        t.IssueDate,
                                        t.InventoryTransactionId,
                                        command.RelevantInventoryId.InventoryId,
                                        j.ItemUnitId.ItemUnitId,
                                        currencyBO.GetDefaultCurrency(uow).CurrencyId);
                                }
                            }
                            #endregion
                            //j.RowStatus = Utility.Constant.ROWSTATUS_BOOKED_ENTRY;
                        }
                        uow.FlushChanges();
                    }
                    t.AccountingPeriodId = AccountingPeriodBO.GetAccountingPeriod(uow, t.IssueDate);
                    t.RowStatus          = Utility.Constant.ROWSTATUS_BOOKED_ENTRY;
                }

                command.RowStatus = Utility.Constant.ROWSTATUS_BOOKED_ENTRY;

                foreach (InventoryTransaction t in command.InventoryCommandItemTransactions)
                {
                    if (t.RowStatus != Utility.Constant.ROWSTATUS_BOOKED_ENTRY && t.RowStatus != Utility.Constant.ROWSTATUS_ACTIVE)
                    {
                        continue;
                    }

                    BusinessObjectBO.CreateBusinessObject(uow,
                                                          objectItemType,
                                                          t.InventoryTransactionId,
                                                          t.IssueDate);
                }

                foreach (InventoryCommandFinancialTransaction tf in command.InventoryCommandFinancialTransactions)
                {
                    if (tf.RowStatus != Utility.Constant.ROWSTATUS_BOOKED_ENTRY && tf.RowStatus != Utility.Constant.ROWSTATUS_ACTIVE)
                    {
                        continue;
                    }

                    BusinessObjectBO.CreateBusinessObject(uow,
                                                          objectFinacialType,
                                                          tf.TransactionId,
                                                          tf.IssueDate);
                }
                uow.CommitChanges();
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (uow != null)
                {
                    uow.Dispose();
                }
            }
        }
Ejemplo n.º 9
0
        public static double AccountBalance(Session session, Account _Account)
        {
            XPQuery <GeneralLedger> LedgerQuery = session.Query <GeneralLedger>();
            GeneralLedger           LastLedger  = (from c in LedgerQuery
                                                   where c.AccountId == _Account &&
                                                   c.TransactionId.AccountingPeriodId == AccountingPeriodBO.getCurrentAccountingPeriod(session)
                                                   orderby c.IssuedDate descending
                                                   , c.UpdateDate descending
                                                   select c).FirstOrDefault();

            if (LastLedger == null)
            {
                return(0);
            }
            return(LastLedger.Balance);
        }