示例#1
0
    protected void GenerateInvoiceItem(int InvoiceId, int CoaItemId, Decimal DormitoryPrice)

    { // Save Invoice Item
        var invoiceItemDormitory = new InvoiceItem();

        invoiceItemDormitory.InvoiceId        = InvoiceId;
        invoiceItemDormitory.InvoiceCoaItemId = CoaItemId;
        invoiceItemDormitory.StandardPrice    = DormitoryPrice;
        invoiceItemDormitory.StudentPrice     = DormitoryPrice;
        invoiceItemDormitory.AgencyPrice      = DormitoryPrice;
        invoiceItemDormitory.CreatedId        = CurrentUserId;
        invoiceItemDormitory.CreatedDate      = DateTime.Now;
        invoiceItemDormitory.UpdatedId        = CurrentUserId;
        invoiceItemDormitory.UpdatedDate      = DateTime.Now;
        var cInvoiceDormitory = new CInvoiceItem();

        cInvoiceDormitory.Add(invoiceItemDormitory);
    }
示例#2
0
        protected void RadToolBar1_ButtonClick(object sender, RadToolBarEventArgs e)
        {
            switch (e.Item.Text)
            {
            case "Save":
                if (IsValid)
                {
                    foreach (var chkItem in RadComboBoxMenu.CheckedItems)
                    {
                        var cInvoice = new CInvoice();
                        var invoice  = new Erp2016.Lib.Invoice();

                        invoice.StudentId = Convert.ToInt32(chkItem.Value);

                        invoice.Status         = (int)CConstValue.InvoiceStatus.Pending; // pending
                        invoice.SiteLocationId = CurrentSiteLocationId;
                        invoice.InvoiceType    = (int)CConstValue.InvoiceType.Simple;    //Simple Invoice(SI)

                        invoice.CreatedId   = CurrentUserId;
                        invoice.CreatedDate = DateTime.Now;

                        var invoiceId = cInvoice.Add(invoice);     //DB:Invoice

                        if (invoiceId > 0)
                        {
                            var cInvoiceItem = new CInvoiceItem();
                            var gridData     = InvoiceItemGrid1.GetGridData();
                            gridData = gridData.Insert(0, ",");
                            var gridDataRows = gridData.Split('|');
                            foreach (var gridDataRow in gridDataRows)
                            {
                                if (string.IsNullOrEmpty(gridDataRow))
                                {
                                    break;
                                }

                                var gridDataRowCell = gridDataRow.Split(',');

                                var invoiceCoaItem = gridDataRowCell[1];
                                var standardPrice  = gridDataRowCell[2];
                                var studentPrice   = gridDataRowCell[3];
                                var agencyPrice    = gridDataRowCell[4];
                                var remark         = gridDataRowCell[5];

                                var invoiceItem = new InvoiceItem();
                                invoiceItem.InvoiceId = invoiceId;
                                var cInvoiceCoaItem = new CInvoiceCoaItem();
                                invoiceItem.InvoiceCoaItemId = cInvoiceCoaItem.Get(invoiceCoaItem).InvoiceCoaItemId;
                                if (!string.IsNullOrEmpty(standardPrice))
                                {
                                    invoiceItem.StandardPrice = Convert.ToDecimal(standardPrice.Replace("$", string.Empty));
                                }
                                if (!string.IsNullOrEmpty(studentPrice))
                                {
                                    invoiceItem.StudentPrice = Convert.ToDecimal(studentPrice.Replace("$", string.Empty));
                                }
                                if (!string.IsNullOrEmpty(agencyPrice))
                                {
                                    invoiceItem.AgencyPrice = Convert.ToDecimal(agencyPrice.Replace("$", string.Empty));
                                }
                                invoiceItem.Remark = remark;

                                invoiceItem.CreatedId   = CurrentUserId;
                                invoiceItem.CreatedDate = DateTime.Now;

                                cInvoiceItem.Add(invoiceItem);
                            }
                        }
                    }
                    RunClientScript("Close();");
                }
                else
                {
                    ShowMessage("Error to add Simple Invoice");
                }
                break;

            case "Cancel":
                RunClientScript("Close();");
                break;
            }
        }
