FrmOverallSearchTable.xml 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015
  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <Forms>
  3. <Form Name="FrmOverallSearchTable">
  4. <Client>
  5. <Events>
  6. <Load>
  7. <![CDATA[
  8. @Title="库存异动汇总";
  9. GetSchema();
  10. Search("SearchLocation");
  11. SuspendLayout();
  12. for(@i=0;@i<RowCount("#Location");@i=@i+1)
  13. {
  14. SetPosition("#Location", @i);
  15. cbLocation.Items.Add(#Location.Name_Location);
  16. }
  17. ResumeLayout();
  18. Search("SearchType");
  19. Search("SearchLowLocation");
  20. Search("SearchProductNo");
  21. Empty();
  22. EndDate.Value=GetCurrentTime();
  23. StartDate.Value=GetCurrentTime();
  24. dgProduct.ColumnVisibleByColumnName("TotalPrice",!GetFieldRight(@Title,"成本及总价","查看"));
  25. dgProduct.ColumnVisibleByColumnName("Cost_Product",!GetFieldRight(@Title,"成本及总价","查看"));
  26. cbLocation.Text = GetCurrentDepot();
  27. ]]>
  28. </Load>
  29. <Closing>
  30. ;<!--TODO-->
  31. </Closing>
  32. <Closed>
  33. ;<!--TODO-->
  34. </Closed>
  35. </Events>
  36. <Mode>
  37. <Search>
  38. <Lable name="Search" />
  39. </Search>
  40. </Mode>
  41. <Controls>
  42. <!--<IKCheckedListBox name="CLB_Location" DataSource="Location" DisplayMember="Name_location" ValueMember="ID_Location">
  43. <Events>
  44. <ItemCheck>
  45. if(CLB_Location.SelectedIndex == 0)
  46. CLB_Location.SelectAllItems();
  47. </ItemCheck>
  48. </Events>
  49. </IKCheckedListBox>-->
  50. <IKComboBox name ="cbLocation" DataSource="Location" DisplayMember="Name_Location" >
  51. </IKComboBox>
  52. <IKTextButton name="tbProductNo1" DataSource="ProductNo.No_Product">
  53. <Events>
  54. <Click>
  55. <![CDATA[
  56. if (tbProductNo1.ReadOnly == false)
  57. {
  58. @temp = ShowSearchBox("ProductSearch","INFOMATION",tbProductNo1.CValue);
  59. if( @temp == "" )
  60. return;
  61. tbProductNo1.CValue = @temp;
  62. }
  63. ]]>
  64. </Click>
  65. </Events>
  66. </IKTextButton>
  67. <IKTextButton name="tbProductNo2" DataSource="ProductNo.No_Product">
  68. <Events>
  69. <Click>
  70. <![CDATA[
  71. if (tbProductNo2.ReadOnly == false)
  72. {
  73. @temp = ShowSearchBox("ProductSearch","INFOMATION",tbProductNo2.CValue);
  74. if( @temp == "" )
  75. return;
  76. tbProductNo2.CValue = @temp;
  77. }
  78. ]]>
  79. </Click>
  80. </Events>
  81. </IKTextButton>
  82. <IKTextButton name="tbLocationNo1" DataSource="LowLocation.No_Location">
  83. <Events>
  84. <Click>
  85. <![CDATA[
  86. if (tbLocationNo1.ReadOnly == false)
  87. {
  88. @temp = ShowSearchBox("LocationSearch","INFOMATION",tbLocationNo1.CValue,cbLocation.SelectedItem);
  89. if( @temp == "" )
  90. return;
  91. tbLocationNo1.CValue = @temp;
  92. }
  93. ]]>
  94. </Click>
  95. </Events>
  96. </IKTextButton>
  97. <IKTextButton name="tbLocationNo2" DataSource="LowLocation.No_Location">
  98. <Events>
  99. <Click>
  100. <![CDATA[
  101. if (tbLocationNo2.ReadOnly == false)
  102. {
  103. @temp = ShowSearchBox("LocationSearch","INFOMATION",tbLocationNo2.CValue,cbLocation.SelectedItem);
  104. if( @temp == "" )
  105. return;
  106. tbLocationNo2.CValue = @temp;
  107. }
  108. ]]>
  109. </Click>
  110. </Events>
  111. </IKTextButton>
  112. <IKComboBoxEx name="cbType1" DataSource="Type" DisplayMember="Name_TypeDef" />
  113. <IKComboBoxEx name="cbType2" DataSource="Type" DisplayMember="Name_TypeDef" />
  114. <IKExtendGrid name="dgProduct" DataSource="Total" TableStyleIndex="0">
  115. <DataColumn Index="0" DataSource="Total.No_Product"/>
  116. <DataColumn Index="1" DataSource="Total.Name_Product"/>
  117. <DataColumn Index="2" DataSource="Total.Type_Product"/>
  118. <DataColumn Index="3" DataSource="Total.OpeningAvailableQty_ProductStocks"/>
  119. <DataColumn Index="4" DataSource="Total.OpeningStockQty_ProductStocks"/>
  120. <DataColumn Index="5" DataSource="Total.Quantity_IndentBillProduct"/>
  121. <DataColumn Index="6" DataSource="Total.Quantity_SaleBillProduct"/>
  122. <DataColumn Index="7" DataSource="Total.Quantity_SaleOutDepotBillProduct"/>
  123. <DataColumn Index="8" DataSource="Total.Quantity_SaleRtnBillProduct"/>
  124. <DataColumn Index="9" DataSource="Total.Quantity_RealSale"/>
  125. <DataColumn Index="10" DataSource="Total.OutQuantity_ModifyDepotBillProduct"/>
  126. <DataColumn Index="11" DataSource="Total.Quantity_PurchaseOrderBillProduct"/>
  127. <DataColumn Index="12" DataSource="Total.Quantity_PurchaseInDepotBillProduct"/>
  128. <DataColumn Index="13" DataSource="Total.InQuantity_ModifyDepotBillProduct"/>
  129. <DataColumn Index="14" DataSource="Total.InQuantity_StocktakingBillProduct"/>
  130. <DataColumn Index="15" DataSource="Total.OutQuantity_StocktakingBillProduct"/>
  131. <DataColumn Index="16" DataSource="Total.AvailableQty_ProductStocks"/>
  132. <DataColumn Index="17" DataSource="Total.StockQty_ProductStocks"/>
  133. <DataColumn Index="18" DataSource="Total.TotalPrice"/>
  134. <DataColumn Index="19" DataSource="Total.Cost_Product"/>
  135. <Events>
  136. <ClickPreview>
  137. PrintReport(dgProduct.CurrentView);
  138. </ClickPreview>
  139. <ClickRefresh>
  140. Empty();
  141. <Lable name="btnActionClick"/>
  142. </ClickRefresh>
  143. <ClickFilter>
  144. txtSum.CValue=SumOfCol("#Total.Quantity_RealSale",dgProduct.FilterCondition,true);
  145. </ClickFilter>
  146. <ClickNOFilter>
  147. txtSum.CValue=SumOfCol("#Total.Quantity_RealSale",dgProduct.FilterCondition,true);
  148. </ClickNOFilter>
  149. </Events>
  150. </IKExtendGrid>
  151. <IKButton name="btnAction">
  152. <Events>
  153. <Click>
  154. <Lable name="btnActionClick"/>
  155. </Click>
  156. </Events>
  157. </IKButton>
  158. <IKButton name="btnEmpty">
  159. <Events>
  160. <Click>
  161. Empty();
  162. </Click>
  163. </Events>
  164. </IKButton>
  165. </Controls>
  166. <ChildForms>
  167. <ChildForm name="LocationSearch" DataSource="Location" SearchFunction="SearchAllLocation" SearchFunctionByNo="" MappingName="库位" >
  168. <DataColumn Index="0" MappingName="#Location.No_Location" HeaderText="库位编号" Width="120" ColumnType="IKDataGridTextBoxColumn" ReturnMappingName="#LowLocation.No_Location"/>
  169. <DataColumn Index="1" MappingName="#Location.Name_Location" HeaderText="库位名称" Width="120" ColumnType="IKDataGridTextBoxColumn" />
  170. </ChildForm>
  171. <ChildForm name="ProductSearch" DataSource="Product" SearchFunction="SearchAllProduct" SearchFunctionByNo="" MappingName="产品" >
  172. <DataColumn Index="0" MappingName="#Product.No_Product" HeaderText="产品编号" Width="120" ColumnType="IKDataGridTextBoxColumn" ReturnMappingName="#ProductNo.No_Product"/>
  173. <DataColumn Index="1" MappingName="#Product.Name_Product" HeaderText="产品名称" Width="120" ColumnType="IKDataGridTextBoxColumn" />
  174. </ChildForm>
  175. </ChildForms>
  176. </Client>
  177. <Server>
  178. <Tables>
  179. <Table name="Total" Type="Parent">
  180. <GetSchema CmdType="Text" CmdText="
  181. Select Top 0 Product.No_Product,Product.Name_Product,Product.Type_Product,Product.Cost_Product,ProductStocks.OpeningAvailableQty_ProductStocks,OpeningStockQty_ProductStocks,ProductStocks.AvailableQty_ProductStocks,StockQty_ProductStocks,SaleBillProduct.Quantity_SaleBillProduct,SaleOutDepotBillProduct.Quantity_SaleOutDepotBillProduct,SaleRtnBillProduct.Quantity_SaleRtnBillProduct,IndentBillProduct.Quantity_IndentBillProduct,
  182. a.Quantity_ModifyDepotBillProduct As OutQuantity_ModifyDepotBillProduct,b.Quantity_ModifyDepotBillProduct As InQuantity_ModifyDepotBillProduct,PurchaseOrderBillProduct.Quantity_PurchaseOrderBillProduct,PurchaseInDepotBillProduct.Quantity_PurchaseInDepotBillProduct,
  183. c.Quantity_StocktakingBillProduct As OutQuantity_StocktakingBillProduct,d.Quantity_StocktakingBillProduct As InQuantity_StocktakingBillProduct,convert(decimal(18,6),0) As TotalPrice,convert(decimal(14,4),0) As Quantity_RealSale
  184. From Product
  185. Left Join ProductStocks On ProductStocks.ID_Product=Product.ID_Product
  186. Left Join IndentBillProduct On IndentBillProduct.ID_Product=Product.ID_Product
  187. Left Join SaleBillProduct On SaleBillProduct.ID_Product=Product.ID_Product
  188. Left Join SaleOutDepotBillProduct On SaleOutDepotBillProduct.ID_Product=Product.ID_Product
  189. Left Join SaleRtnBillProduct On SaleRtnBillProduct.ID_Product=Product.ID_Product
  190. Left Join ModifyDepotBillProduct a On a.ID_Product=Product.ID_Product
  191. Left Join ModifyDepotBillProduct b On b.ID_Product=Product.ID_Product
  192. Left Join PurchaseOrderBillProduct On PurchaseOrderBillProduct.ID_Product=Product.ID_Product
  193. Left Join PurchaseInDepotBillProduct On PurchaseInDepotBillProduct.ID_Product=Product.ID_Product
  194. Left Join StocktakingBillProduct c ON c.ID_Product=Product.ID_Product
  195. Left Join StocktakingBillProduct d On d.ID_Product=Product.ID_Product
  196. "/>
  197. </Table>
  198. </Tables>
  199. <Search>
  200. <SearchLocation CmdType="Text" CmdText="Select Name_Location,No_Location from Location where Level_Location = 0
  201. Union Select '全部' As Name_Location, '00' As No_Location">
  202. <Tables>
  203. <Table name="Location"/>
  204. </Tables>
  205. </SearchLocation>
  206. <SearchType CmdType="Text" CmdText=" SELECT Name_TypeDef From TypeDef Where Type_TypeDef=8 Order By Name_TypeDef ">
  207. <Tables>
  208. <Table name="Type"/>
  209. </Tables>
  210. </SearchType>
  211. <SearchAllLocation CmdType="Text" CmdText="Select No_Location,Name_Location
  212. From Location Where ID_Warehouse IN(
  213. Select ID_Location
  214. From Location
  215. ">
  216. <Tables>
  217. <Table name="AllLocation" />
  218. </Tables>
  219. </SearchAllLocation>
  220. <SearchAllProduct CmdType="Text" CmdText="Select No_Product
  221. ,Name_Product
  222. From Product
  223. Order By No_Product">
  224. <Tables>
  225. <Table name="AllProduct" />
  226. </Tables>
  227. </SearchAllProduct>
  228. <SearchLowLocation CmdType="" CmdText="Select No_Location From Location Where Level_Location = 1">
  229. <Tables>
  230. <Table name="LowLocation"/>
  231. </Tables>
  232. </SearchLowLocation>
  233. <SearchProductNo CmdType="Text" CmdText="Select No_Product From Product Order By No_Product">
  234. <Tables>
  235. <Table name="ProductNo"/>
  236. </Tables>
  237. </SearchProductNo>
  238. <SearchAllLocationID CmdType="Text" CmdText ="Select ID_Location From Location Where Level_Location = 0">
  239. <Tables>
  240. <Table name="AllLocationID"/>
  241. </Tables>
  242. </SearchAllLocationID>
  243. <SearchLocationID CmdType="Text" CmdText="Select ID_Location From Location Where Name_Location = @Name_Location">
  244. <Params>
  245. <Param name="@Name_Location" type="Location.Name_Location" Index="0" />
  246. </Params>
  247. <Tables>
  248. <Table name="LocationID"/>
  249. </Tables>
  250. </SearchLocationID>
  251. </Search>
  252. </Server>
  253. <Lables>
  254. <Search>
  255. </Search>
  256. <btnActionClick>
  257. if(cbLocation.SelectedItem == "全部")
  258. {
  259. if (Search("SearchAllLocationID"))
  260. {
  261. SuspendLayout();
  262. for(@i = 0; @i&lt;RowCount("#AllLocationID");@i=@i+1)
  263. {
  264. SetPosition("#AllLocationID", @i);
  265. if (@i == 0)
  266. @a = "'"+FormatString(#AllLocationID.ID_Location)+"'";
  267. else
  268. @a = @a + "," +"'"+ FormatString(#AllLocationID.ID_Location)+"'";
  269. @Location = " In ( " + @a + ")";
  270. }
  271. ResumeLayout();
  272. }
  273. }
  274. else
  275. {
  276. Search("SearchLocationID",cbLocation.SelectedItem);
  277. @Location = " = '" + FormatString(#LocationID.ID_Location) +"'";
  278. }
  279. @dateCondition=" between "+" DATEADD(day,0,DATEDIFF(day,0,"+"'"+TypeConvert("String",StartDate.Value)+"'"+")) and "+" DATEADD(day,0,(DATEDIFF(day,0,"+"'"+TypeConvert("String",EndDate.Value)+"'"+")+1))";
  280. @bisNow=" &lt;= DATEADD(day,0,(DATEDIFF(day,0,'"+TypeConvert("String",EndDate.Value)+"')+1))";
  281. @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, "
  282. +" (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,"
  283. +" 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, "
  284. +" 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"
  285. +" From "
  286. +" ("
  287. +" Select ProductStocks.ID_Product,Sum(OpeningStockQty_ProductStocks) As OpeningStockQty_ProductStocks"
  288. +" From ProductStocks"
  289. +" Where ID_Location IN("
  290. +" Select x.ID_Location From Location x"
  291. +" Left Join Location s On x.ID_Warehouse = s.ID_Location"
  292. +" Where x.Level_Location = 1"
  293. +" And s.ID_Location" + @Location
  294. +" )"
  295. +" Group By ID_Product"
  296. +" )b "
  297. +" Join"
  298. +" ( "
  299. +" Select Product.ID_Product,Product.No_Product,Product.Type_Product,Product.Name_Product,Product.Cost_Product"
  300. +" From Product"
  301. +" )a On a.ID_Product=b.ID_Product"
  302. +" Join"
  303. +" ("
  304. +" Select ProductStocks.ID_Product,Sum(OpeningAvailableQty_ProductStocks) As OpeningAvailableQty_ProductStocks"
  305. +" From ProductStocks"
  306. +" Where ID_Location" + @Location
  307. +" Group By ID_Product"
  308. +" )pb On b.ID_Product=pb.ID_Product"
  309. +" Left Join"
  310. +" ("
  311. +" Select IndentBillProduct.ID_Product,Sum(IndentBillProduct.Quantity_IndentBillProduct) As Quantity_IndentBillProduct"
  312. +" From IndentBillProduct"
  313. +" Join IndentBill On IndentBill.ID_IndentBill=IndentBillProduct.ID_IndentBill"
  314. +" Where IndentBill.ID_Assessor Is Not Null And IndentBill.Date_IndentBill "+@dateCondition+" And IndentBill.ID_Location " + @Location
  315. +" Group By IndentBillProduct.ID_Product"
  316. +" )ind On b.ID_Product=ind.ID_Product"
  317. +" Left Join"
  318. +" ("
  319. +" Select SaleBillProduct.ID_Product,Sum(SaleBillProduct.Quantity_SaleBillProduct) As Quantity_SaleBillProduct"
  320. +" From SaleBillProduct"
  321. +" Join SaleBill On SaleBill.ID_SaleBill=SaleBillProduct.ID_SaleBill"
  322. +" Where SaleBill.ID_Assessor Is Not Null And SaleBill.Date_SaleBill "+@dateCondition +" And SaleBill.ID_Location " + @Location
  323. +" Group By SaleBillProduct.ID_Product"
  324. +" )c On b.ID_Product=c.ID_Product"
  325. +" Left Join"
  326. +" ("
  327. +" Select SaleOutDepotBillProduct.ID_Product,Sum(SaleOutDepotBillProduct.Quantity_SaleOutDepotBillProduct) As Quantity_SaleOutDepotBillProduct"
  328. +" From SaleOutDepotBillProduct"
  329. +" Join SaleOutDepotBill On SaleOutDepotBill.ID_SaleOutDepotBill=SaleOutDepotBillProduct.ID_SaleOutDepotBill"
  330. +" Where SaleOutDepotBill.ID_Assessor Is Not Null And SaleOutDepotBill.Date_SaleOutDepotBill "+@dateCondition + " And SaleOutDepotBill.ID_Location " + @Location
  331. +" Group By SaleOutDepotBillProduct.ID_Product"
  332. +" )d On b.ID_Product=d.ID_Product"
  333. +" Left Join"
  334. +" ("
  335. +" Select ModifyDepotBillProduct.ID_Product,Sum(Quantity_ModifyDepotBillProduct) As InQuantity_ModifyDepotBillProduct"
  336. +" From ModifyDepotBillProduct"
  337. +" Join ModifyDepotBill On ModifyDepotBillProduct.ID_ModifyDepotBill=ModifyDepotBill.ID_ModifyDepotBill"
  338. +" Join ModifyTypeSettings On ModifyTypeSettings.ID_ModifyTypeSettings=ModifyDepotBill.Style_ModifyDepotBill"
  339. +" Where ModifyDepotBill.ID_Assessor Is Not Null And ModifyTypeSettings.Type_ModifyTypeSettings=1 And Date_ModifyDepotBill "+@dateCondition+ " And ModifyDepotBill.ID_Location " + @Location
  340. +" Group By ModifyDepotBillProduct.ID_Product"
  341. +" )e On b.ID_Product=e.ID_Product"
  342. +" Left Join"
  343. +" ("
  344. +" Select ModifyDepotBillProduct.ID_Product,Sum(Quantity_ModifyDepotBillProduct) As OutQuantity_ModifyDepotBillProduct"
  345. +" From ModifyDepotBillProduct"
  346. +" Join ModifyDepotBill On ModifyDepotBillProduct.ID_ModifyDepotBill=ModifyDepotBill.ID_ModifyDepotBill"
  347. +" Join ModifyTypeSettings On ModifyTypeSettings.ID_ModifyTypeSettings=ModifyDepotBill.Style_ModifyDepotBill"
  348. +" Where ModifyDepotBill.ID_Assessor Is Not Null And ModifyTypeSettings.Type_ModifyTypeSettings=0 And Date_ModifyDepotBill "+@dateCondition+ " And ModifyDepotBill.ID_Location " + @Location
  349. +" Group By ModifyDepotBillProduct.ID_Product"
  350. +" )f On b.ID_Product=f.ID_Product"
  351. +" Left Join"
  352. +" ("
  353. +" Select PurchaseOrderBillProduct.ID_Product,Sum(Quantity_PurchaseOrderBillProduct) As Quantity_PurchaseOrderBillProduct"
  354. +" From PurchaseOrderBillProduct"
  355. +" Join PurchaseOrderBill On PurchaseOrderBill.ID_PurchaseOrderBill=PurchaseOrderBillProduct.ID_PurchaseOrderBill"
  356. +" Where PurchaseOrderBill.ID_Assessor Is Not Null And PurchaseOrderBill.Date_PurchaseOrderBill "+@dateCondition+" And PurchaseOrderBill.ID_Location " + @Location
  357. +" Group By PurchaseOrderBillProduct.ID_Product"
  358. +" )g On a.ID_Product=g.ID_Product"
  359. +" Left Join"
  360. +" ("
  361. +" Select PurchaseInDepotBillProduct.ID_Product,Sum(Quantity_PurchaseInDepotBillProduct) As Quantity_PurchaseInDepotBillProduct"
  362. +" From PurchaseInDepotBillProduct"
  363. +" Join PurchaseInDepotBill On PurchaseInDepotBill.ID_PurchaseInDepotBill=PurchaseInDepotBillProduct.ID_PurchaseInDepotBill"
  364. +" Where PurchaseInDepotBill.ID_Assessor Is Not Null And PurchaseInDepotBill.Date_PurchaseInDepotBill "+@dateCondition+ " And PurchaseInDepotBill.ID_Location " + @Location
  365. +" Group By PurchaseInDepotBillProduct.ID_Product"
  366. +" )h On b.ID_Product=h.ID_Product"
  367. +" Left Join"
  368. +" ("
  369. +" Select StocktakingBillProduct.ID_Product,Sum(StocktakingBillProduct.Quantity_StocktakingBillProduct-StocktakingBillProduct.StockQty_StocktakingBillProduct) As InQuantity_StocktakingBillProduct"
  370. +" From StocktakingBillProduct"
  371. +" Join StocktakingBill On StocktakingBill.ID_StocktakingBill=StocktakingBillProduct.ID_StocktakingBill"
  372. +" Where StocktakingBill.ID_Assessor Is Not Null And (StocktakingBillProduct.Quantity_StocktakingBillProduct-StocktakingBillProduct.StockQty_StocktakingBillProduct) &gt; 0 And StocktakingBill.Date_StocktakingBill "+@dateCondition+ " And StocktakingBill.ID_Location " + @Location
  373. +" Group By StocktakingBillProduct.ID_Product"
  374. +" )i On b.ID_Product=i.ID_Product"
  375. +" Left Join"
  376. +" ("
  377. +" Select StocktakingBillProduct.ID_Product,-Sum(StocktakingBillProduct.Quantity_StocktakingBillProduct-StocktakingBillProduct.StockQty_StocktakingBillProduct) As OutQuantity_StocktakingBillProduct"
  378. +" From StocktakingBillProduct"
  379. +" Join StocktakingBill On StocktakingBill.ID_StocktakingBill=StocktakingBillProduct.ID_StocktakingBill"
  380. +" Where StocktakingBill.ID_Assessor Is Not Null And (StocktakingBillProduct.Quantity_StocktakingBillProduct-StocktakingBillProduct.StockQty_StocktakingBillProduct) &lt; 0 And StocktakingBill.Date_StocktakingBill "+@dateCondition+ " And StocktakingBill.ID_Location " + @Location
  381. +" Group By StocktakingBillProduct.ID_Product"
  382. +" )j On b.ID_Product=j.ID_Product"
  383. +" Left Join"
  384. +" ("
  385. +" Select SaleRtnBillProduct.ID_Product,Sum(Quantity_SaleRtnBillProduct) As Quantity_SaleRtnBillProduct"
  386. +" From SaleRtnBillProduct"
  387. +" Join SaleRtnBill On SaleRtnBill.ID_SaleRtnBill=SaleRtnBillProduct.ID_SaleRtnBill"
  388. +" Where SaleRtnBill.ID_Assessor Is Not Null And SaleRtnBill.Date_SaleRtnBill "+@dateCondition+ " And SaleRtnBill.ID_Location " + @Location
  389. +" Group By SaleRtnBillProduct.ID_Product"
  390. +" )k On b.ID_Product=k.ID_Product"
  391. +" Left Join"
  392. +" ("
  393. +" Select SaleOutDepotBillProduct.ID_Product,Sum(SaleOutDepotBillProduct.Quantity_SaleOutDepotBillProduct) As Quantity_SaleOutDepotBillProduct"
  394. +" From SaleOutDepotBillProduct"
  395. +" Join SaleOutDepotBill On SaleOutDepotBill.ID_SaleOutDepotBill=SaleOutDepotBillProduct.ID_SaleOutDepotBill"
  396. +" Where SaleOutDepotBill.ID_Assessor Is Not Null And SaleOutDepotBill.Date_SaleOutDepotBill "+@bisNow+ " And SaleOutDepotBill.ID_Location " + @Location
  397. +" Group By SaleOutDepotBillProduct.ID_Product"
  398. +" )d1 On b.ID_Product=d1.ID_Product"
  399. +" Left Join"
  400. +" ("
  401. +" Select ModifyDepotBillProduct.ID_Product,Sum(Quantity_ModifyDepotBillProduct) As InQuantity_ModifyDepotBillProduct"
  402. +" From ModifyDepotBillProduct"
  403. +" Join ModifyDepotBill On ModifyDepotBillProduct.ID_ModifyDepotBill=ModifyDepotBill.ID_ModifyDepotBill"
  404. +" Join ModifyTypeSettings On ModifyTypeSettings.ID_ModifyTypeSettings=ModifyDepotBill.Style_ModifyDepotBill"
  405. +" Where ModifyDepotBill.ID_Assessor Is Not Null And ModifyTypeSettings.Type_ModifyTypeSettings=1 And Date_ModifyDepotBill "+@bisNow+ " And ModifyDepotBill.ID_Location " + @Location
  406. +" Group By ModifyDepotBillProduct.ID_Product"
  407. +" )e1 On b.ID_Product=e1.ID_Product"
  408. +" Left Join"
  409. +" ("
  410. +" Select ModifyDepotBillProduct.ID_Product,Sum(Quantity_ModifyDepotBillProduct) As OutQuantity_ModifyDepotBillProduct"
  411. +" From ModifyDepotBillProduct"
  412. +" Join ModifyDepotBill On ModifyDepotBillProduct.ID_ModifyDepotBill=ModifyDepotBill.ID_ModifyDepotBill"
  413. +" Join ModifyTypeSettings On ModifyTypeSettings.ID_ModifyTypeSettings=ModifyDepotBill.Style_ModifyDepotBill"
  414. +" Where ModifyDepotBill.ID_Assessor Is Not Null And ModifyTypeSettings.Type_ModifyTypeSettings=0 And Date_ModifyDepotBill "+@bisNow+ " And ModifyDepotBill.ID_Location " + @Location
  415. +" Group By ModifyDepotBillProduct.ID_Product"
  416. +" )f1 On b.ID_Product=f1.ID_Product"
  417. +" Left Join"
  418. +" ("
  419. +" Select PurchaseInDepotBillProduct.ID_Product,Sum(Quantity_PurchaseInDepotBillProduct) As Quantity_PurchaseInDepotBillProduct"
  420. +" From PurchaseInDepotBillProduct"
  421. +" Join PurchaseInDepotBill On PurchaseInDepotBill.ID_PurchaseInDepotBill=PurchaseInDepotBillProduct.ID_PurchaseInDepotBill"
  422. +" Where PurchaseInDepotBill.ID_Assessor Is Not Null And PurchaseInDepotBill.Date_PurchaseInDepotBill "+@bisNow+ " And PurchaseInDepotBill.ID_Location " + @Location
  423. +" Group By PurchaseInDepotBillProduct.ID_Product"
  424. +" )h1 On b.ID_Product=h1.ID_Product"
  425. +" Left Join"
  426. +" ("
  427. +" Select SaleBillProduct.ID_Product,Sum(SaleBillProduct.Quantity_SaleBillProduct) As Quantity_SaleBillProduct"
  428. +" From SaleBillProduct"
  429. +" Join SaleBill On SaleBill.ID_SaleBill=SaleBillProduct.ID_SaleBill"
  430. +" Where SaleBill.ID_Assessor Is Not Null And SaleBill.Date_SaleBill "+@bisNow+ " And SaleBill.ID_Location " + @Location
  431. +" Group By SaleBillProduct.ID_Product"
  432. +" )c1 On b.ID_Product=c1.ID_Product";
  433. @where=true;
  434. if(cbType1.Text!="")
  435. {
  436. if(@where==true)
  437. {
  438. @sqlCmd=@sqlCmd+" Where Type_Product &gt;=" +"'"+cbType1.Text+"'";
  439. @where=false;
  440. }
  441. else
  442. {
  443. @sqlCmd=@sqlCmd+" And Type_Product &gt;=" +"'"+cbType1.Text+"'";
  444. }
  445. }
  446. if(cbType2.Text!="")
  447. {
  448. if(@where==true)
  449. {
  450. @sqlCmd=@sqlCmd+" Where Type_Product &lt;="+"'"+cbType2.Text+"'";
  451. @where=false;
  452. }
  453. else
  454. {
  455. @sqlCmd=@sqlCmd+" And Type_Product &lt;="+"'"+cbType2.Text+"'";
  456. }
  457. }
  458. if(tbProductNo1.CValue!="")
  459. {
  460. if(@where==true)
  461. {
  462. @sqlCmd=@sqlCmd+" Where No_Product &gt;=" +"'"+tbProductNo1.CValue+"'";
  463. @where=false;
  464. }
  465. else
  466. {
  467. @sqlCmd=@sqlCmd+" And No_Product &gt;=" +"'"+tbProductNo1.CValue+"'";
  468. }
  469. }
  470. if(tbProductNo2.CValue!="")
  471. {
  472. if(@where==true)
  473. {
  474. @sqlCmd=@sqlCmd+" Where No_Product &lt;="+"'"+tbProductNo2.CValue+"'";
  475. @where=false;
  476. }
  477. else
  478. {
  479. @sqlCmd=@sqlCmd+" And No_Product &lt;="+"'"+tbProductNo2.CValue+"'";
  480. }
  481. }
  482. if(ckSuspend.Checked)
  483. {
  484. if(@where==true)
  485. {
  486. @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)) &gt; 0 ";
  487. @where=false;
  488. }
  489. else
  490. {
  491. @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)) &gt; 0 ";
  492. }
  493. }
  494. @sqlCmd=@sqlCmd+" Order By a.No_Product ";
  495. <!--MessageBox(@sqlCmd,"IS");-->
  496. SearchEx(@sqlCmd,"Total");
  497. txtSum.CValue=SumOfCol("#Total.Quantity_RealSale");
  498. </btnActionClick>
  499. <!--<btnActionClick>
  500. @LocationAll = " Location.No_Location In (Select No_Location From Location Where Level_Location = 0)" ;
  501. if(cbLocation.SelectedItem == "全部")
  502. {
  503. @Location = "x.Level_Location = 1";
  504. }
  505. else
  506. {
  507. @Location = " x.Level_Location = 1 And x.No_Location BETWEEN ISNULL(@StartNo_Location,x.No_Location) AND ISNULL(@EndNo_Location,x.No_Location) And s.Name_Location = '" + cbLocation.SelectedItem + "'";
  508. }
  509. @dateCondition=" between "+" DATEADD(day,0,DATEDIFF(day,0,"+"'"+TypeConvert("String",StartDate.Value)+"'"+")) and "+" DATEADD(day,0,(DATEDIFF(day,0,"+"'"+TypeConvert("String",EndDate.Value)+"'"+")+1))";
  510. @bisNow=" &lt;= DATEADD(day,0,(DATEDIFF(day,0,'"+TypeConvert("String",EndDate.Value)+"')+1))";
  511. @sqlCmd=" Declare @StartNo_Location Nvarchar(64) Set @StartNo_Location = Null"
  512. +" Declare @EndNo_Location Nvarchar(64) Set @EndNo_Location = Null";
  513. if(tbLocationNo1.CValue != "")
  514. {
  515. @sqlCmd = @sqlCmd + " Set @StartNo_Location ='" +tbLocationNo1.CValue+"'";
  516. }
  517. if(tbLocationNo2.CValue != "")
  518. {
  519. @sqlCmd = @sqlCmd + " Set @EndNo_Location ='" +tbLocationNo2.CValue+"'";
  520. }
  521. @sqlCmd =@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, "
  522. +" (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,"
  523. +" 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, "
  524. +" 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"
  525. +" From "
  526. +" ( "
  527. +" Select Product.ID_Product,Product.No_Product,Product.Type_Product,Product.Name_Product,Product.Cost_Product"
  528. +" From Product"
  529. +" )a"
  530. +" Join"
  531. +" ("
  532. +" Select ProductStocks.ID_Product,Sum(OpeningStockQty_ProductStocks) As OpeningStockQty_ProductStocks"
  533. +" From ProductStocks"
  534. +" Where ID_Location IN("
  535. +" Select x.ID_Location From Location x"
  536. +" Left Join Location s On x.ID_Warehouse = s.ID_Location Where "
  537. + @Location
  538. +" )"
  539. +" Group By ID_Product"
  540. +" )b On a.ID_Product=b.ID_Product"
  541. +" Join"
  542. +" ("
  543. +" Select ProductStocks.ID_Product,Sum(OpeningAvailableQty_ProductStocks) As OpeningAvailableQty_ProductStocks"
  544. +" From ProductStocks"
  545. +" Where ID_Location IN("
  546. +" Select ID_Location"
  547. +" From Location"
  548. +" Where Name_Location IN (";
  549. if(cbLocation.SelectedItem == "全部")
  550. {
  551. @sqlCmd=@sqlCmd +" Select Name_Location From Location Where Level_Location=0";
  552. }
  553. else
  554. {
  555. @sqlCmd=@sqlCmd +"'"+ cbLocation.SelectedItem+"'";
  556. }
  557. @sqlCmd=@sqlCmd +" )"
  558. +" )"
  559. +" Group By ID_Product"
  560. +" )pb On a.ID_Product=pb.ID_Product"
  561. +" Left Join"
  562. +" ("
  563. +" Select IndentBillProduct.ID_Product,Sum(IndentBillProduct.Quantity_IndentBillProduct) As Quantity_IndentBillProduct"
  564. +" From IndentBillProduct"
  565. +" Join IndentBill On IndentBill.ID_IndentBill=IndentBillProduct.ID_IndentBill"
  566. +" Join Location On Location.ID_Location=IndentBill.ID_Location"
  567. +" Where IndentBill.ID_Assessor Is Not Null And IndentBill.Date_IndentBill "+@dateCondition+ " And "+@LocationAll
  568. +" Group By IndentBillProduct.ID_Product"
  569. +" )ind On a.ID_Product=ind.ID_Product"
  570. +" Left Join"
  571. +" ("
  572. +" Select SaleBillProduct.ID_Product,Sum(SaleBillProduct.Quantity_SaleBillProduct) As Quantity_SaleBillProduct"
  573. +" From SaleBillProduct"
  574. +" Join SaleBill On SaleBill.ID_SaleBill=SaleBillProduct.ID_SaleBill"
  575. +" Join Location On Location.ID_Location=SaleBill.ID_Location"
  576. +" Where SaleBill.ID_Assessor Is Not Null And SaleBill.Date_SaleBill "+@dateCondition+ " And "+@LocationAll
  577. +" Group By SaleBillProduct.ID_Product"
  578. +" )c On a.ID_Product=c.ID_Product"
  579. +" Left Join"
  580. +" ("
  581. +" Select SaleOutDepotBillProduct.ID_Product,Sum(SaleOutDepotBillProduct.Quantity_SaleOutDepotBillProduct) As Quantity_SaleOutDepotBillProduct"
  582. +" From SaleOutDepotBillProduct"
  583. +" Join SaleOutDepotBill On SaleOutDepotBill.ID_SaleOutDepotBill=SaleOutDepotBillProduct.ID_SaleOutDepotBill"
  584. +" Join Location On Location.ID_Location=SaleOutDepotBill.ID_Location"
  585. +" Where SaleOutDepotBill.ID_Assessor Is Not Null And SaleOutDepotBill.Date_SaleOutDepotBill "+@dateCondition+ " And "+@LocationAll
  586. +" Group By SaleOutDepotBillProduct.ID_Product"
  587. +" )d On a.ID_Product=d.ID_Product"
  588. +" Left Join"
  589. +" ("
  590. +" Select ModifyDepotBillProduct.ID_Product,Sum(Quantity_ModifyDepotBillProduct) As InQuantity_ModifyDepotBillProduct"
  591. +" From ModifyDepotBillProduct"
  592. +" Join ModifyDepotBill On ModifyDepotBillProduct.ID_ModifyDepotBill=ModifyDepotBill.ID_ModifyDepotBill"
  593. +" Join ModifyTypeSettings On ModifyTypeSettings.ID_ModifyTypeSettings=ModifyDepotBill.Style_ModifyDepotBill"
  594. +" Join Location On Location.ID_Location=ModifyDepotBill.ID_Location"
  595. +" Where ModifyDepotBill.ID_Assessor Is Not Null And ModifyTypeSettings.Type_ModifyTypeSettings=1 And Date_ModifyDepotBill "+@dateCondition+ " And "+@LocationAll
  596. +" Group By ModifyDepotBillProduct.ID_Product"
  597. +" )e On a.ID_Product=e.ID_Product"
  598. +" Left Join"
  599. +" ("
  600. +" Select ModifyDepotBillProduct.ID_Product,Sum(Quantity_ModifyDepotBillProduct) As OutQuantity_ModifyDepotBillProduct"
  601. +" From ModifyDepotBillProduct"
  602. +" Join ModifyDepotBill On ModifyDepotBillProduct.ID_ModifyDepotBill=ModifyDepotBill.ID_ModifyDepotBill"
  603. +" Join ModifyTypeSettings On ModifyTypeSettings.ID_ModifyTypeSettings=ModifyDepotBill.Style_ModifyDepotBill"
  604. +" Join Location On Location.ID_Location=ModifyDepotBill.ID_Location"
  605. +" Where ModifyDepotBill.ID_Assessor Is Not Null And ModifyTypeSettings.Type_ModifyTypeSettings=0 And Date_ModifyDepotBill "+@dateCondition+ " And "+@LocationAll
  606. +" Group By ModifyDepotBillProduct.ID_Product"
  607. +" )f On a.ID_Product=f.ID_Product"
  608. +" Left Join"
  609. +" ("
  610. +" Select PurchaseOrderBillProduct.ID_Product,Sum(Quantity_PurchaseOrderBillProduct) As Quantity_PurchaseOrderBillProduct"
  611. +" From PurchaseOrderBillProduct"
  612. +" Join PurchaseOrderBill On PurchaseOrderBill.ID_PurchaseOrderBill=PurchaseOrderBillProduct.ID_PurchaseOrderBill"
  613. +" Join Location On Location.ID_Location=PurchaseOrderBill.ID_Location"
  614. +" Where PurchaseOrderBill.ID_Assessor Is Not Null And PurchaseOrderBill.Date_PurchaseOrderBill "+@dateCondition+ " And "+@LocationAll
  615. +" Group By PurchaseOrderBillProduct.ID_Product"
  616. +" )g On a.ID_Product=g.ID_Product"
  617. +" Left Join"
  618. +" ("
  619. +" Select PurchaseInDepotBillProduct.ID_Product,Sum(Quantity_PurchaseInDepotBillProduct) As Quantity_PurchaseInDepotBillProduct"
  620. +" From PurchaseInDepotBillProduct"
  621. +" Join PurchaseInDepotBill On PurchaseInDepotBill.ID_PurchaseInDepotBill=PurchaseInDepotBillProduct.ID_PurchaseInDepotBill"
  622. +" Join Location On Location.ID_Location=PurchaseInDepotBill.ID_Location"
  623. +" Where PurchaseInDepotBill.ID_Assessor Is Not Null And PurchaseInDepotBill.Date_PurchaseInDepotBill "+@dateCondition+ " And "+@LocationAll
  624. +" Group By PurchaseInDepotBillProduct.ID_Product"
  625. +" )h On a.ID_Product=h.ID_Product"
  626. +" Left Join"
  627. +" ("
  628. +" Select StocktakingBillProduct.ID_Product,Sum(StocktakingBillProduct.Quantity_StocktakingBillProduct-StocktakingBillProduct.StockQty_StocktakingBillProduct) As InQuantity_StocktakingBillProduct"
  629. +" From StocktakingBillProduct"
  630. +" Join StocktakingBill On StocktakingBill.ID_StocktakingBill=StocktakingBillProduct.ID_StocktakingBill"
  631. +" Join Location On Location.ID_Location=StocktakingBill.ID_Location"
  632. +" Where StocktakingBill.ID_Assessor Is Not Null And (StocktakingBillProduct.Quantity_StocktakingBillProduct-StocktakingBillProduct.StockQty_StocktakingBillProduct) &gt; 0 And StocktakingBill.Date_StocktakingBill "+@dateCondition+ " And "+@LocationAll
  633. +" Group By StocktakingBillProduct.ID_Product"
  634. +" )i On a.ID_Product=i.ID_Product"
  635. +" Left Join"
  636. +" ("
  637. +" Select StocktakingBillProduct.ID_Product,-Sum(StocktakingBillProduct.Quantity_StocktakingBillProduct-StocktakingBillProduct.StockQty_StocktakingBillProduct) As OutQuantity_StocktakingBillProduct"
  638. +" From StocktakingBillProduct"
  639. +" Join StocktakingBill On StocktakingBill.ID_StocktakingBill=StocktakingBillProduct.ID_StocktakingBill"
  640. +" Join Location On Location.ID_Location=StocktakingBill.ID_Location"
  641. +" Where StocktakingBill.ID_Assessor Is Not Null And (StocktakingBillProduct.Quantity_StocktakingBillProduct-StocktakingBillProduct.StockQty_StocktakingBillProduct) &lt; 0 And StocktakingBill.Date_StocktakingBill "+@dateCondition+ " And "+@LocationAll
  642. +" Group By StocktakingBillProduct.ID_Product"
  643. +" )j On a.ID_Product=j.ID_Product"
  644. +" Left Join"
  645. +" ("
  646. +" Select SaleRtnBillProduct.ID_Product,Sum(Quantity_SaleRtnBillProduct) As Quantity_SaleRtnBillProduct"
  647. +" From SaleRtnBillProduct"
  648. +" Join SaleRtnBill On SaleRtnBill.ID_SaleRtnBill=SaleRtnBillProduct.ID_SaleRtnBill"
  649. +" Join Location On Location.ID_Location=SaleRtnBill.ID_Location"
  650. +" Where SaleRtnBill.ID_Assessor Is Not Null And SaleRtnBill.Date_SaleRtnBill "+@dateCondition+ " And "+@LocationAll
  651. +" Group By SaleRtnBillProduct.ID_Product"
  652. +" )k On a.ID_Product=k.ID_Product"
  653. +" Left Join"
  654. +" ("
  655. +" Select SaleOutDepotBillProduct.ID_Product,Sum(SaleOutDepotBillProduct.Quantity_SaleOutDepotBillProduct) As Quantity_SaleOutDepotBillProduct"
  656. +" From SaleOutDepotBillProduct"
  657. +" Join SaleOutDepotBill On SaleOutDepotBill.ID_SaleOutDepotBill=SaleOutDepotBillProduct.ID_SaleOutDepotBill"
  658. +" Join Location On Location.ID_Location=SaleOutDepotBill.ID_Location"
  659. +" Where SaleOutDepotBill.ID_Assessor Is Not Null And SaleOutDepotBill.Date_SaleOutDepotBill "+@bisNow+ " And "+@LocationAll
  660. +" Group By SaleOutDepotBillProduct.ID_Product"
  661. +" )d1 On a.ID_Product=d1.ID_Product"
  662. +" Left Join"
  663. +" ("
  664. +" Select ModifyDepotBillProduct.ID_Product,Sum(Quantity_ModifyDepotBillProduct) As InQuantity_ModifyDepotBillProduct"
  665. +" From ModifyDepotBillProduct"
  666. +" Join ModifyDepotBill On ModifyDepotBillProduct.ID_ModifyDepotBill=ModifyDepotBill.ID_ModifyDepotBill"
  667. +" Join ModifyTypeSettings On ModifyTypeSettings.ID_ModifyTypeSettings=ModifyDepotBill.Style_ModifyDepotBill"
  668. +" Join Location On Location.ID_Location=ModifyDepotBill.ID_Location"
  669. +" Where ModifyDepotBill.ID_Assessor Is Not Null And ModifyTypeSettings.Type_ModifyTypeSettings=1 And Date_ModifyDepotBill "+@bisNow+ " And "+@LocationAll
  670. +" Group By ModifyDepotBillProduct.ID_Product"
  671. +" )e1 On a.ID_Product=e1.ID_Product"
  672. +" Left Join"
  673. +" ("
  674. +" Select ModifyDepotBillProduct.ID_Product,Sum(Quantity_ModifyDepotBillProduct) As OutQuantity_ModifyDepotBillProduct"
  675. +" From ModifyDepotBillProduct"
  676. +" Join ModifyDepotBill On ModifyDepotBillProduct.ID_ModifyDepotBill=ModifyDepotBill.ID_ModifyDepotBill"
  677. +" Join ModifyTypeSettings On ModifyTypeSettings.ID_ModifyTypeSettings=ModifyDepotBill.Style_ModifyDepotBill"
  678. +" Join Location On Location.ID_Location=ModifyDepotBill.ID_Location"
  679. +" Where ModifyDepotBill.ID_Assessor Is Not Null And ModifyTypeSettings.Type_ModifyTypeSettings=0 And Date_ModifyDepotBill "+@bisNow+ " And "+@LocationAll
  680. +" Group By ModifyDepotBillProduct.ID_Product"
  681. +" )f1 On a.ID_Product=f1.ID_Product"
  682. +" Left Join"
  683. +" ("
  684. +" Select PurchaseInDepotBillProduct.ID_Product,Sum(Quantity_PurchaseInDepotBillProduct) As Quantity_PurchaseInDepotBillProduct"
  685. +" From PurchaseInDepotBillProduct"
  686. +" Join PurchaseInDepotBill On PurchaseInDepotBill.ID_PurchaseInDepotBill=PurchaseInDepotBillProduct.ID_PurchaseInDepotBill"
  687. +" Join Location On Location.ID_Location=PurchaseInDepotBill.ID_Location"
  688. +" Where PurchaseInDepotBill.ID_Assessor Is Not Null And PurchaseInDepotBill.Date_PurchaseInDepotBill "+@bisNow+ " And "+@LocationAll
  689. +" Group By PurchaseInDepotBillProduct.ID_Product"
  690. +" )h1 On a.ID_Product=h1.ID_Product"
  691. +" Left Join"
  692. +" ("
  693. +" Select SaleBillProduct.ID_Product,Sum(SaleBillProduct.Quantity_SaleBillProduct) As Quantity_SaleBillProduct"
  694. +" From SaleBillProduct"
  695. +" Join SaleBill On SaleBill.ID_SaleBill=SaleBillProduct.ID_SaleBill"
  696. +" Join Location On Location.ID_Location=SaleBill.ID_Location"
  697. +" Where SaleBill.ID_Assessor Is Not Null And SaleBill.Date_SaleBill "+@bisNow+ " And "+@LocationAll
  698. +" Group By SaleBillProduct.ID_Product"
  699. +" )c1 On a.ID_Product=c1.ID_Product";
  700. @where=true;
  701. if(cbType1.Text!="")
  702. {
  703. if(@where==true)
  704. {
  705. @sqlCmd=@sqlCmd+" Where Type_Product &gt;=" +"'"+cbType1.Text+"'";
  706. @where=false;
  707. }
  708. else
  709. {
  710. @sqlCmd=@sqlCmd+" And Type_Product &gt;=" +"'"+cbType1.Text+"'";
  711. }
  712. }
  713. if(cbType2.Text!="")
  714. {
  715. if(@where==true)
  716. {
  717. @sqlCmd=@sqlCmd+" Where Type_Product &lt;="+"'"+cbType2.Text+"'";
  718. @where=false;
  719. }
  720. else
  721. {
  722. @sqlCmd=@sqlCmd+" And Type_Product &lt;="+"'"+cbType2.Text+"'";
  723. }
  724. }
  725. if(ckSuspend.Checked)
  726. {
  727. if(@where==true)
  728. {
  729. @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)) &gt; 0 ";
  730. @where=false;
  731. }
  732. else
  733. {
  734. @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)) &gt; 0 ";
  735. }
  736. }
  737. @sqlCmd=@sqlCmd+" Order By a.No_Product ";
  738. MessageBox(@sqlCmd,"IS");
  739. SearchEx(@sqlCmd,"Total");
  740. txtSum.CValue=SumOfCol("#Total.Quantity_RealSale");
  741. </btnActionClick> 2008-11-18-->
  742. <!--<btnActionClick>
  743. @sqlLocation="(";
  744. @empty=true;
  745. @first=true;
  746. for(@i=1;@i &lt; CLB_Location.GetItemsCount();@i++){
  747. if(CLB_Location.GetItemChecked(@i)){
  748. @empty=false;
  749. if(@first==true){
  750. @sqlLocation=@sqlLocation+"'"+CLB_Location.GetSelectedName(@i)+"'";
  751. @first=false;
  752. }else{
  753. @sqlLocation=@sqlLocation+","+"'"+CLB_Location.GetSelectedName(@i)+"'";
  754. }
  755. }
  756. }
  757. @sqlLocation=@sqlLocation+") ";
  758. if(@empty==true)
  759. {
  760. MessageBox("请选择仓库!",@Title);
  761. return;
  762. }
  763. @dateCondition=" between "+" DATEADD(day,0,DATEDIFF(day,0,"+"'"+TypeConvert("String",StartDate.Value)+"'"+")) and "+" DATEADD(day,0,(DATEDIFF(day,0,"+"'"+TypeConvert("String",EndDate.Value)+"'"+")+1))";
  764. @bisNow=" &lt;= DATEADD(day,0,(DATEDIFF(day,0,'"+TypeConvert("String",EndDate.Value)+"')+1))";
  765. @Location=" Location.Name_Location In " +@sqlLocation;
  766. @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, "
  767. +" (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,"
  768. +" 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, "
  769. +" 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"
  770. +" From "
  771. +" ( "
  772. +" Select Product.ID_Product,Product.No_Product,Product.Type_Product,Product.Name_Product,Product.Cost_Product"
  773. +" From Product"
  774. +" )a"
  775. +" Join"
  776. +" ("
  777. +" Select ProductStocks.ID_Product,Sum(OpeningStockQty_ProductStocks) As OpeningStockQty_ProductStocks"
  778. +" From ProductStocks"
  779. +" Where ID_Location IN("
  780. +" Select ID_Location"
  781. +" From Location Where ID_Warehouse IN("
  782. +" Select ID_Location"
  783. +" From Location"
  784. +" Where"
  785. + @Location
  786. +" ) And Level_Location=1"
  787. +" )"
  788. +" Group By ID_Product"
  789. +" )b On a.ID_Product=b.ID_Product"
  790. +" Join"
  791. +" ("
  792. +" Select ProductStocks.ID_Product,Sum(OpeningAvailableQty_ProductStocks) As OpeningAvailableQty_ProductStocks"
  793. +" From ProductStocks"
  794. +" Where ID_Location IN("
  795. +" Select ID_Location"
  796. +" From Location"
  797. +" Where"
  798. + @Location
  799. +" )"
  800. +" Group By ID_Product"
  801. +" )pb On a.ID_Product=pb.ID_Product"
  802. +" Left Join"
  803. +" ("
  804. +" Select IndentBillProduct.ID_Product,Sum(IndentBillProduct.Quantity_IndentBillProduct) As Quantity_IndentBillProduct"
  805. +" From IndentBillProduct"
  806. +" Join IndentBill On IndentBill.ID_IndentBill=IndentBillProduct.ID_IndentBill"
  807. +" Join Location On Location.ID_Location=IndentBill.ID_Location"
  808. +" Where IndentBill.ID_Assessor Is Not Null And IndentBill.Date_IndentBill "+@dateCondition+ " And "+@Location
  809. +" Group By IndentBillProduct.ID_Product"
  810. +" )ind On a.ID_Product=ind.ID_Product"
  811. +" Left Join"
  812. +" ("
  813. +" Select SaleBillProduct.ID_Product,Sum(SaleBillProduct.Quantity_SaleBillProduct) As Quantity_SaleBillProduct"
  814. +" From SaleBillProduct"
  815. +" Join SaleBill On SaleBill.ID_SaleBill=SaleBillProduct.ID_SaleBill"
  816. +" Join Location On Location.ID_Location=SaleBill.ID_Location"
  817. +" Where SaleBill.ID_Assessor Is Not Null And SaleBill.Date_SaleBill "+@dateCondition+ " And "+@Location
  818. +" Group By SaleBillProduct.ID_Product"
  819. +" )c On a.ID_Product=c.ID_Product"
  820. +" Left Join"
  821. +" ("
  822. +" Select SaleOutDepotBillProduct.ID_Product,Sum(SaleOutDepotBillProduct.Quantity_SaleOutDepotBillProduct) As Quantity_SaleOutDepotBillProduct"
  823. +" From SaleOutDepotBillProduct"
  824. +" Join SaleOutDepotBill On SaleOutDepotBill.ID_SaleOutDepotBill=SaleOutDepotBillProduct.ID_SaleOutDepotBill"
  825. +" Join Location On Location.ID_Location=SaleOutDepotBill.ID_Location"
  826. +" Where SaleOutDepotBill.ID_Assessor Is Not Null And SaleOutDepotBill.Date_SaleOutDepotBill "+@dateCondition+ " And "+@Location
  827. +" Group By SaleOutDepotBillProduct.ID_Product"
  828. +" )d On a.ID_Product=d.ID_Product"
  829. +" Left Join"
  830. +" ("
  831. +" Select ModifyDepotBillProduct.ID_Product,Sum(Quantity_ModifyDepotBillProduct) As InQuantity_ModifyDepotBillProduct"
  832. +" From ModifyDepotBillProduct"
  833. +" Join ModifyDepotBill On ModifyDepotBillProduct.ID_ModifyDepotBill=ModifyDepotBill.ID_ModifyDepotBill"
  834. +" Join ModifyTypeSettings On ModifyTypeSettings.ID_ModifyTypeSettings=ModifyDepotBill.Style_ModifyDepotBill"
  835. +" Join Location On Location.ID_Location=ModifyDepotBill.ID_Location"
  836. +" Where ModifyDepotBill.ID_Assessor Is Not Null And ModifyTypeSettings.Type_ModifyTypeSettings=1 And Date_ModifyDepotBill "+@dateCondition+ " And "+@Location
  837. +" Group By ModifyDepotBillProduct.ID_Product"
  838. +" )e On a.ID_Product=e.ID_Product"
  839. +" Left Join"
  840. +" ("
  841. +" Select ModifyDepotBillProduct.ID_Product,Sum(Quantity_ModifyDepotBillProduct) As OutQuantity_ModifyDepotBillProduct"
  842. +" From ModifyDepotBillProduct"
  843. +" Join ModifyDepotBill On ModifyDepotBillProduct.ID_ModifyDepotBill=ModifyDepotBill.ID_ModifyDepotBill"
  844. +" Join ModifyTypeSettings On ModifyTypeSettings.ID_ModifyTypeSettings=ModifyDepotBill.Style_ModifyDepotBill"
  845. +" Join Location On Location.ID_Location=ModifyDepotBill.ID_Location"
  846. +" Where ModifyDepotBill.ID_Assessor Is Not Null And ModifyTypeSettings.Type_ModifyTypeSettings=0 And Date_ModifyDepotBill "+@dateCondition+ " And "+@Location
  847. +" Group By ModifyDepotBillProduct.ID_Product"
  848. +" )f On a.ID_Product=f.ID_Product"
  849. +" Left Join"
  850. +" ("
  851. +" Select PurchaseOrderBillProduct.ID_Product,Sum(Quantity_PurchaseOrderBillProduct) As Quantity_PurchaseOrderBillProduct"
  852. +" From PurchaseOrderBillProduct"
  853. +" Join PurchaseOrderBill On PurchaseOrderBill.ID_PurchaseOrderBill=PurchaseOrderBillProduct.ID_PurchaseOrderBill"
  854. +" Join Location On Location.ID_Location=PurchaseOrderBill.ID_Location"
  855. +" Where PurchaseOrderBill.ID_Assessor Is Not Null And PurchaseOrderBill.Date_PurchaseOrderBill "+@dateCondition+ " And "+@Location
  856. +" Group By PurchaseOrderBillProduct.ID_Product"
  857. +" )g On a.ID_Product=g.ID_Product"
  858. +" Left Join"
  859. +" ("
  860. +" Select PurchaseInDepotBillProduct.ID_Product,Sum(Quantity_PurchaseInDepotBillProduct) As Quantity_PurchaseInDepotBillProduct"
  861. +" From PurchaseInDepotBillProduct"
  862. +" Join PurchaseInDepotBill On PurchaseInDepotBill.ID_PurchaseInDepotBill=PurchaseInDepotBillProduct.ID_PurchaseInDepotBill"
  863. +" Join Location On Location.ID_Location=PurchaseInDepotBill.ID_Location"
  864. +" Where PurchaseInDepotBill.ID_Assessor Is Not Null And PurchaseInDepotBill.Date_PurchaseInDepotBill "+@dateCondition+ " And "+@Location
  865. +" Group By PurchaseInDepotBillProduct.ID_Product"
  866. +" )h On a.ID_Product=h.ID_Product"
  867. +" Left Join"
  868. +" ("
  869. +" Select StocktakingBillProduct.ID_Product,Sum(StocktakingBillProduct.Quantity_StocktakingBillProduct-StocktakingBillProduct.StockQty_StocktakingBillProduct) As InQuantity_StocktakingBillProduct"
  870. +" From StocktakingBillProduct"
  871. +" Join StocktakingBill On StocktakingBill.ID_StocktakingBill=StocktakingBillProduct.ID_StocktakingBill"
  872. +" Join Location On Location.ID_Location=StocktakingBill.ID_Location"
  873. +" Where StocktakingBill.ID_Assessor Is Not Null And (StocktakingBillProduct.Quantity_StocktakingBillProduct-StocktakingBillProduct.StockQty_StocktakingBillProduct) &gt; 0 And StocktakingBill.Date_StocktakingBill "+@dateCondition+ " And "+@Location
  874. +" Group By StocktakingBillProduct.ID_Product"
  875. +" )i On a.ID_Product=i.ID_Product"
  876. +" Left Join"
  877. +" ("
  878. +" Select StocktakingBillProduct.ID_Product,-Sum(StocktakingBillProduct.Quantity_StocktakingBillProduct-StocktakingBillProduct.StockQty_StocktakingBillProduct) As OutQuantity_StocktakingBillProduct"
  879. +" From StocktakingBillProduct"
  880. +" Join StocktakingBill On StocktakingBill.ID_StocktakingBill=StocktakingBillProduct.ID_StocktakingBill"
  881. +" Join Location On Location.ID_Location=StocktakingBill.ID_Location"
  882. +" Where StocktakingBill.ID_Assessor Is Not Null And (StocktakingBillProduct.Quantity_StocktakingBillProduct-StocktakingBillProduct.StockQty_StocktakingBillProduct) &lt; 0 And StocktakingBill.Date_StocktakingBill "+@dateCondition+ " And "+@Location
  883. +" Group By StocktakingBillProduct.ID_Product"
  884. +" )j On a.ID_Product=j.ID_Product"
  885. +" Left Join"
  886. +" ("
  887. +" Select SaleRtnBillProduct.ID_Product,Sum(Quantity_SaleRtnBillProduct) As Quantity_SaleRtnBillProduct"
  888. +" From SaleRtnBillProduct"
  889. +" Join SaleRtnBill On SaleRtnBill.ID_SaleRtnBill=SaleRtnBillProduct.ID_SaleRtnBill"
  890. +" Join Location On Location.ID_Location=SaleRtnBill.ID_Location"
  891. +" Where SaleRtnBill.ID_Assessor Is Not Null And SaleRtnBill.Date_SaleRtnBill "+@dateCondition+ " And "+@Location
  892. +" Group By SaleRtnBillProduct.ID_Product"
  893. +" )k On a.ID_Product=k.ID_Product"
  894. +" Left Join"
  895. +" ("
  896. +" Select SaleOutDepotBillProduct.ID_Product,Sum(SaleOutDepotBillProduct.Quantity_SaleOutDepotBillProduct) As Quantity_SaleOutDepotBillProduct"
  897. +" From SaleOutDepotBillProduct"
  898. +" Join SaleOutDepotBill On SaleOutDepotBill.ID_SaleOutDepotBill=SaleOutDepotBillProduct.ID_SaleOutDepotBill"
  899. +" Join Location On Location.ID_Location=SaleOutDepotBill.ID_Location"
  900. +" Where SaleOutDepotBill.ID_Assessor Is Not Null And SaleOutDepotBill.Date_SaleOutDepotBill "+@bisNow+ " And "+@Location
  901. +" Group By SaleOutDepotBillProduct.ID_Product"
  902. +" )d1 On a.ID_Product=d1.ID_Product"
  903. +" Left Join"
  904. +" ("
  905. +" Select ModifyDepotBillProduct.ID_Product,Sum(Quantity_ModifyDepotBillProduct) As InQuantity_ModifyDepotBillProduct"
  906. +" From ModifyDepotBillProduct"
  907. +" Join ModifyDepotBill On ModifyDepotBillProduct.ID_ModifyDepotBill=ModifyDepotBill.ID_ModifyDepotBill"
  908. +" Join ModifyTypeSettings On ModifyTypeSettings.ID_ModifyTypeSettings=ModifyDepotBill.Style_ModifyDepotBill"
  909. +" Join Location On Location.ID_Location=ModifyDepotBill.ID_Location"
  910. +" Where ModifyDepotBill.ID_Assessor Is Not Null And ModifyTypeSettings.Type_ModifyTypeSettings=1 And Date_ModifyDepotBill "+@bisNow+ " And "+@Location
  911. +" Group By ModifyDepotBillProduct.ID_Product"
  912. +" )e1 On a.ID_Product=e1.ID_Product"
  913. +" Left Join"
  914. +" ("
  915. +" Select ModifyDepotBillProduct.ID_Product,Sum(Quantity_ModifyDepotBillProduct) As OutQuantity_ModifyDepotBillProduct"
  916. +" From ModifyDepotBillProduct"
  917. +" Join ModifyDepotBill On ModifyDepotBillProduct.ID_ModifyDepotBill=ModifyDepotBill.ID_ModifyDepotBill"
  918. +" Join ModifyTypeSettings On ModifyTypeSettings.ID_ModifyTypeSettings=ModifyDepotBill.Style_ModifyDepotBill"
  919. +" Join Location On Location.ID_Location=ModifyDepotBill.ID_Location"
  920. +" Where ModifyDepotBill.ID_Assessor Is Not Null And ModifyTypeSettings.Type_ModifyTypeSettings=0 And Date_ModifyDepotBill "+@bisNow+ " And "+@Location
  921. +" Group By ModifyDepotBillProduct.ID_Product"
  922. +" )f1 On a.ID_Product=f1.ID_Product"
  923. +" Left Join"
  924. +" ("
  925. +" Select PurchaseInDepotBillProduct.ID_Product,Sum(Quantity_PurchaseInDepotBillProduct) As Quantity_PurchaseInDepotBillProduct"
  926. +" From PurchaseInDepotBillProduct"
  927. +" Join PurchaseInDepotBill On PurchaseInDepotBill.ID_PurchaseInDepotBill=PurchaseInDepotBillProduct.ID_PurchaseInDepotBill"
  928. +" Join Location On Location.ID_Location=PurchaseInDepotBill.ID_Location"
  929. +" Where PurchaseInDepotBill.ID_Assessor Is Not Null And PurchaseInDepotBill.Date_PurchaseInDepotBill "+@bisNow+ " And "+@Location
  930. +" Group By PurchaseInDepotBillProduct.ID_Product"
  931. +" )h1 On a.ID_Product=h1.ID_Product"
  932. +" Left Join"
  933. +" ("
  934. +" Select SaleBillProduct.ID_Product,Sum(SaleBillProduct.Quantity_SaleBillProduct) As Quantity_SaleBillProduct"
  935. +" From SaleBillProduct"
  936. +" Join SaleBill On SaleBill.ID_SaleBill=SaleBillProduct.ID_SaleBill"
  937. +" Join Location On Location.ID_Location=SaleBill.ID_Location"
  938. +" Where SaleBill.ID_Assessor Is Not Null And SaleBill.Date_SaleBill "+@bisNow+ " And "+@Location
  939. +" Group By SaleBillProduct.ID_Product"
  940. +" )c1 On a.ID_Product=c1.ID_Product";
  941. @where=true;
  942. if(cbType1.Text!="")
  943. {
  944. if(@where==true)
  945. {
  946. @sqlCmd=@sqlCmd+" Where Type_Product &gt;=" +"'"+cbType1.Text+"'";
  947. @where=false;
  948. }
  949. else
  950. {
  951. @sqlCmd=@sqlCmd+" And Type_Product &gt;=" +"'"+cbType1.Text+"'";
  952. }
  953. }
  954. if(cbType2.Text!="")
  955. {
  956. if(@where==true)
  957. {
  958. @sqlCmd=@sqlCmd+" Where Type_Product &lt;="+"'"+cbType2.Text+"'";
  959. @where=false;
  960. }
  961. else
  962. {
  963. @sqlCmd=@sqlCmd+" And Type_Product &lt;="+"'"+cbType2.Text+"'";
  964. }
  965. }
  966. if(ckSuspend.Checked)
  967. {
  968. if(@where==true)
  969. {
  970. @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)) &gt; 0 ";
  971. @where=false;
  972. }
  973. else
  974. {
  975. @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)) &gt; 0 ";
  976. }
  977. }
  978. @sqlCmd=@sqlCmd+" Order By a.No_Product ";
  979. SearchEx(@sqlCmd,"Total");
  980. txtSum.CValue=SumOfCol("#Total.Quantity_RealSale");
  981. </btnActionClick>-->
  982. </Lables>
  983. </Form>
  984. </Forms>