コード例 #1
0
ファイル: CertificationFee.cs プロジェクト: israelsam/Qantler
        async Task Stage1CertFee(IList <BillLineItem> container, TransactionCode code,
                                 BillRequestLineItem item)
        {
            var duration = item.SubScheme == SubScheme.ShortTerm
        ? (item.ExpiresOn - item.StartsFrom).Days + 1
        : BillingUtils.CalculateNoOfMonths(item.StartsFrom.Date, item.ExpiresOn.Date);

            var factor = await _context.Stage1Factor();

            // Full payment for stage 1
            if (item.Scheme == Scheme.Endorsement ||
                item.SubScheme == SubScheme.Canteen ||
                item.SubScheme == SubScheme.ShortTerm)
            {
                factor = 1M;
            }
            // Short term billed per 7 days
            else if (item.SubScheme == SubScheme.ShortTerm)
            {
                factor = Math.Ceiling(duration / 7M);
            }
            else
            {
                factor = Math.Min(factor, duration / 12M);
            }

            // For case where the pro-rated value is less than stage 1 expected factor.
            factor = Math.Min(duration / 12, factor);

            var unitPrice = code.GetLatestPriceAmount();
            var gst       = await _context.GST();

            var qty       = factor;
            var fee       = qty * unitPrice;
            var gstAmount = fee * gst;

            var section = BillingUtils.LineItemSection(BillType.Stage1);

            var    yearPrefix  = duration > 12 ? " - Year 1" : "";
            string prorateText = duration < 12 ? $" ({duration} of 12 months)" : "";

            container.Add(new BillLineItem
            {
                SectionIndex = section.Item1,
                Section      = section.Item2,
                Qty          = qty,
                CodeID       = code.ID,
                Code         = code.Code,
                Descr        = $"{code.Text}{yearPrefix}{prorateText}",
                UnitPrice    = code.GetLatestPriceAmount(),
                Amount       = decimal.Round(fee, 2),
                GSTAmount    = decimal.Round(gstAmount, 2),
                GST          = gst,
                WillRecord   = true
            });
        }