示例#1
0
        protected void grdBalanceLine_RowInserted(object sender, DevExpress.Web.Data.ASPxDataInsertedEventArgs e)
        {
            if (cboBalanceInitAccount.Value == null || cboBalanceInitCurrency.Value == null)
            {
                return;
            }

            ObjectBO objectBO = new ObjectBO();

            NAS.DAL.CMS.ObjectDocument.Object debitJounalCMSObject = objectBO.CreateCMSObject(session, ObjectTypeEnum.OPENBALANCE_ACCOUTING);

            GeneralJournal debitGeneralJournal = session.GetObjectByKey <GeneralJournal>(Guid.Parse(e.NewValues["GeneralJournalId"].ToString()));

            GeneralJournalObject debitGeneralJournalObject = null;

            debitGeneralJournalObject = new GeneralJournalObject(session);
            debitGeneralJournalObject.GeneralJournalId = debitGeneralJournal;
            debitGeneralJournalObject.ObjectId         = debitJounalCMSObject;
            debitGeneralJournalObject.Save();

            ObjectType objectType = NAS.DAL.CMS.ObjectDocument.ObjectType.GetDefault(session, ObjectTypeEnum.OPENBALANCE_ACCOUTING);

            GeneralJournalCustomType generalJournalCustomType = new GeneralJournalCustomType(session);

            generalJournalCustomType.GeneralJournalId = debitGeneralJournal;
            generalJournalCustomType.ObjectTypeId     = objectType;
            generalJournalCustomType.Save();

            grdBalanceLine.JSProperties.Add("cpRefreshTree", "refresh");
        }
        public override NAS.DAL.Accounting.Journal.GeneralJournal CreateGeneralJournal(DevExpress.Xpo.Session session, Guid transactionId, Guid accountId, NAS.BO.Accounting.Journal.Side side, double amount, string description, NAS.BO.Accounting.Journal.JounalTypeFlag journalType)
        {
            GeneralJournal generalJournal =
                base.CreateGeneralJournal(session,
                                          transactionId,
                                          accountId,
                                          side,
                                          amount,
                                          description,
                                          journalType);
            //Create CMS object...

            ObjectBO objectBO = new ObjectBO();

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

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

            generalJournalObject.Save();

            return(generalJournal);
        }
示例#3
0
        /// <summary>
        /// Tìm đối tượng CMS object của InventoryJournal
        /// </summary>
        /// <param name="InventoryJournalId"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public NAS.DAL.CMS.ObjectDocument.Object GetCMSInventoryJournal(
            Guid InventoryJournalId,
            ObjectTypeEnum type)
        {
            if (type != ObjectTypeEnum.INVENTORY_IN && type != ObjectTypeEnum.INVENTORY_MOVE && type != ObjectTypeEnum.INVENTORY_OUT)
            {
                throw new Exception("The Type is invalid");
            }

            if (InventoryJournalId != null && !InventoryJournalId.Equals(Guid.Empty))
            {
                NAS.DAL.CMS.ObjectDocument.Object cmsObject = null;
                using (UnitOfWork uow = XpoHelper.GetNewUnitOfWork())
                {
                    InventoryJournal       journal       = uow.GetObjectByKey <InventoryJournal>(InventoryJournalId);
                    InventoryJournalObject journalObject =
                        journal.InventoryJournalObjects.FirstOrDefault();
                    if (journalObject == null)
                    {
                        ObjectBO objectBO = new ObjectBO();
                        cmsObject = objectBO.CreateCMSObject(uow, type);
                        InventoryJournalObject newJournalObject = new InventoryJournalObject(uow)
                        {
                            ObjectId           = cmsObject,
                            InventoryJournalId = journal
                        };

                        NAS.DAL.CMS.ObjectDocument.ObjectType objectType
                            = uow.FindObject <ObjectType>(new BinaryOperator("Name", Enum.GetName(typeof(ObjectTypeEnum), type)));

                        if (objectType == null)
                        {
                            throw new Exception("The OjectType is not exist in system");
                        }

                        InventoryJournalCustomType newJournalCustomType = new InventoryJournalCustomType(uow)
                        {
                            ObjectTypeId       = objectType,
                            InventoryJournalId = journal
                        };

                        newJournalCustomType.Save();

                        uow.CommitChanges();
                    }
                    else
                    {
                        cmsObject = journalObject.ObjectId;
                    }
                    return(cmsObject);
                }
            }
            else
            {
                return(null);
            }
        }
示例#4
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);
        }
示例#5
0
        protected void cpAllocation_Callback(object sender, DevExpress.Web.ASPxClasses.CallbackEventArgsBase e)
        {
            CriteriaOperator _filter;

            string[] p = e.Parameter.Split('|');
            switch (p[0])
            {
            case "allocation":

                // Check not has Object to Create

                GeneralJournal debitGeneralJournal = session.GetObjectByKey <GeneralJournal>(Guid.Parse(p[1]));
                if (debitGeneralJournal != null)
                {
                    _filter = new BinaryOperator("GeneralJournalId.GeneralJournalId", debitGeneralJournal.GeneralJournalId, BinaryOperatorType.Equal);
                    GeneralJournalObject debitGeneralJournalObject = session.FindObject <GeneralJournalObject>(_filter);
                    if (debitGeneralJournalObject == null)
                    {
                        ObjectBO objectBO = new ObjectBO();
                        NAS.DAL.CMS.ObjectDocument.Object debitJounalCMSObject = objectBO.CreateCMSObject(session, ObjectTypeEnum.OPENBALANCE_ACCOUTING);

                        debitGeneralJournalObject = new GeneralJournalObject(session);
                        debitGeneralJournalObject.GeneralJournalId = debitGeneralJournal;
                        debitGeneralJournalObject.ObjectId         = debitJounalCMSObject;
                        debitGeneralJournalObject.Save();

                        ObjectType objectType = NAS.DAL.CMS.ObjectDocument.ObjectType.GetDefault(session, ObjectTypeEnum.OPENBALANCE_ACCOUTING);

                        GeneralJournalCustomType generalJournalCustomType = new GeneralJournalCustomType(session);
                        generalJournalCustomType.GeneralJournalId = debitGeneralJournal;
                        generalJournalCustomType.ObjectTypeId     = objectType;
                        generalJournalCustomType.Save();
                    }
                }

                CriteriaOperator     filter = new BinaryOperator("GeneralJournalId.GeneralJournalId", Guid.Parse(p[1]), BinaryOperatorType.Equal);
                GeneralJournalObject generalJournalObject = session.FindObject <GeneralJournalObject>(filter);

                if (generalJournalObject != null)
                {
                    NASCustomFieldDataGridView1.CMSObjectId = Guid.Parse(generalJournalObject.ObjectId.ObjectId.ToString());
                    NASCustomFieldDataGridView1.DataBind();
                }
                break;

            default:
                break;
            }
        }
