Exemple #1
0
        protected void InvoiceToolbarButtonClicked(object sender, RadToolBarEventArgs e)
        {
            switch (e.Item.Text)
            {
            case "Confirm":
                if (RadGridInvoice.SelectedValue != null)
                {
                    var cInvoice = new CInvoice();
                    var invoice  = cInvoice.Get(Convert.ToInt32(RadGridInvoice.SelectedValue));
                    invoice.Status      = (int)CConstValue.InvoiceStatus.Invoiced; // Invoice Status(34) : Invoiced
                    invoice.UpdatedId   = CurrentUserId;
                    invoice.UpdatedDate = DateTime.Now;

                    if (cInvoice.Update(invoice))
                    {
                        ShowMessage("Update inquiry successfully");
                    }
                    else
                    {
                        ShowMessage("Failed to update inquiry");
                    }
                    e.Item.Enabled = false;
                    RadGridInvoice.Rebind();
                }
                break;

            case "Cancel":
                if (RadGridInvoice.SelectedValue != null)
                {
                    var cInvoice = new CInvoice();
                    var invoice  = cInvoice.Get(Convert.ToInt32(RadGridInvoice.SelectedValue));

                    if (invoice.Status == (int)CConstValue.InvoiceStatus.Pending)
                    {
                        RunClientScript("ShowCancelWindow(" + RadGridInvoice.SelectedValue + ");");
                    }
                    else if (invoice.Status == (int)CConstValue.InvoiceStatus.Invoiced)
                    {
                        if (new CPayment().InvoiceCheck(invoice.InvoiceId) == 0)
                        {
                            RunClientScript("ShowCancelWindow(" + RadGridInvoice.SelectedValue + ");");
                        }
                        else
                        {
                            ShowMessage("It can't because of already paid in invoice");
                        }
                    }
                    RadGridInvoice.Rebind();
                }
                break;

            case "Agency Invoice":
                if (RadGridInvoice.SelectedValue != null)
                {
                    var selectedInvoiceList = new List <int>();
                    foreach (GridDataItem item in RadGridInvoice.SelectedItems)
                    {
                        selectedInvoiceList.Add((int)item.GetDataKeyValue("InvoiceId"));
                    }

                    RunClientScript("ShowReportPop('" + String.Join(", ", selectedInvoiceList.ToArray()) + "', '" + (int)CConstValue.Report.InvoiceAgency + "' );");
                }
                break;

            case "Student Invoice":
                if (RadGridInvoice.SelectedValue != null)
                {
                    var selectedInvoiceList = new List <int>();
                    foreach (GridDataItem item in RadGridInvoice.SelectedItems)
                    {
                        selectedInvoiceList.Add((int)item.GetDataKeyValue("InvoiceId"));
                    }

                    RunClientScript("ShowReportPop('" + String.Join(", ", selectedInvoiceList.ToArray()) + "', '" + (int)CConstValue.Report.InvoiceStudent + "' );");
                }
                break;

            case "Modify":
                if (RadGridInvoice.SelectedValue != null)
                {
                    var cInvoice = new CInvoice();
                    var invoice  = cInvoice.Get(Convert.ToInt32(RadGridInvoice.SelectedValue));

                    if (invoice.Status == (int)CConstValue.InvoiceStatus.Invoiced ||
                        invoice.InvoiceType == (int)CConstValue.InvoiceType.General ||
                        invoice.InvoiceType == (int)CConstValue.InvoiceType.Simple ||
                        invoice.InvoiceType == (int)CConstValue.InvoiceType.Manual ||
                        invoice.InvoiceType == (int)CConstValue.InvoiceType.Homestay ||
                        invoice.InvoiceType == (int)CConstValue.InvoiceType.Dormitory)     //invoiced
                    {
                        var payments = new CPayment();

                        if (payments.InvoiceCheck(invoice.InvoiceId) == 0)
                        {
                            invoice.Status      = (int)CConstValue.InvoiceStatus.Cancelled_MD; // Invoice Status(34) : Cancelled_M
                            invoice.UpdatedId   = CurrentUserId;
                            invoice.UpdatedDate = DateTime.Now;

                            if (cInvoice.Update(invoice))
                            {
                                var cNewInvoice = new CInvoice();
                                var newInvoice  = new Erp2016.Lib.Invoice();
                                CGlobal.Copy(invoice, newInvoice);
                                newInvoice.OriginalInvoiceId = invoice.InvoiceId;
                                newInvoice.Status            = (int)CConstValue.InvoiceStatus.Pending; // pending
                                newInvoice.CreatedId         = CurrentUserId;
                                newInvoice.CreatedDate       = DateTime.Now;

                                if (cNewInvoice.Add(newInvoice) > 0)
                                {
                                    var cInvoiceItem = new CInvoiceItem();
                                    List <InvoiceItem> originalInvoiceItems = cInvoiceItem.GetInvoiceItems(invoice.InvoiceId);
                                    List <InvoiceItem> newInvoiceItems      = new List <InvoiceItem>();
                                    foreach (InvoiceItem ori in originalInvoiceItems)
                                    {
                                        var newInvoiceItem = new InvoiceItem();
                                        CGlobal.Copy(ori, newInvoiceItem);
                                        newInvoiceItem.InvoiceId   = newInvoice.InvoiceId;
                                        newInvoiceItem.CreatedId   = CurrentUserId;
                                        newInvoiceItem.CreatedDate = DateTime.Now;
                                        newInvoiceItems.Add(newInvoiceItem);
                                    }
                                    // copy invoiceItems
                                    if (cInvoiceItem.Add(newInvoiceItems) == false)
                                    {
                                        ShowMessage("Error inserting invoice Items");
                                    }

                                    RadGridInvoice.Rebind();
                                }
                            }
                        }
                        else
                        {
                            ShowMessage("It can't because of already paid in invoice");
                        }
                    }
                }
                break;

            case "New Simple Invoice":
                RunClientScript("ShowNewSimpleInvoice();");
                break;

            case "Student Page":
                if (RadGridInvoice.SelectedValue != null)
                {
                    Response.Redirect("~/Student?id=" + RadGridInvoice.SelectedValues["StudentId"]);
                }
                break;

            case "Payment Page":
                if (RadGridInvoice.SelectedValue != null)
                {
                    Response.Redirect("~/Payment?id=" + RadGridInvoice.SelectedValues["StudentId"]);
                }
                break;

            case "Deposit Page":
                if (RadGridInvoice.SelectedValue != null)
                {
                    Response.Redirect("~/Deposit?id=" + RadGridInvoice.SelectedValues["StudentId"]);
                }
                break;

            case "CreditMemo Page":
                if (RadGridInvoice.SelectedValue != null)
                {
                    Response.Redirect("~/CreditMemo?id=" + RadGridInvoice.SelectedValues["StudentId"]);
                }
                break;

            case "Refund Page":
                if (RadGridInvoice.SelectedValue != null)
                {
                    Response.Redirect("~/Refund?id=" + RadGridInvoice.SelectedValues["StudentId"]);
                }
                break;
            }
        }
