Exemple #1
0
        private void bindInvoiceDetailLines(int invoiceID)
        {
            List <InvoiceDetail> invoiceDetails = null;

            invoiceDetails = InvoiceDetailManager.GetInvoiceDetails(invoiceID);

            gvTimeExpense.DataSource = invoiceDetails;
            gvTimeExpense.DataBind();
        }
        //public RuleException TestRule(int clientID, Invoice invoice, int expenseTypeID) {
        //	int carrierID = 0;
        //	bool isRuleMet = false;
        //	List<BusinessRule> rules = null;
        //	string[] properties = { "CarrierID", "ExpenseTypeID" };
        //	string[] values = null;
        //	RuleException ruleException = null;

        //	// get carrier associated with claim/policy
        //	using (ClaimManager repository = new ClaimManager()) {
        //		carrierID = repository.GetCarrier(invoice.ClaimID);
        //	}

        //	// get business rules for client/rule type id
        //	using (BusinessRuleManager repository = new BusinessRuleManager()) {
        //		rules = repository.GetBusinessRules(clientID, Globals.RuleType.SpecificExpenseTypePerCarrier);
        //	}

        //	if (carrierID > 0 && expenseTypeID > 0 && rules != null && rules.Count > 0) {
        //		// build value array
        //		values = new string[] { carrierID.ToString(), expenseTypeID.ToString() };

        //		foreach (BusinessRule rule in rules) {
        //			XElement ruleXML = XElement.Parse(rule.RuleXML);

        //			isRuleMet = base.TestRule(ruleXML, properties, values);

        //			if (isRuleMet) {
        //				// add exception to queue
        //				ruleException = new RuleException();

        //				ruleException.BusinessRuleID = rule.BusinessRuleID;

        //				ruleException.ClientID = clientID;

        //				ruleException.ObjectID = invoice.InvoiceID;

        //				ruleException.ObjectTypeID = (int)Globals.ObjectType.Invoice;

        //				break;
        //			}
        //		}
        //	}

        //	return ruleException;
        //}

        public RuleException TestRule(int clientID, Invoice invoice)
        {
            int        carrierID = 0;
            bool       isRuleMet = false;
            List <int> expenseTypeIDCollection = null;

            // get carrier associated with claim/policy
            using (ClaimManager repository = new ClaimManager()) {
                carrierID = repository.GetCarrier(invoice.ClaimID);
            }

            // get business rules for client of type "SpecificExpenseTypePerCarrier"
            using (BusinessRuleManager repository = new BusinessRuleManager()) {
                rules = repository.GetBusinessRules(clientID, Globals.RuleType.SpecificExpenseTypePerCarrier);
            }

            expenseTypeIDCollection = InvoiceDetailManager.GetInvoiceExpenseTypeIDCollection(invoice.InvoiceID);

            if (carrierID > 0 && rules != null && rules.Count > 0 && expenseTypeIDCollection != null && expenseTypeIDCollection.Count > 0)
            {
                foreach (int expenseTypeID in expenseTypeIDCollection)
                {
                    // build value array
                    values = new string[] { carrierID.ToString(), expenseTypeID.ToString() };

                    foreach (BusinessRule rule in rules)
                    {
                        XElement ruleXML = XElement.Parse(rule.RuleXML);

                        isRuleMet = base.TestRule(ruleXML, properties, values);

                        if (isRuleMet)
                        {
                            // add exception to queue
                            ruleException = new RuleException();

                            ruleException.BusinessRuleID = rule.BusinessRuleID;

                            ruleException.ClientID = clientID;

                            ruleException.ObjectID = invoice.InvoiceID;

                            ruleException.ObjectTypeID = (int)Globals.ObjectType.Invoice;

                            break;
                        }
                    }
                }
            }

            return(ruleException);
        }
