Esempio n. 1
0
        public void DeletePlanningTransaction(Session session, Guid transactionId)
        {
            PurchaseInvoiceTransaction transaction = session.GetObjectByKey <PurchaseInvoiceTransaction>(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;
            }
        }
Esempio n. 2
0
        public void UpdatePlanningTransaction(Session session, Guid transactionId, DateTime _PaymentDate, string _Name, double _Amount, string _Description, Guid _CurrencyId)
        {
            PurchaseInvoiceTransaction transaction = session.GetObjectByKey <PurchaseInvoiceTransaction>(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;
            }
        }
Esempio n. 3
0
        public Guid CreatePlanningTransaction(Session session, Guid billId, DateTime _PaymentDate, string _Name, double _Amount, string _Description, Guid _CurrencyId)
        {
            PurchaseInvoiceTransaction newTransaction = new PurchaseInvoiceTransaction(session);

            if (_Amount == 0)
            {
                return(Guid.Empty);
            }
            try
            {
                AccountingBO accountingBO = new AccountingBO();
                NAS.DAL.Invoice.PurchaseInvoice purchaseInvoice = session.GetObjectByKey <NAS.DAL.Invoice.PurchaseInvoice>(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 (purchaseInvoice == 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.PurchaseInvoiceId = purchaseInvoice;
                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);
        }
Esempio n. 4
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();
        }
Esempio n. 5
0
        protected override void CloneBillTransaction(Session session, Guid billId, ref Bill ret)
        {
            PurchaseInvoiceTransactionBO invoiceTransactionBO = new PurchaseInvoiceTransactionBO();
            var      transactions = invoiceTransactionBO.GetTransactions(session, billId);
            ObjectBO objectBO     = new ObjectBO();

            foreach (var invoiceTransaction in transactions)
            {
                PurchaseInvoiceTransaction sourcePurchaseInvoiceTransaction =
                    (PurchaseInvoiceTransaction)invoiceTransaction;
                PurchaseInvoiceTransaction purchaseInvoiceTransaction = new PurchaseInvoiceTransaction(session)
                {
                    Amount            = sourcePurchaseInvoiceTransaction.Amount,
                    Code              = String.Format("BT_{0}", ret.Code),
                    CreateDate        = DateTime.Now,
                    Description       = String.Format("BT_{0}", ret.Code),
                    IssueDate         = sourcePurchaseInvoiceTransaction.IssueDate,
                    PurchaseInvoiceId = (NAS.DAL.Invoice.PurchaseInvoice)ret,
                    RowStatus         = Utility.Constant.ROWSTATUS_ACTIVE,
                    UpdateDate        = DateTime.Now
                };
                purchaseInvoiceTransaction.Save();
                //Create CMS Object for Transaction
                NAS.DAL.CMS.ObjectDocument.Object transactionCMSObject =
                    objectBO.CreateCMSObject(session, DAL.CMS.ObjectDocument.ObjectTypeEnum.INVOICE_PURCHASE);
                TransactionObject transactionObject = new TransactionObject(session)
                {
                    ObjectId      = transactionCMSObject,
                    TransactionId = purchaseInvoiceTransaction
                };
                transactionObject.Save();
                //Clone GeneralJournal
                var generalJournals = sourcePurchaseInvoiceTransaction.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 = purchaseInvoiceTransaction
                    };
                    generalJournal.Save();
                    //Create CMS object for GeneralJournal
                    NAS.DAL.CMS.ObjectDocument.Object generalJournalCMSObject =
                        objectBO.CreateCMSObject(session, DAL.CMS.ObjectDocument.ObjectTypeEnum.INVOICE_PURCHASE);
                    GeneralJournalObject generalJournalObject = new GeneralJournalObject(session)
                    {
                        GeneralJournalId = generalJournal,
                        ObjectId         = generalJournalCMSObject
                    };
                    generalJournalObject.Save();
                }
            }
        }
Esempio n. 6
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.PurchaseInvoice bill =
                    session.GetObjectByKey <NAS.DAL.Invoice.PurchaseInvoice>(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 actualPurchaseInvoiceTransactions = bill.PurchaseInvoiceTransactions;

                actualPurchaseInvoiceTransactions.Criteria = criteria;

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

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

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

                    transactionObject.Save();
                }

                return(true);
            }
            catch (Exception)
            {
                throw;
            }
        }