protected void ButtonProcess_Click(object sender, EventArgs e)
        {
            double CorrectionAmount = 0;

            try
            {
                CorrectionAmount = Convert.ToDouble(TextBoxPaidAmount.Text);
            }
            catch
            {
            }

            if (CorrectionAmount.ToString() != TextBoxPaidAmount.Text)
            {
                Common.InformUser(Page, "Het bedrag wat u heeft ingevuld is niet juist. Controleer het bedrag.");
                TextBoxPaidAmount.Text = CorrectionAmount.ToString();
            }
            else
            {
                LedgerMutation lm = new LedgerMutation();
                ControlObjectContext.AddToLedgerMutationSet(lm);

                Invoice inv = (DataItem as Invoice);

                lm.Ledger      = ControlObjectContext.GetObjectByKey(new EntityKey("ModelTMSContainer.LedgerSet", "Id", new Guid(DropDownListLedger.SelectedValue))) as Ledger;
                lm.Location    = ControlObjectContext.GetObjectByKey(new EntityKey("ModelTMSContainer.LocationSet", "Id", new Guid(DropDownListLocation.SelectedValue))) as Location;
                lm.Description = "INV / PPaid / Vooruitbetaald bedrag factuur " + inv.InvoiceNumber.ToString();
                lm.GroupCode   = inv.GroupCode;
                lm.BookingType = inv.InvoiceType;
                lm.AmountEXVat = CorrectionAmount;
                lm.VATAmount   = 0;
                lm.TotalAmount = CorrectionAmount;
                lm.Process(ControlObjectContext);

                inv.AlreadyPaid   = inv.AlreadyPaid + CorrectionAmount;
                inv.InvoiceStatus = inv.AlreadyPaid != 0 ? "PPaid" : "Open";

                ControlObjectContext.SaveChanges();
                Common.InformUser(Page, "De vooruitbetaling is verwerkt. U kunt dit scherm nu sluiten.");
            }
        }
        protected void ButtonCorrectNow_Click(object sender, EventArgs e)
        {
            // first get the correction amount
            Double CorrectionAmount = 0;

            try
            {
                CorrectionAmount = Convert.ToDouble(TextBox_CorrectionAmount.Text);
            }
            catch
            {
            }

            // correct now
            if (CorrectionAmount.ToString() != TextBox_CorrectionAmount.Text)
            {
                Common.InformUser(Page, "Het correctiebedrag kan niet goed worden herkend. Voer dit opnieuw in en probeer het nogmaals.");
            }
            else
            {
                // start transaction
                using (TransactionScope TS = new TransactionScope())
                {
                    try
                    {
                        // save current record
                        StandardSaveHandler(null, null, false);

                        // update the ledgercheck & create the mutation
                        LedgerCheck lc = (DataItem as LedgerCheck);

                        LedgerBookingCode lbc         = null;
                        Ledger            lg          = null;
                        String            Description = "";

                        // get the ledger or ledgerbookingcode we have to link to
                        if (Request.Params["LedgerBookingCodeId"] != null)
                        {
                            lbc         = ControlObjectContext.GetObjectByKey(new EntityKey("ModelTMSContainer.LedgerBookingCodeSet", "Id", new Guid(Request.Params["LedgerBookingCodeId"]))) as LedgerBookingCode;
                            Description = lbc.Description;
                        }
                        else
                        { // assume Id
                            lg          = ControlObjectContext.GetObjectByKey(new EntityKey("ModelTMSContainer.LedgerSet", "Id", new Guid(Request.Params["Id"]))) as Ledger;
                            Description = lg.Description;
                        }

                        LedgerMutation lm = new LedgerMutation();
                        ControlObjectContext.AddToLedgerMutationSet(lm);

                        lm.Description       = "CORR / Correctie " + Description;
                        lm.IsCorrection      = true;
                        lm.BookingType       = "Buy";
                        lm.LedgerBookingCode = lbc;
                        lm.Ledger            = lg;
                        lm.AmountEXVat       = CorrectionAmount;
                        lm.VATAmount         = 0;
                        lm.TotalAmount       = lm.AmountEXVat;
                        lm.Process(ControlObjectContext);

                        lc.IsLedgerCorrected = true;

                        ControlObjectContext.SaveChanges();

                        TS.Complete();

                        // relado data
                        RebindControls();
                        UpdateLedgerLevel();

                        // inform user
                        Common.InformUser(Page, "De correctie is succesvol verwerkt.");
                    }
                    catch (Exception ex) // commit or procedure failed somewhere
                    {
                        // rollback transaction
                        TS.Dispose();

                        // inform user
                        Common.InformUserOnTransactionFail(ex, Page);
                    }
                }
            }
        }