示例#6
0
 private Guid GetCMSObjectIdOfTransaction(Guid transactionId)
 {
     if (transactionId != null && !transactionId.Equals(Guid.Empty))
     {
         NAS.DAL.CMS.ObjectDocument.Object cmsObject = null;
         using (UnitOfWork uow = XpoHelper.GetNewUnitOfWork())
         {
             Transaction       transaction       = uow.GetObjectByKey <Transaction>(transactionId);
             TransactionObject transactionObject =
                 transaction.TransactionObjects.FirstOrDefault();
             if (transactionObject == null)
             {
                 ObjectBO objectBO = new ObjectBO();
                 NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum objectType = ObjectTypeEnum.VOUCHER_PAYMENT;;
                 if (Strategy.GetConcreteVoucherType().Equals(typeof(NAS.DAL.Vouches.ReceiptVouches)))
                 {
                     objectType = NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum.VOUCHER_RECEIPT;
                 }
                 else if (Strategy.GetConcreteVoucherType().Equals(typeof(NAS.DAL.Vouches.PaymentVouches)))
                 {
                     objectType = NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum.VOUCHER_PAYMENT;
                 }
                 else
                 {
                     throw new Exception("Create object the specific type is out of scope");
                 }
                 cmsObject = objectBO.CreateCMSObject(uow, objectType);
                 TransactionObject newTransactionObject = new TransactionObject(uow)
                 {
                     ObjectId      = cmsObject,
                     TransactionId = transaction
                 };
                 uow.CommitChanges();
             }
             else
             {
                 cmsObject = transactionObject.ObjectId;
             }
             return(cmsObject.ObjectId);
         }
     }
     else
     {
         return(Guid.Empty);
     }
 }
 private Guid GetCMSObjectIdOfGeneralJounal(Guid generalJounalId)
 {
     if (generalJounalId != null && !generalJounalId.Equals(Guid.Empty))
     {
         NAS.DAL.CMS.ObjectDocument.Object cmsObject = null;
         using (UnitOfWork uow = XpoHelper.GetNewUnitOfWork())
         {
             GeneralJournal       generalJournal       = uow.GetObjectByKey <GeneralJournal>(generalJounalId);
             GeneralJournalObject generalJournalObject =
                 generalJournal.GeneralJournalObjects.FirstOrDefault();
             if (generalJournalObject == null)
             {
                 ObjectBO objectBO = new ObjectBO();
                 NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum objectType = ObjectTypeEnum.VOUCHER_PAYMENT;;
                 if (Strategy.GetConcreteVoucherTransactionType().Equals(typeof(NAS.DAL.Accounting.Journal.ReceiptVouchesTransaction)))
                 {
                     objectType = NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum.VOUCHER_RECEIPT;
                 }
                 else if (Strategy.GetConcreteVoucherTransactionType().Equals(typeof(NAS.DAL.Accounting.Journal.PaymentVouchesTransaction)))
                 {
                     objectType = NAS.DAL.CMS.ObjectDocument.ObjectTypeEnum.VOUCHER_PAYMENT;
                 }
                 else
                 {
                     throw new Exception("Create object the specific type is out of scope");
                 }
                 cmsObject = objectBO.CreateCMSObject(uow, objectType);
                 GeneralJournalObject newTransactionObject = new GeneralJournalObject(uow)
                 {
                     ObjectId         = cmsObject,
                     GeneralJournalId = generalJournal
                 };
                 uow.CommitChanges();
             }
             else
             {
                 cmsObject = generalJournalObject.ObjectId;
             }
             return(cmsObject.ObjectId);
         }
     }
     else
     {
         return(Guid.Empty);
     }
 }
示例#8
0
        public PaymentVouches CreateNewObject(Session session)
        {
            try
            {
                PaymentVouches paymentVouches = new PaymentVouches(session)
                {
                    VouchesId = Guid.NewGuid(),
                    RowStatus = Utility.Constant.ROWSTATUS_TEMP
                };
                paymentVouches.Save();

                ObjectBO objectBO = new ObjectBO();

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

                VoucherObject voucherObject = new VoucherObject(session)
                {
                    ObjectId  = CMSObject,
                    VoucherId = paymentVouches
                };
                voucherObject.Save();

                VoucherCustomType voucherCustomType = new VoucherCustomType(session)
                {
                    VoucherId    = paymentVouches,
                    ObjectTypeId = ObjectType.GetDefault(session, ObjectTypeEnum.VOUCHER_PAYMENT)
                };
                voucherCustomType.Save();

                return(paymentVouches);
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
            }
        }