Exemple #3
0
        protected void bindInvoiceDetails(int invoiceID)
        {
            List <InvoiceDetail> invoiceDetailLines = null;
            decimal?totalAmount = 0;

            invoiceDetailLines = InvoiceDetailManager.GetInvoiceDetails(invoiceID);

            gvInvoiceLines.DataSource = invoiceDetailLines.OrderBy(x => x.LineDate);

            gvInvoiceLines.DataBind();

            // total invoice lines
            if (invoiceDetailLines != null && invoiceDetailLines.Count > 0)
            {
                totalAmount = invoiceDetailLines.Where(x => x.isBillable == true).Sum(x => x.LineAmount);


                txtTotalAmount.Text = string.Format("{0:N2}", totalAmount);
            }
        }
        private ClaimReportView getClaimListingReport(List <ClaimReport> reportData, DateTime txtFromDateTime, DateTime txtToDateTime, int[] ddlCarrierList, string[] gvLocationList)
        {
            List <ClaimReport> ClaimReportArr               = new List <ClaimReport>();
            int                       clientID              = SessionHelper.getClientId();
            ClaimReportView           ClaimReportViewObj    = new ClaimReportView();
            List <ClaimReportAverage> ClaimReportAverageArr = new List <ClaimReportAverage>();
            ClaimReportAverage        ClaimReportAverageObj = new ClaimReportAverage();

            decimal totalCoverageA     = 0;
            decimal totalCoverageB     = 0;
            decimal totalCoverageC     = 0;
            decimal totalCoverageD     = 0;
            decimal totalCoverageE     = 0;
            decimal totalOtherCoverage = 0;
            decimal totalOurInvoice    = 0;
            decimal totalQty           = 0;

            for (var i = 0; i < reportData.Count; i++)
            {
                string insureBranch = getInsureBranch(reportData[i].claimId);
                string insuredName  = getInsuredName(reportData[i].claimId);
                string examinerName = "";
                if (reportData[i].ExaminerId != null)
                {
                    int examinerId = Convert.ToInt32(reportData[i].ExaminerId);

                    examinerName = getExaminerName(examinerId);
                }


                if (((reportData[i].DateReceived >= txtFromDateTime && reportData[i].DateClosed <= txtToDateTime) || txtToDateTime == DateTime.MinValue) && gvLocationList.Contains(insureBranch) && ddlCarrierList.Contains(Convert.ToInt32(reportData[i].CarrierId)))
                {
                    ClaimReport ClaimReportObj = new ClaimReport();
                    ClaimReportObj.AdjusterClaimNumber = reportData[i].AdjusterClaimNumber;
                    ClaimReportObj.InsurerClaim        = reportData[i].InsurerClaim;
                    ClaimReportObj.InsuredName         = insuredName;
                    TimeSpan span = Convert.ToDateTime(reportData[i].DateClosed) - Convert.ToDateTime(reportData[i].DateReceived);
                    ClaimReportObj.DaystoClose = span.Days;

                    ClaimReportObj.DateReceived    = reportData[i].DateReceived;
                    ClaimReportObj.DateClosed      = reportData[i].DateClosed;
                    ClaimReportObj.InsureBranch    = reportData[i].InsureBranch;
                    ClaimReportObj.OurAdjuster     = reportData[i].OurAdjuster;
                    ClaimReportObj.claimId         = reportData[i].claimId;
                    ClaimReportObj.CarrierExaminer = examinerName;


                    int policyId = reportData[i].policyId;

                    ClaimReportObj.CoverageA     = 0;
                    ClaimReportObj.CoverageB     = 0;
                    ClaimReportObj.CoverageC     = 0;
                    ClaimReportObj.CoverageD     = 0;
                    ClaimReportObj.CoverageE     = 0;
                    ClaimReportObj.OtherCoverage = 0;
                    ClaimReportObj.CoverageA     = PolicyLimitManager.getPolicyLimitAmount("A", policyId);
                    ClaimReportObj.CoverageB     = PolicyLimitManager.getPolicyLimitAmount("B", policyId);
                    ClaimReportObj.CoverageC     = PolicyLimitManager.getPolicyLimitAmount("C", policyId);
                    ClaimReportObj.CoverageD     = PolicyLimitManager.getPolicyLimitAmount("D", policyId);
                    ClaimReportObj.CoverageE     = PolicyLimitManager.getPolicyLimitAmount("E", policyId);
                    ClaimReportObj.OtherCoverage = PolicyLimitManager.getPolicyLimitAmountOther(policyId);
                    ClaimReportObj.OurInvoice    = InvoiceDetailManager.getTotalInvoice(reportData[i].claimId);
                    ClaimReportObj.Miles         = InvoiceDetailManager.getTotalMiles(reportData[i].claimId, clientID);



                    ClaimReportObj.CoverageA     = Decimal.Round(Convert.ToDecimal(ClaimReportObj.CoverageA), 2);
                    ClaimReportObj.CoverageB     = Decimal.Round(Convert.ToDecimal(ClaimReportObj.CoverageB), 2);
                    ClaimReportObj.CoverageC     = Decimal.Round(Convert.ToDecimal(ClaimReportObj.CoverageC), 2);
                    ClaimReportObj.CoverageD     = Decimal.Round(Convert.ToDecimal(ClaimReportObj.CoverageD), 2);
                    ClaimReportObj.CoverageE     = Decimal.Round(Convert.ToDecimal(ClaimReportObj.CoverageE), 2);
                    ClaimReportObj.OtherCoverage = Decimal.Round(Convert.ToDecimal(ClaimReportObj.OtherCoverage), 2);
                    ClaimReportObj.OurInvoice    = Decimal.Round(Convert.ToDecimal(ClaimReportObj.OurInvoice), 2);
                    ClaimReportObj.Miles         = Decimal.Round(Convert.ToDecimal(ClaimReportObj.Miles), 2);


                    if (ClaimReportObj.CoverageA != null)
                    {
                        totalCoverageA = Decimal.Round(totalCoverageA + Convert.ToDecimal(ClaimReportObj.CoverageA), 2);
                    }
                    if (ClaimReportObj.CoverageB != null)
                    {
                        totalCoverageB = Decimal.Round(totalCoverageB + Convert.ToDecimal(ClaimReportObj.CoverageB), 2);
                    }
                    if (ClaimReportObj.CoverageC != null)
                    {
                        totalCoverageC = Decimal.Round(totalCoverageC + Convert.ToDecimal(ClaimReportObj.CoverageC), 2);
                    }
                    if (ClaimReportObj.CoverageD != null)
                    {
                        totalCoverageD = Decimal.Round(totalCoverageD + Convert.ToDecimal(ClaimReportObj.CoverageD), 2);
                    }
                    if (ClaimReportObj.CoverageE != null)
                    {
                        totalCoverageE = Decimal.Round(totalCoverageE + Convert.ToDecimal(ClaimReportObj.CoverageE), 2);
                    }
                    if (ClaimReportObj.OtherCoverage != null)
                    {
                        totalOtherCoverage = Decimal.Round(totalOtherCoverage + Convert.ToDecimal(ClaimReportObj.OtherCoverage), 2);
                    }
                    if (ClaimReportObj.OurInvoice != null)
                    {
                        totalOurInvoice = Decimal.Round(totalOurInvoice + Convert.ToDecimal(ClaimReportObj.OurInvoice), 2);
                    }
                    if (ClaimReportObj.Miles != null)
                    {
                        totalQty = Decimal.Round(totalQty + Convert.ToDecimal(ClaimReportObj.Miles), 2);
                    }

                    ClaimReportArr.Add(ClaimReportObj);
                }
            }
            if (reportData != null && reportData.Count != 0)
            {
                ClaimReportViewObj.claimReportArr        = ClaimReportArr;
                ClaimReportAverageObj.totalCoverageA     = totalCoverageA;
                ClaimReportAverageObj.totalCoverageB     = totalCoverageB;
                ClaimReportAverageObj.totalCoverageC     = totalCoverageC;
                ClaimReportAverageObj.totalCoverageD     = totalCoverageD;
                ClaimReportAverageObj.totalCoverageE     = totalCoverageE;
                ClaimReportAverageObj.totalOtherCoverage = totalOtherCoverage;
                ClaimReportAverageObj.totalOurInvoice    = totalOurInvoice;
                ClaimReportAverageObj.totalMiles         = totalQty;
            }


            if (reportData != null && reportData.Count != 0)
            {
                ClaimReportAverageObj.avgCoverageA     = Decimal.Round(totalCoverageA / reportData.Count, 2);
                ClaimReportAverageObj.avgCoverageB     = Decimal.Round(totalCoverageB / reportData.Count, 2);
                ClaimReportAverageObj.avgCoverageC     = Decimal.Round(totalCoverageC / reportData.Count, 2);
                ClaimReportAverageObj.avgCoverageD     = Decimal.Round(totalCoverageD / reportData.Count, 2);
                ClaimReportAverageObj.avgCoverageE     = Decimal.Round(totalCoverageE / reportData.Count, 2);
                ClaimReportAverageObj.avgOtherCoverage = Decimal.Round(totalOtherCoverage / reportData.Count, 2);
                ClaimReportAverageObj.avgOurInvoice    = Decimal.Round(totalOurInvoice / reportData.Count, 2);
                ClaimReportAverageObj.avgMiles         = Decimal.Round(totalQty / reportData.Count, 2);
            }
            ClaimReportAverageArr.Add(ClaimReportAverageObj);
            ClaimReportViewObj.ClaimReportAverageObj = ClaimReportAverageArr;
            return(ClaimReportViewObj);
        }
