Esempio n. 1
0
    public static Hashtable GetBulkCreditNotesByInvoiceID(Invoice[] invoices)
    {
        Hashtable hash = new Hashtable();

        int[] invoiceIDs = new int[invoices.Length];
        for (int i = 0; i < invoices.Length; i++)
        {
            invoiceIDs[i] = invoices[i].InvoiceID;
        }
        CreditNote[] allcurCreditNotes = CreditNoteDB.GetByInvoiceIDs(invoiceIDs);

        foreach (Invoice curInvoice in invoices)
        {
            ArrayList curCreditNotes = new ArrayList();
            for (int i = 0; i < allcurCreditNotes.Length; i++)
            {
                if (allcurCreditNotes[i].Invoice.InvoiceID == curInvoice.InvoiceID)
                {
                    curCreditNotes.Add(allcurCreditNotes[i]);
                }
            }

            hash[curInvoice.InvoiceID] = (CreditNote[])curCreditNotes.ToArray(typeof(CreditNote));
        }

        return(hash);
    }
    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";
        }
    }
Esempio n. 3
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());
        }
    }
Esempio n. 4
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
    }
Esempio n. 5
0
    protected void Repeater16_ItemCreated(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            DataRowView dr = (DataRowView)e.Item.DataItem;
            if (dr == null || dr.Row == null)
            {
                return;
            }
            DataRow row     = dr.Row;
            Invoice invoice = InvoiceDB.LoadAll(row);


            // get controls
            Repeater           lstCreditNotes        = (Repeater)e.Item.FindControl("lstCreditNotes");
            HtmlGenericControl div_credit_notes_list = (HtmlGenericControl)e.Item.FindControl("div_credit_notes_list");
            HtmlGenericControl span_credit_notes_trailing_space_row = (HtmlGenericControl)e.Item.FindControl("span_credit_notes_trailing_space_row");
            Label      lnkAddCreditNote       = (Label)e.Item.FindControl("lnkAddCreditNote");
            LinkButton showHideCreditNoteList = (LinkButton)e.Item.FindControl("showHideCreditNoteList");


            // get credit notes
            DataTable tblCreditNotes = CreditNoteDB.GetDataTableByInvoice(invoice.InvoiceID);
            lstCreditNotes.Visible = tblCreditNotes.Rows.Count > 0;
            span_credit_notes_trailing_space_row.Visible = tblCreditNotes.Rows.Count > 0;
            if (tblCreditNotes.Rows.Count > 0)
            {
                tblCreditNotes.Columns.Add("credit_note_url", typeof(string));
                tblCreditNotes.Columns.Add("show_status", typeof(string));
                tblCreditNotes.Columns.Add("status", typeof(string));
                tblCreditNotes.Columns.Add("show_reverse_link", typeof(string));
                tblCreditNotes.Columns.Add("show_status_column", typeof(string));
                for (int i = 0; i < tblCreditNotes.Rows.Count; i++)
                {
                    CreditNote creditNote = CreditNoteDB.Load(tblCreditNotes.Rows[i]);
                    tblCreditNotes.Rows[i]["credit_note_url"] = creditNote.GetViewPopupLinkV2();

                    tblCreditNotes.Rows[i]["show_status"]        = creditNote.IsReversed ? "1" : "0";
                    tblCreditNotes.Rows[i]["show_reverse_link"]  = !creditNote.IsReversed && !invoice.IsReversed ? "1" : "0";
                    tblCreditNotes.Rows[i]["show_status_column"] = !invoice.IsReversed ? "1" : "0";
                }

                lstCreditNotes.DataSource = tblCreditNotes;
                lstCreditNotes.DataBind();
            }

            if (!invoice.IsPaID) // can add items
            {
                lnkAddCreditNote.Text = CreditNote.GetAddCreditNotePopupLinkV2(invoice.InvoiceID, "window.location.href = window.location.href;");
            }
            else
            {
                lnkAddCreditNote.Text = tblCreditNotes.Rows.Count > 0 ? string.Empty : "No Adjustment Notes";
            }
            //span_add_credit_notes_row.Style["text-align"] = (tblCreditNotes.Rows.Count > 0) ? "center" : null;  // if have table, center add link, else left align
            lnkAddCreditNote.Visible                 = lnkAddCreditNote.Text.Length > 0;
            showHideCreditNoteList.OnClientClick     = "javascript:show_hide_byname('div_credit_notes_list_" + invoice.InvoiceID + "'); return false;";
            showHideCreditNoteList.Visible           = tblCreditNotes.Rows.Count > 0;
            div_credit_notes_list.Attributes["name"] = "div_credit_notes_list_" + invoice.InvoiceID;
        }
    }