示例#9
0
        protected void Unnamed1_Callback(object sender, DevExpress.Web.ASPxClasses.CallbackEventArgsBase e)
        {
            ItemBO itemBO = new ItemBO();
            int    cnt    = 0;

            using (UnitOfWork uow = XpoHelper.GetNewUnitOfWork())
            {
                try
                {
                    XPCollection <NAS.DAL.Nomenclature.Item.Item> items = new XPCollection <NAS.DAL.Nomenclature.Item.Item>(uow, new BinaryOperator("RowStatus", 0, BinaryOperatorType.Greater));
                    foreach (NAS.DAL.Nomenclature.Item.Item i in items)
                    {
                        ObjectBO objectBO = new ObjectBO();
                        Item     item     = uow.GetObjectByKey <Item>(i.ItemId);
                        if (item == null)
                        {
                            throw new Exception("The key is not exist in Item");
                        }

                        List <NAS.DAL.CMS.ObjectDocument.ObjectType> typeList = null;

                        if (item.ItemCustomTypes != null)
                        {
                            typeList = item.ItemCustomTypes.Select(r => r.ObjectTypeId).ToList();
                        }

                        if (typeList != null)
                        {
                            foreach (NAS.DAL.CMS.ObjectDocument.ObjectType type in typeList)
                            {
                                if (!itemBO.checkAlreadyHasObjectWithObjectType(uow, i.ItemId, type.ObjectTypeId))
                                {
                                    NAS.DAL.CMS.ObjectDocument.Object o = objectBO.CreateCMSObject(uow, type.ObjectTypeId);
                                    ItemObject it = new ItemObject(uow);
                                    it.ObjectId = o;
                                    it.ItemId   = item;
                                }
                            }
                        }

                        uow.FlushChanges();
                        cnt++;
                    }
                    lblnum.Text = cnt.ToString();

                    ////Get MANUFACTURER object type
                    //NAS.DAL.CMS.ObjectDocument.ObjectType objectType = Util.getXPCollection<NAS.DAL.CMS.ObjectDocument.ObjectType>(uow, "Name", "MANUFACTURER").FirstOrDefault();
                    //XPCollection<NAS.DAL.Nomenclature.Organization.ManufacturerOrg> manufacturers = new XPCollection<NAS.DAL.Nomenclature.Organization.ManufacturerOrg>(uow);
                    //manufacturers.Criteria = new UnaryOperator(UnaryOperatorType.IsNull, "ObjectId");
                    //foreach (var manufacturer in manufacturers)
                    //{
                    //    //Create new CMS object
                    //    NAS.DAL.CMS.ObjectDocument.Object CMSObject = new NAS.DAL.CMS.ObjectDocument.Object(uow)
                    //    {
                    //        ObjectId = Guid.NewGuid(),
                    //        ObjectTypeId = objectType
                    //    };
                    //    CMSObject.Save();
                    //    manufacturer.ObjectTypeId = objectType;
                    //    manufacturer.ObjectId = CMSObject;
                    //    manufacturer.Save();
                    //}
                    uow.CommitChanges();
                }
                catch
                {
                    throw;
                }
            }
        }
