Ejemplo n.º 1
0
        protected void gridviewGeneralJournal_RowDeleting(object sender, DevExpress.Web.Data.ASPxDataDeletingEventArgs e)
        {
            ASPxGridView grid = sender as ASPxGridView;

            try
            {
                Guid transactionId = (Guid)grid.GetMasterRowKeyValue();
                TransactionBOBase transactionBOBase = new TransactionBOBase();
                Transaction       transaction       = null;
                string            message;
                bool isBooked = transactionBOBase.IsBookedTransaction(session, (Guid)transactionId, out transaction);
                if (isBooked)
                {
                    message = String.Format("Bút toán '{0}' đã được ghi sổ", transaction.Code);
                    throw new Exception(message);
                }

                GeneralJournalBO generalJournalBO = new GeneralJournalBO();
                Guid             generalJournalId = (Guid)e.Keys["GeneralJournalId"];
                Strategy.DeleteGeneralJournal(generalJournalId);
                grid.JSProperties["cpEvent"] = "GeneralJournalChanged";
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                e.Cancel = true;
            }
        }
Ejemplo n.º 2
0
        protected void gridBookingEntries_RowDeleting(object sender, DevExpress.Web.Data.ASPxDataDeletingEventArgs e)
        {
            try
            {
                var transactionId = e.Keys["TransactionId"];
                TransactionBOBase transactionBOBase = new TransactionBOBase();
                Transaction       transaction       = null;
                string            message;
                bool isBooked = transactionBOBase.IsBookedTransaction(session, (Guid)transactionId, out transaction);
                if (isBooked)
                {
                    message = String.Format("Bút toán '{0}' đã được ghi sổ", transaction.Code);
                    throw new Exception(message);
                }

                ManualBookingTransactionBO manualBookingTransactionBO = new ManualBookingTransactionBO();
                //Create manual booking transaction
                manualBookingTransactionBO.DeleteTransaction((Guid)transactionId);

                gridBookingEntries.JSProperties["cpDataChanged"] = true;
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                e.Cancel = true;
            }
        }
