コード例 #1
0
        public void ValidateInvoiceItems()
        {
            if (ViewState["IsSaveChanged"] != null)
            {
                // init
                ViewState["IsSaveChanged"] = null;

                // ===========
                // validation
                // ===========
                var cInvoice = new CInvoice();
                var invoice  = cInvoice.Get(InvoiceId);

                var cInvoiceItem = new CInvoiceItem();
                var invoiceItem  = cInvoiceItem.GetInvoiceItems(InvoiceId);

                decimal calCommissionFee = 0;
                foreach (InvoiceItem item in invoiceItem)
                {
                    // direct Student
                    if (invoice.AgencyId == null)
                    {
                        if (item.AgencyPrice != 0)
                        {
                            // update price which isnot zero
                            item.AgencyPrice = 0;
                            cInvoiceItem.Update(item);
                        }
                    }
                    // from Agency
                    else
                    {
                        switch (item.InvoiceCoaItemId)
                        {
                        // tuition
                        case 1:
                            calCommissionFee = (decimal)item.AgencyPrice;
                            break;

                        // scholarship
                        case 2:
                        // promotion Credit
                        case 3:
                        // Advertising fee
                        case 4:
                        // Commision - Incentive
                        case 5:
                            calCommissionFee += (decimal)item.AgencyPrice;
                            break;


                        // Commission - Tuition
                        case 6:
                            var cAgency = new CAgency();
                            var agency  = cAgency.Get((int)invoice.AgencyId);
                            if (agency.CommissionRateBasic != null)
                            {
                                // update calculated commissionFee
                                item.AgencyPrice = calCommissionFee * ((decimal)agency.CommissionRateBasic / -100);
                                cInvoiceItem.Update(item);
                            }
                            break;
                        }
                    }

                    // get standardPrice
                    decimal maximumPrice = (decimal)(item.StudentPrice > item.AgencyPrice ?
                                                     (item.StudentPrice < 0 ? 0 : item.StudentPrice) : (item.AgencyPrice < 0 ? 0 : item.AgencyPrice));

                    decimal?tempStandardPrice = 0;
                    // tuition
                    if (item.InvoiceCoaItemId == 1)
                    {
                        if (item.StandardPrice > 0)
                        {
                            tempStandardPrice = item.StandardPrice;
                        }
                        else
                        {
                            tempStandardPrice = item.StandardPrice > maximumPrice ? item.StandardPrice : maximumPrice;
                        }
                    }
                    // others
                    else
                    {
                        tempStandardPrice = item.StandardPrice > maximumPrice ? item.StandardPrice : maximumPrice;
                    }

                    if (item.StandardPrice != tempStandardPrice)
                    {
                        item.StandardPrice = tempStandardPrice;
                        cInvoiceItem.Update(item);
                    }
                }
            }
        }
コード例 #2
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();
        }