Пример #1
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);
            }
        }
Пример #2
0
        protected void btnSaveExpense_Click(object sender, EventArgs e)
        {
            Claim                 claim          = null;
            Claim                 myClaim        = null;
            ClaimExpense          claimExpense   = null;
            AdjusterMaster        adjuster       = null;
            CarrierInvoiceProfile CarrierInvoice = null;

            int clientID      = SessionHelper.getClientId();
            int userID        = SessionHelper.getUserId();
            int claimID       = SessionHelper.getClaimID();
            int myAdjusterID  = 0;
            int profileID     = 0;
            int expenseTypeID = 0;
            int id            = 0;


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

            id = Convert.ToInt32(ViewState["ClaimExpenseID"]);

            ClaimManager cm = new ClaimManager();

            myClaim = cm.Get(claimID);

            try
            {
                expenseTypeID = Convert.ToInt32(ddlExpenseType.SelectedValue);

                using (TransactionScope scope = new TransactionScope())
                {
                    using (ClaimExpenseManager repository = new ClaimExpenseManager())
                    {
                        if (id == 0)
                        {
                            claimExpense         = new ClaimExpense();
                            claimExpense.ClaimID = claimID;
                        }
                        else
                        {
                            claimExpense = repository.Get(id);
                        }

                        // populate fields
                        if (txtExpenseAmount.Visible == false)
                        {
                            var x = Session["multiplier"].ToString();

                            double expenseAmount = Convert.ToDouble(x) * Convert.ToDouble(txtExpenseQty.ValueDecimal); //newOC 10/7/14
                            claimExpense.ExpenseAmount = Convert.ToDecimal(expenseAmount);

                            decimal d = Convert.ToDecimal(expenseAmount);
                            //Session["EmailAmount"] = "$" + Math.Round(d, 2);
                            Session["EmailAmount"] = String.Format("{0:0.00}", expenseAmount);
                            // Session["EmailAmount"] = expenseAmount;
                        }
                        else
                        {
                            claimExpense.ExpenseAmount = txtExpenseAmount.ValueDecimal;
                        }
                        claimExpense.ExpenseDate        = txtExpenseDate.Date;
                        claimExpense.ExpenseDescription = txtExpenseDescription.Text.Trim();
                        claimExpense.ExpenseTypeID      = expenseTypeID;
                        claimExpense.IsReimbursable     = cbxExpenseReimburse.Checked;
                        claimExpense.UserID             = userID;
                        claimExpense.AdjusterID         = Convert.ToInt32(hf_expenseAdjusterID.Value);
                        claimExpense.ExpenseQty         = txtExpenseQty.ValueDecimal;
                        claimExpense.InternalComments   = txtMyComments.Text.Trim();
                        claimExpense.Billed             = false;
                        // claimExpense.IsBillable = cbIsBillable.Checked;
                        // save expense
                        claimExpense = repository.Save(claimExpense);
                    }

                    // update diary entry
                    ClaimComment diary = new ClaimComment();
                    diary.ClaimID     = claimID;
                    diary.CommentDate = DateTime.Now;
                    diary.UserId      = userID;
                    diary.CommentText = string.Format("Expense: {0}, Description: {1}, Date: {2:MM/dd/yyyy}, Amount: {3:N2}, Adjuster: {4} Qty: {5:N2}",
                                                      ddlExpenseType.SelectedItem.Text,
                                                      claimExpense.ExpenseDescription,
                                                      claimExpense.ExpenseDate,
                                                      claimExpense.ExpenseAmount,
                                                      txtExpenseAdjuster.Text,
                                                      claimExpense.ExpenseQty
                                                      );
                    ClaimCommentManager.Save(diary);

                    // 2014-05-02 apply rule
                    using (SpecificExpenseTypePerCarrier ruleEngine = new SpecificExpenseTypePerCarrier())
                    {
                        claim         = new Claim();
                        claim.ClaimID = claimID;
                        RuleException ruleException = ruleEngine.TestRule(clientID, claim, expenseTypeID);

                        if (ruleException != null)
                        {
                            ruleException.UserID = Core.SessionHelper.getUserId();
                            ruleEngine.AddException(ruleException);
                            CheckSendMail(ruleException);
                        }
                    }
                    myAdjusterID = Convert.ToInt32(claimExpense.AdjusterID); //Convert.ToInt32(myClaim.AdjusterID);
                    //EMAIL ADJUSTER OC 10/22/2014
                    if (myAdjusterID != 0 || myAdjusterID != null)
                    {
                        adjuster = AdjusterManager.GetAdjusterId(myAdjusterID);
                    }
                    if (cbEmailAdjuster.Checked == true)
                    {
                        try
                        {
                            notifyAdjuster(adjuster, claimExpense, myClaim);
                        }
                        catch (Exception ex)
                        {
                            lblMessage.Text     = "Unable to send email to adjuster";
                            lblMessage.CssClass = "error";
                        }
                    }
                    //EMAIL CLIENT CONTACT OC 10/22/2014
                    if (cbEmailClient.Checked == true)              //Dont need to check if invoice Pro ID is empty becuase to get to this point, one has to exist already
                    {
                        if (Session["ComingFromAllClaims"] != null) //if the user got here straight from the all claims screen
                        {
                            profileID = Convert.ToInt32(Session["CarrierInvoiceID"]);
                        }
                        else//coming from claim detail page
                        {
                            profileID = Convert.ToInt32(Session["InvoiceProfileID"]);
                        }
                        CarrierInvoice = CarrierInvoiceProfileManager.Get(profileID);
                        try
                        {
                            notifyClientContact(CarrierInvoice, claimExpense, myClaim, adjuster);
                        }
                        catch (Exception ex)
                        {
                            lblMessage.Text     = "Unable to send email to client contact";
                            lblMessage.CssClass = "error";
                        }
                    }
                    //EMAIL TO WHOMEVER OC 10/22/2014
                    if (txtEmailTo.Text != "")
                    {
                        try
                        {
                            notifySpecifiedUser(adjuster, claimExpense, myClaim);
                        }
                        catch (Exception ex)
                        {
                            lblMessage.Text     = "Unable to send email to adjuster";
                            lblMessage.CssClass = "error";
                        }
                    }

                    // complete transaction
                    scope.Complete();
                }

                lblMessage.Text     = "Expense saved successfully.";
                lblMessage.CssClass = "ok";

                // refresh grid
                gvExpense.DataSource = loadExpenses(claimID);
                gvExpense.DataBind();

                // keep edit form active
                lbtnNewExpense_Click(null, null);
                lblAmount.Text           = "";
                lblAmount.Visible        = false;
                txtExpenseAmount.Visible = true;
            }
            catch (Exception ex) {
                Core.EmailHelper.emailError(ex);

                lblMessage.Text     = "Unable to save claim expense.";
                lblMessage.CssClass = "error";
            }
        }
Пример #3
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;
            int     policyID          = 0;
            decimal taxAmount         = 0;


            // 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
                            invoice = InvoiceManager.Get(invoiceID);

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

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

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

                            InvoiceManager.Save(invoice);

                            // update comment
                            updateInvoiceComment(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();
                }

                // refresh invoice detail lines
                bindInvoiceDetails(invoiceID);

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

                clearFields();

                showToolbarButtons();
                lblMessage.Text     = "Invoice save successfully.";
                lblMessage.CssClass = "ok";
            }
            catch (Exception ex) {
                lblMessage.Text     = "Error while saving invoice.";
                lblMessage.CssClass = "error";
                Core.EmailHelper.emailError(ex);
            }
        }