Exemple #5
0
        // generate invoices
        protected void btnGenerate_Click(object sender, EventArgs e)
        {
            Carrier carrier = null;
            CarrierInvoiceProfile profile = null;

            Invoice invoice       = null;
            int     carrierID     = Convert.ToInt32(ddlCarrier.SelectedValue);
            decimal invoiceAmount = 0;
            int     policyID      = 0;

            int profileID = Convert.ToInt32(this.ddlInvoiceProfile.SelectedValue);

            if (carrierID == 0 || profileID == 0)
            {
                return;
            }

            try {
                profile = CarrierInvoiceProfileManager.Get(profileID);

                carrier = CarrierManager.Get(carrierID);
            }
            catch (Exception ex) {
                Core.EmailHelper.emailError(ex);

                showErrorMessage();

                return;
            }

            try {
                using (TransactionScope scope = new TransactionScope()) {
                    foreach (GridViewRow row in gvCarrierPolicy.Rows)
                    {
                        if (row.RowType == DataControlRowType.DataRow)
                        {
                            CheckBox cbxSelect = row.FindControl("cbxSelect") as CheckBox;

                            if (cbxSelect.Checked)
                            {
                                invoice = new Invoice();
                                //invoice.ClientID = clientID;
                                //invoice.CarrierID = carrierID;
                                invoice.InvoiceDate = DateTime.Now;

                                invoice.InvoiceTypeID = profile.InvoiceType;

                                invoice.CarrierInvoiceProfileID = profileID;

                                invoice.IsVoid = false;

                                invoice.BillToAddress1 = carrier.AddressLine1;
                                invoice.BillToAddress2 = carrier.AddressLine2;
                                invoice.BillToAddress3 = string.Empty;
                                invoice.BillToName     = carrier.CarrierName;

                                policyID = (int)gvCarrierPolicy.DataKeys[row.RowIndex].Values[0];

                                //invoice.PolicyID = policyID;

                                //invoice.LeadId = (int)gvCarrierPolicy.DataKeys[row.RowIndex].Values[1];

                                //invoice.PolicyTypeID = (int)gvCarrierPolicy.DataKeys[row.RowIndex].Values[2];

                                Label lblInvoiceAmount = row.FindControl("lblInvoiceAmount") as Label;

                                decimal.TryParse(lblInvoiceAmount.Text, out invoiceAmount);

                                invoice.TotalAmount = invoiceAmount;

                                invoice.InvoiceNumber = InvoiceManager.GetNextInvoiceNumber(clientID);

                                int invoiceID = InvoiceManager.Save(invoice);

                                InvoiceDetail invoiceDetail = new InvoiceDetail();
                                invoiceDetail.InvoiceID       = invoiceID;
                                invoiceDetail.isBillable      = true;
                                invoiceDetail.Qty             = 1;
                                invoiceDetail.Rate            = invoiceAmount;
                                invoiceDetail.LineAmount      = invoiceAmount;
                                invoiceDetail.LineDate        = DateTime.Now;
                                invoiceDetail.LineDescription = "As per contract";

                                InvoiceDetailManager.Save(invoiceDetail);

                                // flag policy as invoiced
                                CRM.Data.Entities.LeadPolicy policy = LeadPolicyManager.Get(policyID);

                                if (policy != null)
                                {
                                    policy.IsInvoiced = true;

                                    LeadPolicyManager.Save(policy);
                                }
                            }
                        }
                    }                     // foreach

                    // complete transaction
                    scope.Complete();

                    lblMessage.Text     = "Invoice(s) have been generated.";
                    lblMessage.CssClass = "ok";
                }
            }
            catch (Exception ex) {
                Core.EmailHelper.emailError(ex);

                showErrorMessage();
            }
            finally {
                // refresh those policies to be invoiced
                bindPoliciesReadyForInvoice();
            }
        }