示例#3
0
        protected void ToolbarButtonClick(object sender, RadToolBarEventArgs e)
        {
            if (e.Item.Text == "Save")
            {
                if (IsValid)
                {
                    if (!string.IsNullOrEmpty(ddlAgency.SelectedValue) && (tbCommissionRate.Value == 0 || tbCommissionRate.Value == null))
                    {
                        ShowMessage("Commision Rate should be written.");
                        return;
                    }

                    var cScholarship = new CScholarship();
                    if (ScholarshipId != null)
                    {
                        var scholarship = cScholarship.GetVwScholarship((int)ScholarshipId);
                        if (RadButtonAvailableScholarshipAmount.Checked)
                        {
                            if (scholarship.AvailableAmount == 0 || (double)scholarship.AvailableAmount < RadNumericTextBoxScholarshipAmount.Value)
                            {
                                ShowMessage("Scholarship Amount is bigger than availalble Amount.");
                                return;
                            }
                        }
                        else
                        {
                            if (scholarship.AvailableWeeks == 0 || (double)scholarship.AvailableWeeks < RadNumericTextBoxScholarshipWeeks.Value)
                            {
                                ShowMessage("Scholarship Weeks are bigger than availalble Weeks.");
                                return;
                            }
                        }
                    }

                    var cProgramReg = new CProgramRegistration();
                    var programReg  = new ProgramRegistration();

                    programReg.StudentId = Id;
                    programReg.ProgramId = Convert.ToInt32(ddlProgramName.SelectedValue);

                    programReg.StartDate = tbPrgStartDate.SelectedDate;
                    programReg.EndDate   = tbPrgEndDate.SelectedDate;
                    programReg.ProgramRegistrationType = 9;

                    if (!string.IsNullOrEmpty(ddlProgramWeeks.SelectedValue))
                    {
                        programReg.Weeks = Convert.ToInt32(ddlProgramWeeks.SelectedValue);
                    }

                    if (!string.IsNullOrEmpty(ddlPrgHours.SelectedValue))
                    {
                        programReg.HrsStatus = Convert.ToInt32(ddlPrgHours.SelectedValue);
                    }

                    programReg.CreatedId   = CurrentUserId;
                    programReg.CreatedDate = DateTime.Now;

                    var proRegId = cProgramReg.Add(programReg); //DB:ProgramRegistration

                    if (proRegId > 0)
                    {
                        var cInvoice = new CInvoice();
                        var invoice  = new Invoice();

                        invoice.ProgramRegistrationId = proRegId;
                        invoice.StudentId             = Id;
                        if (!string.IsNullOrEmpty(ddlAgency.SelectedValue))
                        {
                            invoice.AgencyId             = Convert.ToInt32(ddlAgency.SelectedValue);
                            invoice.IsAgencySeasonalRate = RadButtonAgencyRateSeasonal.Checked;
                            invoice.AgencyRate           = tbCommissionRate.Value;
                        }

                        if (ScholarshipId != null)
                        {
                            invoice.ScholarshipId = ScholarshipId;
                            if (RadButtonAvailableScholarshipAmount.Checked)
                            {
                                invoice.ScholarshipAmount = (decimal)RadNumericTextBoxScholarshipAmount.Value;
                            }
                            else
                            {
                                invoice.ScholarshipAmount = (decimal)RadNumericTextBoxScholarshipAmount.Value;
                                invoice.ScholarshipWeeks  = (int)RadNumericTextBoxScholarshipWeeks.Value;
                            }
                        }
                        invoice.PromotionId = PromotionId;

                        invoice.SiteLocationId = CurrentSiteLocationId;
                        invoice.InvoiceType    = (int)CConstValue.InvoiceType.General; //General Invoice(IN)


                        invoice.Status      = (int)CConstValue.InvoiceStatus.Pending; // Pending
                        invoice.CreatedId   = CurrentUserId;
                        invoice.CreatedDate = DateTime.Now;

                        var invoiceId = cInvoice.Add(invoice); //DB:Invoice

                        if (invoiceId > 0)
                        {
                            var cInvoiceItem = new CInvoiceItem();

                            foreach (GridDataItem item in _radGridInvoiceItems.Items)
                            {
                                var invoiceCoaItemId = (RadDropDownList)item.FindControl("ddlInvoiceItems");
                                var standardPrice    = (Label)item.FindControl("lblStandardPrice");
                                var studentPrice     = (Label)item.FindControl("lblStudentPrice");
                                var agencyPrice      = (Label)item.FindControl("lblAgencyPrice");

                                var invoiceItem = new InvoiceItem();
                                invoiceItem.InvoiceId = invoiceId;

                                invoiceItem.InvoiceCoaItemId = Convert.ToInt32(invoiceCoaItemId.SelectedValue);
                                invoiceItem.StandardPrice    = Convert.ToDecimal(standardPrice.Text.Replace("$", string.Empty));
                                invoiceItem.StudentPrice     = Convert.ToDecimal(studentPrice.Text.Replace("$", string.Empty));
                                invoiceItem.AgencyPrice      = Convert.ToDecimal(agencyPrice.Text.Replace("$", string.Empty));

                                invoiceItem.CreatedId   = CurrentUserId;
                                invoiceItem.CreatedDate = DateTime.Now;

                                cInvoiceItem.Add(invoiceItem);
                            }

                            // disable used scholarship
                            if (ScholarshipId != null)
                            {
                                var sScholarship = new CScholarship();
                                var scholarship  = sScholarship.Get((int)ScholarshipId);
                                scholarship.IsActive = true;
                                sScholarship.Update(scholarship);
                            }

                            RunClientScript("Close();");
                        }
                        else
                        {
                            ShowMessage("failed to update inqury (Add Invoice Items)");
                        }
                    }
                    else
                    {
                        ShowMessage("failed to update inqury (Invoice)");
                    }
                }
            }
            else
            {
                ShowMessage("Fill in data");
            }
        }