示例#10
0
        public void BillTransactionInit(Session session,
                                        Guid BillId,
                                        double TotalAmount,
                                        double DiscountAmount,
                                        double TaxAmount,
                                        double ItemAmount
                                        )
        {
            CriteriaOperator filter = new GroupOperator(GroupOperatorType.And,
                                                        new BinaryOperator("Code", "", BinaryOperatorType.Equal),
                                                        //new BinaryOperator("SalesInvoiceId", BillId, BinaryOperatorType.Equal),
                                                        new BinaryOperator("SalesInvoiceId", BillId, BinaryOperatorType.Equal));

            SaleInvoiceTransaction saleInvoiceTransaction = session.FindObject <SaleInvoiceTransaction>(filter);

            if (saleInvoiceTransaction != null)
            {
                filter = new BinaryOperator("TransactionId", saleInvoiceTransaction.TransactionId, BinaryOperatorType.Equal);
                TransactionObject transactionO = session.FindObject <TransactionObject>(filter);

                if (transactionO != null)
                {
                    transactionO.Delete();
                    transactionO.Save();
                }

                filter = new BinaryOperator("GeneralJournalId.TransactionId", saleInvoiceTransaction.TransactionId, BinaryOperatorType.Equal);
                XPCollection <GeneralJournalObject> collectGeneralJournalObject = new XPCollection <GeneralJournalObject>(session, filter);

                if (collectGeneralJournalObject.Count > 0)
                {
                    session.Delete(collectGeneralJournalObject);
                    session.Save(collectGeneralJournalObject);
                }

                filter = new BinaryOperator("TransactionId", saleInvoiceTransaction.TransactionId, BinaryOperatorType.Equal);
                XPCollection <GeneralJournal> collectGeneralJournal = new XPCollection <GeneralJournal>(session, filter);
                if (collectGeneralJournal.Count > 0)
                {
                    session.Delete(collectGeneralJournal);
                    session.Save(collectGeneralJournal);
                }

                Transaction transaction = session.GetObjectByKey <Transaction>(saleInvoiceTransaction.TransactionId);
                if (transaction != null)
                {
                    transaction.Delete();
                    transaction.Save();
                }

                saleInvoiceTransaction.Delete();
                saleInvoiceTransaction.Save();
            }



            saleInvoiceTransaction = new SaleInvoiceTransaction(session);

            saleInvoiceTransaction.Code           = "";
            saleInvoiceTransaction.TransactionId  = Guid.NewGuid();
            saleInvoiceTransaction.CreateDate     = saleInvoiceTransaction.IssueDate = DateTime.Now;
            saleInvoiceTransaction.Amount         = TotalAmount;
            saleInvoiceTransaction.RowStatus      = Utility.Constant.ROWSTATUS_ACTIVE;
            saleInvoiceTransaction.SalesInvoiceId = session.GetObjectByKey <SalesInvoice>(BillId);

            saleInvoiceTransaction.Save();

            ObjectBO objectBO = new ObjectBO();

            NAS.DAL.CMS.ObjectDocument.Object transactionCMSObject =
                objectBO.CreateCMSObject(session,
                                         DAL.CMS.ObjectDocument.ObjectTypeEnum.INVOICE_SALE);

            TransactionObject transactionObject = new TransactionObject(session)
            {
                ObjectId      = transactionCMSObject,
                TransactionId = saleInvoiceTransaction
            };

            transactionObject.Save();

            filter = new BinaryOperator("Code", DefaultAccountEnum.NAAN_DEFAULT.ToString(), BinaryOperatorType.Equal);
            Account account = session.FindObject <Account>(filter);

            // total
            GeneralJournal generalJournal = new GeneralJournal(session);

            generalJournal.GeneralJournalId = Guid.NewGuid();
            generalJournal.TransactionId    = saleInvoiceTransaction;
            generalJournal.RowStatus        = Utility.Constant.ROWSTATUS_ACTIVE;
            generalJournal.JournalType      = 'A';

            generalJournal.AccountId = account;
            generalJournal.Debit     = TotalAmount;
            generalJournal.Save();

            GeneralJournalObject debitGeneralJournalObject = null;

            NAS.DAL.CMS.ObjectDocument.Object debitJounalCMSObject =
                objectBO.CreateCMSObject(session,
                                         DAL.CMS.ObjectDocument.ObjectTypeEnum.INVOICE_SALE);
            debitGeneralJournalObject = new GeneralJournalObject(session)
            {
                GeneralJournalId = generalJournal,
                ObjectId         = debitJounalCMSObject
            };

            debitGeneralJournalObject.Save();

            // Discount
            generalJournal = new GeneralJournal(session);
            generalJournal.GeneralJournalId = Guid.NewGuid();
            generalJournal.TransactionId    = saleInvoiceTransaction;
            generalJournal.RowStatus        = Utility.Constant.ROWSTATUS_ACTIVE;
            generalJournal.JournalType      = 'A';

            generalJournal.AccountId = account;
            generalJournal.Credit    = DiscountAmount;
            generalJournal.Save();

            debitJounalCMSObject =
                objectBO.CreateCMSObject(session,
                                         DAL.CMS.ObjectDocument.ObjectTypeEnum.INVOICE_SALE);
            debitGeneralJournalObject = new GeneralJournalObject(session)
            {
                GeneralJournalId = generalJournal,
                ObjectId         = debitJounalCMSObject
            };

            debitGeneralJournalObject.Save();

            // Tax

            generalJournal = new GeneralJournal(session);
            generalJournal.GeneralJournalId = Guid.NewGuid();
            generalJournal.TransactionId    = saleInvoiceTransaction;
            generalJournal.RowStatus        = Utility.Constant.ROWSTATUS_ACTIVE;
            generalJournal.JournalType      = 'A';

            generalJournal.AccountId = account;
            generalJournal.Credit    = TaxAmount;
            generalJournal.Save();

            debitJounalCMSObject =
                objectBO.CreateCMSObject(session,
                                         DAL.CMS.ObjectDocument.ObjectTypeEnum.INVOICE_SALE);
            debitGeneralJournalObject = new GeneralJournalObject(session)
            {
                GeneralJournalId = generalJournal,
                ObjectId         = debitJounalCMSObject
            };

            debitGeneralJournalObject.Save();

            // Item
            generalJournal = new GeneralJournal(session);
            generalJournal.GeneralJournalId = Guid.NewGuid();
            generalJournal.TransactionId    = session.GetObjectByKey <Transaction>(saleInvoiceTransaction.TransactionId);
            generalJournal.RowStatus        = Utility.Constant.ROWSTATUS_ACTIVE;
            generalJournal.JournalType      = 'A';

            generalJournal.AccountId = account;
            generalJournal.Credit    = ItemAmount;
            generalJournal.Save();

            debitJounalCMSObject =
                objectBO.CreateCMSObject(session,
                                         DAL.CMS.ObjectDocument.ObjectTypeEnum.INVOICE_SALE);
            debitGeneralJournalObject = new GeneralJournalObject(session)
            {
                GeneralJournalId = generalJournal,
                ObjectId         = debitJounalCMSObject
            };

            debitGeneralJournalObject.Save();
        }
示例#11
0
        public override bool Save(
            DevExpress.Xpo.Session session,
            Guid billId,
            string billCode,
            DateTime issuedDate,
            DAL.Nomenclature.Organization.Organization sourceOrganizationBill,
            DAL.Nomenclature.Organization.Person targetOrganizationBill)
        {
            try
            {
                //Get bill by ID
                NAS.DAL.Invoice.SalesInvoice bill =
                    session.GetObjectByKey <NAS.DAL.Invoice.SalesInvoice>(billId);
                if (bill == null)
                {
                    throw new Exception("Could not found bill");
                }

                bill.Code                 = billCode;
                bill.IssuedDate           = issuedDate;
                bill.SourceOrganizationId = sourceOrganizationBill;
                bill.TargetOrganizationId = targetOrganizationBill;
                bill.RowStatus            = Utility.Constant.ROWSTATUS_ACTIVE;

                bill.Save();

                //Create default actual transaction
                CriteriaOperator criteria = CriteriaOperator.And(
                    new BinaryOperator("RowStatus", Utility.Constant.ROWSTATUS_ACTIVE, BinaryOperatorType.GreaterOrEqual),
                    CriteriaOperator.Or(
                        new ContainsOperator("GeneralJournals",
                                             new BinaryOperator("JournalType", JounalTypeConstant.ACTUAL)
                                             ),
                        new BinaryOperator(new AggregateOperand("GeneralJournals", Aggregate.Count), 0, BinaryOperatorType.Equal)
                        )
                    );

                var actualSaleInvoiceTransactions = bill.SaleInvoiceTransactions;

                actualSaleInvoiceTransactions.Criteria = criteria;

                if (actualSaleInvoiceTransactions == null ||
                    actualSaleInvoiceTransactions.Count == 0)
                {
                    SaleInvoiceTransaction saleInvoiceTransaction
                        = new SaleInvoiceTransaction(session)
                        {
                        Code           = "BT_" + bill.Code,
                        CreateDate     = DateTime.Now,
                        Description    = "BT_" + bill.Code,
                        IssueDate      = issuedDate,
                        RowStatus      = Utility.Constant.ROWSTATUS_ACTIVE,
                        UpdateDate     = DateTime.Now,
                        SalesInvoiceId = bill
                        };
                    saleInvoiceTransaction.Save();

                    ObjectBO objectBO = new ObjectBO();
                    NAS.DAL.CMS.ObjectDocument.Object cmsObject =
                        objectBO.CreateCMSObject(session, DAL.CMS.ObjectDocument.ObjectTypeEnum.INVOICE_SALE);

                    TransactionObject transactionObject = new TransactionObject(session)
                    {
                        ObjectId      = cmsObject,
                        TransactionId = saleInvoiceTransaction
                    };

                    transactionObject.Save();
                }

                return(true);
            }
            catch (Exception)
            {
                throw;
            }
        }