Exemple #6
0
        private void saveInvoice()
        {
            int           clientID          = 0;
            int           invoiceID         = 0;
            int           InvoiceLineID     = 0;
            Invoice       invoice           = null;
            InvoiceDetail invoiceDetailLine = null;
            InvoiceDetail invoiceDetail     = null;


            int     nextInvoiceNumber = 0;
            decimal taxAmount         = 0;


            clientID = Core.SessionHelper.getClientId();

            invoiceID = ViewState["InvoiceID"] == null ? 0 : Convert.ToInt32(ViewState["InvoiceID"].ToString());


            if (invoiceID == 0)
            {
                invoice = new Invoice();

                // get id for current lead
                invoice.ClaimID = Core.SessionHelper.getClaimID();

                invoice.IsVoid = false;
            }
            else
            {
                invoice = InvoiceManager.Get(invoiceID);
            }


            //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();


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

                        invoice.InvoiceNumber = nextInvoiceNumber;
                    }

                    invoiceID = InvoiceManager.Save(invoice);

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

                    #region get detail line from gridview
                    foreach (GridViewRow row in gvTimeExpense.Rows)
                    {
                        // get detail line from grid
                        invoiceDetailLine = getInvoiceDetailLine(row);

                        if (invoiceDetailLine != null)
                        {
                            if (invoiceDetailLine.InvoiceLineID > 0)
                            {
                                invoiceDetail = InvoiceDetailManager.Get(InvoiceLineID);
                            }
                            else
                            {
                                invoiceDetail = new InvoiceDetail();
                            }

                            // update fields
                            invoiceDetail.InvoiceID       = invoiceID;
                            invoiceDetail.ServiceTypeID   = invoiceDetailLine.ServiceTypeID;
                            invoiceDetail.ExpenseTypeID   = invoiceDetailLine.ExpenseTypeID;
                            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
                            InvoiceDetailManager.Save(invoiceDetail);
                        }
                    }                     // foreach
                    #endregion

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

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

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

                    InvoiceManager.Save(invoice);

                    // add invoice to claim diary comment
                    addInvoiceToClaimDiary(invoice, invoiceDetail);

                    // 2014-05-02 apply rule
                    using (SpecificExpenseTypePerCarrier ruleEngine = new SpecificExpenseTypePerCarrier()) {
                        RuleException ruleException = ruleEngine.TestRule(clientID, invoice);

                        if (ruleException != null)
                        {
                            ruleException.UserID = Core.SessionHelper.getUserId();
                            ruleEngine.AddException(ruleException);
                            CheckSendMail(ruleException);
                        }
                    }


                    // complete transaction
                    scope.Complete();
                }                 // using


                // refresh invoice number on UI
                txtInvoiceNumber.Text = (invoice.InvoiceNumber ?? 0).ToString();


                showToolbarButtons();

                lblMessage.Text     = "Invoice was generated successfully.";
                lblMessage.CssClass = "ok";
            }
            catch (Exception ex) {
                lblMessage.Text     = "Error while saving invoice.";
                lblMessage.CssClass = "error";
                Core.EmailHelper.emailError(ex);
            }
        }
