Esempio n. 1
0
        protected void updateInvoiceComment(Data.Entities.LeadInvoice invoice, LeadInvoiceDetail invoiceDetail)
        {
            LeadComment comment = null;

            // retrieve comment by reference
            comment = LeadCommentManager.GetLeadCommentByReferenceId(invoiceDetail.InvoiceLineID);

            if (comment == null)
            {
                comment = new LeadComment();
            }

            comment.InsertBy    = Core.SessionHelper.getUserId();
            comment.InsertDate  = DateTime.Now;
            comment.LeadId      = invoice.LeadId;
            comment.PolicyType  = invoice.PolicyTypeID;
            comment.ReferenceID = invoiceDetail.InvoiceLineID;
            comment.Status      = 1;            // active
            comment.UserId      = Core.SessionHelper.getUserId();
            comment.CommentText = string.Format("<div>Invoice # {0} - {1:MM-dd-yyyy} for {2} Qty:{3:N2} Rate:{4:N2} Item Total:{5:N2}</div><div>{6}</div>",
                                                invoice.AdjusterInvoiceNumber,
                                                invoiceDetail.LineDate,
                                                invoiceDetail.LineDescription ?? "",
                                                invoiceDetail.Qty ?? 0,
                                                invoiceDetail.Rate ?? 0,
                                                invoiceDetail.LineAmount ?? 0,
                                                invoiceDetail.Comments ?? ""
                                                );

            LeadCommentManager.Save(comment);
        }
Esempio n. 2
0
        static public LeadInvoiceDetail GetInvoiceDetailLine(int invoiceLineID)
        {
            LeadInvoiceDetail invoiceLine = (from x in DbContextHelper.DbContext.LeadInvoiceDetail
                                             where x.InvoiceLineID == invoiceLineID
                                             select x).FirstOrDefault <LeadInvoiceDetail>();

            return(invoiceLine);
        }
Esempio n. 3
0
        public static LeadInvoice Save_bak(LeadInvoice invoice)
        {
            LeadInvoice       updateInvoice     = null;
            LeadInvoiceDetail updateinvoiceLine = null;

            if (invoice.InvoiceID == 0)
            {
                DbContextHelper.DbContext.Add(invoice);

                //DbContextHelper.DbContext.SaveChanges();
            }
            else
            {
                updateInvoice = Get(invoice.InvoiceID);

                updateInvoice.InvoiceDate = invoice.InvoiceDate;

                updateInvoice.PolicyTypeID = invoice.PolicyTypeID;

                updateInvoice.BillToName     = invoice.BillToName;
                updateInvoice.BillToAddress1 = invoice.BillToAddress1;
                updateInvoice.BillToAddress2 = invoice.BillToAddress2;
                updateInvoice.BillToAddress3 = invoice.BillToAddress3;

                updateInvoice.AdjusterInvoiceNumber = invoice.AdjusterInvoiceNumber;

                //DbContextHelper.DbContext.SaveChanges();

                foreach (LeadInvoiceDetail invoiceLine in invoice.LeadInvoiceDetail)
                {
                    if (invoiceLine.InvoiceLineID == 0)
                    {
                        updateinvoiceLine = new LeadInvoiceDetail();

                        updateinvoiceLine.InvoiceID = invoice.InvoiceID;

                        DbContextHelper.DbContext.Add(updateinvoiceLine);
                    }
                    else
                    {
                        updateinvoiceLine = GetInvoiceDetailLine(invoiceLine.InvoiceLineID);
                    }

                    updateinvoiceLine.LineItemNo = invoiceLine.LineItemNo;

                    updateinvoiceLine.LineDescription = invoiceLine.LineDescription;

                    updateinvoiceLine.LineAmount = invoiceLine.LineAmount;
                }
            }

            DbContextHelper.DbContext.SaveChanges();

            return(invoice);
        }
        static public int Save(LeadInvoiceDetail invoiceDetail)
        {
            if (invoiceDetail.InvoiceLineID == 0)
            {
                DbContextHelper.DbContext.Add(invoiceDetail);
            }

            DbContextHelper.DbContext.SaveChanges();

            return(invoiceDetail.InvoiceLineID);
        }
        static public void Delete(int id)
        {
            LeadInvoiceDetail invoiceDetail = null;

            invoiceDetail = Get(id);
            if (invoiceDetail != null)
            {
                DbContextHelper.DbContext.DeleteObject(invoiceDetail);

                DbContextHelper.DbContext.SaveChanges();
            }
        }
        static public LeadInvoiceDetail Get(int id)
        {
            LeadInvoiceDetail invoiceDetail = null;

            invoiceDetail = (from x in DbContextHelper.DbContext.LeadInvoiceDetail
                             .Include("InvoiceServiceType")
                             .Include("InvoiceServiceType.InvoiceServiceUnit")
                             where x.InvoiceLineID == id
                             select x).FirstOrDefault <LeadInvoiceDetail>();

            return(invoiceDetail);
        }