示例#12
0
        protected override void CloneBillTransaction(Session session, Guid billId, ref Bill ret)
        {
            SaleInvoiceTransactionBO invoiceTransactionBO = new SaleInvoiceTransactionBO();
            var      transactions = invoiceTransactionBO.GetTransactions(session, billId);
            ObjectBO objectBO     = new ObjectBO();

            foreach (var invoiceTransaction in transactions)
            {
                SaleInvoiceTransaction sourceSaleInvoiceTransaction =
                    (SaleInvoiceTransaction)invoiceTransaction;
                SaleInvoiceTransaction saleInvoiceTransaction = new SaleInvoiceTransaction(session)
                {
                    Amount         = sourceSaleInvoiceTransaction.Amount,
                    Code           = String.Format("BT_{0}", ret.Code),
                    CreateDate     = DateTime.Now,
                    Description    = String.Format("BT_{0}", ret.Code),
                    IssueDate      = sourceSaleInvoiceTransaction.IssueDate,
                    SalesInvoiceId = (NAS.DAL.Invoice.SalesInvoice)ret,
                    RowStatus      = Utility.Constant.ROWSTATUS_ACTIVE,
                    UpdateDate     = DateTime.Now
                };
                saleInvoiceTransaction.Save();
                //Create CMS Object for Transaction
                NAS.DAL.CMS.ObjectDocument.Object transactionCMSObject =
                    objectBO.CreateCMSObject(session, DAL.CMS.ObjectDocument.ObjectTypeEnum.INVOICE_SALE);
                TransactionObject transactionObject = new TransactionObject(session)
                {
                    ObjectId      = transactionCMSObject,
                    TransactionId = saleInvoiceTransaction
                };
                transactionObject.Save();
                //Clone GeneralJournal
                var generalJournals = sourceSaleInvoiceTransaction.GeneralJournals
                                      .Where(r => r.RowStatus >= Utility.Constant.ROWSTATUS_ACTIVE);
                foreach (var sourceGeneralJournal in generalJournals)
                {
                    GeneralJournal generalJournal = new GeneralJournal(session)
                    {
                        AccountId     = sourceGeneralJournal.AccountId,
                        CreateDate    = DateTime.Now,
                        Credit        = sourceGeneralJournal.Credit,
                        CurrencyId    = sourceGeneralJournal.CurrencyId,
                        Debit         = sourceGeneralJournal.Debit,
                        Description   = sourceGeneralJournal.Description,
                        JournalType   = sourceGeneralJournal.JournalType,
                        RowStatus     = Utility.Constant.ROWSTATUS_ACTIVE,
                        TransactionId = saleInvoiceTransaction
                    };
                    generalJournal.Save();
                    //Create CMS object for GeneralJournal
                    NAS.DAL.CMS.ObjectDocument.Object generalJournalCMSObject =
                        objectBO.CreateCMSObject(session, DAL.CMS.ObjectDocument.ObjectTypeEnum.INVOICE_SALE);
                    GeneralJournalObject generalJournalObject = new GeneralJournalObject(session)
                    {
                        GeneralJournalId = generalJournal,
                        ObjectId         = generalJournalCMSObject
                    };
                    generalJournalObject.Save();
                }
            }
        }
示例#13
0
        protected void grdBalanceLine_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs 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;
            }

            CriteriaOperator _filter = null;

            BalanceForwardTransaction balanceForwardTransaction = session.GetObjectByKey <BalanceForwardTransaction>(Guid.Parse(e.OldValues["TransactionId!Key"].ToString()));

            if (balanceForwardTransaction != null)
            {
                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.Code        = e.NewValues["TransactionId.Code"].ToString();
                balanceForwardTransaction.Description = e.NewValues["TransactionId.Description"].ToString();

                balanceForwardTransaction.Save();
            }

            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["AccountId!Key"]  = cboBalanceInitAccount.Value.ToString();
            e.NewValues["CurrencyId!Key"] = cboBalanceInitCurrency.Value.ToString();

            // Check not has Object to Create

            GeneralJournal debitGeneralJournal = session.GetObjectByKey <GeneralJournal>(Guid.Parse(e.OldValues["GeneralJournalId"].ToString()));

            if (debitGeneralJournal != null)
            {
                _filter = new BinaryOperator("GeneralJournalId.GeneralJournalId", debitGeneralJournal.GeneralJournalId, BinaryOperatorType.Equal);
                GeneralJournalObject debitGeneralJournalObject = session.FindObject <GeneralJournalObject>(_filter);
                if (debitGeneralJournalObject == null)
                {
                    ObjectBO objectBO = new ObjectBO();
                    NAS.DAL.CMS.ObjectDocument.Object debitJounalCMSObject = objectBO.CreateCMSObject(session, ObjectTypeEnum.OPENBALANCE_ACCOUTING);

                    debitGeneralJournalObject = new GeneralJournalObject(session);
                    debitGeneralJournalObject.GeneralJournalId = debitGeneralJournal;
                    debitGeneralJournalObject.ObjectId         = debitJounalCMSObject;
                    debitGeneralJournalObject.Save();

                    ObjectType objectType = NAS.DAL.CMS.ObjectDocument.ObjectType.GetDefault(session, ObjectTypeEnum.OPENBALANCE_ACCOUTING);

                    GeneralJournalCustomType generalJournalCustomType = new GeneralJournalCustomType(session);
                    generalJournalCustomType.GeneralJournalId = debitGeneralJournal;
                    generalJournalCustomType.ObjectTypeId     = objectType;
                    generalJournalCustomType.Save();
                }
            }

            BalanceLineSetData();
            grdBalanceLine.JSProperties.Add("cpRefreshTree", "refresh");
        }