Esempio n. 6
0
    protected void GrdOrgInvoicesOutstanding_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Email")
        {
            int          organisationID = Convert.ToInt32(e.CommandArgument);
            Organisation org            = OrganisationDB.GetByID(organisationID);
            string[]     emails         = ContactDB.GetEmailsByEntityID(org.EntityID);

            if (emails.Length == 0)
            {
                SetErrorMessage("No email address set for '" + org.Name + "'. Please set one to email invoices to them.");
                return;
            }
            else
            {
                DataTable dt  = Session["orginvoicesoutstanding_data"] as DataTable;
                DataRow   row = dt.Select("organisation_id = " + organisationID)[0];

                string invoiceIDsCommaSep = (string)row["invoice_ids_comma_sep"];
                int[]  invoiceIDs         = Array.ConvertAll <string, int>(invoiceIDsCommaSep.Split(','), Convert.ToInt32);


                string tmpLettersDirectory = Letter.GetTempLettersDirectory();
                string originalFile        = Letter.GetLettersDirectory() + (!UserView.GetInstance().IsAgedCareView ? @"OverdueInvoiceTemplate.docx" : @"OverdueInvoiceTemplateAC.docx");
                string tmpDir = FileHelper.GetTempDirectoryName(tmpLettersDirectory);
                System.IO.Directory.CreateDirectory(tmpDir);
                string outputFile = tmpDir + "OverdueInvoices.pdf";


                try
                {
                    Letter.GenerateOutstandingInvoices(originalFile, outputFile, invoiceIDs, -1, organisationID);

                    EmailerNew.SimpleEmail(
                        ((SystemVariables)System.Web.HttpContext.Current.Session["SystemVariables"])["Email_FromEmail"].Value,
                        ((SystemVariables)System.Web.HttpContext.Current.Session["SystemVariables"])["Email_FromName"].Value,
                        string.Join(",", emails),
                        "Overdue Invoices",
                        "Pease find your Invoices attached. <br/>Please call us if you do not agree with the Invoice amount stated.<br /><br />Thank you.",
                        true,
                        new string[] { outputFile },
                        false,
                        null
                        );

                    SetErrorMessage("Invoices Emailed to " + org.Name + " (" + string.Join(",", emails) + ")");
                }
                catch (CustomMessageException cmEx)
                {
                    SetErrorMessage(cmEx.Message);
                }
                catch (Exception ex)
                {
                    SetErrorMessage("", ex.ToString());
                }
                finally
                {
                    try { if (System.IO.File.Exists(outputFile))
                          {
                              System.IO.File.Delete(outputFile);
                          }
                    }
                    catch (Exception) { }

                    // delete temp dir
                    if (tmpDir != null)
                    {
                        try { System.IO.Directory.Delete(tmpDir, true); }
                        catch (Exception) { }
                    }
                }
            }
        }

        if (e.CommandName == "Print")
        {
            int organisationID = Convert.ToInt32(e.CommandArgument);

            DataTable dt  = Session["orginvoicesoutstanding_data"] as DataTable;
            DataRow   row = dt.Select("organisation_id = " + organisationID)[0];

            SetErrorMessage("Org ID: " + row["organisation_id"] + "<br />Invoices: " + row["invoice_ids_comma_sep"]);

            string invoiceIDsCommaSep = (string)row["invoice_ids_comma_sep"];
            int[]  invoiceIDs         = Array.ConvertAll <string, int>(invoiceIDsCommaSep.Split(','), Convert.ToInt32);

            Letter.GenerateOutstandingInvoicesToPrint(Response, invoiceIDs, -1, organisationID, !UserView.GetInstance().IsAgedCareView);
        }

        if (e.CommandName == "SetAllPaid" || e.CommandName == "SetAllWiped")
        {
            try
            {
                int organisationID = Convert.ToInt32(e.CommandArgument);

                DataTable dt  = Session["orginvoicesoutstanding_data"] as DataTable;
                DataRow   row = dt.Select("organisation_id = " + organisationID)[0];

                string invoiceIDsCommaSep = (string)row["invoice_ids_comma_sep"];
                int[]  invoiceIDs         = Array.ConvertAll <string, int>(invoiceIDsCommaSep.Split(','), Convert.ToInt32);


                foreach (int invoiceID in invoiceIDs)
                {
                    Invoice invoice = InvoiceDB.GetByID(invoiceID);
                    if (invoice == null || invoice.IsPaID)
                    {
                        continue;
                    }

                    if (e.CommandName.Equals("SetAllPaid"))
                    {
                        ReceiptDB.Insert(null, 362, invoice.InvoiceID, invoice.TotalDue, Convert.ToDecimal(0.00), false, false, DateTime.MinValue, Convert.ToInt32(Session["StaffID"]));
                        InvoiceDB.UpdateIsPaid(null, invoice.InvoiceID, true);
                    }
                    else if (e.CommandName.Equals("SetAllWiped"))
                    {
                        CreditNoteDB.Insert(invoice.InvoiceID, invoice.TotalDue, string.Empty, Convert.ToInt32(Session["StaffID"]));
                        InvoiceDB.UpdateIsPaid(null, invoice.InvoiceID, true);
                    }
                }

                SetErrorMessage("Invoices Set As " + (e.CommandName.Equals("SetAllPaid") ? "Paid" : "Wiped") + " : " + row["invoice_ids_comma_sep"]);

                GrdOrgInvoicesOutstanding_FillGrid();
            }
            catch (CustomMessageException cmEx)
            {
                SetErrorMessage(cmEx.Message);
            }
            catch (Exception ex)
            {
                SetErrorMessage("", ex.ToString());
            }
        }
    }