Exemple #7
0
        private void saveInvoice()
        {
            string[] billToValues  = null;
            int      clientID      = 0;
            int      invoiceID     = 0;
            int      InvoiceLineID = 0;
            Invoice  invoice       = null;

            CRM.Data.Entities.LeadPolicy policy = null;
            InvoiceDetail invoiceDetailLine     = null;
            InvoiceDetail 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 Invoice();

                // get id for current lead
                invoice.ClaimID = Core.SessionHelper.getClaimID();

                invoice.IsVoid = false;

                // assign client
                //invoice.ClientID = clientID;

                // hide print button
                //btnPrint.Visible = false;
            }
            else
            {
                invoice = InvoiceManager.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 = InvoiceManager.GetNextInvoiceNumber(clientID);

                        invoice.InvoiceNumber = nextInvoiceNumber;
                    }

                    invoiceID = InvoiceManager.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 = InvoiceDetailManager.Get(InvoiceLineID);
                    }
                    else
                    {
                        invoiceDetail = new InvoiceDetail();
                    }


                    // 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
                            InvoiceDetailManager.Save(invoiceDetail);

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

                    // update invoice total after adding new detail line
                    invoice = InvoiceManager.Get(invoiceID);

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

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

                    InvoiceManager.Save(invoice);

                    // update claim diarycomment
                    updateClaimDiary(invoice, invoiceDetail);

                    // complete transaction
                    scope.Complete();
                }

                // refresh invoice detail lines
                bindInvoiceDetails(invoiceID);

                // refresh invoice number on UI
                txtInvoiceNumber.Text = (invoice.InvoiceNumber ?? 0).ToString();

                clearFields();

                showToolbarButtons();

                refreshParentWindow();
            }
            catch (Exception ex) {
                lblMessage.Text     = "Error while saving invoice.";
                lblMessage.CssClass = "error";
                Core.EmailHelper.emailError(ex);
            }
        }