示例#14
0
        /// <summary>
        /// Tạo dữ liệu cho CMS Object Inventory
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="uow"></param>
        /// <param name="InventoryObjectId"></param>
        /// <param name="CMSObjectType"></param>
        public void PopulateCMSObjecForInventoryObject <T>(
            UnitOfWork uow,
            Guid InventoryObjectId,
            DAL.CMS.ObjectDocument.ObjectTypeEnum CMSObjectType)
        {
            ObjectBO bo = new ObjectBO();

            if (typeof(T).Equals(typeof(NAS.DAL.Inventory.Command.InventoryCommand)))
            {
                NAS.DAL.Inventory.Command.InventoryCommand inventoryObject =
                    uow.GetObjectByKey <NAS.DAL.Inventory.Command.InventoryCommand>(InventoryObjectId);
                NAS.DAL.CMS.ObjectDocument.Object o   = bo.CreateCMSObject(uow, CMSObjectType);
                InventoryCommandObject            ICO = new InventoryCommandObject(uow);
                ICO.ObjectId           = o;
                ICO.InventoryCommandId = (inventoryObject as NAS.DAL.Inventory.Command.InventoryCommand);
                ICO.Save();
                NAS.DAL.CMS.ObjectDocument.ObjectType type =
                    NAS.DAL.CMS.ObjectDocument.ObjectType.GetDefault(uow, CMSObjectType);
                if (type == null)
                {
                    throw new Exception("The ObjectType is not exist in system");
                }

                InventoryCommandCustomType ICCT = new InventoryCommandCustomType(uow);
                ICCT.ObjectTypeId       = type;
                ICCT.InventoryCommandId = (inventoryObject as NAS.DAL.Inventory.Command.InventoryCommand);
                ICCT.Save();
            }
            else if (typeof(T).Equals(typeof(NAS.DAL.Inventory.Command.InventoryCommandItemTransaction)))
            {
                InventoryCommandItemTransaction transactionObject =
                    uow.GetObjectByKey <InventoryCommandItemTransaction>(InventoryObjectId);
                NAS.DAL.CMS.ObjectDocument.Object o   = bo.CreateCMSObject(uow, CMSObjectType);
                InventoryTransactionObject        ITO = new InventoryTransactionObject(uow);
                ITO.ObjectId = o;
                ITO.InventoryTransactionId = (transactionObject as NAS.DAL.Inventory.Journal.InventoryTransaction);
                ITO.Save();

                NAS.DAL.CMS.ObjectDocument.ObjectType type =
                    NAS.DAL.CMS.ObjectDocument.ObjectType.GetDefault(uow, CMSObjectType);
                InventoryTransactionCustomType ITCT = new InventoryTransactionCustomType(uow);
                ITCT.ObjectTypeId           = type;
                ITCT.InventoryTransactionId = (transactionObject as NAS.DAL.Inventory.Journal.InventoryTransaction);
                ITCT.Save();
            }
            else if (typeof(T).Equals(typeof(NAS.DAL.Inventory.Command.InventoryCommandFinancialTransaction)))
            {
                InventoryCommandFinancialTransaction transactionObject =
                    uow.GetObjectByKey <InventoryCommandFinancialTransaction>(InventoryObjectId);
                NAS.DAL.CMS.ObjectDocument.Object o = bo.CreateCMSObject(uow, CMSObjectType);
                TransactionObject TO = new TransactionObject(uow);
                TO.ObjectId      = o;
                TO.TransactionId = (transactionObject as Transaction);
                TO.Save();
            }
            else if (typeof(T).Equals(typeof(NAS.DAL.Accounting.Journal.GeneralJournal)))
            {
                GeneralJournal journalObject =
                    uow.GetObjectByKey <GeneralJournal>(InventoryObjectId);
                NAS.DAL.CMS.ObjectDocument.Object o = bo.CreateCMSObject(uow, CMSObjectType);
                GeneralJournalObject GJO            = new GeneralJournalObject(uow);
                GJO.ObjectId         = o;
                GJO.GeneralJournalId = (journalObject as GeneralJournal);
                GJO.Save();
                NAS.DAL.CMS.ObjectDocument.ObjectType type =
                    NAS.DAL.CMS.ObjectDocument.ObjectType.GetDefault(uow, CMSObjectType);
                GeneralJournalCustomType GJCT = new GeneralJournalCustomType(uow);
                GJCT.ObjectTypeId     = type;
                GJCT.GeneralJournalId = (journalObject as GeneralJournal);
                GJCT.Save();
            }
            else if (typeof(T).Equals(typeof(NAS.DAL.Inventory.Journal.InventoryJournal)))
            {
                InventoryJournal journalObject =
                    uow.GetObjectByKey <InventoryJournal>(InventoryObjectId);
                NAS.DAL.CMS.ObjectDocument.Object o   = bo.CreateCMSObject(uow, CMSObjectType);
                InventoryJournalObject            ITO = new InventoryJournalObject(uow);
                ITO.ObjectId           = o;
                ITO.InventoryJournalId = (journalObject as InventoryJournal);
                ITO.Save();

                NAS.DAL.CMS.ObjectDocument.ObjectType type =
                    NAS.DAL.CMS.ObjectDocument.ObjectType.GetDefault(uow, CMSObjectType);
                InventoryJournalCustomType ITCT = new InventoryJournalCustomType(uow);
                ITCT.ObjectTypeId       = type;
                ITCT.InventoryJournalId = (journalObject as InventoryJournal);
                ITCT.Save();
            }
            uow.FlushChanges();
        }