Esempio n. 7
0
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (!IsValidFormID())
        {
            HideTableAndSetErrorMessage();
            return;
        }
        Invoice invoice = InvoiceDB.GetByID(GetFormID());

        if (invoice == null)
        {
            HideTableAndSetErrorMessage("Invalid invoice ID");
            return;
        }


        decimal total = 0;


        ArrayList receipts = new ArrayList();

        for (int i = 0; i < lstPayments.Items.Count; i++)
        {
            Label   lblTypeID = (Label)lstPayments.Items[i].FindControl("lblTypeID");
            TextBox txtAmount = (TextBox)lstPayments.Items[i].FindControl("txtAmount");

            txtAmount.Text = txtAmount.Text.Trim();
            if (txtAmount.Text.Length > 0 && lblTypeID != null)
            {
                receipts.Add(new Tuple <int, decimal>(Convert.ToInt32(lblTypeID.Text), Convert.ToDecimal(txtAmount.Text)));
                total += Convert.ToDecimal(txtAmount.Text);
            }
        }


        ArrayList vouchers = new ArrayList();

        for (int i = 0; i < lstVouchers.Items.Count; i++)
        {
            HiddenField hiddenCreditID = (HiddenField)lstVouchers.Items[i].FindControl("hiddenCreditID");
            HiddenField hiddenEntityID = (HiddenField)lstVouchers.Items[i].FindControl("hiddenEntityID");
            TextBox     txtAmount      = (TextBox)lstVouchers.Items[i].FindControl("txtAmount");

            txtAmount.Text = txtAmount.Text.Trim();
            if (txtAmount.Text.Length > 0)
            {
                vouchers.Add(new Tuple <int, int, decimal>(Convert.ToInt32(hiddenCreditID.Value), Convert.ToInt32(hiddenEntityID.Value), Convert.ToDecimal(txtAmount.Text)));
                total += Convert.ToDecimal(txtAmount.Text);
            }
        }


        if (txtCreditNoteTotal.Text == string.Empty)
        {
            txtCreditNoteTotal.Text = "0";
        }
        total += Convert.ToDecimal(txtCreditNoteTotal.Text);

        decimal totalOwed  = invoice.TotalDue - total;
        bool    isOverPaid = totalOwed < 0;
        bool    isPaid     = totalOwed <= 0;

        if (isOverPaid)
        {
            SetErrorMessage("Total can not be more than the amount owing.");
            return;
        }


        // put in try/catch block in case someone just used the vouchers and there is more being used than is remaining in the voucher
        ArrayList creditIDsAdded = new ArrayList();

        try
        {
            foreach (Tuple <int, int, decimal> item in vouchers)
            {
                int creditID = CreditDB.Insert_UseVoucher(item.Item2, item.Item3, item.Item1, invoice.InvoiceID, Convert.ToInt32(Session["StaffID"]));
                creditIDsAdded.Add(creditID);
            }
        }
        catch (Exception ex)
        {
            // roll back
            foreach (int creditID in creditIDsAdded)
            {
                CreditDB.Delete(creditID);
            }

            SetErrorMessage(ex.Message);
            return;
        }

        foreach (Tuple <int, decimal> item in receipts)
        {
            ReceiptDB.Insert(null, item.Item1, invoice.InvoiceID, item.Item2, Convert.ToDecimal(0.00), false, isOverPaid, DateTime.MinValue, Convert.ToInt32(Session["StaffID"]));
        }

        if (Convert.ToDecimal(txtCreditNoteTotal.Text) > 0)
        {
            CreditNoteDB.Insert(invoice.InvoiceID, Convert.ToDecimal(txtCreditNoteTotal.Text), txtCreditCardReason.Text, Convert.ToInt32(Session["StaffID"]));
        }

        if (isPaid)
        {
            InvoiceDB.UpdateIsPaid(null, invoice.InvoiceID, true);
        }

        FillEmptyAddForm();

        // close this window
        string returnValue = Request.QueryString["returnValue"] != null ? Request.QueryString["returnValue"] : "false";

        Page.ClientScript.RegisterStartupScript(this.GetType(), "close", "<script language=javascript>window.returnValue=" + returnValue + ";window.opener.location.href = window.opener.location.href;self.close();</script>");
    }