Exemple #2
0
 protected void ButtonGridRefresh_OnClick(object sender, EventArgs e)
 {
     RadGridInvoice.Rebind();
 }
Exemple #3
0
        protected void ddlFG_OnSelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
        {
            var cInvoice = new CInvoice();
            var invoice  = cInvoice.Get(Convert.ToInt32(RadGridInvoice.SelectedValue.ToString()));

            invoice.IsFinancialGurantee = Convert.ToBoolean(ddlFG.SelectedValue);

            if (cInvoice.Update(invoice))
            {
                var cInvoiceItem = new CInvoiceItem();
                var invoiceItems = cInvoiceItem.GetInvoiceItems(invoice.InvoiceId);

                // fg mode
                if (invoice.IsFinancialGurantee)
                {
                    foreach (var v in invoiceItems)
                    {
                        // save fg
                        var cInvoiceItemFg = new CInvoiceItemFg();
                        var InvoiceItemFg  = cInvoiceItemFg.Get(v.InvoiceItemId);
                        if (InvoiceItemFg == null)
                        {
                            cInvoiceItemFg.Add(new InvoiceItemFg()
                            {
                                InvoiceItemId = v.InvoiceItemId,
                                StandardPrice = v.StandardPrice,
                                StudentPrice  = v.StudentPrice,
                                AgencyPrice   = v.AgencyPrice,
                                CreatedId     = CurrentUserId,
                                CreatedDate   = DateTime.Now
                            });
                        }
                        else
                        {
                            InvoiceItemFg.StandardPrice = v.StandardPrice;
                            InvoiceItemFg.StudentPrice  = v.StudentPrice;
                            InvoiceItemFg.AgencyPrice   = v.AgencyPrice;
                            InvoiceItemFg.UpdatedId     = CurrentUserId;
                            InvoiceItemFg.UpdatedDate   = DateTime.Now;

                            cInvoiceItemFg.Update(InvoiceItemFg);
                        }

                        // original invoice set negative value to zero
                        if (v.StandardPrice < 0)
                        {
                            v.StandardPrice = 0;
                        }

                        if (v.StudentPrice < 0)
                        {
                            v.StudentPrice = 0;
                        }

                        cInvoiceItem.Update(v);
                    }
                }
                else
                {
                    foreach (var v in invoiceItems)
                    {
                        // save fg
                        var cInvoiceItemFg = new CInvoiceItemFg();
                        var invoiceItemFg  = cInvoiceItemFg.Get(v.InvoiceItemId);

                        if (invoiceItemFg != null)
                        {
                            v.StandardPrice = invoiceItemFg.StandardPrice;
                            v.StudentPrice  = invoiceItemFg.StudentPrice;
                            v.AgencyPrice   = invoiceItemFg.AgencyPrice;
                            v.UpdatedId     = CurrentUserId;
                            v.UpdatedDate   = DateTime.Now;
                        }
                        cInvoiceItem.Update(v);
                    }
                }

                ShowMessage("Updated to Financial Gurantee status");
            }

            RadGridInvoice.Rebind();
        }