; ; PrintReport(dgProduct.CurrentView); Empty(); txtSum.CValue=SumOfCol("#Total.Quantity_RealSale",dgProduct.FilterCondition,true); txtSum.CValue=SumOfCol("#Total.Quantity_RealSale",dgProduct.FilterCondition,true); Empty();
if(cbLocation.SelectedItem == "全部") { if (Search("SearchAllLocationID")) { SuspendLayout(); for(@i = 0; @i<RowCount("#AllLocationID");@i=@i+1) { SetPosition("#AllLocationID", @i); if (@i == 0) @a = "'"+FormatString(#AllLocationID.ID_Location)+"'"; else @a = @a + "," +"'"+ FormatString(#AllLocationID.ID_Location)+"'"; @Location = " In ( " + @a + ")"; } ResumeLayout(); } } else { Search("SearchLocationID",cbLocation.SelectedItem); @Location = " = '" + FormatString(#LocationID.ID_Location) +"'"; } @dateCondition=" between "+" DATEADD(day,0,DATEDIFF(day,0,"+"'"+TypeConvert("String",StartDate.Value)+"'"+")) and "+" DATEADD(day,0,(DATEDIFF(day,0,"+"'"+TypeConvert("String",EndDate.Value)+"'"+")+1))"; @bisNow=" <= DATEADD(day,0,(DATEDIFF(day,0,'"+TypeConvert("String",EndDate.Value)+"')+1))"; @sqlCmd =" Select a.No_Product,a.Name_Product,a.Type_Product,a.Cost_Product,(IsNull(b.OpeningStockQty_ProductStocks,0)-IsNull(d1.Quantity_SaleOutDepotBillProduct,0)-IsNull(f1.OutQuantity_ModifyDepotBillProduct,0)+IsNull(h1.Quantity_PurchaseInDepotBillProduct,0)+IsNull(e1.InQuantity_ModifyDepotBillProduct,0)+IsNull(d.Quantity_SaleOutDepotBillProduct,0)+IsNull(f.OutQuantity_ModifyDepotBillProduct,0)-IsNull(h.Quantity_PurchaseInDepotBillProduct,0)-IsNull(e.InQuantity_ModifyDepotBillProduct,0)) As OpeningStockQty_ProductStocks ,(IsNull(b.OpeningStockQty_ProductStocks,0)-IsNull(d1.Quantity_SaleOutDepotBillProduct,0)-IsNull(f1.OutQuantity_ModifyDepotBillProduct,0)+IsNull(h1.Quantity_PurchaseInDepotBillProduct,0)+IsNull(e1.InQuantity_ModifyDepotBillProduct,0)) As StockQty_ProductStocks,a.Cost_Product*(IsNull(b.OpeningStockQty_ProductStocks,0)-IsNull(d1.Quantity_SaleOutDepotBillProduct,0)-IsNull(f1.OutQuantity_ModifyDepotBillProduct,0)+IsNull(h1.Quantity_PurchaseInDepotBillProduct,0)+IsNull(e1.InQuantity_ModifyDepotBillProduct,0)) As TotalPrice, " +" (IsNull(pb.OpeningAvailableQty_ProductStocks,0)-IsNull(c1.Quantity_SaleBillProduct,0)-IsNull(f1.OutQuantity_ModifyDepotBillProduct,0)+IsNull(h1.Quantity_PurchaseInDepotBillProduct,0)+IsNull(e1.InQuantity_ModifyDepotBillProduct,0)+IsNull(c.Quantity_SaleBillProduct,0)+IsNull(f.OutQuantity_ModifyDepotBillProduct,0)-IsNull(h.Quantity_PurchaseInDepotBillProduct,0)-IsNull(e.InQuantity_ModifyDepotBillProduct,0)) As OpeningAvailableQty_ProductStocks ,(IsNull(pb.OpeningAvailableQty_ProductStocks,0)-IsNull(c1.Quantity_SaleBillProduct,0)-IsNull(f1.OutQuantity_ModifyDepotBillProduct,0)+IsNull(h1.Quantity_PurchaseInDepotBillProduct,0)+IsNull(e1.InQuantity_ModifyDepotBillProduct,0)) As AvailableQty_ProductStocks," +" IsNull(c.Quantity_SaleBillProduct,0) As Quantity_SaleBillProduct,IsNull(d.Quantity_SaleOutDepotBillProduct,0) As Quantity_SaleOutDepotBillProduct,IsNull(e.InQuantity_ModifyDepotBillProduct,0) As InQuantity_ModifyDepotBillProduct,IsNull(f.OutQuantity_ModifyDepotBillProduct,0) As OutQuantity_ModifyDepotBillProduct,(IsNull(d.Quantity_SaleOutDepotBillProduct,0)-IsNull(k.Quantity_SaleRtnBillProduct,0)) As Quantity_RealSale, " +" IsNull(g.Quantity_PurchaseOrderBillProduct,0) As Quantity_PurchaseOrderBillProduct,IsNull(h.Quantity_PurchaseInDepotBillProduct,0) As Quantity_PurchaseInDepotBillProduct,IsNull(i.InQuantity_StocktakingBillProduct,0) As InQuantity_StocktakingBillProduct,IsNull(j.OutQuantity_StocktakingBillProduct,0) As OutQuantity_StocktakingBillProduct,IsNull(k.Quantity_SaleRtnBillProduct,0) As Quantity_SaleRtnBillProduct,IsNull(ind.Quantity_IndentBillProduct,0) As Quantity_IndentBillProduct" +" From " +" (" +" Select ProductStocks.ID_Product,Sum(OpeningStockQty_ProductStocks) As OpeningStockQty_ProductStocks" +" From ProductStocks" +" Where ID_Location IN(" +" Select x.ID_Location From Location x" +" Left Join Location s On x.ID_Warehouse = s.ID_Location" +" Where x.Level_Location = 1" +" And s.ID_Location" + @Location +" )" +" Group By ID_Product" +" )b " +" Join" +" ( " +" Select Product.ID_Product,Product.No_Product,Product.Type_Product,Product.Name_Product,Product.Cost_Product" +" From Product" +" )a On a.ID_Product=b.ID_Product" +" Join" +" (" +" Select ProductStocks.ID_Product,Sum(OpeningAvailableQty_ProductStocks) As OpeningAvailableQty_ProductStocks" +" From ProductStocks" +" Where ID_Location" + @Location +" Group By ID_Product" +" )pb On b.ID_Product=pb.ID_Product" +" Left Join" +" (" +" Select IndentBillProduct.ID_Product,Sum(IndentBillProduct.Quantity_IndentBillProduct) As Quantity_IndentBillProduct" +" From IndentBillProduct" +" Join IndentBill On IndentBill.ID_IndentBill=IndentBillProduct.ID_IndentBill" +" Where IndentBill.ID_Assessor Is Not Null And IndentBill.Date_IndentBill "+@dateCondition+" And IndentBill.ID_Location " + @Location +" Group By IndentBillProduct.ID_Product" +" )ind On b.ID_Product=ind.ID_Product" +" Left Join" +" (" +" Select SaleBillProduct.ID_Product,Sum(SaleBillProduct.Quantity_SaleBillProduct) As Quantity_SaleBillProduct" +" From SaleBillProduct" +" Join SaleBill On SaleBill.ID_SaleBill=SaleBillProduct.ID_SaleBill" +" Where SaleBill.ID_Assessor Is Not Null And SaleBill.Date_SaleBill "+@dateCondition +" And SaleBill.ID_Location " + @Location +" Group By SaleBillProduct.ID_Product" +" )c On b.ID_Product=c.ID_Product" +" Left Join" +" (" +" Select SaleOutDepotBillProduct.ID_Product,Sum(SaleOutDepotBillProduct.Quantity_SaleOutDepotBillProduct) As Quantity_SaleOutDepotBillProduct" +" From SaleOutDepotBillProduct" +" Join SaleOutDepotBill On SaleOutDepotBill.ID_SaleOutDepotBill=SaleOutDepotBillProduct.ID_SaleOutDepotBill" +" Where SaleOutDepotBill.ID_Assessor Is Not Null And SaleOutDepotBill.Date_SaleOutDepotBill "+@dateCondition + " And SaleOutDepotBill.ID_Location " + @Location +" Group By SaleOutDepotBillProduct.ID_Product" +" )d On b.ID_Product=d.ID_Product" +" Left Join" +" (" +" Select ModifyDepotBillProduct.ID_Product,Sum(Quantity_ModifyDepotBillProduct) As InQuantity_ModifyDepotBillProduct" +" From ModifyDepotBillProduct" +" Join ModifyDepotBill On ModifyDepotBillProduct.ID_ModifyDepotBill=ModifyDepotBill.ID_ModifyDepotBill" +" Join ModifyTypeSettings On ModifyTypeSettings.ID_ModifyTypeSettings=ModifyDepotBill.Style_ModifyDepotBill" +" Where ModifyDepotBill.ID_Assessor Is Not Null And ModifyTypeSettings.Type_ModifyTypeSettings=1 And Date_ModifyDepotBill "+@dateCondition+ " And ModifyDepotBill.ID_Location " + @Location +" Group By ModifyDepotBillProduct.ID_Product" +" )e On b.ID_Product=e.ID_Product" +" Left Join" +" (" +" Select ModifyDepotBillProduct.ID_Product,Sum(Quantity_ModifyDepotBillProduct) As OutQuantity_ModifyDepotBillProduct" +" From ModifyDepotBillProduct" +" Join ModifyDepotBill On ModifyDepotBillProduct.ID_ModifyDepotBill=ModifyDepotBill.ID_ModifyDepotBill" +" Join ModifyTypeSettings On ModifyTypeSettings.ID_ModifyTypeSettings=ModifyDepotBill.Style_ModifyDepotBill" +" Where ModifyDepotBill.ID_Assessor Is Not Null And ModifyTypeSettings.Type_ModifyTypeSettings=0 And Date_ModifyDepotBill "+@dateCondition+ " And ModifyDepotBill.ID_Location " + @Location +" Group By ModifyDepotBillProduct.ID_Product" +" )f On b.ID_Product=f.ID_Product" +" Left Join" +" (" +" Select PurchaseOrderBillProduct.ID_Product,Sum(Quantity_PurchaseOrderBillProduct) As Quantity_PurchaseOrderBillProduct" +" From PurchaseOrderBillProduct" +" Join PurchaseOrderBill On PurchaseOrderBill.ID_PurchaseOrderBill=PurchaseOrderBillProduct.ID_PurchaseOrderBill" +" Where PurchaseOrderBill.ID_Assessor Is Not Null And PurchaseOrderBill.Date_PurchaseOrderBill "+@dateCondition+" And PurchaseOrderBill.ID_Location " + @Location +" Group By PurchaseOrderBillProduct.ID_Product" +" )g On a.ID_Product=g.ID_Product" +" Left Join" +" (" +" Select PurchaseInDepotBillProduct.ID_Product,Sum(Quantity_PurchaseInDepotBillProduct) As Quantity_PurchaseInDepotBillProduct" +" From PurchaseInDepotBillProduct" +" Join PurchaseInDepotBill On PurchaseInDepotBill.ID_PurchaseInDepotBill=PurchaseInDepotBillProduct.ID_PurchaseInDepotBill" +" Where PurchaseInDepotBill.ID_Assessor Is Not Null And PurchaseInDepotBill.Date_PurchaseInDepotBill "+@dateCondition+ " And PurchaseInDepotBill.ID_Location " + @Location +" Group By PurchaseInDepotBillProduct.ID_Product" +" )h On b.ID_Product=h.ID_Product" +" Left Join" +" (" +" Select StocktakingBillProduct.ID_Product,Sum(StocktakingBillProduct.Quantity_StocktakingBillProduct-StocktakingBillProduct.StockQty_StocktakingBillProduct) As InQuantity_StocktakingBillProduct" +" From StocktakingBillProduct" +" Join StocktakingBill On StocktakingBill.ID_StocktakingBill=StocktakingBillProduct.ID_StocktakingBill" +" Where StocktakingBill.ID_Assessor Is Not Null And (StocktakingBillProduct.Quantity_StocktakingBillProduct-StocktakingBillProduct.StockQty_StocktakingBillProduct) > 0 And StocktakingBill.Date_StocktakingBill "+@dateCondition+ " And StocktakingBill.ID_Location " + @Location +" Group By StocktakingBillProduct.ID_Product" +" )i On b.ID_Product=i.ID_Product" +" Left Join" +" (" +" Select StocktakingBillProduct.ID_Product,-Sum(StocktakingBillProduct.Quantity_StocktakingBillProduct-StocktakingBillProduct.StockQty_StocktakingBillProduct) As OutQuantity_StocktakingBillProduct" +" From StocktakingBillProduct" +" Join StocktakingBill On StocktakingBill.ID_StocktakingBill=StocktakingBillProduct.ID_StocktakingBill" +" Where StocktakingBill.ID_Assessor Is Not Null And (StocktakingBillProduct.Quantity_StocktakingBillProduct-StocktakingBillProduct.StockQty_StocktakingBillProduct) < 0 And StocktakingBill.Date_StocktakingBill "+@dateCondition+ " And StocktakingBill.ID_Location " + @Location +" Group By StocktakingBillProduct.ID_Product" +" )j On b.ID_Product=j.ID_Product" +" Left Join" +" (" +" Select SaleRtnBillProduct.ID_Product,Sum(Quantity_SaleRtnBillProduct) As Quantity_SaleRtnBillProduct" +" From SaleRtnBillProduct" +" Join SaleRtnBill On SaleRtnBill.ID_SaleRtnBill=SaleRtnBillProduct.ID_SaleRtnBill" +" Where SaleRtnBill.ID_Assessor Is Not Null And SaleRtnBill.Date_SaleRtnBill "+@dateCondition+ " And SaleRtnBill.ID_Location " + @Location +" Group By SaleRtnBillProduct.ID_Product" +" )k On b.ID_Product=k.ID_Product" +" Left Join" +" (" +" Select SaleOutDepotBillProduct.ID_Product,Sum(SaleOutDepotBillProduct.Quantity_SaleOutDepotBillProduct) As Quantity_SaleOutDepotBillProduct" +" From SaleOutDepotBillProduct" +" Join SaleOutDepotBill On SaleOutDepotBill.ID_SaleOutDepotBill=SaleOutDepotBillProduct.ID_SaleOutDepotBill" +" Where SaleOutDepotBill.ID_Assessor Is Not Null And SaleOutDepotBill.Date_SaleOutDepotBill "+@bisNow+ " And SaleOutDepotBill.ID_Location " + @Location +" Group By SaleOutDepotBillProduct.ID_Product" +" )d1 On b.ID_Product=d1.ID_Product" +" Left Join" +" (" +" Select ModifyDepotBillProduct.ID_Product,Sum(Quantity_ModifyDepotBillProduct) As InQuantity_ModifyDepotBillProduct" +" From ModifyDepotBillProduct" +" Join ModifyDepotBill On ModifyDepotBillProduct.ID_ModifyDepotBill=ModifyDepotBill.ID_ModifyDepotBill" +" Join ModifyTypeSettings On ModifyTypeSettings.ID_ModifyTypeSettings=ModifyDepotBill.Style_ModifyDepotBill" +" Where ModifyDepotBill.ID_Assessor Is Not Null And ModifyTypeSettings.Type_ModifyTypeSettings=1 And Date_ModifyDepotBill "+@bisNow+ " And ModifyDepotBill.ID_Location " + @Location +" Group By ModifyDepotBillProduct.ID_Product" +" )e1 On b.ID_Product=e1.ID_Product" +" Left Join" +" (" +" Select ModifyDepotBillProduct.ID_Product,Sum(Quantity_ModifyDepotBillProduct) As OutQuantity_ModifyDepotBillProduct" +" From ModifyDepotBillProduct" +" Join ModifyDepotBill On ModifyDepotBillProduct.ID_ModifyDepotBill=ModifyDepotBill.ID_ModifyDepotBill" +" Join ModifyTypeSettings On ModifyTypeSettings.ID_ModifyTypeSettings=ModifyDepotBill.Style_ModifyDepotBill" +" Where ModifyDepotBill.ID_Assessor Is Not Null And ModifyTypeSettings.Type_ModifyTypeSettings=0 And Date_ModifyDepotBill "+@bisNow+ " And ModifyDepotBill.ID_Location " + @Location +" Group By ModifyDepotBillProduct.ID_Product" +" )f1 On b.ID_Product=f1.ID_Product" +" Left Join" +" (" +" Select PurchaseInDepotBillProduct.ID_Product,Sum(Quantity_PurchaseInDepotBillProduct) As Quantity_PurchaseInDepotBillProduct" +" From PurchaseInDepotBillProduct" +" Join PurchaseInDepotBill On PurchaseInDepotBill.ID_PurchaseInDepotBill=PurchaseInDepotBillProduct.ID_PurchaseInDepotBill" +" Where PurchaseInDepotBill.ID_Assessor Is Not Null And PurchaseInDepotBill.Date_PurchaseInDepotBill "+@bisNow+ " And PurchaseInDepotBill.ID_Location " + @Location +" Group By PurchaseInDepotBillProduct.ID_Product" +" )h1 On b.ID_Product=h1.ID_Product" +" Left Join" +" (" +" Select SaleBillProduct.ID_Product,Sum(SaleBillProduct.Quantity_SaleBillProduct) As Quantity_SaleBillProduct" +" From SaleBillProduct" +" Join SaleBill On SaleBill.ID_SaleBill=SaleBillProduct.ID_SaleBill" +" Where SaleBill.ID_Assessor Is Not Null And SaleBill.Date_SaleBill "+@bisNow+ " And SaleBill.ID_Location " + @Location +" Group By SaleBillProduct.ID_Product" +" )c1 On b.ID_Product=c1.ID_Product"; @where=true; if(cbType1.Text!="") { if(@where==true) { @sqlCmd=@sqlCmd+" Where Type_Product >=" +"'"+cbType1.Text+"'"; @where=false; } else { @sqlCmd=@sqlCmd+" And Type_Product >=" +"'"+cbType1.Text+"'"; } } if(cbType2.Text!="") { if(@where==true) { @sqlCmd=@sqlCmd+" Where Type_Product <="+"'"+cbType2.Text+"'"; @where=false; } else { @sqlCmd=@sqlCmd+" And Type_Product <="+"'"+cbType2.Text+"'"; } } if(tbProductNo1.CValue!="") { if(@where==true) { @sqlCmd=@sqlCmd+" Where No_Product >=" +"'"+tbProductNo1.CValue+"'"; @where=false; } else { @sqlCmd=@sqlCmd+" And No_Product >=" +"'"+tbProductNo1.CValue+"'"; } } if(tbProductNo2.CValue!="") { if(@where==true) { @sqlCmd=@sqlCmd+" Where No_Product <="+"'"+tbProductNo2.CValue+"'"; @where=false; } else { @sqlCmd=@sqlCmd+" And No_Product <="+"'"+tbProductNo2.CValue+"'"; } } if(ckSuspend.Checked) { if(@where==true) { @sqlCmd=@sqlCmd+" Where (IsNull(c.Quantity_SaleBillProduct,0)+IsNull(d.Quantity_SaleOutDepotBillProduct,0)+IsNull(f.OutQuantity_ModifyDepotBillProduct,0)+IsNull(g.Quantity_PurchaseOrderBillProduct,0)+IsNull(h.Quantity_PurchaseInDepotBillProduct,0)+IsNull(e.InQuantity_ModifyDepotBillProduct,0)+IsNull(i.InQuantity_StocktakingBillProduct,0)+IsNull(j.OutQuantity_StocktakingBillProduct,0)+IsNull(k.Quantity_SaleRtnBillProduct,0)+IsNull(ind.Quantity_IndentBillProduct,0)) > 0 "; @where=false; } else { @sqlCmd=@sqlCmd+" And (IsNull(c.Quantity_SaleBillProduct,0)+IsNull(d.Quantity_SaleOutDepotBillProduct,0)+IsNull(f.OutQuantity_ModifyDepotBillProduct,0)+IsNull(g.Quantity_PurchaseOrderBillProduct,0)+IsNull(h.Quantity_PurchaseInDepotBillProduct,0)+IsNull(e.InQuantity_ModifyDepotBillProduct,0)+IsNull(i.InQuantity_StocktakingBillProduct,0)+IsNull(j.OutQuantity_StocktakingBillProduct,0)+IsNull(k.Quantity_SaleRtnBillProduct,0)) > 0 "; } } @sqlCmd=@sqlCmd+" Order By a.No_Product "; SearchEx(@sqlCmd,"Total"); txtSum.CValue=SumOfCol("#Total.Quantity_RealSale");