Commit 68133b63 by guanzhenshan

调整应收帐号页面和统计服务

parent 04096dde
......@@ -15,6 +15,7 @@
<ItemGroup>
<ProjectReference Include="..\Bailun.DC.Common\Bailun.DC.Common.csproj" />
<ProjectReference Include="..\Bailun.DC.Models\Bailun.DC.Models.csproj" />
<ProjectReference Include="..\Bailun.DC.Services\Bailun.DC.Services.csproj" />
</ItemGroup>
</Project>
......@@ -23,7 +23,7 @@ namespace Bailun.DC.DailyPlatformReceivable
// var _services = new Services();
// var start = DateTime.Parse("2020-01-01");
// var start = DateTime.Parse("2020-02-01");
// while (start.AddDays(1) < DateTime.Now)
// {
// Console.WriteLine(start);
......
......@@ -122,13 +122,73 @@ namespace Bailun.DC.DailyPlatformReceivable
m_ebay.lastupdateuserid = 0;
m_ebay.lastupdateusername = "system";
}
//非Ebay 应收账款=期初应收余额+本期销售收入-平台扣费-放款金额-退款金额+其他
//shopify 预收账款=期初预收余额+本期收款(订单付款金额)-发货金额-退款(未发货的)+其他
//期初预收余额
sql = $"select * from dc_daily_receivable where day='{day.AddDays(-1).ToString("yyyy-MM-dd")}' and platform='shopify'";
objBefore = cn.QueryFirstOrDefault<dc_daily_receivable>(sql);
//本期收款
sql = $"select sum(amount_sales*seller_order_exchange_rate) amount from dc_base_oms_order where platform_type='shopify' and paid_time>='{day.ToString("yyyy-MM-dd")}' and paid_time<'{day.AddDays(1).ToString("yyyy-MM-dd")}' and company_id=1 and bailun_order_status!='Canceled' and has_scalp=0 and has_innersale=0 and bailun_interception_status in ('None','Failed')";
EbaySales = cn.QueryFirstOrDefault<decimal?>(sql) ?? 0;
//发货金额
sql = $@"select sum(t1.amount_sales*t2.quantity_shipped*t1.seller_order_exchange_rate) amount
from dc_base_oms_pick t2
join dc_base_oms_sku t1 on t1.bailun_order_id=t2.bailun_order_id and t1.bailun_sku=t2.bailun_sku and t1.has_scalp=0 and t1.has_delete=0 and t1.has_innersale=0 and t1.bailun_order_status!='Canceled' and t1.has_innersale=0 and t1.company_id=1 and t1.platform_type='shopify'
where t2.has_delete=0 and t2.shipping_status='TotalShipping' and t2.company_id=1 and t2.shipping_time>='{day.ToString("yyyy-MM-dd")}' and t2.shipping_time<'{day.AddDays(1).ToString("yyyy-MM-dd")}' ";
EbayShipping = cn.QueryFirstOrDefault<decimal?>(sql) ?? 0;
//退款(未发货的)
sql = $"select sum(amount_refund_rmb) amount from dc_base_crm_refund where platform_type = 'shopify' and company_id = 1 and is_deleted = 0 and is_freeze = 0 and shipping_status = 'UnShipping' and refund_time>= '{day.ToString("yyyy-MM-dd")}' and refund_time<'{day.AddDays(1).ToString("yyyy-MM-dd")}'";
EbayRefund = cn.QueryFirstOrDefault<decimal?>(sql) ?? 0;
sql = $"select * from dc_daily_receivable where day='{day.ToString("yyyy-MM-dd")}' and platform='shopify'";
var m_shopify = cn.QueryFirstOrDefault<dc_daily_receivable>(sql);
if (m_shopify == null)
{
m_shopify = new dc_daily_receivable
{
day = day,
amount_end = (objBefore != null ? objBefore.amount_end : 0) + EbaySales - EbayShipping - EbayRefund,
amount_start = (objBefore != null ? objBefore.amount_end : 0),
amount_sale_pay = EbaySales,
amount_shipping = EbayShipping,
amount_refund = EbayRefund,
amount_incoming = 0,
amount_other = 0,
amount_platformfee = 0,
amount_sale_shipping = 0,
createtime = DateTime.Now,
lastupdatetime = DateTime.Now,
lastupdateuserid = 0,
lastupdateusername = "system",
platform = "shopify",
};
}
else
{
m_shopify.amount_start = (objBefore != null ? objBefore.amount_end : 0);
m_shopify.amount_sale_pay = EbaySales;
m_shopify.amount_shipping = EbayShipping;
m_shopify.amount_refund = EbayRefund;
m_shopify.amount_end = m_ebay.amount_start + EbaySales - EbayShipping - EbayRefund + m_ebay.amount_other;
m_shopify.lastupdatetime = DateTime.Now;
m_shopify.lastupdateuserid = 0;
m_shopify.lastupdateusername = "system";
}
//非Ebay\shopify 应收账款=期初应收余额+本期销售收入-平台扣费-放款金额-退款金额+其他
sql = $@"select * from (
select t1.platform_type,sum(t1.amount_sales*t1.seller_order_exchange_rate*t2.quantity_shipped) amount,sum(t1.cost_platform_fee*t1.seller_order_exchange_rate*t2.quantity_shipped) cost_platform_fee,0 as cost_fba_fee
from dc_base_oms_pick t2
join dc_base_oms_sku t1 on t1.bailun_order_id=t2.bailun_order_id and t1.bailun_sku=t2.bailun_sku and t1.has_scalp=0 and t1.has_delete=0 and t1.has_innersale=0 and t1.bailun_order_status!='Canceled' and t1.has_innersale=0 and t1.company_id=1 and t1.platform_type!='Ebay' and t1.platform_type!='FBA'
join dc_base_oms_sku t1 on t1.bailun_order_id=t2.bailun_order_id and t1.bailun_sku=t2.bailun_sku and t1.has_scalp=0 and t1.has_delete=0 and t1.has_innersale=0 and t1.bailun_order_status!='Canceled' and t1.has_innersale=0 and t1.company_id=1 and t1.platform_type!='Ebay' and t1.platform_type!='shopify' and t1.platform_type!='FBA'
where t2.has_delete=0 and t2.shipping_status='TotalShipping' and t2.company_id=1 and t2.shipping_time>='{day.ToString("yyyy-MM-dd")}' and t2.shipping_time<'{day.AddDays(1).ToString("yyyy-MM-dd")}' group by platform_type
union all
select platform_type,sum(amount_sales*seller_order_exchange_rate) amount,sum((cost_platform_fee+cost_fba_fee)*seller_order_exchange_rate) cost_platform_fee,sum(cost_fba_fee*seller_order_exchange_rate) cost_fba_fee from dc_base_oms_order where platform_type='FBA' and create_time>='{day.ToString("yyyy-MM-dd")}' and create_time<'{day.AddDays(1).ToString("yyyy-MM-dd")}' and company_id=1 and bailun_order_status!='Canceled' and has_scalp=0 and has_innersale=0
......@@ -138,17 +198,17 @@ namespace Bailun.DC.DailyPlatformReceivable
//非Ebay 平台费,按付款时间
sql = $@"select * from (
select t1.platform_type,sum(t1.cost_platform_fee*t1.seller_order_exchange_rate*t1.bailun_sku_quantity_ordered) cost_platform_fee,0 as cost_fba_fee
from dc_base_oms_sku t1 where t1.has_scalp=0 and t1.has_delete=0 and t1.has_innersale=0 and t1.bailun_order_status!='Canceled' and t1.has_innersale=0 and t1.company_id=1 and t1.platform_type!='Ebay' and t1.platform_type!='FBA' and t1.paid_time>='{day.ToString("yyyy-MM-dd")}' and t1.paid_time<'{day.AddDays(1).ToString("yyyy-MM-dd")}' and t1.bailun_interception_status in ('None','Failed') and (t1.platform_type!='FBA' and t1.bailun_order_status!='CantHandle')
from dc_base_oms_sku t1 where t1.has_scalp=0 and t1.has_delete=0 and t1.has_innersale=0 and t1.bailun_order_status!='Canceled' and t1.has_innersale=0 and t1.company_id=1 and t1.platform_type!='Ebay' and t1.platform_type!='shopify' and t1.platform_type!='FBA' and t1.paid_time>='{day.ToString("yyyy-MM-dd")}' and t1.paid_time<'{day.AddDays(1).ToString("yyyy-MM-dd")}' and t1.bailun_interception_status in ('None','Failed') and (t1.platform_type!='FBA' and t1.bailun_order_status!='CantHandle')
group by platform_type
union all
select platform_type,sum((cost_platform_fee+cost_fba_fee)*seller_order_exchange_rate) cost_platform_fee,sum(cost_fba_fee*seller_order_exchange_rate) cost_fba_fee from dc_base_oms_order where platform_type='FBA' and create_time>='{day.ToString("yyyy-MM-dd")}' and create_time<'{day.AddDays(1).ToString("yyyy-MM-dd")}' and company_id=1 and bailun_order_status!='Canceled' and has_scalp=0 and has_innersale=0 and bailun_interception_status in ('None','Failed')
) tb";
var listPlatformFee = cn.Query<platformamount>(sql);
var listPlatform = cn.Query<string>("select platform_type from dc_base_oms_order group by platform_type").Where(a=>a.ToLower()!= "amazon2b" && a.ToLower()!= "fba" && a.ToLower()!="ebay").ToList();
var listPlatform = cn.Query<string>("select platform_type from dc_base_oms_order group by platform_type").Where(a=>a.ToLower()!= "amazon2b" && a.ToLower()!= "fba" && a.ToLower()!= "ebay" && a.ToLower() != "shopify").ToList();
//退款
sql = $"select sum(amount_refund_rmb) as amount,platform_type from dc_base_crm_refund where platform_type!='Ebay' and company_id=1 and is_deleted=0 and is_freeze=0 and shipping_status='TotalShipping' and refund_time>='{day.ToString("yyyy-MM-dd")}' and refund_time<'{day.AddDays(1).ToString("yyyy-MM-dd")}' GROUP BY platform_type;";
sql = $"select sum(amount_refund_rmb) as amount,platform_type from dc_base_crm_refund where platform_type!='Ebay' and platform_type!='shopify' and company_id=1 and is_deleted=0 and is_freeze=0 and shipping_status='TotalShipping' and refund_time>='{day.ToString("yyyy-MM-dd")}' and refund_time<'{day.AddDays(1).ToString("yyyy-MM-dd")}' GROUP BY platform_type;";
var listRefund = cn.Query<platformamount>(sql);
//提现金额
......@@ -157,7 +217,7 @@ namespace Bailun.DC.DailyPlatformReceivable
where createTime>='{day.ToString("yyyy-MM-dd")}' and createTime<'{day.AddDays(1).ToString("yyyy-MM-dd")}' group by salesl_platform";
var listIncome = cn.Query<platformamount>(sql);
var listM = new List<dc_daily_receivable>() { m_ebay };
var listM = new List<dc_daily_receivable>() { m_ebay, m_shopify };
foreach (var item in listPlatform)
{
//期初
......@@ -286,10 +346,21 @@ namespace Bailun.DC.DailyPlatformReceivable
sql = $"insert dc_daily_receivable (platform,day,amount_start,amount_sale_pay,amount_shipping,amount_refund,amount_sale_shipping,amount_platformfee,amount_incoming,amount_other,amount_end,createtime,lastupdatetime,lastupdateuserid,lastupdateusername) values ('{item.platform}','{item.day.ToString("yyyy-MM-dd")}',{item.amount_start},{item.amount_sale_pay},{item.amount_shipping},{item.amount_refund},{item.amount_sale_shipping},{item.amount_platformfee},{item.amount_incoming},{item.amount_other},{item.amount_end},'{item.createtime.ToString("yyyy-MM-dd HH:mm:ss")}','{item.lastupdatetime.ToString("yyyy-MM-dd HH:mm:ss")}',{item.lastupdateuserid},'{item.lastupdateusername}')";
cn.Execute(sql);
}
//更新资产负债表的应收账款
//Ebay+shopify
var listEbayAmount = listM.Where(a => a.platform.ToLower() == "ebay" || a.platform.ToLower() == "shopify");
//其他平台
var listOtherAmount = listM.Where(a => a.platform.ToLower() != "ebay" && a.platform.ToLower() != "shopify");
new Bailun.DC.Services.FinanceReportServices().UpdateLogisticsEndAmount(day, (listOtherAmount.Count() > 0 ? listOtherAmount.Sum(a => a.amount_end) : 0) - (listEbayAmount.Count() > 0 ? listEbayAmount.Sum(a => a.amount_end) : 0), "accountsReceivableUpdate");
}
}
}
public class platformamount
......
......@@ -1879,7 +1879,7 @@ namespace Bailun.DC.Services
cn.Open();
}
var sql = $"select sum(case when platform != 'Ebay' then amount_end else 0 end) - sum(case when platform = 'Ebay' then amount_end else 0 end) as amount from dc_daily_receivable where day = '{date.ToString("yyyy-MM-dd")}'";
var sql = $"select sum(case when (platform != 'Ebay' and platform != 'shopify') then amount_end else -amount_end end) as amount from dc_daily_receivable where day = '{date.ToString("yyyy-MM-dd")}'";
var objRec = cn.QueryFirstOrDefault<decimal?>(sql);
//sql = $"select sum((amount - ifnull(had_pay, 0) + ifnull(compensate, 0)) * to_rmb_rate) from dc_daily_fee where recoed_time = '{date.ToString("yyyy-MM-dd")}' and company_value in (53,3,5,60,66,59,50,8,1,61,2,70)";
......@@ -1907,7 +1907,7 @@ namespace Bailun.DC.Services
cn.Open();
}
var sql = $"select (case when platform != 'Ebay' then amount_end else -amount_end end) as amount_end,day,platform from dc_daily_receivable where day = '{date.ToString("yyyy-MM-dd")}'";
var sql = $"select (case when (platform != 'Ebay' and platform != 'shopify') then amount_end else -amount_end end) as amount_end,day,platform from dc_daily_receivable where day = '{date.ToString("yyyy-MM-dd")}'";
var obj = cn.Page<dc_daily_receivable>(request.pageIndex, request.limit, sql, ref total, null, null, 2 * 60).ToList();
......@@ -5230,15 +5230,15 @@ group by currency";
if (type == 1) //Ebay
{
sql += " and platform='Ebay'";
sql_start += " and platform='Ebay'";
sql_end += " and platform='Ebay'";
sql += " and platform in ('Ebay','shopify') ";
sql_start += " and platform in ('Ebay','shopify') ";
sql_end += " and platform in ('Ebay','shopify') ";
}
else if (type == 2) //非Ebay
{
sql += " and platform!='Ebay'";
sql_start += " and platform!='Ebay'";
sql_end += " and platform!='Ebay'";
sql += " and platform!='Ebay' and platform!='shopify' ";
sql_start += " and platform!='Ebay' and platform!='shopify' ";
sql_end += " and platform!='Ebay' and platform!='shopify' ";
}
sql += " group by platform";
......@@ -5302,11 +5302,11 @@ group by currency";
if (type == 1) //Ebay
{
sql += " and platform='Ebay'";
sql += " and platform in('Ebay','shopify') ";
}
else if (type == 2) //非Ebay
{
sql += " and platform!='Ebay'";
sql += " and platform!='Ebay' and platform!='shopify' "; ;
}
using (var cn = new MySqlConnection(Common.GlobalConfig.ConnectionString))
......@@ -5343,11 +5343,11 @@ group by currency";
if (type == 1) //Ebay
{
sql += " and platform='Ebay'";
sql += " and platform in ('Ebay','shopify') ";
}
else if (type == 2) //非Ebay
{
sql += " and platform!='Ebay'";
sql += " and platform!='Ebay' and platform!='shopify' ";
}
using (var cn = new MySqlConnection(Common.GlobalConfig.ConnectionString))
......@@ -5403,7 +5403,7 @@ group by currency";
}
if (obj.platform.ToLower() == "ebay")
if (obj.platform.ToLower() == "ebay" || obj.platform.ToLower() == "shopify")
{
//期初预收余额+本期收款(订单付款金额)-发货金额-退款(未发货的)+其他
obj.amount_end = obj.amount_start + obj.amount_sale_pay - obj.amount_shipping - obj.amount_refund + obj.amount_other;
......
......@@ -19,8 +19,8 @@
<div class="form-inline" style="line-height:40px;">
<div class="form-group">
<label>类型</label>
<select id="type" name="type" class="form-control" style="width:100px;">
<option value="1">Ebay</option>
<select id="type" name="type" class="form-control" style="width:160px;">
<option value="1">Ebay和shopify</option>
<option value="2">非Ebay</option>
</select>
</div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment