当前位置: 首页 > news >正文

为了 门户网站建设dz网站模版

为了 门户网站建设,dz网站模版,黄骅港怎么读,wordpress自动发货插件题目 我看了一下,这个题目应该不是什么机密,所以先放上来了。大概意思是根据合同信息生成交租阶段信息。 解答 要求是要使用 Ruby 生成交租阶段信息,由于时间比较仓促,变量名那些就用得随意了些。要点主要有下面这些&#xff1a…

题目

我看了一下,这个题目应该不是什么机密,所以先放上来了。大概意思是根据合同信息生成交租阶段信息。

解答

要求是要使用 Ruby 生成交租阶段信息,由于时间比较仓促,变量名那些就用得随意了些。要点主要有下面这些:

  • 第一个交费阶段是要单独算
  • 整月和非整月的计算方式是不一样的(同样的整月,不同月的天数不一样,但是租金还是要算成一样的,我目前是把合同起始结束月都当做非整月来算)
  • 循环结束时间判断(其实也就是缴费阶段结束日期和合同的结束日期进行对比判断)
require 'time'
require 'terminal-table'class Rentdef initialize(contract_start, contract_end, month_rent, cycle)@contract_start = Time.strptime(contract_start, "%Y-%m-%d").to_date@contract_end = Time.strptime(contract_end, "%Y-%m-%d").to_date@month_rent = month_rent@cycle = cycle@year_total_rent = 12 * month_rent.to_f@tb = Terminal::Table.newenddef generate_next_month_last_day(time)date = Date.new(time.year, time.month, time.day)date = date.next_monthDate.civil(date.year, date.month, -1)enddef calculate_first_month_rent(time)month_last_day = Date.civil(time.year, time.month, -1)month_day_left = month_last_day.day - time.day + 1@year_total_rent * month_day_left / 365enddef calculate_last_month_rent(time)@year_total_rent * time.day / 365enddef add_rows# 合同起始和结束日期当月都按非整月计算,其他整月按整月的租金计算rent_day = @contract_starttotal = calculate_first_month_rent(@contract_start)to_end = falsetmp_cycle = @cycle - 1next_month_last_day = rent_dayif tmp_cycle == 0 # 一月一租next_month_last_day = Date.civil(next_month_last_day.year, next_month_last_day.month, -1)enduntil tmp_cycle == 0next_month_last_day = generate_next_month_last_day(next_month_last_day)if next_month_last_day > @contract_endtotal += calculate_last_month_rent(@contract_end)next_month_last_day = @contract_endto_end = truebreakendtotal += @month_renttmp_cycle -= 1endstart_date = rent_dayend_date = next_month_last_day@tb.add_row([start_date, end_date, rent_day, "%.2f" % total])total = 0until to_endtmp_cycle = @cyclerent_day = Date.new(next_month_last_day.year, next_month_last_day.month, 15)start_date = next_month_last_day + 1until tmp_cycle == 0next_month_last_day = generate_next_month_last_day(next_month_last_day)if next_month_last_day > @contract_endtotal += calculate_last_month_rent(@contract_end)next_month_last_day = @contract_endto_end = truebreakendtotal += @month_renttmp_cycle -= 1endend_date = next_month_last_day@tb.add_row([start_date, end_date, rent_day, "%.2f" % total])total = 0endenddef show_tableset_table_titleset_table_headingsadd_rowsprint_tableenddef set_table_title@tb.title = "交租阶段信息"enddef set_table_headings@tb.headings = ["开始日期", "结束日期", "交租日期", "交租阶段总租金"]enddef set_align_column@tb.number_of_columns.times do |index|@tb.align_column(index + 1, :right)end@tb.align_column(0, :left)enddef print_tableputs @tbputsend
endrent = Rent.new("2020-11-16", "2021-03-16", 5000, 2)
rent.show_table
+------------+------------+------------+----------------+
|                     交租阶段信息                      |
+------------+------------+------------+----------------+
| 开始日期   | 结束日期   | 交租日期   | 交租阶段总租金 |
+------------+------------+------------+----------------+
| 2020-11-16 | 2020-12-31 | 2020-11-16 | 7465.75        |
| 2021-01-01 | 2021-02-28 | 2020-12-15 | 10000.00       |
| 2021-03-01 | 2021-03-16 | 2021-02-15 | 2630.14        |
+------------+------------+------------+----------------+

目前按照一月一交的话,交租日期那块显示还有点问题,这个后面再优化吧。

+------------+------------+------------+----------------+
|                     交租阶段信息                      |
+------------+------------+------------+----------------+
| 开始日期   | 结束日期   | 交租日期   | 交租阶段总租金 |
+------------+------------+------------+----------------+
| 2020-11-16 | 2020-11-30 | 2020-11-16 | 2465.75        |
| 2020-12-01 | 2020-12-31 | 2020-11-15 | 5000.00        |
| 2021-01-01 | 2021-01-31 | 2020-12-15 | 5000.00        |
| 2021-02-01 | 2021-02-28 | 2021-01-15 | 5000.00        |
| 2021-03-01 | 2021-03-16 | 2021-02-15 | 2630.14        |
+------------+------------+------------+----------------+
http://www.yayakq.cn/news/841240/

相关文章:

  • 做网站需要收付款功能吗网站404 模板
  • 简述电子商务网站的建设步骤永康网站建设公司
  • 烟台网站建设便宜臻动传媒网站备案 服务内容
  • 国外设计学院网站亚马逊网站首页
  • 怎么申请 免费网站网站建设保报价文档
  • 国外做任务网站有哪些方面凡客网站做SEO能被收录吗
  • 渭南做网站哪家公司公司网站开发费用账务处理
  • 有备案号的网站是公司的吗做响应式网站的体会
  • 做网站用个人还是企业比较好在线制作生成器
  • 网站开发有很多种吗wordpress 快站
  • 河北住房城乡建设厅官方网站网站建设的潜在客户
  • 汕头自助建站wordpress网站设置关键词
  • 网站建设流程行情网站做宣传
  • 肥乡邯郸做网站长春网站建设产品展示
  • 合肥市网站建设新能源电动车
  • 登录功能网站怎么做四川省建设厅官网信息查询平台
  • 做网站需要会什么软件想学网站建设什么的
  • 游戏周边产品 做网站网页设计后怎么上传到网站
  • 做亚马逊需要的图片外链网站wordpress 照片
  • 织梦电影网站模板下载管理系统软件开发
  • 圣诞节网站模板计算机软件技术主要学什么
  • seo网络贸易网站推广wordpress 聚美优品
  • 网站服务器建设的三种方法是什么南通做网站软件
  • 合肥 企业网站设计seo优化技术
  • 中山网站的优化wordpress更新了固定连接文章失效
  • vs网站开发 怎么运行新开传奇网站曾劲松
  • 深圳做英文网站的公司互联网网站建设咨询
  • 网站正在建设中色无夜wordpress显示产品类别
  • 东莞网站设计报价wordpress仿next主题
  • 网站建设制作经验足做网站和网页