示例#4
0
        protected void ToolbarButtonClick(object sender, RadToolBarEventArgs e)
        {
            if (e.Item.Text == @"Save")
            {
                if (IsValid)
                {
                    if (!string.IsNullOrEmpty(ddlAgency.SelectedValue) && (tbCommissionRate.Value == 0 || tbCommissionRate.Value == null))
                    {
                        ShowMessage("Commision Rate should be written.");
                        return;
                    }

                    var programId        = Convert.ToInt32(ddlPackageProgram.SelectedValue.Split(',')[1]);
                    var packageProgramId = Convert.ToInt32(ddlPackageProgram.SelectedValue.Split(',')[0]);

                    var cProgramReg = new CProgramRegistration();
                    var programReg  = new ProgramRegistration();

                    programReg.StudentId        = Id;
                    programReg.ProgramId        = programId;
                    programReg.PackageProgramId = packageProgramId;

                    programReg.StartDate = tbPrgStartDate.SelectedDate;
                    programReg.EndDate   = tbPrgEndDate.SelectedDate;

                    programReg.ProgramRegistrationType = 9;

                    programReg.CreatedId   = CurrentUserId;
                    programReg.CreatedDate = DateTime.Now;

                    var proRegId = cProgramReg.Add(programReg); //DB:ProgramRegistration

                    if (proRegId > 0)
                    {
                        // add basic invoice first, then homestay or dormitory if exists.
                        var cInvoice = new CInvoice();
                        var invoice  = new Invoice();

                        invoice.ProgramRegistrationId = proRegId;
                        invoice.StudentId             = Id;
                        if (!string.IsNullOrEmpty(ddlAgency.SelectedValue))
                        {
                            invoice.AgencyId             = Convert.ToInt32(ddlAgency.SelectedValue);
                            invoice.IsAgencySeasonalRate = RadButtonAgencyRateSeasonal.Checked;
                            invoice.AgencyRate           = tbCommissionRate.Value;
                        }
                        invoice.SiteLocationId = CurrentSiteLocationId;
                        invoice.InvoiceType    = (int)CConstValue.InvoiceType.General;   //General Invoice(IN)
                        invoice.Status         = (int)CConstValue.InvoiceStatus.Pending; // Pending
                        invoice.CreatedId      = CurrentUserId;
                        invoice.CreatedDate    = DateTime.Now;

                        var invoiceId = cInvoice.Add(invoice); //DB:Invoice

                        if (invoiceId > 0)
                        {
                            var invoiceItems          = new List <InvoiceItem>();
                            var homestayInvoiceItems  = new List <InvoiceItem>();
                            var dormitoryInvoiceItems = new List <InvoiceItem>();
                            var airportInvoiceItems   = new List <InvoiceItem>();

                            var cInvoiceItem = new CInvoiceItem();

                            foreach (GridDataItem item in _radGridInvoiceItems.Items)
                            {
                                var invoiceCoaItemId = (RadDropDownList)item.FindControl("ddlInvoiceItems");
                                var standardPrice    = (Label)item.FindControl("lblStandardPrice");
                                var studentPrice     = (Label)item.FindControl("lblStudentPrice");
                                var agencyPrice      = (Label)item.FindControl("lblAgencyPrice");

                                var invoiceItem = new InvoiceItem();
                                invoiceItem.InvoiceId = invoiceId;

                                invoiceItem.InvoiceCoaItemId = Convert.ToInt32(invoiceCoaItemId.SelectedValue);
                                invoiceItem.StandardPrice    = Convert.ToDecimal(standardPrice.Text.Replace("$", string.Empty));
                                invoiceItem.StudentPrice     = Convert.ToDecimal(studentPrice.Text.Replace("$", string.Empty));
                                invoiceItem.AgencyPrice      = Convert.ToDecimal(agencyPrice.Text.Replace("$", string.Empty));

                                invoiceItem.CreatedId   = CurrentUserId;
                                invoiceItem.CreatedDate = DateTime.Now;

                                switch (invoiceItem.InvoiceCoaItemId)
                                {
                                case (int)CConstValue.InvoiceCoaItemForHomestay.HomestayBasic:
                                case (int)CConstValue.InvoiceCoaItemForHomestay.HomestayBasicDiscount:
                                case (int)CConstValue.InvoiceCoaItemForHomestay.HomestayPlacement:
                                case (int)CConstValue.InvoiceCoaItemForHomestay.HomestayPlacementDiscount:
                                case (int)CConstValue.InvoiceCoaItemForHomestay.HomestayInternetGuarantee:
                                case (int)CConstValue.InvoiceCoaItemForHomestay.HomestayOtherDiscount:
                                    homestayInvoiceItems.Add(invoiceItem);
                                    break;

                                case (int)CConstValue.InvoiceCoaItemForDormitory.DormitoryBasic:
                                case (int)CConstValue.InvoiceCoaItemForDormitory.DormitoryBasicDiscount:
                                case (int)CConstValue.InvoiceCoaItemForDormitory.DormitoryPlacement:
                                case (int)CConstValue.InvoiceCoaItemForDormitory.DormitoryPlacementDiscount:
                                case (int)CConstValue.InvoiceCoaItemForDormitory.DormitoryKeyDeposit:
                                case (int)CConstValue.InvoiceCoaItemForDormitory.DormitoryKeyDepositDiscount:
                                    dormitoryInvoiceItems.Add(invoiceItem);
                                    break;

                                case (int)CConstValue.InvoiceCoaItem.AirportPickup:
                                case (int)CConstValue.InvoiceCoaItem.AirportPickupDiscount:
                                case (int)CConstValue.InvoiceCoaItem.AirportDropoff:
                                case (int)CConstValue.InvoiceCoaItem.AirportDropoffDiscount:
                                case (int)CConstValue.InvoiceCoaItem.AirportPickupAndDropoff:
                                case (int)CConstValue.InvoiceCoaItem.AirportPickupAndDropoffDiscount:
                                    airportInvoiceItems.Add(invoiceItem);
                                    break;

                                default:
                                    invoiceItems.Add(invoiceItem);
                                    break;
                                }
                            }

                            // add invoiceItems except for homestay and dormitory
                            if (cInvoiceItem.Add(invoiceItems) == false)
                            {
                                ShowMessage("Error : add invoiceItem");
                            }

                            // add homestay if exist.
                            if (homestayInvoiceItems.Count > 0)
                            {
                                var newHomestayRegistrationId = new CHomestayStudentRequest().Add(new HomestayStudentBasic()
                                {
                                    HomestayStudentStatus = 0, // Pending
                                    StudentId             = Id,
                                    PlacedUserId          = 0,
                                    CreatedUserId         = CurrentUserId,
                                    CreatedDate           = DateTime.Now
                                });

                                if (newHomestayRegistrationId > 0)
                                {
                                    var invoiceForHomestay = new Invoice();
                                    invoiceForHomestay.HomestayRegistrationId = newHomestayRegistrationId;
                                    invoiceForHomestay.StudentId = Id;
                                    if (!string.IsNullOrEmpty(ddlAgency.SelectedValue))
                                    {
                                        invoiceForHomestay.AgencyId             = Convert.ToInt32(ddlAgency.SelectedValue);
                                        invoiceForHomestay.IsAgencySeasonalRate = RadButtonAgencyRateSeasonal.Checked;
                                        invoiceForHomestay.AgencyRate           = tbCommissionRate.Value;
                                    }
                                    invoiceForHomestay.SiteLocationId = CurrentSiteLocationId;
                                    invoiceForHomestay.InvoiceType    = (int)CConstValue.InvoiceType.Homestay;
                                    invoiceForHomestay.Status         = (int)CConstValue.InvoiceStatus.Pending;
                                    invoiceForHomestay.CreatedId      = CurrentUserId;
                                    invoiceForHomestay.CreatedDate    = DateTime.Now;

                                    var invoiceForHomestayId = cInvoice.Add(invoiceForHomestay);
                                    if (invoiceForHomestayId > 0)
                                    {
                                        foreach (var h in homestayInvoiceItems)
                                        {
                                            h.InvoiceId = invoiceForHomestayId;
                                        }
                                        foreach (var a in airportInvoiceItems)
                                        {
                                            a.InvoiceId = invoiceForHomestayId;
                                        }

                                        // merge between homestay Items and airport Items
                                        homestayInvoiceItems.AddRange(airportInvoiceItems);

                                        if (cInvoiceItem.Add(homestayInvoiceItems) == false)
                                        {
                                            ShowMessage("Error : add invoiceHomestayItem");
                                        }
                                    }
                                    else
                                    {
                                        ShowMessage("Error : add Homestay");
                                    }
                                }
                                else
                                {
                                    ShowMessage("Error : add Homestay registration");
                                }
                            }

                            // add dormitory if exist.
                            if (dormitoryInvoiceItems.Count > 0)
                            {
                                var newDormitoryRegistrationId = new CDormitoryRegistrations().Add(new DormitoryRegistration()
                                {
                                    DormitoryStudentStatus = 0, // Pending
                                    StudentId    = Id,
                                    PlacedUserId = 0,
                                    CreatedId    = CurrentUserId,
                                    CreatedDate  = DateTime.Now
                                });

                                if (newDormitoryRegistrationId > 0)
                                {
                                    var invoiceForDormitory = new Invoice();
                                    invoiceForDormitory.DormitoryRegistrationId = newDormitoryRegistrationId;
                                    invoiceForDormitory.StudentId = Id;
                                    if (!string.IsNullOrEmpty(ddlAgency.SelectedValue))
                                    {
                                        invoiceForDormitory.AgencyId             = Convert.ToInt32(ddlAgency.SelectedValue);
                                        invoiceForDormitory.IsAgencySeasonalRate = RadButtonAgencyRateSeasonal.Checked;
                                        invoiceForDormitory.AgencyRate           = tbCommissionRate.Value;
                                    }
                                    invoiceForDormitory.SiteLocationId = CurrentSiteLocationId;
                                    invoiceForDormitory.InvoiceType    = (int)CConstValue.InvoiceType.Dormitory;
                                    invoiceForDormitory.Status         = (int)CConstValue.InvoiceStatus.Pending;
                                    invoiceForDormitory.CreatedId      = CurrentUserId;
                                    invoiceForDormitory.CreatedDate    = DateTime.Now;

                                    var invoiceForDormitoryId = cInvoice.Add(invoiceForDormitory);
                                    if (invoiceForDormitoryId > 0)
                                    {
                                        foreach (var h in dormitoryInvoiceItems)
                                        {
                                            h.InvoiceId = invoiceForDormitoryId;
                                        }
                                        foreach (var a in airportInvoiceItems)
                                        {
                                            a.InvoiceId = invoiceForDormitoryId;
                                        }

                                        // merge between dormitory Items and airport Items
                                        dormitoryInvoiceItems.AddRange(airportInvoiceItems);

                                        if (cInvoiceItem.Add(dormitoryInvoiceItems) == false)
                                        {
                                            ShowMessage("Error : add invoiceDormitoryItem");
                                        }
                                    }
                                    else
                                    {
                                        ShowMessage("Error : add Dormitory");
                                    }
                                }
                                else
                                {
                                    ShowMessage("Error : add Dormitory registration");
                                }
                            }

                            RunClientScript("Close();");
                        }
                        else
                        {
                            ShowMessage("failed to update inqury (Invoice)");
                        }
                    }
                    else
                    {
                        ShowMessage("failed to update inqury (Program Registragion)");
                    }
                }
            }
        }