示例#15
0
        /// <summary>
        /// Tìm đối tượng CMS object của InventoryJournal
        /// </summary>
        /// <typeparam name="T">is NAS.DAL.Inventory.Command.InventoryCommandFinancialTransaction
        ///         or NAS.DAL.Inventory.Command.InventoryCommandItemTransaction
        /// </typeparam>
        /// <param name="transactionId"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public NAS.DAL.CMS.ObjectDocument.Object GetCMSTransaction <T>(
            Guid transactionId,
            ObjectTypeEnum type)
        {
            if (type != ObjectTypeEnum.INVENTORY_IN && type != ObjectTypeEnum.INVENTORY_MOVE && type != ObjectTypeEnum.INVENTORY_OUT)
            {
                throw new Exception("The Type is invalid");
            }

            if (!typeof(T).Equals(typeof(NAS.DAL.Inventory.Command.InventoryCommandFinancialTransaction)) &&
                !typeof(T).Equals(typeof(NAS.DAL.Inventory.Command.InventoryCommandItemTransaction)))
            {
                throw new Exception("The Generic Type is invalid");
            }

            if (transactionId != null && !transactionId.Equals(Guid.Empty))
            {
                NAS.DAL.CMS.ObjectDocument.Object cmsObject = null;
                using (UnitOfWork uow = XpoHelper.GetNewUnitOfWork())
                {
                    if (typeof(T).Equals(typeof(NAS.DAL.Inventory.Command.InventoryCommandItemTransaction)))
                    {
                        InventoryCommandItemTransaction transaction       = uow.GetObjectByKey <InventoryCommandItemTransaction>(transactionId);
                        InventoryTransactionObject      transactionObject =
                            transaction.InventoryTransactionObjects.FirstOrDefault();
                        if (transactionObject == null)
                        {
                            ObjectBO objectBO = new ObjectBO();
                            cmsObject = objectBO.CreateCMSObject(uow, type);
                            InventoryTransactionObject newTransactionObject = new InventoryTransactionObject(uow)
                            {
                                ObjectId = cmsObject,
                                InventoryTransactionId = transaction
                            };

                            NAS.DAL.CMS.ObjectDocument.ObjectType objectType
                                = uow.FindObject <ObjectType>(new BinaryOperator("Name", Enum.GetName(typeof(ObjectTypeEnum), type)));

                            if (objectType == null)
                            {
                                throw new Exception("The OjectType is not exist in system");
                            }

                            InventoryTransactionCustomType newTransactionCustomType = new InventoryTransactionCustomType(uow)
                            {
                                ObjectTypeId           = objectType,
                                InventoryTransactionId = transaction
                            };

                            newTransactionCustomType.Save();
                            uow.CommitChanges();
                        }
                        else
                        {
                            cmsObject = transactionObject.ObjectId;
                        }
                        return(cmsObject);
                    }
                    else
                    {
                        InventoryCommandFinancialTransaction transaction = uow.GetObjectByKey <InventoryCommandFinancialTransaction>(transactionId);
                        TransactionObject transactionObject =
                            transaction.TransactionObjects.FirstOrDefault();
                        if (transactionObject == null)
                        {
                            ObjectBO objectBO = new ObjectBO();
                            cmsObject = objectBO.CreateCMSObject(uow, type);
                            TransactionObject newTransactionObject = new TransactionObject(uow)
                            {
                                ObjectId      = cmsObject,
                                TransactionId = transaction
                            };
                            uow.CommitChanges();
                        }
                        else
                        {
                            cmsObject = transactionObject.ObjectId;
                        }
                        return(cmsObject);
                    }
                }
            }
            else
            {
                return(null);
            }
        }
示例#16
0
        public void BillTransactionInit(Session session,
                                        Guid BillId,
                                        double TotalAmount,
                                        double DiscountAmount,
                                        double TaxAmount,
                                        double ItemAmount
                                        )
        {
            CriteriaOperator filter  = new BinaryOperator("Code", DefaultAccountEnum.NAAN_DEFAULT.ToString(), BinaryOperatorType.Equal);
            Account          account = session.FindObject <Account>(filter);

            PurchaseInvoiceTransaction saleInvoiceTransaction = new PurchaseInvoiceTransaction(session);

            saleInvoiceTransaction.TransactionId = Guid.NewGuid();
            saleInvoiceTransaction.CreateDate    = saleInvoiceTransaction.IssueDate = DateTime.Now;
            saleInvoiceTransaction.Amount        = TotalAmount;
            saleInvoiceTransaction.RowStatus     = 0;

            saleInvoiceTransaction.Save();

            ObjectBO objectBO = new ObjectBO();

            NAS.DAL.CMS.ObjectDocument.Object transactionCMSObject =
                objectBO.CreateCMSObject(session,
                                         DAL.CMS.ObjectDocument.ObjectTypeEnum.INVOICE_SALE);

            TransactionObject transactionObject = new TransactionObject(session)
            {
                ObjectId      = transactionCMSObject,
                TransactionId = saleInvoiceTransaction
            };

            transactionObject.Save();

            // total
            GeneralJournal generalJournal = new GeneralJournal(session);

            generalJournal.GeneralJournalId = Guid.NewGuid();
            generalJournal.TransactionId    = session.GetObjectByKey <Transaction>(saleInvoiceTransaction.TransactionId);
            generalJournal.RowStatus        = 0;
            generalJournal.JournalType      = 'A';

            generalJournal.AccountId = account;
            generalJournal.Debit     = TotalAmount;
            generalJournal.Save();

            GeneralJournalObject debitGeneralJournalObject = null;

            NAS.DAL.CMS.ObjectDocument.Object debitJounalCMSObject =
                objectBO.CreateCMSObject(session,
                                         DAL.CMS.ObjectDocument.ObjectTypeEnum.INVOICE_SALE);
            debitGeneralJournalObject = new GeneralJournalObject(session)
            {
                GeneralJournalId = generalJournal,
                ObjectId         = debitJounalCMSObject
            };

            debitGeneralJournalObject.Save();

            // Discount
            generalJournal = new GeneralJournal(session);
            generalJournal.GeneralJournalId = Guid.NewGuid();
            generalJournal.TransactionId    = session.GetObjectByKey <Transaction>(saleInvoiceTransaction.TransactionId);
            generalJournal.RowStatus        = 0;
            generalJournal.JournalType      = 'A';

            generalJournal.AccountId = account;
            generalJournal.Credit    = DiscountAmount;
            generalJournal.Save();

            debitJounalCMSObject =
                objectBO.CreateCMSObject(session,
                                         DAL.CMS.ObjectDocument.ObjectTypeEnum.INVOICE_SALE);
            debitGeneralJournalObject = new GeneralJournalObject(session)
            {
                GeneralJournalId = generalJournal,
                ObjectId         = debitJounalCMSObject
            };

            debitGeneralJournalObject.Save();

            // Tax

            generalJournal = new GeneralJournal(session);
            generalJournal.GeneralJournalId = Guid.NewGuid();
            generalJournal.TransactionId    = session.GetObjectByKey <Transaction>(saleInvoiceTransaction.TransactionId);
            generalJournal.RowStatus        = 0;
            generalJournal.JournalType      = 'A';

            generalJournal.AccountId = account;
            generalJournal.Credit    = DiscountAmount;
            generalJournal.Save();

            debitJounalCMSObject =
                objectBO.CreateCMSObject(session,
                                         DAL.CMS.ObjectDocument.ObjectTypeEnum.INVOICE_SALE);
            debitGeneralJournalObject = new GeneralJournalObject(session)
            {
                GeneralJournalId = generalJournal,
                ObjectId         = debitJounalCMSObject
            };

            debitGeneralJournalObject.Save();

            // Item
            generalJournal = new GeneralJournal(session);
            generalJournal.GeneralJournalId = Guid.NewGuid();
            generalJournal.TransactionId    = session.GetObjectByKey <Transaction>(saleInvoiceTransaction.TransactionId);
            generalJournal.RowStatus        = 0;
            generalJournal.JournalType      = 'A';

            generalJournal.AccountId = account;
            generalJournal.Credit    = ItemAmount;
            generalJournal.Save();

            debitJounalCMSObject =
                objectBO.CreateCMSObject(session,
                                         DAL.CMS.ObjectDocument.ObjectTypeEnum.INVOICE_SALE);
            debitGeneralJournalObject = new GeneralJournalObject(session)
            {
                GeneralJournalId = generalJournal,
                ObjectId         = debitJounalCMSObject
            };

            debitGeneralJournalObject.Save();
        }
