예제 #1
0
        protected void grdBooking_RowDeleting(object sender, DevExpress.Web.Data.ASPxDataDeletingEventArgs e)
        {
            CriteriaOperator filter = new BinaryOperator("SalesInvoiceInventoryTransactionId", Guid.Parse(Session["SaleBillId"].ToString()), BinaryOperatorType.Equal);
            XPCollection <SalesInvoiceInventoryAccountingTransaction> saleInvoiceTransaction = new XPCollection <SalesInvoiceInventoryAccountingTransaction>(session, filter);

            if (saleInvoiceTransaction.Count > 0)
            {
                foreach (SalesInvoiceInventoryAccountingTransaction item in saleInvoiceTransaction)
                {
                    if (item.RowStatus == ROW_NOT_DELETE)
                    {
                        e.Cancel = true;
                        return;
                    }
                }
            }

            filter = new BinaryOperator("TransactionId", Guid.Parse(e.Values["TransactionId"].ToString()), BinaryOperatorType.Equal);
            SalesInvoiceInventoryAccountingTransaction salesInvoiceInventoryTransaction = session.FindObject <SalesInvoiceInventoryAccountingTransaction>(filter);

            if (salesInvoiceInventoryTransaction != null)
            {
                salesInvoiceInventoryTransaction.RowStatus = ROW_DELETE;
                salesInvoiceInventoryTransaction.Save();
            }

            //e.Cancel = true;
        }
예제 #2
0
        protected void cpBooking_Callback(object sender, DevExpress.Web.ASPxClasses.CallbackEventArgsBase e)
        {
            session = XpoHelper.GetNewSession();


            switch (e.Parameter)
            {
            case "view":

                grdBooking.DetailRows.CollapseAllRows();

                if (Session["SaleBillId"] == null)
                {
                    return;
                }

                session = XpoHelper.GetNewSession();
                SalesInvoice salesInvoice = session.GetObjectByKey <SalesInvoice>(Guid.Parse(Session["SaleBillId"].ToString()));

                CriteriaOperator filter = new BinaryOperator("SalesInvoiceInventoryTransactionId", Guid.Parse(Session["SaleBillId"].ToString()), BinaryOperatorType.Equal);
                XPCollection <SalesInvoiceInventoryAccountingTransaction> saleInvoiceTransaction = new XPCollection <SalesInvoiceInventoryAccountingTransaction>(session, filter);

                if (saleInvoiceTransaction.Count > 0)
                {
                    foreach (SalesInvoiceInventoryAccountingTransaction item in saleInvoiceTransaction)
                    {
                        if (item.RowStatus == ROW_NOT_DELETE)
                        {
                            grdBooking.Columns["Thao tác"].Visible = false;
                            break;
                        }
                        else
                        {
                            grdBooking.Columns["Thao tác"].Visible = true;
                        }
                    }
                }
                else
                {
                    grdBooking.AddNewRow();
                    grdBooking.Columns["Thao tác"].Visible = true;
                }

                cpBooking.JSProperties.Add("cpEnable", "true");


                /////


                break;

            case "booking":

                salesInvoice = session.GetObjectByKey <SalesInvoice>(Guid.Parse(Session["SaleBillId"].ToString()));

                filter = new BinaryOperator("SalesInvoiceInventoryTransactionId", Guid.Parse(Session["SaleBillId"].ToString()), BinaryOperatorType.Equal);
                saleInvoiceTransaction = new XPCollection <SalesInvoiceInventoryAccountingTransaction>(session, filter);

                foreach (SalesInvoiceInventoryAccountingTransaction item in saleInvoiceTransaction)
                {
                    double credit = 0;
                    double debit  = 0;

                    filter = new GroupOperator(GroupOperatorType.And,
                                               new BinaryOperator("TransactionId", item.TransactionId, BinaryOperatorType.Equal),
                                               new BinaryOperator("RowStatus", ROW_NEW, BinaryOperatorType.Equal));
                    XPCollection <GeneralJournal> generalJournal = new XPCollection <GeneralJournal>(session, filter);

                    foreach (GeneralJournal x in generalJournal)
                    {
                        filter = new GroupOperator(GroupOperatorType.And,
                                                   new BinaryOperator("TransactionId", item.TransactionId, BinaryOperatorType.Equal),
                                                   new BinaryOperator("AccountId", x.AccountId, BinaryOperatorType.Equal),
                                                   new BinaryOperator("RowStatus", ROW_NEW, BinaryOperatorType.Equal));

                        XPCollection <GeneralJournal> generalJ = new XPCollection <GeneralJournal>(session, filter);
                        if (generalJ.Count >= 2)
                        {
                            cpBooking.JSProperties.Add("cpUnbooked", "1");
                            return;
                        }

                        credit += x.Credit;
                        debit  += x.Debit;
                    }

                    if (credit != debit)
                    {
                        cpBooking.JSProperties.Add("cpUnbooked", "2");
                        return;
                    }
                }

                foreach (SalesInvoiceInventoryAccountingTransaction item in saleInvoiceTransaction)
                {
                    item.RowStatus = ROW_NOT_DELETE;
                    item.Save();

                    filter = new BinaryOperator("TransactionId", item.TransactionId, BinaryOperatorType.Equal);
                    XPCollection <GeneralJournal> generalJournal = new XPCollection <GeneralJournal>(session, filter);
                    double milsec = 0;
                    foreach (GeneralJournal x in generalJournal)
                    {
                        NAS.DAL.Accounting.AccountChart.Account account = session.GetObjectByKey <NAS.DAL.Accounting.AccountChart.Account>(x.AccountId.AccountId);
                        //General general = new General();
                        //general.BalanceUpdate(session, account, x, false, x.Debit-x.Credit);
                        AccountingBO accountBO = new AccountingBO();
                        accountBO.CreateGeneralLedger(session, x.TransactionId.TransactionId, x.GeneralJournalId, milsec);

                        milsec += 10;
                    }
                }


                filter = new BinaryOperator("SalesInvoiceInventoryTransactionId", Guid.Parse(Session["SaleBillId"].ToString()), BinaryOperatorType.Equal);
                SalesInvoiceInventoryAccountingTransaction purchaseInvoiceInventoryTransaction = session.FindObject <SalesInvoiceInventoryAccountingTransaction>(filter);

                purchaseInvoiceInventoryTransaction.RowStatus = ROW_NOT_DELETE;
                purchaseInvoiceInventoryTransaction.Save();

                grdBooking.DetailRows.CollapseAllRows();
                grdBooking.Columns["Thao tác"].Visible = false;

                cpBooking.JSProperties.Add("cpEnable", "true");

                break;


            default:
                break;
            }
        }