示例#5
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;
            }
        }
示例#6
0
        protected void MainToolBar_ButtonClick(object sender, RadToolBarEventArgs e)
        {
            if (e.Item.Text == @"Approve" && !string.IsNullOrEmpty(hfId.Value))
            {
                if (IsValid)
                {
                    var type     = Convert.ToInt32(hfType.Value);
                    var id       = Convert.ToInt32(hfId.Value);
                    var idNumber = string.Empty;

                    var cApprovalHistory = new CApprovalHistory();
                    var approvalHistory  = cApprovalHistory.Get(type, id, CurrentUserId);
                    approvalHistory.ApprovalDate = DateTime.Now;
                    approvalHistory.ApprovalMemo = tbRemark.Text;
                    // cal
                    int approvalStatus = cApprovalHistory.CheckApprovalStep(type, id);
                    if (approvalStatus == (int)CConstValue.ApprovalStatus.Approved)
                    {
                        approvalStatus = new CGlobal().GetApprovalValue(type);
                    }
                    approvalHistory.ApprovalStep = approvalStatus;
                    // update approvalHistory
                    cApprovalHistory.Update(approvalHistory);

                    //Refund & Commission
                    if (type == (int)CConstValue.Approval.Refund)
                    {
                        var cRefundInfo = new CRefund();
                        var refundInfo  = cRefundInfo.Get(Convert.ToInt32(hfId.Value));

                        refundInfo.ApprovalDate   = approvalHistory.ApprovalDate;
                        refundInfo.ApprovalId     = approvalHistory.ApprovalUser;
                        refundInfo.ApprovalMemo   = approvalHistory.ApprovalMemo;
                        refundInfo.ApprovalStatus = approvalHistory.ApprovalStep;

                        if (cRefundInfo.Update(refundInfo))
                        {
                            //if last approve
                            if (refundInfo.ApprovalStatus == (int)CConstValue.ApprovalStatus.Approved)
                            {
                                var vwRefund      = cRefundInfo.GetVwRefund(refundInfo.RefundId);
                                var refundAmount  = Math.Abs((decimal)vwRefund.RefundAmount);
                                var sumOfMdfAndCp = new CCreditMemo().GetSumOfMdfAndCp(vwRefund.RefundId);

                                var cCreditMemoPayout = new CCreditMemoPayout();
                                var creditMemoPayout  = cCreditMemoPayout.Get(refundInfo.CreditMemoPayoutId);

                                var cCreditMemo = new CCreditMemo();
                                var creditMemo  = cCreditMemo.Get(creditMemoPayout.CreditMemoId);

                                creditMemo.OriginalCreditMemoAmount = refundAmount - sumOfMdfAndCp;
                                creditMemo.CreditMemoStartDate      = DateTime.Now;
                                creditMemo.CreditMemoEndDate        = DateTime.Now.AddYears(1);
                                creditMemo.IsActive    = true;
                                creditMemo.UpdatedId   = CurrentUserId;
                                creditMemo.UpdatedDate = DateTime.Now;

                                // Approved
                                creditMemoPayout.ApprovalStatus = (int)CConstValue.ApprovalStatus.Approved;
                                creditMemoPayout.ApprovalDate   = DateTime.Now;
                                creditMemoPayout.ApprovalId     = CurrentUserId;
                                creditMemoPayout.Amount         = refundAmount;
                                creditMemoPayout.PayoutMethod   = vwRefund.PayoutMethod;
                                creditMemoPayout.IsActive       = true;

                                creditMemoPayout.UpdatedId   = CurrentUserId;
                                creditMemoPayout.UpdatedDate = DateTime.Now;

                                cCreditMemoPayout.Update(creditMemoPayout);

                                if (cCreditMemo.Update(creditMemo))
                                {
                                    var cInvoiceInfo = new CInvoice();
                                    var invoiceInfo  = cInvoiceInfo.Get(refundInfo.InvoiceId);

                                    var cOriginalInvoiceInfo = new CInvoice();
                                    var originalInvoiceInfo  = cOriginalInvoiceInfo.Get(Convert.ToInt32(invoiceInfo.OriginalInvoiceId));

                                    invoiceInfo.Status    = (int)CConstValue.InvoiceStatus.Invoiced; // Invoiced
                                    invoiceInfo.UpdatedId = CurrentUserId;

                                    originalInvoiceInfo.Status    = (int)CConstValue.InvoiceStatus.Cancelled_RF; // Canceled_RF
                                    originalInvoiceInfo.UpdatedId = CurrentUserId;

                                    var startDate = DateTime.Now;
                                    var endDate   = DateTime.Now;

                                    //invoice status update
                                    if (cInvoiceInfo.Update(invoiceInfo) && cOriginalInvoiceInfo.Update(originalInvoiceInfo))
                                    {
                                        // Program
                                        if (invoiceInfo.ProgramRegistrationId != null)
                                        {
                                            var cProgramRegiInfo = new CProgramRegistration();
                                            var programRegiInfo  = cProgramRegiInfo.Get(Convert.ToInt32(invoiceInfo.ProgramRegistrationId));
                                            programRegiInfo.UpdatedId               = CurrentUserId;
                                            programRegiInfo.UpdatedDate             = DateTime.Now;
                                            programRegiInfo.ProgramRegistrationType = 12; // cancel

                                            cProgramRegiInfo.Update(programRegiInfo);

                                            startDate = programRegiInfo.StartDate.Value;
                                            endDate   = programRegiInfo.EndDate.Value;
                                        }
                                        // Homestay
                                        else if (invoiceInfo.HomestayRegistrationId != null)
                                        {
                                            var cHomestayStudentRequest = new CHomestayStudentRequest();
                                            var homestayStudentRequest  = cHomestayStudentRequest.GetHomestayStudentRequest(Convert.ToInt32(invoiceInfo.HomestayRegistrationId));
                                            homestayStudentRequest.UpdateUserId          = CurrentUserId;
                                            homestayStudentRequest.UpdatedDate           = DateTime.Now;
                                            homestayStudentRequest.HomestayStudentStatus = 1; // cancel

                                            cHomestayStudentRequest.Update(homestayStudentRequest);

                                            startDate = homestayStudentRequest.StartDate.Value;
                                            endDate   = homestayStudentRequest.EndDate.Value;
                                        }
                                        // Dormitory
                                        else if (invoiceInfo.DormitoryRegistrationId != null)
                                        {
                                            var cDormitoryStudentRequest = new CDormitoryRegistrations();
                                            var dormitoryStudentRequest  = cDormitoryStudentRequest.GetDormitoryStudentRequest(Convert.ToInt32(invoiceInfo.ProgramRegistrationId));
                                            dormitoryStudentRequest.DormitoryStudentStatus = 1; // cancel
                                            dormitoryStudentRequest.UpdatedId   = CurrentUserId;
                                            dormitoryStudentRequest.UpdatedDate = DateTime.Now;

                                            cDormitoryStudentRequest.Update(dormitoryStudentRequest);

                                            startDate = dormitoryStudentRequest.StartDate.Value;
                                            endDate   = dormitoryStudentRequest.EndDate.Value;
                                        }

                                        // Rev
                                        var cInterimInvoice = new CInvoice();
                                        var interimInvoice  = new Invoice();
                                        CGlobal.Copy(invoiceInfo, interimInvoice);
                                        interimInvoice.OriginalInvoiceId = invoiceInfo.InvoiceId;
                                        interimInvoice.InvoiceType       = (int)CConstValue.InvoiceType.Refund_RV;
                                        interimInvoice.Status            = (int)CConstValue.InvoiceStatus.Invoiced;
                                        interimInvoice.CreatedId         = CurrentUserId;
                                        interimInvoice.CreatedDate       = DateTime.Now;

                                        if (cInterimInvoice.Add(interimInvoice) > 0)
                                        {
                                            var totalDays   = Convert.ToDateTime(endDate) - Convert.ToDateTime(startDate);
                                            var interimDays = Convert.ToDateTime(endDate) - Convert.ToDateTime(refundInfo.RefundDate);
                                            var interimRate = Math.Round((interimDays.TotalDays / totalDays.TotalDays), 2) * 100;

                                            var cInvoiceItem = new CInvoiceItem();
                                            var cOriginalInvoiceItemModels     = cInvoiceItem.GetInvoiceItemModels(invoiceInfo.InvoiceId);
                                            List <InvoiceItem> newInvoiceItems = new List <InvoiceItem>();
                                            foreach (CInvoiceItemModel ori in cOriginalInvoiceItemModels)
                                            {
                                                if (ori.InvoiceCoaItem.RevenueRecognition == 1)
                                                {
                                                    var newInvoiceRevItem = new InvoiceItem();
                                                    CGlobal.Copy(ori.InvoiceItem, newInvoiceRevItem);
                                                    newInvoiceRevItem.InvoiceId = interimInvoice.InvoiceId;

                                                    newInvoiceRevItem.StandardPrice *= (decimal)interimRate;
                                                    newInvoiceRevItem.StudentPrice  *= (decimal)interimRate;
                                                    newInvoiceRevItem.AgencyPrice   *= (decimal)interimRate;

                                                    newInvoiceRevItem.CreatedId   = CurrentUserId;
                                                    newInvoiceRevItem.CreatedDate = DateTime.Now;
                                                    newInvoiceRevItem.Remark      = "Refund Rev";
                                                    newInvoiceItems.Add(newInvoiceRevItem);
                                                }
                                            }

                                            if (newInvoiceItems.Count > 0)
                                            {
                                                // copy invoiceItems
                                                if (cInvoiceItem.Add(newInvoiceItems))
                                                {
                                                    RunClientScript("Close();");
                                                }
                                                else
                                                {
                                                    ShowMessage("failed to update inqury (Refund Ref Invoice Item)");
                                                }
                                            }
                                            else
                                            {
                                                RunClientScript("Close();");
                                            }
                                        }
                                        else
                                        {
                                            ShowMessage("failed to update inqury (Refund Ref Invoice)");
                                        }
                                    }
                                    else
                                    {
                                        ShowMessage("failed to update inqury (Original Invoice and Refund Invoice)");
                                    }
                                }
                                else
                                {
                                    ShowMessage("failed to update inqury (CreditMemo Info)");
                                }
                            }
                            else
                            {
                                RunClientScript("Close();");
                            }
                        }
                        else
                        {
                            ShowMessage("failed to update inqury (Refund Info)");
                        }
                    }
                    // Agency
                    else if (type == (int)CConstValue.Approval.Agency)
                    {
                        try
                        {
                            var cAgency = new CAgency();
                            var agency  = cAgency.Get(id);

                            idNumber              = agency.AgencyNumber;
                            agency.ApprovalDate   = approvalHistory.ApprovalDate;
                            agency.ApprovalId     = approvalHistory.ApprovalUser;
                            agency.ApprovalMemo   = approvalHistory.ApprovalMemo;
                            agency.ApprovalStatus = approvalHistory.ApprovalStep;

                            cAgency.Update(agency);

                            RunClientScript("Close();");
                        }
                        catch (Exception ex)
                        {
                            ShowMessage(ex.Message);
                        }
                    }
                    // BusinessTrip
                    else if (type == (int)CConstValue.Approval.BusinessTrip)
                    {
                        try
                        {
                            var cBusinessTrip = new CBusinessTrip();
                            var businessTrip  = cBusinessTrip.Get(id);

                            businessTrip.ApprovalDate   = approvalHistory.ApprovalDate;
                            businessTrip.ApprovalId     = approvalHistory.ApprovalUser;
                            businessTrip.ApprovalMemo   = approvalHistory.ApprovalMemo;
                            businessTrip.ApprovalStatus = approvalHistory.ApprovalStep;

                            cBusinessTrip.Update(businessTrip);

                            RunClientScript("Close();");
                        }
                        catch (Exception ex)
                        {
                            ShowMessage(ex.Message);
                        }
                    }
                    // Purchase Order
                    else if (type == (int)CConstValue.Approval.PurchaseOrder)
                    {
                        try
                        {
                            var cPurchaseOrder = new CPurchaseOrder();
                            var purchaseOrder  = cPurchaseOrder.Get(id);

                            purchaseOrder.ApprovalDate   = approvalHistory.ApprovalDate;
                            purchaseOrder.ApprovalId     = approvalHistory.ApprovalUser;
                            purchaseOrder.ApprovalMemo   = approvalHistory.ApprovalMemo;
                            purchaseOrder.ApprovalStatus = approvalHistory.ApprovalStep;

                            cPurchaseOrder.Update(purchaseOrder);
                            RunClientScript("Close();");
                        }
                        catch (Exception ex)
                        {
                            ShowMessage(ex.Message);
                        }
                    }
                    // Package Program
                    else if (type == (int)CConstValue.Approval.Package)
                    {
                        try
                        {
                            var cP             = new CPackageProgram();
                            var packageProgram = cP.GetPackageProgram(id);

                            packageProgram.ApprovalDate   = approvalHistory.ApprovalDate;
                            packageProgram.ApprovalId     = approvalHistory.ApprovalUser;
                            packageProgram.ApprovalMemo   = approvalHistory.ApprovalMemo;
                            packageProgram.ApprovalStatus = approvalHistory.ApprovalStep;
                            if (packageProgram.ApprovalStatus == (int)CConstValue.ApprovalStatus.Approved)
                            {
                                packageProgram.IsActive = true;
                            }

                            cP.Update(packageProgram);
                            RunClientScript("Close();");
                        }
                        catch (Exception ex)
                        {
                            ShowMessage(ex.Message);
                        }
                    }
                    //Scholarship//
                    else if (type == (int)CConstValue.Approval.Scholarship)
                    {
                        try
                        {
                            var cScholar = new CScholarship();
                            var scholar  = cScholar.Get(Convert.ToInt32(id));

                            idNumber               = scholar.ScholarshipMasterNo;
                            scholar.ApprovalDate   = approvalHistory.ApprovalDate;
                            scholar.ApprovalId     = approvalHistory.ApprovalUser;
                            scholar.ApprovalMemo   = approvalHistory.ApprovalMemo;
                            scholar.ApprovalStatus = approvalHistory.ApprovalStep;
                            if (scholar.ApprovalStatus == (int)CConstValue.ApprovalStatus.Approved)
                            {
                                scholar.IsActive = true;
                            }

                            cScholar.Update(scholar);
                            RunClientScript("Close();");
                        }
                        catch (Exception ex)
                        {
                            ShowMessage(ex.Message);
                        }
                    }
                    //Promotion//
                    else if (type == (int)CConstValue.Approval.Promotion)
                    {
                        try
                        {
                            var cPromo = new CPromotion();
                            var promo  = cPromo.Get(Convert.ToInt32(id));

                            idNumber             = promo.PromotionMasterNo;
                            promo.ApprovalDate   = approvalHistory.ApprovalDate;
                            promo.ApprovalId     = approvalHistory.ApprovalUser;
                            promo.ApprovalMemo   = approvalHistory.ApprovalMemo;
                            promo.ApprovalStatus = approvalHistory.ApprovalStep;
                            if (promo.ApprovalStatus == (int)CConstValue.ApprovalStatus.Approved)
                            {
                                promo.IsActive = true;
                            }

                            cPromo.Update(promo);
                            RunClientScript("Close();");
                        }
                        catch (Exception ex)
                        {
                            ShowMessage(ex.Message);
                        }
                    }
                    // Expense Program
                    else if (type == (int)CConstValue.Approval.Expense)
                    {
                        try
                        {
                            var cExpense = new CExpense();
                            var expense  = cExpense.Get(id);

                            expense.ApprovalDate   = approvalHistory.ApprovalDate;
                            expense.ApprovalId     = approvalHistory.ApprovalUser;
                            expense.ApprovalMemo   = approvalHistory.ApprovalMemo;
                            expense.ApprovalStatus = approvalHistory.ApprovalStep;

                            cExpense.Update(expense);
                            RunClientScript("Close();");
                        }
                        catch (Exception ex)
                        {
                            ShowMessage(ex.Message);
                        }
                    }
                    // Hire
                    else if (type == (int)CConstValue.Approval.Hire)
                    {
                        try
                        {
                            var cHire = new CHire();
                            var hire  = cHire.Get(id);

                            hire.ApprovalDate   = approvalHistory.ApprovalDate;
                            hire.ApprovalId     = approvalHistory.ApprovalUser;
                            hire.ApprovalMemo   = approvalHistory.ApprovalMemo;
                            hire.ApprovalStatus = approvalHistory.ApprovalStep;

                            cHire.Update(hire);
                            RunClientScript("Close();");
                        }
                        catch (Exception ex)
                        {
                            ShowMessage(ex.Message);
                        }
                    }
                    // Vacation
                    else if (type == (int)CConstValue.Approval.Vacation)
                    {
                        try
                        {
                            var cVacationDetail = new CVacation();
                            var vacation        = cVacationDetail.Get(id);

                            vacation.ApprovalDate   = approvalHistory.ApprovalDate;
                            vacation.ApprovalId     = approvalHistory.ApprovalUser;
                            vacation.ApprovalMemo   = approvalHistory.ApprovalMemo;
                            vacation.ApprovalStatus = approvalHistory.ApprovalStep;

                            cVacationDetail.Update(vacation);
                            RunClientScript("Close();");
                        }
                        catch (Exception ex)
                        {
                            ShowMessage(ex.Message);
                        }
                    }
                    // CreditMemoPayout
                    else if (type == (int)CConstValue.Approval.CreditMemoPayout)
                    {
                        try
                        {
                            var cCreditMemo = new CCreditMemoPayout();
                            var creditMemo  = cCreditMemo.Get(id);

                            creditMemo.ApprovalDate   = approvalHistory.ApprovalDate;
                            creditMemo.ApprovalId     = approvalHistory.ApprovalUser;
                            creditMemo.ApprovalMemo   = approvalHistory.ApprovalMemo;
                            creditMemo.ApprovalStatus = approvalHistory.ApprovalStep;

                            cCreditMemo.Update(creditMemo);
                            RunClientScript("Close();");
                        }
                        catch (Exception ex)
                        {
                            ShowMessage(ex.Message);
                        }
                    }


                    if (approvalHistory.ApprovalStep != (int)CConstValue.ApprovalStatus.Approved) //if has a next approver, request approve
                    {
                        var approvalInfo = new CApproval();
                        var supervisor   = approvalInfo.GetSupuervisor(type, CurrentUserId);

                        if (supervisor > 0)
                        {
                            var cNextApprove = new CApprovalHistory();
                            var nextApprove  = cNextApprove.Get(type, id, supervisor);

                            nextApprove.IsApprovalRequest = true;
                            cNextApprove.Update(nextApprove);
                        }

                        new CMail().SendMail((CConstValue.Approval)type, CConstValue.MailStatus.ToApproveUserAndRequestUser, id, idNumber, CurrentUserId);
                    }
                    // approved
                    else
                    {
                        new CMail().SendMail((CConstValue.Approval)type, CConstValue.MailStatus.ToRequestUser, id, idNumber, CurrentUserId);
                    }
                }
            }
        }