需求:统计所有用代金券消费明细,并计算出是否回本?
情况 三张表 商品表bi_t_item_info 流水表pos_t_saleflow 代金券消费明细表pos_t_payflow 爷父孙 关联。
我用以下方式把3张表合并到一起,但代金券消费明细表比较特殊,因为他的代金券额度是10元一张,所以我上传的图片里,比如他有一张50元的代金券,但消费后在门店用的前台软件里产生的数据是10元一条数据, 既出现了5条, 我不知道为啥用t.Filter = " pay_way = \'N\' and flow_no = \'021316073100006\'" 筛选出来的翻了一倍成10条了。
所以 目前难点是 : 1. 【销售流水】里的一条流水记录,每个商品是一条记录,但流水号一样,有销售额sale_amount 和每个商品的进价price ,但是【代金券消费明细表】里的每条记录额度都是10元,和销售流水的流水号也一样。 比如你消耗了一张50元券,他会有5条10元的记录产生。
所以我想以 流水单号 为单位, 算每个流水里的代金券赚回本了吗? 公式应该是 销售额 - 进价 = 毛利润 毛利润 - 代金券总额 = ? 如果是正数那就回本了。 我该怎么统计啊?
Dim jb As new SQLJoinTableBuilder("查询表1","pos_t_payflow")
jb.C
jb.AddTable("pos_t_payflow","flow_no","pos_t_saleflow","flow_no")
jb.AddTable("pos_t_saleflow","item_no","bi_t_item_info","item_no")
jb.AddCols("{bi_t_item_info}.item_name","{bi_t_item_info}.barcode","{bi_t_item_info}.price","{pos_t_payflow}.branch_no","{pos_t_payflow}.oper_date","{pos_t_payflow}.oper_id","{pos_t_payflow}.sale_amount","{pos_t_payflow}.vip_no","{pos_t_payflow}.flow_no","{pos_t_payflow}.pay_way","{pos_t_payflow}.pay_amount")
Dim t As Table = e.Form.Controls("Table1").Table
t.DataSource = jb.BuildDataSource
此主题相关图片如下:20168119495313307.png
t.DataTable.DataCols.Add("毛利", Gettype(Double))
t.Filter = " pay_way = \'N\' and flow_no = \'021316073100006\'"
For Each r As Row In t.Rows
Next