示例#1
0
        public void DeletePlanningTransaction(Session session, Guid transactionId)
        {
            SaleInvoiceTransaction transaction = session.GetObjectByKey <SaleInvoiceTransaction>(transactionId);

            if (transaction == null)
            {
                return;
            }
            try
            {
                transaction.RowStatus = Constant.ROWSTATUS_DELETED;
                transaction.Save();

                CriteriaOperator criteria_0 = new BinaryOperator("TransactionId", transaction, BinaryOperatorType.Equal);
                CriteriaOperator criteria_1 = new BinaryOperator("RowStatus", Constant.ROWSTATUS_ACTIVE, BinaryOperatorType.GreaterOrEqual);
                CriteriaOperator criteria_2 = new BinaryOperator("JournalType", Constant.PLANNING_JOURNAL, BinaryOperatorType.Equal);
                CriteriaOperator criteria   = new GroupOperator(GroupOperatorType.And, criteria_0, criteria_2);

                XPCollection <GeneralJournal> journalList = new XPCollection <GeneralJournal>(session, criteria);

                foreach (GeneralJournal generalJournal in journalList)
                {
                    generalJournal.RowStatus = Constant.ROWSTATUS_DELETED;
                    generalJournal.Save();
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
示例#2
0
        public void UpdatePlanningTransaction(Session session, Guid transactionId, DateTime _PaymentDate, string _Name, double _Amount, string _Description, Guid _CurrencyId)
        {
            SaleInvoiceTransaction transaction = session.GetObjectByKey <SaleInvoiceTransaction>(transactionId);

            if (transaction == null || _Amount == 0)
            {
                return;
            }
            try
            {
                AccountingBO accountingBO = new AccountingBO();

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

                if (currency == null || account == null)
                {
                    return;
                }

                transaction.IssueDate   = _PaymentDate;
                transaction.Code        = _Name;
                transaction.Amount      = _Amount;
                transaction.Description = _Description;
                transaction.RowStatus   = Utility.Constant.ROWSTATUS_ACTIVE;
                transaction.UpdateDate  = DateTime.Now;
                transaction.Save();

                CriteriaOperator criteria_0 = new BinaryOperator("TransactionId", transaction, BinaryOperatorType.Equal);
                CriteriaOperator criteria_1 = new BinaryOperator("RowStatus", Constant.ROWSTATUS_ACTIVE, BinaryOperatorType.GreaterOrEqual);
                CriteriaOperator criteria_2 = new BinaryOperator("JournalType", Constant.PLANNING_JOURNAL, BinaryOperatorType.Equal);
                CriteriaOperator criteria   = new GroupOperator(GroupOperatorType.And, criteria_0, criteria_1, criteria_2);

                XPCollection <GeneralJournal> journalList = new XPCollection <GeneralJournal>(session, criteria);

                foreach (GeneralJournal generalJournal in journalList)
                {
                    generalJournal.AccountId = account;
                    if (generalJournal.Credit == 0)
                    {
                        generalJournal.Debit = _Amount;
                    }
                    else
                    {
                        generalJournal.Credit = _Amount;
                    }
                    generalJournal.Description = _Name;
                    generalJournal.CurrencyId  = currency;
                    generalJournal.Save();
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
示例#3
0
        public Guid CreatePlanningTransaction(Session session, Guid billId, DateTime _PaymentDate, string _Name, double _Amount, string _Description, Guid _CurrencyId)
        {
            SaleInvoiceTransaction newTransaction = new SaleInvoiceTransaction(session);

            try
            {
                AccountingBO accountingBO = new AccountingBO();
                SalesInvoice salesInvoice = session.GetObjectByKey <SalesInvoice>(billId);
                Currency     currency     = session.GetObjectByKey <Currency>(_CurrencyId);

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

                if (salesInvoice == null || currency == null || account == null)
                {
                    return(Guid.Empty);
                }

                newTransaction.IssueDate      = _PaymentDate;
                newTransaction.Code           = _Name;
                newTransaction.Amount         = _Amount;
                newTransaction.Description    = _Description;
                newTransaction.RowStatus      = Utility.Constant.ROWSTATUS_ACTIVE;
                newTransaction.SalesInvoiceId = salesInvoice;
                newTransaction.CreateDate     = DateTime.Now;
                newTransaction.UpdateDate     = DateTime.Now;
                newTransaction.Save();

                accountingBO.CreateGeneralJournal(session, newTransaction.TransactionId, account.AccountId, Constant.PLANNING_JOURNAL, _Name, _Amount, 0, Constant.ROWSTATUS_ACTIVE, _CurrencyId);
                accountingBO.CreateGeneralJournal(session, newTransaction.TransactionId, account.AccountId, Constant.PLANNING_JOURNAL, _Name, 0, _Amount, Constant.ROWSTATUS_ACTIVE, _CurrencyId);
            }
            catch (Exception)
            {
                throw;
            }
            return(newTransaction.TransactionId);
        }
示例#4
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();
                }
            }
        }
示例#5
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;
            }
        }
示例#6
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();
        }