Exemple #8
0
        // process gridview commands for detail lines
        protected void gvInvoiceLines_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            int           invoiceID     = 0;
            int           invoiceLineID = 0;
            Invoice       invoice       = null;
            InvoiceDetail invoiceLine   = null;
            TextBox       txtLineAmount;

            switch (e.CommandName)
            {
            case "DoSave":
                Page.Validate("invoice");
                if (!Page.IsValid)
                {
                    return;
                }

                Page.Validate("invoiceLine");
                if (!Page.IsValid)
                {
                    return;
                }


                saveInvoice();
                break;

            case "DoEdit":
                invoiceLineID = Convert.ToInt32(e.CommandArgument);

                invoiceLine = InvoiceDetailManager.Get(invoiceLineID);

                if (invoiceLine != null)
                {
                    ViewState["InvoiceLineID"] = invoiceLineID.ToString();


                    // date
                    WebDatePicker txtDate = gvInvoiceLines.FooterRow.FindControl("txtDate") as WebDatePicker;
                    if (txtDate != null && invoiceLine.LineDate != null)
                    {
                        txtDate.Text = string.Format("{0:MM/dd/yyyy}", invoiceLine.LineDate);
                    }

                    // service description
                    DropDownList cbx = gvInvoiceLines.FooterRow.FindControl("cbxServiceDescription") as DropDownList;
                    if (cbx != null && invoiceLine.ServiceTypeID != null)
                    {
                        ListItem item = cbx.Items.FindByText(invoiceLine.LineDescription.Trim());
                        if (item != null)
                        {
                            cbx.SelectedIndex = cbx.Items.IndexOf(item);
                        }
                    }
                    else
                    {
                        ListItem item = new ListItem(invoiceLine.LineDescription, invoiceLine.LineDescription);
                        cbx.Items.Add(item);
                        cbx.Text = invoiceLine.LineDescription;
                    }

                    // quantity
                    WebNumericEditor txtQty = gvInvoiceLines.FooterRow.FindControl("txtQty") as WebNumericEditor;
                    if (txtQty != null && invoiceLine.Qty != null)
                    {
                        txtQty.Text = invoiceLine.Qty.ToString();
                    }

                    // rate
                    WebNumericEditor txtRate = gvInvoiceLines.FooterRow.FindControl("txtRate") as WebNumericEditor;
                    if (txtRate != null)
                    {
                        txtRate.Value = invoiceLine.Rate;
                    }

                    //// service unit
                    //Label lblUnitDescription = gvInvoiceLines.FooterRow.FindControl("lblUnitDescription") as Label;
                    //if (lblUnitDescription != null && invoiceLine.InvoiceServiceType != null && invoiceLine.InvoiceServiceType.InvoiceServiceUnit != null)
                    //	lblUnitDescription.Text = invoiceLine.InvoiceServiceType.InvoiceServiceUnit.UnitDescription;

                    // total amount
                    txtLineAmount = gvInvoiceLines.FooterRow.FindControl("txtLineAmount") as TextBox;
                    if (txtLineAmount != null)
                    {
                        txtLineAmount.Text = string.Format("{0:N2}", invoiceLine.LineAmount ?? 0);
                    }

                    //billable
                    CheckBox cbxBillable = gvInvoiceLines.FooterRow.FindControl("cbxBillable") as CheckBox;
                    if (cbxBillable != null && invoiceLine.isBillable != null)
                    {
                        cbxBillable.Checked = invoiceLine.isBillable ?? false;
                    }

                    // comments
                    WebTextEditor txtComments = gvInvoiceLines.FooterRow.FindControl("txtComments") as WebTextEditor;
                    if (txtComments != null && invoiceLine.Comments != null)
                    {
                        txtComments.Text = invoiceLine.Comments;
                    }

                    // show cancel icon
                    ImageButton ibtnCancel = gvInvoiceLines.FooterRow.FindControl("ibtnCancel") as ImageButton;
                    ibtnCancel.Visible = true;
                }
                break;

            case "DoDelete":
                invoiceLineID = Convert.ToInt32(e.CommandArgument);
                invoiceID     = ViewState["InvoiceID"] != null?Convert.ToInt32(ViewState["InvoiceID"]) : 0;

                if (invoiceLineID > 0 && invoiceID > 0)
                {
                    try {
                        using (TransactionScope scope = new TransactionScope()) {
                            deleteInvoiceComment(invoiceLineID);

                            InvoiceDetailManager.Delete(invoiceLineID);

                            // update invoice total after deleting detail line
                            invoice = InvoiceManager.Get(invoiceID);

                            if (invoice != null && invoice.InvoiceDetail != null)
                            {
                                invoice.TotalAmount = invoice.InvoiceDetail.Where(x => x.isBillable == true).Sum(x => x.LineAmount);

                                InvoiceManager.Save(invoice);
                            }

                            // complete transaction
                            scope.Complete();

                            refreshParentWindow();
                        }
                        bindInvoiceDetails(invoiceID);
                    }
                    catch (Exception ex) {
                        lblMessage.Text     = "Error while deleting invoice detail line.";
                        lblMessage.CssClass = "error";
                        Core.EmailHelper.emailError(ex);
                    }
                }

                break;
            }
        }