Esempio n. 8
0
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (GetUrlParamType() == UrlParamType.View)
        {
            Response.Redirect(UrlParamModifier.AddEdit(Request.RawUrl, "type", "edit"));
        }
        //else if (GetUrlParamType() == UrlParamType.Edit)
        //{
        //    if (!IsValidFormID())
        //    {
        //        HideTableAndSetErrorMessage();
        //        return;
        //    }
        //    Receipt receipt = ReceiptDB.GetByID(GetFormID());
        //    if (receipt == null)
        //    {
        //        HideTableAndSetErrorMessage("Invalid receipt ID");
        //        return;
        //    }

        //    ReceiptDB.Update(receipt.ReceiptID, Convert.ToInt32(ddlPaymentType.SelectedValue), Convert.ToDecimal(txtTotal.Text), Convert.ToDecimal(txtAmountReconciled.Text), chkFailedToClear.Checked, receipt.IsOverpaid, GetBankProcessedDateFromForm());

        //    Response.Redirect(UrlParamModifier.AddEdit(Request.RawUrl, "type", "view_only"));


        //    // close this window
        //    //Page.ClientScript.RegisterStartupScript(this.GetType(), "close", "<script language=javascript>window.returnValue=false;self.close();</script>");
        //}
        else if (GetUrlParamType() == UrlParamType.Add)
        {
            if (!IsValidFormID())
            {
                HideTableAndSetErrorMessage();
                return;
            }
            Invoice invoice = InvoiceDB.GetByID(GetFormID());
            if (invoice == null)
            {
                HideTableAndSetErrorMessage("Invalid invoice ID");
                return;
            }

            decimal thisRefundAmount = Convert.ToDecimal(txtTotal.Text);
            if (thisRefundAmount > invoice.ReceiptsTotal)
            {
                SetErrorMessage("Can not be more than the amount receipted.");
                return;
            }


            if (!invoice.IsPaID)
            {
                int credit_note_id = CreditNoteDB.Insert(invoice.InvoiceID, invoice.TotalDue, "Auto credit noted to set inv as paid so can refund.", Convert.ToInt32(Session["StaffID"]));
                InvoiceDB.UpdateIsPaid(null, invoice.InvoiceID, true);
            }

            int refund_id = RefundDB.Insert(invoice.InvoiceID, thisRefundAmount, Convert.ToInt32(ddlRefundReason.SelectedValue), txtComment.Text, Convert.ToInt32(Session["StaffID"]));
            InvoiceDB.UpdateIsRefund(invoice.InvoiceID, true);


            // close this window
            Page.ClientScript.RegisterStartupScript(this.GetType(), "close", "<script language=javascript>window.returnValue=false;self.close();</script>");
        }
        else
        {
            HideTableAndSetErrorMessage("", "Invalid URL Parameters");
        }
    }