Esempio n. 7
0
        static public void DeleteInvoiceDetailLine(int invoiceLineID, int lineItemNo)
        {
            LeadInvoiceDetail invoiceLine = (from x in DbContextHelper.DbContext.LeadInvoiceDetail
                                             where x.InvoiceLineID == invoiceLineID &&
                                             x.LineItemNo == lineItemNo
                                             select x).FirstOrDefault <LeadInvoiceDetail>();

            if (invoiceLine != null)
            {
                DbContextHelper.DbContext.DeleteObject(invoiceLine);

                DbContextHelper.DbContext.SaveChanges();
            }
        }
        private void saveInvoice()
        {
            string[] billToValues = null;
            int clientID = 0;
            int invoiceID = 0;
            int InvoiceLineID = 0;
            Data.Entities.LeadInvoice invoice = null;
            CRM.Data.Entities.LeadPolicy policy = null;
            LeadInvoiceDetail invoiceDetailLine = null;
            LeadInvoiceDetail invoiceDetail = null;

            int nextInvoiceNumber = 0;
            int policyID = 0;
            decimal taxAmount = 0;

            billToValues = ddlBillTo.SelectedValue.Split(new char[] { '|' });

            // get invoice id
            invoiceID = Convert.ToInt32(ViewState["InvoiceID"].ToString());

            clientID = Core.SessionHelper.getClientId();

            // current policy being edited
            policyID = Session["policyID"] == null ? 0 : Convert.ToInt32(Session["policyID"]);
            policy = LeadPolicyManager.GetByID(policyID);

            if (invoiceID == 0) {
                invoice = new Data.Entities.LeadInvoice();

                // get id for current lead
                invoice.LeadId = Core.SessionHelper.getLeadId();

                invoice.isVoid = false;

                // assign client
                invoice.ClientID = clientID;

                // hide print button
                //btnPrint.Visible = false;
            }
            else {
                invoice = LeadInvoiceManager.Get(invoiceID);

                // show print button
                //btnPrint.Visible = true;

            }

            invoice.PolicyID = policy.PolicyType;

            invoice.InvoiceDate = Convert.ToDateTime(txtInvoiceDate.Text);
            invoice.DueDate = Convert.ToDateTime(txtDueDate.Text);
            invoice.BillToName = txtBillTo.Text.Trim();
            invoice.BillToAddress1 = txtBillToAddress1.Text.Trim();
            invoice.BillToAddress2 = txtBillToAddress2.Text.Trim();
            invoice.BillToAddress3 = txtBillToAddress3.Text.Trim();

            invoice.AdjusterID = policy.AdjusterID;

            invoice.AdjusterInvoiceNumber = txtReferenceNumber.Text.Trim();

            try {
                using (TransactionScope scope = new TransactionScope()) {
                    if (invoiceID == 0) {
                        // assign next invoice number to new invoice
                        nextInvoiceNumber = LeadInvoiceManager.GetNextInvoiceNumber(clientID);

                        invoice.InvoiceNumber = nextInvoiceNumber;
                    }

                    invoiceID = LeadInvoiceManager.Save(invoice);

                    // save newly generated invoice id
                    ViewState["InvoiceID"] = invoiceID.ToString();

                    // check for add/edit invoice detail line
                    InvoiceLineID = ViewState["InvoiceLineID"] == null ? 0 : Convert.ToInt32(ViewState["InvoiceLineID"]);

                    if (InvoiceLineID > 0)
                        invoiceDetail = LeadInvoiceDetailManager.Get(InvoiceLineID);
                    else
                        invoiceDetail = new LeadInvoiceDetail();

                    // get detail line from gridview footer
                    if (invoiceDetail != null) {
                        invoiceDetailLine = getInvoiceDetailLine();

                        if (invoiceDetailLine.LineDate != null && !string.IsNullOrEmpty(invoiceDetailLine.LineDescription) && invoiceDetailLine.Qty > 0 &&
                            invoiceDetailLine.Rate > 0) {

                            // update fields
                            invoiceDetail.InvoiceID = invoiceID;
                            invoiceDetail.InvoiceLineID = InvoiceLineID;
                            invoiceDetail.ServiceTypeID = invoiceDetailLine.ServiceTypeID;
                            invoiceDetail.Comments = invoiceDetailLine.Comments;
                            invoiceDetail.isBillable = invoiceDetailLine.isBillable;
                            invoiceDetail.LineAmount = invoiceDetailLine.LineAmount;
                            invoiceDetail.LineDate = invoiceDetailLine.LineDate;
                            invoiceDetail.LineDescription = invoiceDetailLine.LineDescription;
                            invoiceDetail.Qty = invoiceDetailLine.Qty;
                            invoiceDetail.Rate = invoiceDetailLine.Rate;
                            invoiceDetail.UnitDescription = invoiceDetailLine.UnitDescription;
                            invoiceDetail.Total = invoiceDetailLine.Total;

                            // save invoice detail
                            LeadInvoiceDetailManager.Save(invoiceDetail);

                            // clear
                            ViewState["InvoiceLineID"] = "0";

                            // update invoice total after adding
                            invoice = LeadInvoiceManager.Get(invoiceID);

                            invoice.TotalAmount = invoice.LeadInvoiceDetail.Where(x => x.isBillable == true).Sum(x => x.LineAmount);

                            taxAmount = (invoice.TotalAmount ?? 0) * ((invoice.TaxRate ?? 0) / 100);

                            //invoice.TotalAmount = invoice.TotalAmount + taxAmount;

                            LeadInvoiceManager.Save(invoice);

                            // update comment
                            updateInvoiceComment(invoice, invoiceDetail);
                        }
                    }
                    // complete transaction
                    scope.Complete();
                }

                // refresh invoice detail lines
                bindInvoiceDetails(invoiceID);

                clearFields();

                showToolbarButtons();
            }
            catch (Exception ex) {
                lblMessage.Text = "Error while saving invoice.";
                lblMessage.CssClass = "error";
                Core.EmailHelper.emailError(ex);
            }
        }
        protected void updateInvoiceComment(Data.Entities.LeadInvoice invoice, LeadInvoiceDetail invoiceDetail)
        {
            LeadComment comment = null;

            // retrieve comment by reference
            comment = LeadCommentManager.GetLeadCommentByReferenceId(invoiceDetail.InvoiceLineID);

            if (comment == null)
                comment = new LeadComment();

            comment.InsertBy = Core.SessionHelper.getUserId();
            comment.InsertDate = DateTime.Now;
            comment.LeadId = invoice.LeadId;
            comment.PolicyType = invoice.PolicyTypeID;
            comment.ReferenceID = invoiceDetail.InvoiceLineID;
            comment.Status = 1;	// active
            comment.UserId = Core.SessionHelper.getUserId();
            comment.CommentText = string.Format("<div>Invoice # {0} - {1:MM-dd-yyyy} for {2} Qty:{3:N2} Rate:{4:N2} Item Total:{5:N2}</div><div>{6}</div>",
                invoice.AdjusterInvoiceNumber,
                invoiceDetail.LineDate,
                invoiceDetail.LineDescription ?? "",
                invoiceDetail.Qty ?? 0,
                invoiceDetail.Rate ?? 0,
                invoiceDetail.LineAmount ?? 0,
                invoiceDetail.Comments ?? ""
                );

            LeadCommentManager.Save(comment);
        }
        /// <summary>
        /// Gathers information from gridview footer
        /// </summary>
        /// <returns></returns>
        protected LeadInvoiceDetail getInvoiceDetailLine()
        {
            decimal qty = 0;
            decimal rate = 0;
            decimal totalAmount = 0;
            string[] values = null;
            int serviceTypeID = 0;
            DateTime date = DateTime.MaxValue;

            LeadInvoiceDetail invoiceDetailLine = new LeadInvoiceDetail();

            // service date
            WebDatePicker txtDate = gvInvoiceLines.FooterRow.FindControl("txtDate") as WebDatePicker;
            if (txtDate != null && !string.IsNullOrEmpty(txtDate.Text))
                invoiceDetailLine.LineDate = Convert.ToDateTime(txtDate.Text);

            // service description
            DropDownList cbx = gvInvoiceLines.FooterRow.FindControl("cbxServiceDescription") as DropDownList;

            if (cbx != null) {
                values = cbx.SelectedValue.Split(new char[] { '|' });
                if (values.Length >= 3) {
                    int.TryParse(values[0], out serviceTypeID);

                    invoiceDetailLine.ServiceTypeID = serviceTypeID;

                    invoiceDetailLine.LineDescription = cbx.SelectedItem.Text.Trim();
                }
            }

            // quantity
            WebNumericEditor txtQty = gvInvoiceLines.FooterRow.FindControl("txtQty") as WebNumericEditor;
            if (txtQty != null) {
                qty = txtQty.Value == null ? 0 : Convert.ToDecimal(txtQty.Value);

                invoiceDetailLine.Qty = qty;
            }

            // unit description
            Label lblUnitDescription = gvInvoiceLines.FooterRow.FindControl("lblUnitDescription") as Label;
            if (lblUnitDescription != null)
                invoiceDetailLine.UnitDescription = lblUnitDescription.Text;

            // rate
            WebNumericEditor txtRate = gvInvoiceLines.FooterRow.FindControl("txtRate") as WebNumericEditor;
            if (txtRate != null) {
                rate = txtRate.Value == null ? 0 : Convert.ToDecimal(txtRate.Value);

                invoiceDetailLine.Rate = rate;
            }

            // total amount
            // quantity
            TextBox txtLineAmount = gvInvoiceLines.FooterRow.FindControl("txtLineAmount") as TextBox;
            if (txtLineAmount != null) {
                decimal.TryParse(txtLineAmount.Text.Trim().Replace(",", ""), out totalAmount);
                invoiceDetailLine.LineAmount = totalAmount;
            }
            //if (invoiceDetailLine.UnitDescription != null && invoiceDetailLine.UnitDescription.ToLower() == "percentage")
            //     totalAmount = (rate / 100 ) * qty;
            //else
            //     totalAmount = rate * qty;

            // comments
            WebTextEditor txtComments = gvInvoiceLines.FooterRow.FindControl("txtComments") as WebTextEditor;
            if (txtComments != null)
                invoiceDetailLine.Comments = txtComments.Text.Trim();

            // is billable
            CheckBox cbxBillable = gvInvoiceLines.FooterRow.FindControl("cbxBillable") as CheckBox;
            if (cbxBillable != null)
                invoiceDetailLine.isBillable = cbxBillable.Checked;

            return invoiceDetailLine;
        }
