Exemple #1
0
        //public abstract IEnumerable<NAS.DAL.Accounting.Journal.Transaction> GetTransactions(Session session);

        //public abstract NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum GetObjectTypeEnum();

        public virtual GeneralJournal CreateGeneralJournal(
            Session session,
            Guid transactionId,
            Guid accountId,
            Side side,
            double amount,
            string description,
            JounalTypeFlag journalType)
        {
            GeneralJournal   ret              = null;
            ObjectBO         objectBO         = new ObjectBO();
            GeneralJournalBO generalJournalBO = new GeneralJournalBO();

            ret = generalJournalBO.CreateGeneralJournal(
                session,
                transactionId,
                accountId,
                side,
                amount,
                description,
                journalType);

            //Create CMS object...
            Guid objectTypeId = ret.TransactionId.TransactionObjects.First().ObjectId.ObjectTypeId.ObjectTypeId;

            NAS.DAL.CMS.ObjectDocument.Object CMSObject =
                objectBO.CreateCMSObject(session, objectTypeId);

            GeneralJournalObject generalJournalObject = new GeneralJournalObject(session)
            {
                GeneralJournalId = ret,
                ObjectId         = CMSObject
            };

            generalJournalObject.Save();

            if (session is UnitOfWork)
            {
                session.FlushChanges();
            }
            //Copy readonly data from transaction to journal
            //Get transaction object
            NAS.DAL.CMS.ObjectDocument.Object transactionCMSObject
                = session.GetObjectByKey <NAS.DAL.Accounting.Journal.Transaction>(transactionId)
                  .TransactionObjects.First().ObjectId;
            //Get general journal object
            NAS.DAL.CMS.ObjectDocument.Object generalJournalCMSObject =
                ret.GeneralJournalObjects.First().ObjectId;

            objectBO.CopyReadOnlyCustomFieldData(
                transactionCMSObject.ObjectId,
                generalJournalCMSObject.ObjectId);

            return(ret);
        }