Ejemplo n.º 3
0
        public bool CanBookEntries(out IEnumerable <string> messages)
        {
            TransactionBOBase transactionBOBase = new TransactionBOBase();

            messages = new List <string>();
            var transactions = Strategy.TransactionsDataSource;

            foreach (var transaction in transactions)
            {
                CanBookingEntryReturnValue canBookingEntryReturnValue =
                    transactionBOBase.CanBookingEntry(transaction.TransactionId, true);
                if (canBookingEntryReturnValue != CanBookingEntryReturnValue.BALANCED)
                {
                    string message = null;
                    if (!CanBookEntry(transaction, out message))
                    {
                        ((List <string>)messages).Add(message);
                    }
                }
            }
            if (messages.Count() != 0)
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 4
0
        protected void customFieldDataGridView_BeforeDataEditing(object sender, EventArgs args)
        {
            TransactionBOBase transactionBOBase = new TransactionBOBase();
            Transaction       transaction       = null;
            string            message;
            bool isBooked = transactionBOBase.IsBookedTransaction(session, TransactionId, out transaction);

            if (isBooked)
            {
                message = String.Format("Bút toán '{0}' đã được ghi sổ", transaction.Code);
                throw new Exception(message);
            }
        }
Ejemplo n.º 5
0
        public bool CanBookEntry(NAS.DAL.Accounting.Journal.Transaction transaction, out string message)
        {
            message = null;
            TransactionBOBase          transactionBOBase          = new TransactionBOBase();
            CanBookingEntryReturnValue canBookingEntryReturnValue =
                transactionBOBase.CanBookingEntry(transaction.TransactionId, true);

            if (canBookingEntryReturnValue != CanBookingEntryReturnValue.BALANCED)
            {
                switch (canBookingEntryReturnValue)
                {
                case CanBookingEntryReturnValue.HAVE_NO_JOURNAL:
                    message = String.Format("Chưa có phát sinh nào trong bút toán '{0}'",
                                            transaction.Code);
                    break;

                case CanBookingEntryReturnValue.DEBIT_CREDIT_ZERO:
                    message = String.Format("Phát sinh 'Nợ' và phát sinh 'Có' cùng bằng 0 trong bút toán '{0}'",
                                            transaction.Code);
                    break;

                case CanBookingEntryReturnValue.NOT_BALANCED:
                    message = String.Format("Phát sinh 'Nợ' và phát sinh 'Có' không cân bằng trong bút toán '{0}'",
                                            transaction.Code);
                    break;

                case CanBookingEntryReturnValue.NOT_EQUAL_WITH_TOTAL:
                    message = String.Format("Phát sinh 'Nợ' và phát sinh 'Có' không bằng với tổng tiền trong bút toán '{0}'",
                                            transaction.Code);
                    break;

                case CanBookingEntryReturnValue.INVALID_TRANSACTION_STATUS:
                    message = String.Format("Trạng thái của bút toán '{0}' không hợp lệ", transaction.Code);
                    break;

                case CanBookingEntryReturnValue.MANY_SIDE:
                    message = String.Format("Bút toán '{0}' vừa có nhiều Phát sinh 'Nợ' và nhiều phát sinh 'Có'",
                                            transaction.Code);
                    break;

                default:
                    break;
                }
            }
            if (message != null)
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 6
0
        protected void gridviewGeneralJournal_InitNewRow(object sender, DevExpress.Web.Data.ASPxDataInitNewRowEventArgs e)
        {
            ASPxGridView      grid              = sender as ASPxGridView;
            Guid              transactionId     = (Guid)grid.GetMasterRowKeyValue();
            TransactionBOBase transactionBOBase = new TransactionBOBase();
            Transaction       transaction       = null;
            string            message;
            bool              isBooked = transactionBOBase.IsBookedTransaction(session, (Guid)transactionId, out transaction);

            if (isBooked)
            {
                message = String.Format("Bút toán '{0}' đã được ghi sổ", transaction.Code);
                throw new Exception(message);
            }
        }
Ejemplo n.º 7
0
        protected void gridBookingEntries_StartRowEditing(object sender, DevExpress.Web.Data.ASPxStartRowEditingEventArgs e)
        {
            var transactionId = e.EditingKeyValue;
            TransactionBOBase transactionBOBase = new TransactionBOBase();
            Transaction       transaction       = null;
            string            message;
            bool isBooked = transactionBOBase.IsBookedTransaction(session, (Guid)transactionId, out transaction);

            if (isBooked)
            {
                message = String.Format("Bút toán '{0}' đã được ghi sổ", transaction.Code);
                throw new Exception(message);
            }

            gridBookingEntries.JSProperties.Add("cpShowEditForm", transactionId.ToString());
            gridBookingEntries.CancelEdit();
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Kiểm tra phiếu kho đã ghi sổ hay chưa
        /// </summary>
        /// <param name="_InventoryCommand"></param>
        /// <returns></returns>
        public bool IsBookedEntriesForInventoryCommand(Session _Session, Guid _InventoryCommand)
        {
            try
            {
                NAS.BO.Accounting.Journal.TransactionBOBase transactionBOBase = new TransactionBOBase();
                InventoryCommand command = _Session.GetObjectByKey <InventoryCommand>(_InventoryCommand);
                if (command == null)
                {
                    throw new Exception("The InventoryCommand is not exist in system");
                }

                command.Reload();

                if (command.InventoryCommandFinancialTransactions != null && command.InventoryCommandFinancialTransactions.Count > 0)
                {
                    foreach (InventoryCommandFinancialTransaction t in command.InventoryCommandFinancialTransactions)
                    {
                        Transaction transaction = null;
                        if (!transactionBOBase.IsBookedTransaction(_Session, t.TransactionId, out transaction))
                        {
                            return(false);
                        }
                    }
                }

                if (command.RowStatus != Utility.Constant.ROWSTATUS_BOOKED_ENTRY)
                {
                    return(false);
                }

                return(true);
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 9
0
        protected void gridBookingEntries_CustomCallback(object sender, ASPxGridViewCustomCallbackEventArgs e)
        {
            string[]   args    = e.Parameters.Split('|');
            string     command = args[0];
            UnitOfWork uow     = XpoHelper.GetNewUnitOfWork();

            try
            {
                if (command.Equals("Book"))
                {
                    if (args.Length < 2)
                    {
                        throw new Exception("Invalid parameter");
                    }
                    TransactionBOBase transactionBOBase = new TransactionBOBase();
                    int visibleIndex  = int.Parse(args[1]);
                    var transactionId = gridBookingEntries.GetRowValues(visibleIndex, "TransactionId");
                    //Get transaction
                    string      message;
                    Transaction transaction = null;
                    bool        isBooked    = transactionBOBase.IsBookedTransaction(session, (Guid)transactionId, out transaction);
                    if (isBooked)
                    {
                        message = String.Format("Bút toán '{0}' đã được ghi sổ", transaction.Code);
                        throw new Exception(message);
                    }
                    if (!CanBookEntry(transaction, out message))
                    {
                        throw new Exception(message);
                    }
                    if (transaction != null)
                    {
                        ////2014/02/13 Duc.Vo DEL-----START
                        //transactionBOBase.BookEntry(transaction.TransactionId);
                        ////2014/02/13 Duc.Vo DEL-----END

                        ////2014/02/13 Duc.Vo INS-----START
                        if (!transactionBOBase.BookEntry(uow, transaction.TransactionId))
                        {
                            throw new Exception("Xử lý ghi sổ phát sinh lỗi");
                        }

                        BusinessObjectBO.CreateBusinessObject(uow,
                                                              Utility.Constant.BusinessObjectType_FinancialTransaction,
                                                              transaction.TransactionId,
                                                              transaction.IssueDate);
                        ////2014/02/13 Duc.Vo INS-----END
                    }
                    gridBookingEntries.JSProperties["cpDataChanged"] = true;
                    uow.CommitChanges();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                uow.Dispose();
            }
        }
Ejemplo n.º 10
0
        protected void gridviewGeneralJournal_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e)
        {
            ASPxGridView grid = sender as ASPxGridView;
            UnitOfWork   uow  = null;

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

                double amount = 0;
                string description;
                Side   side;

                Guid transactionId = (Guid)grid.GetMasterRowKeyValue();
                TransactionBOBase transactionBOBase = new TransactionBOBase();
                Transaction       transaction       = null;
                string            message;
                bool isBooked = transactionBOBase.IsBookedTransaction(session, (Guid)transactionId, out transaction);
                if (isBooked)
                {
                    message = String.Format("Bút toán '{0}' đã được ghi sổ", transaction.Code);
                    throw new Exception(message);
                }

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

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

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

                uow.CommitChanges();

                grid.JSProperties["cpEvent"] = "GeneralJournalChanged";
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                e.Cancel = true;
                grid.CancelEdit();
                if (uow != null)
                {
                    uow.Dispose();
                }
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Ghi sổ tài chính phiếu kho
        /// </summary>
        /// <param name="_InventoryCommand"></param>
        public void BookFinancialEntriesOfInventoryCommand(Guid _InventoryCommand)
        {
            UnitOfWork uow = null;

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

                InventoryCommandBO CheckBO = new InventoryCommandBO();

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

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

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

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

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

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

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

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

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

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

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

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

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

                command.RowStatus = Utility.Constant.ROWSTATUS_BOOKED_ENTRY;

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

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

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

                    BusinessObjectBO.CreateBusinessObject(uow,
                                                          objectFinacialType,
                                                          tf.TransactionId,
                                                          tf.IssueDate);
                }
                uow.CommitChanges();
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (uow != null)
                {
                    uow.Dispose();
                }
            }
        }
Ejemplo n.º 12
0
        protected void panelBookingEntriesPopup_Callback(object sender, DevExpress.Web.ASPxClasses.CallbackEventArgsBase e)
        {
            string[] args    = e.Parameter.Split('|');
            string   command = args[0];

            NAS.BO.Invoice.PurchaseInvoiceBO purchaseInvoiceBO
                = new NAS.BO.Invoice.PurchaseInvoiceBO();
            switch (command)
            {
            case "Show":
                popupBookingEntriesForm.ShowOnPageLoad = true;
                BillId = Guid.Parse(args[1]);
                BindData();
                popupBookingEntriesForm.HeaderText = String.Format("Hạch toán phiếu mua hàng - {0}",
                                                                   purchaseInvoiceBO.GetBillById(session, BillId).Code);
                break;

            case "Book":
                popupBookingEntriesForm.ShowOnPageLoad = true;
                /*2014-02-13 ERP-1417 Duc.Vo INS START*/
                BusinessObjectBO BusinessObjectBO = new BusinessObjectBO();
                int objectInventoryFinacialType   = int.MinValue;
                //int objectInventoryItemType = int.MinValue;
                int objectInvoiceFinacialType = int.MinValue;
                int objectVoucherItemType     = int.MinValue;
                /*2014-02-13 ERP-1417 Duc.Vo INS END*/
                string messages = null;

                UnitOfWork uow = null;
                try
                {
                    uow = XpoHelper.GetNewUnitOfWork();
                    Bill bill = purchaseInvoiceBO.GetBillById(uow, BillId);

                    popupBookingEntriesForm.HeaderText = String.Format("Hạch toán phiếu mua hàng - {0}", bill.Code);

                    if (bill.RowStatus.Equals(Utility.Constant.ROWSTATUS_BOOKED_ENTRY))
                    {
                        messages = String.Format("Phiếu mua hàng '{0}' đã được ghi sổ", bill.Code);
                    }
                    else
                    {
                        IEnumerable <string> temp;
                        List <string>        errorList = new List <string>();
                        bool canBookEntriesTemp;
                        bool canBookEntries = true;

                        canBookEntriesTemp = gridviewBookingEntriesForm.CanBookEntries(out temp);
                        canBookEntries     = canBookEntries & canBookEntriesTemp;
                        errorList.AddRange(temp);

                        canBookEntriesTemp = gridviewVoucherBookingEntriesForm.CanBookEntries(out temp);
                        canBookEntries     = canBookEntries & canBookEntriesTemp;
                        errorList.AddRange(temp);

                        canBookEntriesTemp = gridviewInventoryBookingEntriesForm.CanBookEntries(out temp);
                        canBookEntries     = canBookEntries & canBookEntriesTemp;
                        errorList.AddRange(temp);

                        /*2014-02-13 ERP-1417 Duc.Vo INS START*/
                        if (bill is NAS.DAL.Invoice.PurchaseInvoice)
                        {
                            objectInventoryFinacialType = Utility.Constant.BusinessObjectType_InputInventoryCommandFinancialTransaction;
                            //objectInventoryItemType = Utility.Constant.BusinessObjectType_InputInventoryCommandItemTransaction;
                            objectInvoiceFinacialType = Utility.Constant.BusinessObjectType_PurcharseFinancialTransaction;
                            objectVoucherItemType     = Utility.Constant.BusinessObjectType_PaymentVoucherTransaction;
                        }
                        else if (bill is NAS.DAL.Invoice.SalesInvoice)
                        {
                            objectInventoryFinacialType = Utility.Constant.BusinessObjectType_OutputInventoryCommandFinancialTransaction;
                            //objectInventoryItemType = Utility.Constant.BusinessObjectType_OutputInventoryCommandItemTransaction;
                            objectInvoiceFinacialType = Utility.Constant.BusinessObjectType_SalesFinancialTransaction;
                            objectVoucherItemType     = Utility.Constant.BusinessObjectType_ReceiptVoucherTransaction;
                        }
                        /*2014-02-13 ERP-1417 Duc.Vo INS END*/

                        if (canBookEntries)
                        {
                            TransactionBOBase transactionBOBase = new TransactionBOBase();

                            bill.RowStatus = Utility.Constant.ROWSTATUS_BOOKED_ENTRY;
                            //Book entries
                            //var transactions = new XPCollection<Transaction>(uow,
                            //    gridviewBookingEntriesForm.GetDataSource());

                            var transactions1 = gridviewBookingEntriesForm.GetDataSource();
                            foreach (var transaction in transactions1)
                            {
                                transactionBOBase.BookEntry(uow, transaction.TransactionId);
                            }

                            var transactions2 = gridviewVoucherBookingEntriesForm.GetDataSource();
                            foreach (var transaction in transactions2)
                            {
                                transactionBOBase.BookEntry(uow, transaction.TransactionId);
                            }

                            var transactions3 = gridviewInventoryBookingEntriesForm.GetDataSource();
                            foreach (var transaction in transactions3)
                            {
                                transactionBOBase.BookEntry(uow, transaction.TransactionId);
                            }

                            /*2014-02-13 ERP-1417 Duc.Vo INS START*/
                            foreach (var transaction in transactions1)
                            {
                                BusinessObjectBO.CreateBusinessObject(uow,
                                                                      objectInvoiceFinacialType,
                                                                      transaction.TransactionId,
                                                                      transaction.IssueDate);
                            }

                            foreach (var transaction in transactions2)
                            {
                                BusinessObjectBO.CreateBusinessObject(uow,
                                                                      objectVoucherItemType,
                                                                      transaction.TransactionId,
                                                                      transaction.IssueDate);
                            }

                            foreach (var transaction in transactions3)
                            {
                                BusinessObjectBO.CreateBusinessObject(uow,
                                                                      objectInventoryFinacialType,
                                                                      transaction.TransactionId,
                                                                      transaction.IssueDate);
                            }
                            /*2014-02-13 ERP-1417 Duc.Vo INS END*/
                        }
                        else
                        {
                            foreach (var message in errorList)
                            {
                                messages += message + "\n";
                            }
                        }
                    }

                    uow.CommitChanges();

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

                    if (messages != null)
                    {
                        panelBookingEntriesPopup.JSProperties["cpError"] = messages;
                    }
                }
                break;

            case "Cancel":
                popupBookingEntriesForm.ShowOnPageLoad = false;
                BillId = Guid.Empty;
                panelBookingEntriesPopup.JSProperties["cpEvent"] = "Closing";
                break;

            default:
                break;
            }
        }
Ejemplo n.º 13
0
        protected void panelBookingEntriesPopup_Callback(object sender, DevExpress.Web.ASPxClasses.CallbackEventArgsBase e)
        {
            string[] args    = e.Parameter.Split('|');
            string   command = args[0];

            NAS.BO.Invoice.PurchaseInvoiceBO purchaseInvoiceBO
                = new NAS.BO.Invoice.PurchaseInvoiceBO();
            switch (command)
            {
            case "Show":
                popupBookingEntriesForm.ShowOnPageLoad = true;
                BillId = Guid.Parse(args[1]);
                BindData();
                popupBookingEntriesForm.HeaderText = String.Format("Hạch toán phiếu mua hàng - {0}",
                                                                   purchaseInvoiceBO.GetBillById(session, BillId).Code);
                break;

            case "Book":
                popupBookingEntriesForm.ShowOnPageLoad = true;
                string messages = null;

                UnitOfWork uow = null;
                try
                {
                    uow = XpoHelper.GetNewUnitOfWork();
                    Bill bill = purchaseInvoiceBO.GetBillById(uow, BillId);

                    popupBookingEntriesForm.HeaderText = String.Format("Hạch toán phiếu mua hàng - {0}", bill.Code);

                    if (bill.RowStatus.Equals(Utility.Constant.ROWSTATUS_BOOKED_ENTRY))
                    {
                        messages = String.Format("Phiếu mua hàng '{0}' đã được ghi sổ", bill.Code);
                    }
                    else
                    {
                        IEnumerable <string> temp;
                        bool canBookEntries = gridviewBookingEntriesForm.CanBookEntries(out temp);
                        if (canBookEntries)
                        {
                            bill.RowStatus = Utility.Constant.ROWSTATUS_BOOKED_ENTRY;
                            //Book entries
                            //var transactions = new XPCollection<Transaction>(uow,
                            //    gridviewBookingEntriesForm.GetDataSource());

                            var transactions = gridviewBookingEntriesForm.GetDataSource();

                            foreach (var transaction in transactions)
                            {
                                TransactionBOBase transactionBOBase = new TransactionBOBase();
                                transactionBOBase.BookEntry(uow, transaction.TransactionId);
                            }
                        }
                        else
                        {
                            foreach (var message in temp)
                            {
                                messages += message + "\n";
                            }
                        }
                    }

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

                    if (messages != null)
                    {
                        panelBookingEntriesPopup.JSProperties["cpError"] = messages;
                    }
                }
                break;

            case "Cancel":
                popupBookingEntriesForm.ShowOnPageLoad = false;
                BillId = Guid.Empty;
                panelBookingEntriesPopup.JSProperties["cpEvent"] = "Closing";
                break;

            default:
                break;
            }
        }