Beispiel #1
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();
            }
        }
Beispiel #2
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();
                }
            }
        }
Beispiel #3
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;
            }
        }
Beispiel #4
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;
            }
        }
        protected void PanelGeneralBooking_Callback(object sender, DevExpress.Web.ASPxClasses.CallbackEventArgsBase e)
        {
            m_ParamCallBack = e.Parameter.Split('|');

            switch (m_ParamCallBack[0])
            {
            case "edit":

                txtGeneralBookingCode.Text        = "";
                txtGeneralBookingDate.Value       = DateTime.Now;
                txtGeneralBookingStatus.Text      = "Chưa ghi sổ";
                txtGeneralBookingAmount.Value     = null;
                txtGeneralBookingDescription.Text = "";

                m_TransactionId = Guid.Parse(m_ParamCallBack[1].ToString());
                m_Transaction   = m_Session.GetObjectByKey <Transaction>(m_TransactionId);
                if (m_Transaction != null)
                {
                    txtGeneralBookingCode.Text        = m_Transaction.Code;
                    txtGeneralBookingAmount.Value     = m_Transaction.Amount;
                    txtGeneralBookingDate.Value       = m_Transaction.IssueDate;
                    txtGeneralBookingDescription.Text = m_Transaction.Description;
                    txtGeneralBookingStatus.Text      = "";

                    gridviewGeneralJournal.CriteriaParameters.Add("TransactionId", m_TransactionId.ToString());
                    gridviewGeneralJournal.CriteriaParameters.Add("RowStatus", Utility.Constant.ROWSTATUS_ACTIVE.ToString());

                    grdGeneralBookingJournal.DataBind();
                }
                else
                {
                    m_TransactionId = Guid.NewGuid();
                }

                Session["TransactionId"]           = m_TransactionId;
                PopupGeneralBooking.ShowOnPageLoad = true;

                gridviewGeneralJournal.CriteriaParameters.Add("TransactionId", m_TransactionId.ToString());
                gridviewGeneralJournal.CriteriaParameters.Add("RowStatus", Utility.Constant.ROWSTATUS_ACTIVE.ToString());

                break;

            case "cancel":
                Session["TransactionId"]           = null;
                PopupGeneralBooking.ShowOnPageLoad = false;
                break;

            case "book":
                UnitOfWork uow = XpoHelper.GetNewUnitOfWork();


                string      message;
                Transaction transaction = null;
                bool        isBooked    = m_TransactionBOBase.IsBookedTransaction(m_Session, (Guid)Session["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)
                {
                    if (!m_TransactionBOBase.BookEntry(uow, transaction.TransactionId))
                    {
                        throw new Exception("Xử lý ghi sổ phát sinh lỗi");
                    }

                    m_BusinessObjectBO.CreateBusinessObject(uow,
                                                            Utility.Constant.BusinessObjectType_FinancialTransaction,
                                                            transaction.TransactionId,
                                                            transaction.IssueDate);
                }

                uow.CommitChanges();
                PanelGeneralBooking.JSProperties.Add("cpBooked", "Complete");
                Session["TransactionId"] = null;
                break;

            case "save":

                if (txtGeneralBookingCode.Text == "" ||
                    txtGeneralBookingDate.Value == null ||
                    txtGeneralBookingAmount.Value == null)
                {
                    return;
                }

                m_TransactionId = (Guid)Session["TransactionId"];

                m_Code        = txtGeneralBookingCode.Text;
                m_Description = txtGeneralBookingDescription.Text;
                m_IssuedDate  = (DateTime)txtGeneralBookingDate.Value;
                m_Amount      = double.Parse(txtGeneralBookingAmount.Value.ToString());

                m_ManualBookingTransactionBO = new ManualBookingTransactionBO();

                m_Transaction = m_Session.GetObjectByKey <Transaction>(m_TransactionId);
                if (m_Transaction != null)
                {
                    isBooked = m_TransactionBOBase.IsBookedTransaction(m_Session, (Guid)Session["TransactionId"], out transaction);
                    if (isBooked)
                    {
                        message = String.Format("Bút toán '{0}' đã được ghi sổ", transaction.Code);
                        throw new Exception(message);
                    }

                    m_ManualBookingTransactionBO.UpdateTransaction(m_TransactionId, m_Code, m_IssuedDate, m_Amount, m_Description);
                }
                else
                {
                    m_TransactionId = m_ManualBookingTransactionBO.CreateTransaction(m_Code, m_IssuedDate, m_Amount, m_Description);
                }

                Session["TransactionId"] = m_TransactionId;

                gridviewGeneralJournal.CriteriaParameters.Add("TransactionId", m_TransactionId.ToString());
                gridviewGeneralJournal.CriteriaParameters.Add("RowStatus", Utility.Constant.ROWSTATUS_ACTIVE.ToString());

                break;
            }
        }