Esempio n. 11
0
        static public List <InvoiceView> GetInvoiceForReport(int invoiceID)
        {
            InvoiceView        invoice       = null;
            List <InvoiceView> invoices      = new List <InvoiceView>();
            ZipCodeMaster      zipCodeMaster = null;

            LeadInvoice leadInvoice = (from x in DbContextHelper.DbContext
                                       .LeadInvoice
                                       .Include("LeadInvoiceDetail")
                                       .Include("LeadInvoiceDetail.InvoiceServiceType")
                                       .Include("LeadInvoiceDetail.InvoiceServiceType.InvoiceServiceUnit")
                                       .Include("Leads")
                                       .Include("Leads.Client")
                                       .Include("Leads.Client.StateMaster")
                                       .Include("Leads.Client.CityMaster")
                                       .Include("Leads.LeadPolicy")
                                       .Include("Leads.LeadPolicy.LeadPolicyType")
                                       where x.InvoiceID == invoiceID
                                       select x
                                       ).FirstOrDefault <LeadInvoice>();



            if (leadInvoice != null)
            {
                invoice               = new InvoiceView();
                invoice.invoiceID     = leadInvoice.InvoiceID;
                invoice.invoiceDate   = (DateTime)leadInvoice.InvoiceDate;
                invoice.dueDate       = leadInvoice.DueDate == null ? DateTime.Now : (DateTime)leadInvoice.DueDate;
                invoice.invoiceNumber = (int)(leadInvoice.InvoiceNumber ?? 0);

                invoice.billTo         = leadInvoice.BillToName;
                invoice.billToAddress1 = leadInvoice.BillToAddress1;
                invoice.billToAddress2 = leadInvoice.BillToAddress2;
                invoice.billToAddress3 = leadInvoice.BillToAddress3;
                invoice.totalAmount    = leadInvoice.TotalAmount ?? 0;

                invoice.adjusterInvoiceNumber = leadInvoice.AdjusterInvoiceNumber;

                // get policy type associated with invoice
                leadInvoice.Leads.LeadPolicy.FirstOrDefault(x => x.PolicyType == leadInvoice.PolicyTypeID);

                //if (leadInvoice.Leads.LeadPolicy != null && leadInvoice.Leads.LeadPolicy.LeadPolicyType != null)
                //    invoice.policyType = leadInvoice.Leads.LeadPolicy.Description;

                //invoice.policyNumber = leadInvoice.Leads.LeadPolicy;
                //invoice.claimNumber = leadInvoice.Leads.LeadPolicy.ClaimNumber;
                //invoice.insurerFileNo = leadInvoice.Leads.LeadPolicy.InsurerFileNo;


                if (leadInvoice.Leads.LeadPolicy != null && leadInvoice.Leads.LeadPolicy.FirstOrDefault().LeadPolicyType != null)
                {
                    invoice.policyType = leadInvoice.Leads.LeadPolicy.FirstOrDefault().LeadPolicyType.Description;
                }

                invoice.policyNumber  = leadInvoice.Leads.LeadPolicy.FirstOrDefault().PolicyNumber;
                invoice.claimNumber   = leadInvoice.Leads.LeadPolicy.FirstOrDefault().ClaimNumber;
                invoice.insurerFileNo = leadInvoice.Leads.LeadPolicy.FirstOrDefault().InsurerFileNo;



                invoice.claimantName     = leadInvoice.Leads.ClaimantFirstName + " " + leadInvoice.Leads.ClaimantLastName;
                invoice.claimantAddress1 = leadInvoice.Leads.LossAddress;
                invoice.claimantAddress2 = leadInvoice.Leads.LossAddress2;
                invoice.claimantAddress3 = string.Format("{0}, {1} {2}",
                                                         leadInvoice.Leads.CityName ?? "",
                                                         leadInvoice.Leads.StateName ?? "",
                                                         leadInvoice.Leads.Zip ?? "");

                invoice.taxRate = leadInvoice.TaxRate ?? 0;


                if (leadInvoice.Leads.DateSubmitted != null)
                {
                    invoice.claimDate = (DateTime)leadInvoice.Leads.DateSubmitted;
                }

                invoice.legacyInvoiceLines = leadInvoice.LeadInvoiceDetail.ToList();

                // add sales tax
                if (invoice.taxRate > 0)
                {
                    LeadInvoiceDetail invoiceTaxLine = new LeadInvoiceDetail();
                    invoiceTaxLine.InvoiceID       = invoice.invoiceID;
                    invoiceTaxLine.LineDescription = "Sales Tax";
                    invoiceTaxLine.isBillable      = true;
                    invoiceTaxLine.LineAmount      = invoice.totalAmount * (invoice.taxRate / 100);
                    invoice.legacyInvoiceLines.Add(invoiceTaxLine);
                }

                if (leadInvoice.Leads.Client != null)
                {
                    invoice.adjusterInvoiceNumber = leadInvoice.AdjusterInvoiceNumber;

                    invoice.clientName     = leadInvoice.Leads.Client.BusinessName;
                    invoice.clientAddress1 = leadInvoice.Leads.Client.StreetAddress1;
                    invoice.clientAddress2 = leadInvoice.Leads.Client.StreetAddress2;

                    string stateName = leadInvoice.Leads.Client.StateMaster != null ? leadInvoice.Leads.Client.StateMaster.StateCode : "";
                    string cityName  = leadInvoice.Leads.Client.CityMaster != null ? leadInvoice.Leads.Client.CityMaster.CityName : "";
                    string zipCode   = leadInvoice.Leads.Client.ZipCode ?? "";

                    // this is badly designed.
                    if (!string.IsNullOrEmpty(zipCode))
                    {
                        zipCodeMaster = ZipCode.Get(zipCode);
                        if (zipCodeMaster != null)
                        {
                            zipCode = zipCodeMaster.ZipCode;
                        }
                    }

                    invoice.clientAddress3 = cityName + ", " + stateName + " " + zipCode;

                    invoice.clientPhone = leadInvoice.Leads.Client.PrimaryPhoneNo;
                    invoice.clientFax   = leadInvoice.Leads.Client.SecondaryPhoneNo;
                    invoice.clientEmail = leadInvoice.Leads.Client.PrimaryEmailId;

                    invoice.logoPath = string.Format("{0}/ClientLogo/{1}.jpg", ConfigurationManager.AppSettings["appURL"].ToString(), leadInvoice.Leads.ClientID);
                }
                else
                {
                    invoice.logoPath       = ConfigurationManager.AppSettings["appURL"].ToString() + "/images/claim_ruler_logo.jpg";
                    invoice.clientName     = "Claim Ruler Demo";
                    invoice.clientAddress1 = "400 East Las Olas Blvd";
                    invoice.clientAddress2 = "Suite 404";
                    invoice.clientAddress3 = "Ft. Lauderdale, FL 33301";
                    invoice.clientPhone    = "999-999-9999";
                    invoice.clientFax      = "999-999-9999";
                    invoice.clientEmail    = "*****@*****.**";
                    invoice.federalIDNo    = "99999999";
                }

                invoices.Add(invoice);
            }

            return(invoices);
        }
