深刻な脳力が必要です!! 特定の 2 つの日付範囲からの日数として価格の超過料金を計算しようとしている問題があります。基本的に、私は以下のような請求書行を持っています:
BillID AccountID BilledFrom BillTo Price
34 3456 10/10/2012 10/12/2012 86p
次に、次のような価格マトリックスがあります。
AccountID EffectiveFrom EffectiveTo Price
3456 09/09/2009 10/11/2012 86p
3456 11/11/2012 20/11/2012 56p
3456 21/11/2012 10/12/2013 24p
3456 11/12/2013 null 18p -- null never expires
現在、BillFrom の日付がEffectiveFrom とEffectiveTo の日付の間にある場合に初期価格が取得され、日ごとに請求されます。ここで、BillTo の日付が 86p 明細のEffectiveTo の日付を超えていることがわかるので、請求書から過剰請求を解決したいと思います。そのため、1 か月間、顧客が 2 行目として過大請求されているか、料金が発生する必要があります。SQL または C# で次のような関数が必要です。
OverchargeID type BillID Reason Days Price
1 Credit 34 PriceChange 10 36p (86p-56p)
2 Credit 34 PriceChange 19 64p (86p-24p)
最大 10 の価格帯を持つことができる 56000 のレコードを処理します。サーバー側で動作する以下のコードがありますが、まったく実用的ではなく、約10分かかります。このコードの解決策または修正をいただければ幸いです。
foreach (InvoiceOverchargePriceChange_SelectResult line in result) {
//Get the invoiceLineRecord
InvoiceLine invoiceLine = _dataContext.InvoiceLines.Where(m=>m.InvoiceLineID == line.InvoiceLineID).FirstOrDefault();
// get the prices for each line
List<Pricing_SelectResult> prices = ctrl.Select(line.AccountID, null, null, null, null)
.Where(m=>m.BillingMethodID == line.BillingMethodID)
.OrderByDescending(m=>m.EffectiveFrom).ToList();
// if the price count is greater than 1 then need to check if overcharges occurred
if (prices.Count > 1) {
DateTime date = new DateTime();
int days = 0;
decimal charge = 0; ;
for (int i = 0; i < prices.Count(); i++) {
days = 0;
charge = 0;
//if it goes in we found our price that we used
if (invoiceLine.BillFrom >= prices[i].EffectiveFrom && prices[i].EffectiveTo != null) {
date = invoiceLine.BillTo;
if (prices[i].EffectiveTo == null) break;
//check the Bill to date does not exceed the effective To date, if it does go in
while (date >= prices[i].EffectiveTo) {
if (date == invoiceLine.BillTo) {
//if its first go set the price
charge = prices.Where(m => date >= m.EffectiveFrom).FirstOrDefault().Price;
}
if (charge == prices.Where(m => date >= m.EffectiveFrom).FirstOrDefault().Price) {
//increment the days counter
days++;
date = date.AddDays(-1);
}
else {
//insert the days and price into db here...
//reset the days
days = 0;
charge = prices.Where(m => date >= m.EffectiveFrom).FirstOrDefault().Price;
}
}
}
}
}
}
前もって感謝します