private void FillEditViewForm(bool isEditMode)
    {
        lblHeading.Text = isEditMode ? "Edit Credit Note" : "View Credit Note";
        Page.Title      = isEditMode ? "Edit Credit Note" : "View Credit Note";

        CreditNote creditNote = CreditNoteDB.GetByID(GetFormID());

        if (creditNote == null)
        {
            HideTableAndSetErrorMessage("Invalid Credit Note ID");
            return;
        }


        lblId.Text             = creditNote.CreditNoteID.ToString();
        lblInvoiceId.Text      = creditNote.Invoice.InvoiceID.ToString();
        lblCreditNoteDate.Text = creditNote.CreditNoteDateAdded.ToString("d MMM, yyyy");
        lblAddedBy.Text        = creditNote.Staff.Person.FullnameWithoutMiddlename;
        lblTotal.Font.Bold     = !isEditMode;


        if (isEditMode)
        {
            txtTotal.Text       = creditNote.Total.ToString();
            txtReason.Text      = creditNote.Reason;
            lblAmountOwing.Text = (InvoiceDB.GetByID(creditNote.Invoice.InvoiceID).TotalDue - creditNote.Total).ToString();
            lblTotal.Visible    = false;
            lblReason.Visible   = false;
        }
        else
        {
            lblTotal.Text         = creditNote.Total.ToString();
            lblReason.Text        = creditNote.Reason;
            amountOwedRow.Visible = false;
            txtTotal.Visible      = false;
            txtReason.Visible     = false;
        }



        if (isEditMode)
        {
            btnSubmit.Text = "Update Details";
        }
        else // is view mode
        {
            btnSubmit.Visible = false;
            btnCancel.Text    = "Close";
        }
    }
예제 #2
0
    protected void ReverseCreditNote_Command(object sender, CommandEventArgs e)
    {
        try
        {
            // for some reason, it doesn't keep the command argument when set in
            // the code behind in a nested repeater, so set it in a hidden control and its fine

            //int creditNoteID = Convert.ToInt32(e.CommandArgument);

            int creditNoteID = -1;
            foreach (Control c in ((Control)sender).Parent.Controls)
            {
                if (c.ID == "lblHiddenCreditNoteID")
                {
                    creditNoteID = Convert.ToInt32(((HiddenField)c).Value);
                }
            }


            CreditNote creditNote = CreditNoteDB.GetByID(creditNoteID);
            if (creditNote == null)
            {
                throw new CustomMessageException("Adjustment note - does not exist");
            }
            if (creditNote.IsReversed)
            {
                throw new CustomMessageException("Adjustment note already reversed");
            }

            CreditNoteDB.Reverse(creditNote.CreditNoteID, Convert.ToInt32(Session["StaffID"]));

            FillInvoicesList();
        }
        catch (CustomMessageException cmEx)
        {
            SetErrorMessage(cmEx.Message);
        }
        catch (Exception ex)
        {
            SetErrorMessage("", ex.ToString());
        }
    }
예제 #3
0
    public static void Reverse(int creditnote_id, int reversed_by)
    {
        CreditNote creditNote = CreditNoteDB.GetByID(creditnote_id);

        if (creditNote == null)
        {
            throw new CustomMessageException("Adjustment note - does not exist");
        }
        if (creditNote.IsReversed)
        {
            throw new CustomMessageException("Adjustment note already reversed");
        }

        // set total=0, set who and when it was reversed, and original amount
        string sql = "UPDATE CreditNote SET total = 0, reversed_by = " + reversed_by + ",reversed_date = '" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "',pre_reversed_amount = " + creditNote.Total + " WHERE creditnote_id = " + creditnote_id.ToString();

        DBBase.ExecuteNonResult(sql);

        // set invoice as not paid
        InvoiceDB.UpdateIsPaid(null, creditNote.Invoice.InvoiceID, false);

        // update the GL for the year this was done
    }