Esempio n. 12
0
        private void saveInvoice()
        {
            string[] billToValues  = null;
            int      clientID      = 0;
            int      invoiceID     = 0;
            int      InvoiceLineID = 0;

            Data.Entities.LeadInvoice    invoice           = null;
            CRM.Data.Entities.LeadPolicy policy            = null;
            LeadInvoiceDetail            invoiceDetailLine = null;
            LeadInvoiceDetail            invoiceDetail     = null;

            int     nextInvoiceNumber = 0;
            int     policyID          = 0;
            decimal taxAmount         = 0;

            billToValues = ddlBillTo.SelectedValue.Split(new char[] { '|' });

            // get invoice id
            invoiceID = Convert.ToInt32(ViewState["InvoiceID"].ToString());

            clientID = Core.SessionHelper.getClientId();

            // current policy being edited
            policyID = Session["policyID"] == null ? 0 : Convert.ToInt32(Session["policyID"]);
            policy   = LeadPolicyManager.GetByID(policyID);



            if (invoiceID == 0)
            {
                invoice = new Data.Entities.LeadInvoice();

                // get id for current lead
                invoice.LeadId = Core.SessionHelper.getLeadId();

                invoice.isVoid = false;

                // assign client
                invoice.ClientID = clientID;

                // hide print button
                //btnPrint.Visible = false;
            }
            else
            {
                invoice = LeadInvoiceManager.Get(invoiceID);

                // show print button
                //btnPrint.Visible = true;
            }


            invoice.PolicyID = policy.PolicyType;

            invoice.InvoiceDate    = Convert.ToDateTime(txtInvoiceDate.Text);
            invoice.DueDate        = Convert.ToDateTime(txtDueDate.Text);
            invoice.BillToName     = txtBillTo.Text.Trim();
            invoice.BillToAddress1 = txtBillToAddress1.Text.Trim();
            invoice.BillToAddress2 = txtBillToAddress2.Text.Trim();
            invoice.BillToAddress3 = txtBillToAddress3.Text.Trim();

            invoice.AdjusterID = policy.AdjusterID;

            invoice.AdjusterInvoiceNumber = txtReferenceNumber.Text.Trim();

            try {
                using (TransactionScope scope = new TransactionScope()) {
                    if (invoiceID == 0)
                    {
                        // assign next invoice number to new invoice
                        nextInvoiceNumber = LeadInvoiceManager.GetNextInvoiceNumber(clientID);

                        invoice.InvoiceNumber = nextInvoiceNumber;
                    }

                    invoiceID = LeadInvoiceManager.Save(invoice);

                    // save newly generated invoice id
                    ViewState["InvoiceID"] = invoiceID.ToString();

                    // check for add/edit invoice detail line
                    InvoiceLineID = ViewState["InvoiceLineID"] == null ? 0 : Convert.ToInt32(ViewState["InvoiceLineID"]);

                    if (InvoiceLineID > 0)
                    {
                        invoiceDetail = LeadInvoiceDetailManager.Get(InvoiceLineID);
                    }
                    else
                    {
                        invoiceDetail = new LeadInvoiceDetail();
                    }


                    // get detail line from gridview footer
                    if (invoiceDetail != null)
                    {
                        invoiceDetailLine = getInvoiceDetailLine();

                        if (invoiceDetailLine.LineDate != null && !string.IsNullOrEmpty(invoiceDetailLine.LineDescription) && invoiceDetailLine.Qty > 0 &&
                            invoiceDetailLine.Rate > 0)
                        {
                            // update fields
                            invoiceDetail.InvoiceID       = invoiceID;
                            invoiceDetail.InvoiceLineID   = InvoiceLineID;
                            invoiceDetail.ServiceTypeID   = invoiceDetailLine.ServiceTypeID;
                            invoiceDetail.Comments        = invoiceDetailLine.Comments;
                            invoiceDetail.isBillable      = invoiceDetailLine.isBillable;
                            invoiceDetail.LineAmount      = invoiceDetailLine.LineAmount;
                            invoiceDetail.LineDate        = invoiceDetailLine.LineDate;
                            invoiceDetail.LineDescription = invoiceDetailLine.LineDescription;
                            invoiceDetail.Qty             = invoiceDetailLine.Qty;
                            invoiceDetail.Rate            = invoiceDetailLine.Rate;
                            invoiceDetail.UnitDescription = invoiceDetailLine.UnitDescription;
                            invoiceDetail.Total           = invoiceDetailLine.Total;

                            // save invoice detail
                            LeadInvoiceDetailManager.Save(invoiceDetail);

                            // clear
                            ViewState["InvoiceLineID"] = "0";

                            // update invoice total after adding
                            invoice = LeadInvoiceManager.Get(invoiceID);

                            invoice.TotalAmount = invoice.LeadInvoiceDetail.Where(x => x.isBillable == true).Sum(x => x.LineAmount);

                            taxAmount = (invoice.TotalAmount ?? 0) * ((invoice.TaxRate ?? 0) / 100);

                            //invoice.TotalAmount = invoice.TotalAmount + taxAmount;

                            LeadInvoiceManager.Save(invoice);

                            // update comment
                            updateInvoiceComment(invoice, invoiceDetail);
                        }
                    }
                    // complete transaction
                    scope.Complete();
                }

                // refresh invoice detail lines
                bindInvoiceDetails(invoiceID);

                clearFields();

                showToolbarButtons();
            }
            catch (Exception ex) {
                lblMessage.Text     = "Error while saving invoice.";
                lblMessage.CssClass = "error";
                Core.EmailHelper.emailError(ex);
            }
        }