Exemple #9
0
        private void calculateLineTotal()
        {
            int     invoiceID                   = 0;
            decimal qty                         = 0;
            decimal rate                        = 0;
            decimal totalAmount                 = 0;
            decimal taxableTotal                = 0;
            string  unitDescription             = null;
            List <InvoiceDetail> invoiceDetails = null;

            // get service unit type
            Label lblUnitDescription = gvInvoiceLines.FooterRow.FindControl("lblUnitDescription") as Label;

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

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

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

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

            // remove any % symbol
            if (txtRate != null)
            {
                rate = txtRate.Value == null ? 0 : Convert.ToDecimal(txtRate.Value);
            }

            if (!string.IsNullOrEmpty(unitDescription) && unitDescriptions.Contains(unitDescription.ToLower()))
            {
                rate /= 100;                    // make it a percent for "percentage, sales tax"
            }
            totalAmount = rate * qty;

            if (!string.IsNullOrEmpty(unitDescription) && unitDescription.ToLower().Equals("sales tax"))
            {
                int.TryParse(ViewState["InvoiceID"].ToString(), out invoiceID);

                invoiceDetails = InvoiceDetailManager.GetInvoiceDetails(invoiceID);

                taxableTotal = (decimal)invoiceDetails.Where(x => x.isBillable == true &&
                                                             x.InvoiceServiceType.InvoiceServiceUnit.UnitID != SALES_TAX_ID)
                               .Sum(x => x.LineAmount);

                totalAmount = taxableTotal * rate;
            }


            TextBox txtLineAmount = gvInvoiceLines.FooterRow.FindControl("txtLineAmount") as TextBox;

            if (txtLineAmount != null)
            {
                txtLineAmount.Text = totalAmount.ToString("N2");
            }
        }