Пример #1
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);
        }
Пример #2
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);
        }
Пример #3
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();
                }
            }
        }