Exemple #2
0
        public override void CreateTransaction(Guid voucherId, string code, DateTime issuedDate, double amount, string description)
        {
            UnitOfWork uow = null;

            try
            {
                GeneralJournalBO generalJournalBO = new GeneralJournalBO();
                uow = XpoHelper.GetNewUnitOfWork();
                //Get the origin artifact
                ReceiptVouches receiptVouches = uow.GetObjectByKey <ReceiptVouches>(voucherId);

                //Create new transaction
                ReceiptVouchesTransaction transaction = new ReceiptVouchesTransaction(uow)
                {
                    TransactionId    = Guid.NewGuid(),
                    Amount           = amount,
                    Code             = code,
                    CreateDate       = DateTime.Now,
                    Description      = description,
                    IssueDate        = issuedDate,
                    ReceiptVouchesId = receiptVouches,
                    RowStatus        = Utility.Constant.ROWSTATUS_ACTIVE,
                    UpdateDate       = DateTime.Now
                };
                uow.FlushChanges();
                //Create double entry
                //Create debit jounal
                GeneralJournal debitGeneralJournal = generalJournalBO.CreateGeneralJournal
                                                     (
                    uow,
                    transaction.TransactionId,
                    Account.GetDefault(uow, DefaultAccountEnum.NAAN_DEFAULT).AccountId,
                    Side.DEBIT,
                    amount,
                    description,
                    JounalTypeFlag.ACTUAL
                                                     );
                //Create credit jounal
                GeneralJournal creditGeneralJournal = generalJournalBO.CreateGeneralJournal
                                                      (
                    uow,
                    transaction.TransactionId,
                    Account.GetDefault(uow, DefaultAccountEnum.NAAN_DEFAULT).AccountId,
                    Side.CREDIT,
                    amount,
                    description,
                    JounalTypeFlag.ACTUAL
                                                      );

                ObjectBO objectBO = new ObjectBO();
                //Create CMS object for transaction
                NAS.DAL.CMS.ObjectDocument.Object transactionCMSObject =
                    objectBO.CreateCMSObject(uow,
                                             DAL.CMS.ObjectDocument.ObjectTypeEnum.VOUCHER_RECEIPT);

                TransactionObject transactionObject = new TransactionObject(uow)
                {
                    ObjectId      = transactionCMSObject,
                    TransactionId = transaction
                };

                GeneralJournalObject debitGeneralJournalObject  = null;
                GeneralJournalObject creditGeneralJournalObject = null;
                //Create CMS object for debit jounal
                NAS.DAL.CMS.ObjectDocument.Object debitJounalCMSObject =
                    objectBO.CreateCMSObject(uow,
                                             DAL.CMS.ObjectDocument.ObjectTypeEnum.VOUCHER_RECEIPT);
                debitGeneralJournalObject = new GeneralJournalObject(uow)
                {
                    GeneralJournalId = debitGeneralJournal,
                    ObjectId         = debitJounalCMSObject
                };

                //Create CMS object for debit jounal
                NAS.DAL.CMS.ObjectDocument.Object creditJounalCMSObject =
                    objectBO.CreateCMSObject(uow,
                                             DAL.CMS.ObjectDocument.ObjectTypeEnum.VOUCHER_RECEIPT);
                creditGeneralJournalObject = new GeneralJournalObject(uow)
                {
                    GeneralJournalId = creditGeneralJournal,
                    ObjectId         = creditJounalCMSObject
                };

                uow.FlushChanges();

                //Copy readonly data from original artifact
                //Get origin CMS object
                VoucherObject voucherObject = receiptVouches.VoucherObjects.FirstOrDefault();
                if (voucherObject != null)
                {
                    NAS.DAL.CMS.ObjectDocument.Object CMSVoucherObject = voucherObject.ObjectId;
                    //Copy artifact's data to cms object of transaction
                    objectBO.CopyReadOnlyCustomFieldData(
                        CMSVoucherObject.ObjectId,
                        transactionCMSObject.ObjectId);
                    //Copy artifact's data to cms object of default general journals
                    objectBO.CopyReadOnlyCustomFieldData(
                        CMSVoucherObject.ObjectId,
                        debitJounalCMSObject.ObjectId);

                    objectBO.CopyReadOnlyCustomFieldData(
                        CMSVoucherObject.ObjectId,
                        creditJounalCMSObject.ObjectId);
                }

                uow.CommitChanges();
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (uow != null)
                {
                    uow.Dispose();
                }
            }
        }
        protected void gridviewGeneralJournal_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e)
        {
            ASPxGridView grid = sender as ASPxGridView;
            UnitOfWork   uow  = null;

            try
            {
                uow = XpoHelper.GetNewUnitOfWork();
                GeneralJournalBO generalJournalBO = new GeneralJournalBO();
                ObjectBO         objectBO         = new ObjectBO();

                double amount = 0;
                string description;
                Side   side;

                Guid transactionId = (Guid)grid.GetMasterRowKeyValue();
                Guid accountId     = (Guid)e.NewValues["AccountId!Key"];
                description = (string)e.NewValues["Description"];

                if (e.NewValues["Debit"] != null && (double)e.NewValues["Debit"] > 0)
                {
                    amount = (double)e.NewValues["Debit"];
                    side   = Side.DEBIT;
                }
                else if (e.NewValues["Credit"] != null && (double)e.NewValues["Credit"] > 0)
                {
                    amount = (double)e.NewValues["Credit"];
                    side   = Side.CREDIT;
                }
                else
                {
                    throw new Exception("Invaild parameter");
                }

                GeneralJournal generalJournal = Strategy.CreateGeneralJournal(
                    uow,
                    transactionId,
                    accountId,
                    side,
                    amount,
                    description,
                    JounalTypeFlag.ACTUAL);

                uow.FlushChanges();

                //Copy readonly data from transaction to journal
                //Get transaction object
                NAS.DAL.CMS.ObjectDocument.Object transactionCMSObject
                    = uow.GetObjectByKey <Transaction>(transactionId).TransactionObjects.First().ObjectId;
                //Get general journal object
                NAS.DAL.CMS.ObjectDocument.Object generalJournalCMSObject =
                    generalJournal.GeneralJournalObjects.First().ObjectId;

                objectBO.CopyReadOnlyCustomFieldData(
                    transactionCMSObject.ObjectId,
                    generalJournalCMSObject.ObjectId);

                uow.CommitChanges();

                grid.JSProperties["cpEvent"] = "GeneralJournalChanged";
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                e.Cancel = true;
                grid.CancelEdit();
                if (uow != null)
                {
                    uow.Dispose();
                }
            }
        }