@ -9,109 +9,13 @@ using System.Threading.Tasks;
using Volo.Abp.DependencyInjection ;
using Volo.Abp.DependencyInjection ;
using Volo.Abp.Domain.Repositories.Dapper ;
using Volo.Abp.Domain.Repositories.Dapper ;
using Volo.Abp.EntityFrameworkCore ;
using Volo.Abp.EntityFrameworkCore ;
using Win.Sfs.SettleAccount.Entities ;
using Win.Sfs.SettleAccount.Reports ;
using Win.Sfs.SettleAccount.Reports ;
using Win.Sfs.SettleAccount.Reports.InvoiceSettledDiffs ;
namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report
namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report
{
{
[ExcelExporter(MaxRowNumberOnASheet = 900000)]
public class InvoiceSettledDetailDiff
: ReportDetailBase
{
//public InvoiceSettledDetailDiff(string wmsBillNum, DateTime cP5Time, string kENNCode, string chassisNumber, string wmsState, string sapMaterialCode, string materialDesc, string materialCode, string parentSapMaterialCode, string parentMaterialDesc, string materialGroup, decimal price, decimal amt, decimal qty, decimal settledQty, DateTime cP7Time, decimal diffSettleFisQty, decimal diffSettleInvQty, decimal invoiceQty, decimal invoicePrice, decimal invocieAmt, decimal settleAmt, decimal diffPrice)
//{
// WmsBillNum = wmsBillNum;
// CP5Time = cP5Time;
// KENNCode = kENNCode;
// ChassisNumber = chassisNumber;
// WmsState = wmsState;
// SapMaterialCode = sapMaterialCode;
// MaterialDesc = materialDesc;
// MaterialCode = materialCode;
// ParentSapMaterialCode = parentSapMaterialCode;
// ParentMaterialDesc = parentMaterialDesc;
// MaterialGroup = materialGroup;
// Price = price;
// Amt = amt;
// Qty = qty;
// SettledQty = settledQty;
// CP7Time = cP7Time;
// DiffSettleFisQty = diffSettleFisQty;
// DiffSettleInvQty = diffSettleInvQty;
// InvoiceQty = invoiceQty;
// InvoicePrice = invoicePrice;
// InvocieAmt = invocieAmt;
// SettleAmt = settleAmt;
// DiffPrice = diffPrice;
//}
[ExporterHeader(DisplayName = "交货单号")]
public override string WmsBillNum { set ; get ; }
[ExporterHeader(DisplayName = "实际发货日期", Format = "yyyy-MM-dd")]
public override DateTime CP5Time { set ; get ; }
[ExporterHeader(DisplayName = "KENN号")]
public override string KENNCode { set ; get ; }
[ExporterHeader(DisplayName = "底盘号")]
public override string ChassisNumber { set ; get ; }
[ExporterHeader(DisplayName = "交货状态")]
public override string WmsState { set ; get ; }
[ExporterHeader(DisplayName = "物料号")]
public override string SapMaterialCode { set ; get ; }
[ExporterHeader(DisplayName = "物料描述")]
public override string MaterialDesc { set ; get ; }
[ExporterHeader(DisplayName = "客户物料")]
public override string MaterialCode { set ; get ; }
[ExporterHeader(DisplayName = "组件组物料")]
public override string ParentSapMaterialCode { set ; get ; }
[ExporterHeader(DisplayName = "组件组物料描述")]
public override string ParentMaterialDesc { set ; get ; }
[ExporterHeader(DisplayName = "物料组(车型)")]
public override string MaterialGroup { set ; get ; }
[ExporterHeader(DisplayName = "定价")]
public override decimal Price { set ; get ; }
[ExporterHeader(DisplayName = "金额") ]
public override decimal Amt { set ; get ; }
//发运数量
[ExporterHeader(DisplayName = "M100数量")]
public decimal Qty { set ; get ; }
//结算数量
[ExporterHeader(DisplayName = "结算数量")]
public decimal SettledQty { set ; get ; }
//结算日期
[ExporterHeader(DisplayName = "结算日期", Format = "yyyy-MM-dd")]
public override DateTime CP7Time { set ; get ; }
//结算与发货差异
[ExporterHeader(DisplayName = "结算与发货差异")]
public decimal DiffSettleFisQty { set ; get ; }
//结算与开票差异
[ExporterHeader(DisplayName = "结算与开票差异")]
public decimal DiffSettleInvQty { set ; get ; }
//开票数量
[ExporterHeader(DisplayName = "开票数量")]
public decimal InvoiceQty { set ; get ; }
//开票单价
[ExporterHeader(DisplayName = "开票单价")]
public override decimal InvoicePrice { set ; get ; }
//开票金额
[ExporterHeader(DisplayName = "开票金额")]
public decimal InvoiceAmt { set ; get ; }
//结算金额
[ExporterHeader(DisplayName = "结算金额")]
public decimal SettleAmt { set ; get ; }
//单价差异
[ExporterHeader(DisplayName = "单价差异")]
public decimal DiffPrice { set ; get ; }
[ExporterHeader(DisplayName = "结算实际数量",IsIgnore =true)]
public decimal SettleReadyQty { set ; get ; }
//总金额差异
//[ExporterHeader(DisplayName = "总金额差异")]
//public decimal AmtDiffPrice { set; get; }
}
/// <summary>
/// <summary>
/// 2.大众发票与结算核对明细表-准时化
/// 2.大众发票与结算核对明细表-准时化
/// </summary>
/// </summary>
@ -123,163 +27,117 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report
}
}
public virtual List < InvoiceSettledDetailDiff > GetInvoiceSettledDetailDiffReportList ( string version , string materialCode , string begin , string end , string cp7begin , string cp7end , string kennCode , string chassisNumber , string materialGroup )
public virtual List < InvoiceSettledDetailDiff > GetInvoiceSettledDetailDiffReportList ( string version , string materialCode , string begin , string end , string cp7begin , string cp7end , string kennCode , string chassisNumber , string materialGroup )
{
{
List < InvoiceSettledDetailDiff > _l ist = new List < InvoiceSettledDetailDiff > ( ) ;
List < InvoiceSettledDetailDiff > _l ist = new List < InvoiceSettledDetailDiff > ( ) ;
string condition = " where 1=1 " ;
if ( CacheManager . CacheMaterials ! = null & & CacheManager . CacheInvoiceSettledDetailDiff . Count ( p = > p . Version = = version ) > 0 )
//if (!string.IsNullOrEmpty(materialCode))
//{
// condition += string.Format(" and d.MaterialCode in ({0}) ", materialCode);
//}
if ( ! string . IsNullOrEmpty ( begin ) )
{
condition + = string . Format ( " and a.BeginTime>='{0}' " , begin ) ;
}
if ( ! string . IsNullOrEmpty ( end ) )
{
condition + = string . Format ( " and a.BeginTime<='{0}' " , end ) ;
}
if ( ! string . IsNullOrEmpty ( cp7begin ) )
{
{
condition + = string . Format ( " and B.cp7>='{0}' " , cp7begin ) ;
_l ist = CacheManager . CacheInvoiceSettledDetailDiff . Where ( p = > p . Version = = version ) . ToList ( ) ;
_l ist = _l ist . GroupBy ( p = > new { p . ChassisNumber , p . MaterialCode , p . ParentSapMaterialCode } ) . Select ( p = > p . FirstOrDefault ( ) ) . ToList ( ) ;
}
}
if ( ! string . IsNullOrEmpty ( cp7end ) )
else
{
{
condition + = string . Format ( " and B.cp7<='{0}' " , cp7end ) ;
}
//if (!string.IsNullOrEmpty(kennCode))
//{
// condition += string.Format(" and B.kenncode='{0}' ", kennCode);
//}
//if (!string.IsNullOrEmpty(chassisNumber))
//{
// condition += string.Format(" and B.chassisNumber='{0}' ", chassisNumber);
//}
//if (!string.IsNullOrEmpty(materialGroup))
//{
// condition += string.Format(" B.chassisNumber='{0}' ", materialGroup);
//}
// string str= "SELECT\n" +
//" temp1.*,\n" +
//" TEMP2.Price,(\n" +
//" Isnull( temp2.Price, 0 ) * isnull( temp1.Qty, 0 )) Amt \n" +
//"FROM\n" +
//" (\n" +
//" SELECT\n" +
//" b.YEAR,\n" +
//" isnull( a.OrderBillNum, b.Kenncode ) kennocode,\n" +
//" b.MaterialCode,\n" +
//" b.Model,\n" +
//" isnull( a.ChassisNumber, b.ChassisNumber ) ChassisNumber,\n" +
//" isnull( a.Qty, 0 ) Qty,\n" +
//" isnull( a.BeginTime, b.CP5A ) CP5Time,\n" +
//" a.ChassisNumber2,\n" +
//" B.CP7 CP7Time,\n" +
//" isnull( a.QTY, b.Qty ) SettledQty,\n" +
//" a.ErpMaterialCode ParentSapMaterialCode,\n" +
//" isnull( a.WMSState, '' ) WMSState,\n" +
//" isnull( a.WMSBillNum, '' ) WMSBillNum,\n" +
//" d.MaterialCode SapMaterialCode,\n" +
//" d.MaterialDesc MaterialDesc,\n" +
//" d.EstimateTypeDesc MaterialGroup,\n" +
//" e.MaterialDesc ParentMaterialDesc,\n" +
//" c.InvoicePrice,\n" +
//" Round( c.InvoicePrice * isnull( a.QTY, b.Qty ), 2 ) InvoiceAmt,\n" +
//" Round( c.InvoicePrice * isnull( a.QTY, b.Qty ), 2 ) SettleAmt,\n" +
//" isnull( a.Qty, 0 ) - IsNull( B.Qty, 0 ) DiffSettleFisQty,\n" +
//" 0 DiffSettleInvQty,\n" +
//" isnull( a.QTY, b.Qty ) InvoiceQty \n" +
//" FROM\n" +
//" ( SELECT * FROM Set_Settle b WHERE b.Version = '{0}' ) b\n" +
//" LEFT JOIN Set_fis a ON b.ChassisNumber = a.ChassisNumber2 \n" +
//" AND b.KENNCode = a.KENNCode \n" +
//" AND b.MaterialCode = a.ItemCode\n" +
//" LEFT JOIN ( SELECT SUM( amt )/ SUM( Qty ) InvoicePrice, MaterialCode FROM set_invoice WHERE version = '{0}' GROUP BY materialcode ) c ON b.MaterialCode = c.MaterialCode\n" +
//" LEFT JOIN set_material d ON b.MaterialCode = d.CustomerPartCode\n" +
//" LEFT JOIN set_material e ON a.ErpMaterialCode = e.MaterialCode \n" +
//" ) TEMP1\n" +
//" LEFT JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE version = ( SELECT Max( Version ) FROM Set_PriceList ) AND type = 10 ) TEMP2 ON TEMP1.SapMaterialCode = TEMP2.MaterialCode"
string isExistSql = string . Format ( "SELECT count(1) lincount FROM [Set_Settle1] WITH(SNAPSHOT) where Version = '{0}'" , version ) ;
int _ count = DbConnection . ExecuteScalar < int > ( isExistSql ) ;
string condition = " where 1=1 " ;
if ( ! string . IsNullOrEmpty ( begin ) )
{
condition + = string . Format ( " and a.BeginTime>='{0}' " , begin ) ;
}
if ( ! string . IsNullOrEmpty ( end ) )
{
condition + = string . Format ( " and a.BeginTime<='{0}' " , end ) ;
}
if ( ! string . IsNullOrEmpty ( cp7begin ) )
{
condition + = string . Format ( " and B.cp7>='{0}' " , cp7begin ) ;
}
if ( ! string . IsNullOrEmpty ( cp7end ) )
{
condition + = string . Format ( " and B.cp7<='{0}' " , cp7end ) ;
}
string tablestr = ( _ count = = 0 ) ?
" ( SELECT * FROM Set_Settle b WHERE b.Version = '{0}' ) b\n" :
" (SELECT count(1) lincount FROM [Set_Settle1] WITH(SNAPSHOT) where Version = '{0}') b \n" ;
string str =
"SELECT\n" +
string . Format ( " '{0}' version ,\n" , version ) +
" temp1.*,\n" +
" TEMP2.Price,(\n" +
" Isnull( temp2.Price, 0 ) * isnull( temp1.Qty, 0 )) Amt \n" +
"FROM\n" +
" (\n" +
" SELECT\n" +
" b.YEAR,\n" +
" a.OrderBillNum Kenncode,\n" +
" b.MaterialCode,\n" +
" b.Model,\n" +
" a.ChassisNumber,\n" +
" a.Qty,\n" +
" a.BeginTime CP5Time,\n" +
" a.ChassisNumber2,\n" +
" B.CP7 CP7Time,\n" +
" a.QTY SettledQty,\n" +
" a.ErpMaterialCode ParentSapMaterialCode,\n" +
" a.WMSState,\n" +
" a.WMSBillNum,\n" +
" d.MaterialCode SapMaterialCode,\n" +
" d.MaterialDesc MaterialDesc,\n" +
" d.EstimateTypeDesc MaterialGroup,\n" +
" e.MaterialDesc ParentMaterialDesc,\n" +
" c.InvoicePrice,\n" +
" Round( c.InvoicePrice * a.qty,2 ) InvoiceAmt,\n" +
" Round( c.InvoicePrice * a.Qty,2 ) SettleAmt,\n" +
" 0 DiffSettleFisQty,\n" +
" 0 DiffSettleInvQty, \n" +
" a.Qty InvoiceQty ,\n" +
" IsNull( B.Qty, 0 ) SettleReadyQty \n" +
" FROM\n" +
tablestr +
" INNER JOIN Set_fis a ON b.ChassisNumber = a.ChassisNumber2 \n" +
" AND b.KENNCode = a.KENNCode \n" +
" AND b.MaterialCode = a.ItemCode\n" +
" LEFT JOIN ( SELECT SUM( amt )/ SUM( Qty ) InvoicePrice, MaterialCode FROM set_invoice WHERE version = '{0}' GROUP BY materialcode ) c ON a.ItemCode = c.MaterialCode\n" +
" LEFT JOIN set_material d ON a.ItemCode = d.CustomerPartCode\n" +
" LEFT JOIN (select max(Id) Id,MaterialCode,MaterialDesc from Set_material group by MaterialCode,MaterialDesc) e ON a.ErpMaterialCode = e.MaterialCode {1} \n" +
" ) TEMP1\n" +
" LEFT JOIN (\n" +
" SELECT\n" +
" Price,\n" +
" MaterialCode \n" +
" FROM\n" +
" Set_PriceList \n" +
" WHERE\n" +
" version = ( SELECT Max( Version ) FROM Set_PriceList ) and type=10 ) TEMP2 ON TEMP1.SapMaterialCode = TEMP2.MaterialCode" ;
var _ sql = string . Format ( str , version , condition ) ;
var _ query = DbConnection . Query < InvoiceSettledDetailDiff > ( _ sql , null , null , true , 1 2 0 0 , null ) ;
_l ist = _ query . ToList ( ) ;
if ( CacheManager . CacheMaterials ! = null & & CacheManager . CacheInvoiceSettledDetailDiff . Count ( p = > p . Version = = version ) > 0 )
{
_l ist = CacheManager . CacheInvoiceSettledDetailDiff . Where ( p = > p . Version = = version ) . ToList ( ) ;
_l ist = _l ist . GroupBy ( p = > new { p . ChassisNumber , p . MaterialCode , p . ParentSapMaterialCode } ) . Select ( p = > p . FirstOrDefault ( ) ) . ToList ( ) ;
}
else
{
CacheManager . CacheInvoiceSettledDetailDiff . AddRange ( _l ist ) ;
}
}
string str =
"SELECT\n" +
" temp1.*,\n" +
" TEMP2.Price,(\n" +
" Isnull( temp2.Price, 0 ) * isnull( temp1.Qty, 0 )) Amt \n" +
"FROM\n" +
" (\n" +
" SELECT\n" +
" b.YEAR,\n" +
" a.OrderBillNum Kenncode,\n" +
" b.MaterialCode,\n" +
" b.Model,\n" +
" a.ChassisNumber,\n" +
" a.Qty,\n" +
" a.BeginTime CP5Time,\n" +
" a.ChassisNumber2,\n" +
" B.CP7 CP7Time,\n" +
" a.QTY SettledQty,\n" +
" a.ErpMaterialCode ParentSapMaterialCode,\n" +
" a.WMSState,\n" +
" a.WMSBillNum,\n" +
" d.MaterialCode SapMaterialCode,\n" +
" d.MaterialDesc MaterialDesc,\n" +
" d.EstimateTypeDesc MaterialGroup,\n" +
" e.MaterialDesc ParentMaterialDesc,\n" +
" c.InvoicePrice,\n" +
" Round( c.InvoicePrice * a.qty,2 ) InvoiceAmt,\n" +
" Round( c.InvoicePrice * a.Qty,2 ) SettleAmt,\n" +
" 0 DiffSettleFisQty,\n" +
" 0 DiffSettleInvQty, \n" +
" a.Qty InvoiceQty ,\n" +
" IsNull( B.Qty, 0 ) SettleReadyQty \n" +
" FROM\n" +
" ( SELECT * FROM Set_Settle b WHERE b.Version = '{0}' ) b\n" +
" INNER JOIN Set_fis a ON b.ChassisNumber = a.ChassisNumber2 \n" +
" AND b.KENNCode = a.KENNCode \n" +
" AND b.MaterialCode = a.ItemCode\n" +
" LEFT JOIN ( SELECT SUM( amt )/ SUM( Qty ) InvoicePrice, MaterialCode FROM set_invoice WHERE version = '{0}' GROUP BY materialcode ) c ON a.ItemCode = c.MaterialCode\n" +
" LEFT JOIN set_material d ON a.ItemCode = d.CustomerPartCode\n" +
" LEFT JOIN (select max(Id) Id,MaterialCode,MaterialDesc from Set_material group by MaterialCode,MaterialDesc) e ON a.ErpMaterialCode = e.MaterialCode {1} \n" +
" ) TEMP1\n" +
" LEFT JOIN (\n" +
" SELECT\n" +
" Price,\n" +
" MaterialCode \n" +
" FROM\n" +
" Set_PriceList \n" +
" WHERE\n" +
" version = ( SELECT Max( Version ) FROM Set_PriceList ) and type=10 ) TEMP2 ON TEMP1.SapMaterialCode = TEMP2.MaterialCode" ;
var _ sql = string . Format ( str , version , condition ) ;
var _ query = DbConnection . Query < InvoiceSettledDetailDiff > ( _ sql , null , null , true , 1 2 0 0 , null ) ;
_l ist = _ query . ToList ( ) ;
return _l ist ;
return _l ist ;
}
}