示例#17
0
文件: ItemBO.cs 项目: ewin66/dev
        public void updateAllCommonInfoOfItem(Session session, Guid ItemId, string code, string name,
                                              Guid manufacturerId, List <Guid> objectTypeId)
        {
            ObjectBO bo = new ObjectBO();

            try
            {
                session.BeginTransaction();
                Item item = session.GetObjectByKey <Item>(ItemId);
                if (item == null)
                {
                    throw new Exception(String.Format("Không tồn tại ItemId: {0} trong Item table", ItemId));
                }

                ManufacturerOrg manu = session.GetObjectByKey <ManufacturerOrg>(manufacturerId);
                //Issue dropdownlist ---START
                //if (manu == null)
                //    throw new Exception(String.Format("Không tồn tại ManufacturerOrgId: {0} trong Item ManufacturerOrg", manufacturerId));
                //Issue dropdownlist ---END
                item.Code = code;
                item.Name = name;
                item.ManufacturerOrgId = manu;
                item.RowStatus         = Utility.Constant.ROWSTATUS_ACTIVE;
                item.Save();

                removeItemCustomTypeFromItem(session, ItemId);

                foreach (Guid g in objectTypeId)
                {
                    addItemCustomTypeToItem(session, g, ItemId);
                }

                foreach (Guid g in objectTypeId)
                {
                    if (!checkAlreadyHasObjectWithObjectType(session, ItemId, g))
                    {
                        NAS.DAL.CMS.ObjectDocument.Object o = bo.CreateCMSObject(session, g);
                        ItemObject it = new ItemObject(session);
                        it.ObjectId = o;
                        it.ItemId   = item;
                        it.Save();
                    }
                }

                for (int i = item.ItemObjects.Count - 1; i >= 0; i--)
                {
                    ItemObject tmp = item.ItemObjects[i];
                    if (!item.ItemCustomTypes.Select(r => r.ObjectTypeId).Contains(tmp.ObjectId.ObjectTypeId))
                    {
                        bo.DeleteCMSObject(session, tmp.ObjectId.ObjectId);
                    }
                }

                //foreach (ItemObject io in item.ItemObjects)
                //{
                //    if(!item.ItemCustomTypes.Select(r => r.ObjectTypeId).Contains(io.ObjectId.ObjectTypeId)) {
                //        bo.DeleteCMSObject(session, io.ObjectId.ObjectId);
                //    }
                //}

                session.CommitTransaction();
            }
            catch (Exception)
            {
                session.RollbackTransaction();
                throw;
            }
        }
示例#18
0
        public Guid CreateTransaction(string code, DateTime issuedDate, double amount, string description)
        {
            UnitOfWork uow             = null;
            Guid       m_TransactionId = Guid.NewGuid();

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

                //Create new transaction
                ManualBookingTransaction transaction = new ManualBookingTransaction(uow)
                {
                    TransactionId = m_TransactionId,
                    Amount        = amount,
                    Code          = code,
                    CreateDate    = DateTime.Now,
                    Description   = description,
                    IssueDate     = issuedDate,
                    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.MANUAL_BOOKING);

                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.MANUAL_BOOKING);
                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.MANUAL_BOOKING);
                creditGeneralJournalObject = new GeneralJournalObject(uow)
                {
                    GeneralJournalId = creditGeneralJournal,
                    ObjectId         = creditJounalCMSObject
                };

                uow.CommitChanges();
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (uow != null)
                {
                    uow.Dispose();
                }
            }

            return(m_TransactionId);
        }
示例#19
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();
                }
            }
        }