CSDN博客

img jason2008

计算合同内各级别的价格函数 -- 精华推荐

发表于2002/11/29 14:49:00  518人阅读

分类: ASP

需求:
按月计算合同内各级别物品的总价
给定条件如下:
1.合同内共有四种级别物别,且价格不同;
2.各级别物品价格的定义为每月的价格;
3.每天的价格为各级别物品的价格除以30;
4.要求计算输入的日期段内的价格,(截止日期大于起始日期,如小于不必考虑)
5.如果两日期相差不到一个月,则小于15天的,总价按天数计算;大于等于15天的按月计算
6.如果两日期相差大于一个月,则整月的,总价按月计算;
7.大于一个月且非整月的,则小于15天的,总价按天数计算;大于等于15天的按月计算

实现:
计算指定时间段内的合同总价:<br><br>
<form method="post" action="test.asp?action=1">
   发布起始日期:<input type="text" name="DateStart" value="<%=request("DateStart")%>"><br>
   发布截止日期:<input type="text" name="DateEnd" value="<%=request("DateEnd")%>"><br>
     AA 级价格:<input type="text" name="AA" value="6000"> /月 __ 200.00 /日<br>
     A 级价格:<input type="text" name="A" value="4800"> /月 __ 160.00 /日<br>
     B 级价格:<input type="text" name="B" value="3200"> /月 __ 106.66~/日<br>
     C 级价格:<input type="text" name="C" value="2400"> /月 __ 80.00 /日<br>
           各个级别数量按 10 个计算<br>
             <input type="submit" name="Submit3" value="总 计">
</form>
<%
if request("Action")=1 then
 response.write "总价= "&Diff_Month(request("DateStart"),request("DateEnd"),request("AA"),request("A"),request("B"),request("C"),10,10,10,10)
end if
function Diff_Month(StartDate,EndDate,MoneyF_AA,MoneyF_A,MoneyF_B,MoneyF_C,AmountAA,AmountA,AmountB,AmountC)

 Different=DateDiff("m",StartDate,EndDate)

 '如果在一个月内
 if DateDiff("m", StartDate, EndDate)=0 then
  if DateDiff("d", StartDate, EndDate)+1<15 then
   Diff_Month=(MoneyF_AA/30)*AmountAA*(DateDiff("d", StartDate, EndDate)+1) + (MoneyF_A/30)*AmountA*(DateDiff("d", StartDate, EndDate)+1) + (MoneyF_B/30)*AmountB*(DateDiff("d", StartDate, EndDate)+1) + (MoneyF_C/30)*AmountC*(DateDiff("d", StartDate, EndDate)+1)
  end if
  if DateDiff("d", StartDate, EndDate)+1>=15 then
   Diff_Month=MoneyF_AA*AmountAA + MoneyF_A*AmountA + MoneyF_B*AmountB + MoneyF_C*AmountC
  end if
 end if

 '如果相差大于一个月的整月
 if DateDiff("m", StartDate, EndDate)>0 and DateDiff("d", DateAdd("m", Different, StartDate), EndDate)=0 then
   Diff_Month=(MoneyF_AA*AmountAA + MoneyF_A*AmountA + MoneyF_B*AmountB + MoneyF_C*AmountC)*Different
 end if

 '如果形如2002-03-15、2002-05-25
 if DateDiff("m", StartDate, EndDate)>0 and DateDiff("d", DateAdd("m", Different, StartDate), EndDate)>0 then
  '如果相差大于一个月且<15天
  if DateDiff("d", DateAdd("m", Different, StartDate), EndDate)+1<15 then
   Diff_Month=(MoneyF_AA*AmountAA + MoneyF_A*AmountA + MoneyF_B*AmountB + MoneyF_C*AmountC)*Different
   Diff_Month=Diff_Month+((MoneyF_AA/30)*AmountAA*(DateDiff("d", DateAdd("m", Different, StartDate), EndDate)+1) + (MoneyF_A/30)*AmountA*(DateDiff("d", DateAdd("m", Different, StartDate), EndDate)+1) + (MoneyF_B/30)*AmountB*(DateDiff("d", DateAdd("m", Different, StartDate), EndDate)+1) + (MoneyF_C/30)*AmountC*(DateDiff("d", DateAdd("m", Different, StartDate), EndDate)+1))
  end if

  '如果相差大于一个月且>=15天
  if DateDiff("d", DateAdd("m", Different, StartDate), EndDate)+1>=15 then
   Diff_Month=(MoneyF_AA*AmountAA + MoneyF_A*AmountA + MoneyF_B*AmountB + MoneyF_C*AmountC)*(Different+1)
  end if
 end if

 '如果形如2002-03-15、2002-05-01
 if DateDiff("m", StartDate, EndDate)>=1 and DateDiff("d", DateAdd("m", Different, StartDate), EndDate)<0 then
  Different=DateDiff("m",StartDate,EndDate)-1

  '如果相差大于一个月且<15天
  if DateDiff("d", DateAdd("m", Different, StartDate), EndDate)<15 then
   Diff_Month=(MoneyF_AA*AmountAA + MoneyF_A*AmountA + MoneyF_B*AmountB + MoneyF_C*AmountC)*Different
   Diff_Month=Diff_Month+((MoneyF_AA/30)*AmountAA*(DateDiff("d", DateAdd("m", Different, StartDate), EndDate)+1) + (MoneyF_A/30)*AmountA*(DateDiff("d", DateAdd("m", Different, StartDate), EndDate)+1) + (MoneyF_B/30)*AmountB*(DateDiff("d", DateAdd("m", Different, StartDate), EndDate)+1) + (MoneyF_C/30)*AmountC*(DateDiff("d", DateAdd("m", Different, StartDate), EndDate)+1))
  end if

  '如果相差大于一个月且>=15天
  if DateDiff("d", DateAdd("m", Different, StartDate), EndDate)>=15 then
   Diff_Month=(MoneyF_AA*AmountAA + MoneyF_A*AmountA + MoneyF_B*AmountB + MoneyF_C*AmountC)*(Different+1)
  end if
 end if
end function
%>

0 0

相关博文

我的热门文章

img
取 消
img