Esempio n. 13
0
        /// <summary>
        /// Gathers information from gridview footer
        /// </summary>
        /// <returns></returns>
        protected LeadInvoiceDetail getInvoiceDetailLine()
        {
            decimal qty         = 0;
            decimal rate        = 0;
            decimal totalAmount = 0;

            string[] values        = null;
            int      serviceTypeID = 0;
            DateTime date          = DateTime.MaxValue;

            LeadInvoiceDetail invoiceDetailLine = new LeadInvoiceDetail();

            // service date
            WebDatePicker txtDate = gvInvoiceLines.FooterRow.FindControl("txtDate") as WebDatePicker;

            if (txtDate != null && !string.IsNullOrEmpty(txtDate.Text))
            {
                invoiceDetailLine.LineDate = Convert.ToDateTime(txtDate.Text);
            }


            // service description
            DropDownList cbx = gvInvoiceLines.FooterRow.FindControl("cbxServiceDescription") as DropDownList;

            if (cbx != null)
            {
                values = cbx.SelectedValue.Split(new char[] { '|' });
                if (values.Length >= 3)
                {
                    int.TryParse(values[0], out serviceTypeID);

                    invoiceDetailLine.ServiceTypeID = serviceTypeID;

                    invoiceDetailLine.LineDescription = cbx.SelectedItem.Text.Trim();
                }
            }

            // quantity
            WebNumericEditor txtQty = gvInvoiceLines.FooterRow.FindControl("txtQty") as WebNumericEditor;

            if (txtQty != null)
            {
                qty = txtQty.Value == null ? 0 : Convert.ToDecimal(txtQty.Value);

                invoiceDetailLine.Qty = qty;
            }

            // unit description
            Label lblUnitDescription = gvInvoiceLines.FooterRow.FindControl("lblUnitDescription") as Label;

            if (lblUnitDescription != null)
            {
                invoiceDetailLine.UnitDescription = lblUnitDescription.Text;
            }

            // rate
            WebNumericEditor txtRate = gvInvoiceLines.FooterRow.FindControl("txtRate") as WebNumericEditor;

            if (txtRate != null)
            {
                rate = txtRate.Value == null ? 0 : Convert.ToDecimal(txtRate.Value);

                invoiceDetailLine.Rate = rate;
            }

            // total amount
            // quantity
            TextBox txtLineAmount = gvInvoiceLines.FooterRow.FindControl("txtLineAmount") as TextBox;

            if (txtLineAmount != null)
            {
                decimal.TryParse(txtLineAmount.Text.Trim().Replace(",", ""), out totalAmount);
                invoiceDetailLine.LineAmount = totalAmount;
            }
            //if (invoiceDetailLine.UnitDescription != null && invoiceDetailLine.UnitDescription.ToLower() == "percentage")
            //     totalAmount = (rate / 100 ) * qty;
            //else
            //     totalAmount = rate * qty;



            // comments
            WebTextEditor txtComments = gvInvoiceLines.FooterRow.FindControl("txtComments") as WebTextEditor;

            if (txtComments != null)
            {
                invoiceDetailLine.Comments = txtComments.Text.Trim();
            }

            // is billable
            CheckBox cbxBillable = gvInvoiceLines.FooterRow.FindControl("cbxBillable") as CheckBox;

            if (cbxBillable != null)
            {
                invoiceDetailLine.isBillable = cbxBillable.Checked;
            }

            return(invoiceDetailLine);
        }