Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
<%@ WebHandler Language="C#" Class="AjaxInventoryAdjust" %>
using System;
using System.Web;
using System.Data;
using System.Data.SqlClient;
public class AjaxInventoryAdjust : IHttpHandler, System.Web.SessionState.IRequiresSessionState
{
Kenanfans.KDO.SqlDataBaseOperator _Sdbo = null;
public void ProcessRequest(HttpContext context)
{
_Sdbo = DataService.Sdbo;
String act = context.Request["Action"];
String msg = "";
JSONObject jo = new JSONObject();
jo.Add("Action", act);
if (act == "GetList") //配送点变更
{
string sqlString = "";
string deliveryID = context.Request["DeliveryID"].ToString();
string pandianDate = context.Request["PandianDate"].ToString();//盘点日期
if (deliveryID == "")
{
//江桥的商品一律排除
sqlString = @"select B.GoodsName,D.ItemName,C.GroupId,C.GroupName,A.ACount,B.ISZJZC,A.Memo from dbo.StorageInfo A
left join Supplier.Goods B on A.GoodsID=B.GoodsID
inner join Common.DictItem D on D.ItemID=B.MainUnit
inner join Permission.GroupInfo C on B.SupplierID=C.GroupID
where B.SupplierID !='00000003-0001-0000-0000-000000000000' ";
if (MySession.UserID == GlobalDefine.PD300AdminUserID || MySession.UserGroupID == GlobalDefine.PD300DeliveryID)//如果300号登陆,库存单打印中数据排除掉pd300的直进直出数据记录
{
sqlString += @" and A.GoodsID not in (select GoodsID from PD300GoodsSet)
order by C.GroupName";//
}
else
{
sqlString += @" and B.ISZJZC='false' order by C.GroupName ";
}
}
else
{
sqlString = @"select B.GoodsName,D.ItemName,C.GroupId,C.GroupName,A.ACount,A.GoodsID,B.ISZJZC,A.Memo
from dbo.StorageInfo A left join Supplier.Goods B on A.GoodsID=B.GoodsID
inner join Common.DictItem D on D.ItemID=B.MainUnit
inner join Permission.GroupInfo C on B.SupplierID=C.GroupID
where A.DeliveryID='" + deliveryID + "' and B.SupplierID !='00000003-0001-0000-0000-000000000000' ";
if (MySession.UserID == GlobalDefine.PD300AdminUserID || MySession.UserGroupID == GlobalDefine.PD300DeliveryID)//如果300号登陆,库存单打印中数据排除掉pd300的直进直出数据记录
{
sqlString += @" and A.GoodsID not in (select GoodsID from PD300GoodsSet)
order by C.GroupName";//
}
else
{
sqlString += @"and B.ISZJZC='false' order by C.GroupName ";
}
}
DataTable dt = _Sdbo.ExecuteDataTable(sqlString);
if (deliveryID == "")
{
sqlString = @"select B.GoodsName,D.ItemName,A.ACount,B.ISZJZC,A.Memo from dbo.StorageInfo A
left join Supplier.Goods B on A.GoodsID=B.GoodsID
inner join Common.DictItem D on D.ItemID=B.MainUnit
where b.SupplierID='" + GlobalDefine.LingXingCaiGouID + "'";
if (MySession.UserID == GlobalDefine.PD300AdminUserID || MySession.UserGroupID == GlobalDefine.PD300DeliveryID)//如果300号登陆,库存单打印中数据排除掉pd300的直进直出数据记录
{
sqlString += @" and A.GoodsID not in (select GoodsID from PD300GoodsSet) ";
}
else
{
sqlString += "and B.ISZJZC='false'";
}
}
else
{
sqlString = @"select B.GoodsName,D.ItemName,A.ACount,A.GoodsID,B.ISZJZC,A.Memo from dbo.StorageInfo A
left join Supplier.Goods B on A.GoodsID=B.GoodsID
inner join Common.DictItem D on D.ItemID=B.MainUnit
where A.DeliveryID='" + deliveryID + "'and b.SupplierID='" + GlobalDefine.LingXingCaiGouID + "'";
if (MySession.UserID == GlobalDefine.PD300AdminUserID || MySession.UserGroupID == GlobalDefine.PD300DeliveryID)//如果300号登陆,库存单打印中数据排除掉pd300的直进直出数据记录
{
sqlString += @" and A.GoodsID not in (select GoodsID from PD300GoodsSet)";
}
else
{
sqlString += " and B.ISZJZC='false'";
}
}
DataTable dt1 = _Sdbo.ExecuteDataTable(sqlString);
String outStr = String.Empty;
if (dt.Rows.Count != 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
string pdcc = GetGoodsKC(dt.Rows[i]["GoodsID"].ToString(), pandianDate, deliveryID);//盘点日库存
string pj = GetPanDianRiPrice(dt.Rows[i]["GoodsID"].ToString(), deliveryID, Convert.ToDecimal(dt.Rows[i]["ACount"]), pandianDate);//盘点日金额
decimal pdjj = 0;
if (pdcc != "0.00")
{
pdjj = Convert.ToDecimal(pj) / Convert.ToDecimal(pdcc);//盘点日均价
}
string dqje = GetGoodsJE(dt.Rows[i]["GoodsID"].ToString(), deliveryID, Convert.ToDecimal(dt.Rows[i]["ACount"]));//当前金额
decimal dqjj = 0;
if (dqje != "0.00")
{
dqjj = Convert.ToDecimal(dqje) / Convert.ToDecimal(dt.Rows[i]["ACount"]);//当前均价
}
outStr += String.Format("<tr id='lie'>");
outStr += String.Format("<td width='220'>{0}</td>", dt.Rows[i]["GoodsName"]);//品名
outStr += String.Format("<td width='100'>{0}</td>", dt.Rows[i]["GroupName"]);//供应商
outStr += String.Format("<td width='80'>{0}</td>", dt.Rows[i]["ItemName"]);//单位
outStr += String.Format("<td width='100' id='td{1}' style='text-align:right'><span >{0} </span></td>", pdcc , dt.Rows[i]["GoodsID"].ToString());//盘点日库存
outStr += String.Format("<td width='100' id='td{1}'style='text-align:right'><span >{0} </span></td>", pj, dt.Rows[i]["GoodsID"].ToString());//盘点日总额
outStr += String.Format("<td width='100' id='td{1}'style='text-align:right'><span >{0} </span></td>", String.Format("{0:F}", pdjj), dt.Rows[i]["GoodsID"].ToString());//盘点日均价
outStr += String.Format("<td width='100' id='td{1}'style='text-align:right'><span >{0} </span></td>", dt.Rows[i]["ACount"], dt.Rows[i]["GoodsID"].ToString());//当前库存
outStr += String.Format("<td width='100' id='td{1}'style='text-align:right'><span >{0} </span></td>", dqje, dt.Rows[i]["GoodsID"].ToString());//当前总额
outStr += String.Format("<td width='100' id='td{1}'style='text-align:right'><span >{0} </span></td>", String.Format("{0:F}", dqjj), dt.Rows[i]["GoodsID"].ToString());//当前均价
outStr += "</tr>";
}
}
if (dt1.Rows.Count != 0)
{
for (int i = 0; i < dt1.Rows.Count; i++)
{
string pdcc = GetGoodsKC(dt1.Rows[i]["GoodsID"].ToString(), pandianDate, deliveryID);//盘点日库存
string pj = GetPanDianRiPrice(dt1.Rows[i]["GoodsID"].ToString(), deliveryID, Convert.ToDecimal(dt1.Rows[i]["ACount"]), pandianDate);//盘点日金额
decimal pdjj = 0;
if (pdcc != "0.00")
{
pdjj = Convert.ToDecimal(pj) / Convert.ToDecimal(pdcc);//盘点日均价
}
string dqje = GetGoodsJE(dt1.Rows[i]["GoodsID"].ToString(), deliveryID, Convert.ToDecimal(dt1.Rows[i]["ACount"]));//当前金额
decimal dqjj = 0;
if (dqje != "0.00")
{
dqjj = Convert.ToDecimal(dqje) / Convert.ToDecimal(dt1.Rows[i]["ACount"]);//当前均价
}
outStr += String.Format("<tr id='lie'>");
outStr += String.Format("<td width='220'>{0}</td>", dt1.Rows[i]["GoodsName"]);//品名
outStr += String.Format("<td width='100'>{0}</td>", dt.Rows[i]["GroupName"]);//供应商
outStr += String.Format("<td width='80'>{0}</td>", dt1.Rows[i]["ItemName"]);//单位
outStr += String.Format("<td width='100' id='td{1}'style='text-align:right'><span >{0} </span></td>", pdcc, dt1.Rows[i]["GoodsID"].ToString());//盘点日库存
outStr += String.Format("<td width='100' id='td{1}'style='text-align:right'><span >{0} </span></td>", pj, dt1.Rows[i]["GoodsID"].ToString());//盘点日总额
outStr += String.Format("<td width='100' id='td{1}'style='text-align:right'><span >{0} </span></td>", String.Format("{0:F}", pdjj), dt1.Rows[i]["GoodsID"].ToString());//盘点日均价
outStr += String.Format("<td width='100' id='td{1}'style='text-align:right'><span >{0} </span></td>", dt1.Rows[i]["ACount"], dt1.Rows[i]["GoodsID"].ToString());//当前库存
outStr += String.Format("<td width='100' id='td{1}'style='text-align:right'><span >{0} </span></td>", dqje, dt1.Rows[i]["GoodsID"].ToString());//当前总额
outStr += String.Format("<td width='100' id='td{1}'style='text-align:right'><span >{0} </span></td>", String.Format("{0:F}", dqjj), dt1.Rows[i]["GoodsID"].ToString());//当前均价
outStr += "</tr>";
}
}
if (dt1.Rows.Count == 0 && dt.Rows.Count == 0)
{
outStr += "<tr>";
outStr += String.Format("<td width='960'>{0}</td>", "无相关数据");
outStr += "</tr>";
}
context.Response.Write(outStr);
}
}
/// <summary>
/// 根据盘点日期计算出商品库存 (盘点日库存)
/// </summary>
/// <param name="goodsID">商品ID</param>
/// <param name="pandianDate">盘点日期</param>
/// <returns></returns>
private string GetGoodsKC(string goodsID, string pandianDate, string deliveryID)
{
pandianDate = Convert.ToDateTime(pandianDate).ToString("yyyy-MM-dd") + " 23:59:59";
//***********************入库总量*******************************//
decimal a = 0;//总数量
string sql = @"select SUM(Amount) as kcl from Warehouse.InventoryDetail a left join Warehouse.Inventory b on a.InventoryID=b.InventoryID
where GoodsID='{0}' and DeliveryID='{1}' and [Type]='入库' and InventoryTime > '{2}'";
DataRow rukuzongl = _Sdbo.ExecuteDataRow(sql, goodsID, deliveryID, pandianDate);
if (rukuzongl != null && rukuzongl["kcl"].ToString() != "")
{
a = Convert.ToDecimal(rukuzongl["kcl"]);
}
//***********************领料总量*******************************//
decimal b = 0;
sql = @"select SUM(Amount) as kcl from Warehouse.InventoryDetail a
left join Warehouse.Inventory b on a.InventoryID=b.InventoryID
left join Permission.GroupInfo c on b.DeliveryID=c.GroupID
where GoodsID='{0}' and ( DeliveryID='{1}' or c.ParentID='{1}')
and [Type]='领料' and InventoryTime > '{2}'";
DataRow lingliaozongl = _Sdbo.ExecuteDataRow(sql, goodsID, deliveryID, pandianDate);
if (lingliaozongl != null && lingliaozongl["kcl"].ToString() != "")
{
b = Convert.ToDecimal(lingliaozongl["kcl"]);
}
//***********************库存表总量*******************************//
decimal c = 0;
sql = @"select ACount from dbo.StorageInfo where GoodsID='{0}' and DeliveryID='{1}'";
DataRow kcbzl = _Sdbo.ExecuteDataRow(sql, goodsID, deliveryID);
if (kcbzl != null && kcbzl["ACount"].ToString() != "")
{
c = Convert.ToDecimal(kcbzl["ACount"]);
}
//盘点日期当天库存量=总库存量-(盘点日期之后的入库总量-盘点日期之后的领料总量)
decimal kc = c - (a - b);
return kc.ToString();
}
/// <summary>
/// 获得盘点总金额(当前金额)
/// </summary>
/// <param name="goodsID"></param>
/// <param name="pandianDate"></param>
/// <param name="deliveryID"></param>
/// <returns></returns>
private string GetGoodsJE(string goodsID, string deliveryID, decimal totalLast)
{
//求出商品余量大于0的总和
string sql = @"select a.InventoryID,InvertoryLast,InvertoryPrice from Warehouse.InventoryDetail a left join Warehouse.Inventory b on a.InventoryID=b.InventoryID
where GoodsID='{0}' and DeliveryID='{1}' and [Type]='入库' and InvertoryLast>0 order by InventoryTime asc";
DataTable dt = _Sdbo.ExecuteDataTable(sql, goodsID, deliveryID);
decimal totalPrice = 0;
if (dt != null && dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
if (totalLast > Convert.ToDecimal(dt.Rows[i][1]))//如果输入的商品数量大于 该条库存的库存数量,则需往下循环领取
{
totalLast = totalLast - Convert.ToDecimal(dt.Rows[i][1]);
totalPrice = totalPrice + Convert.ToDecimal(dt.Rows[i][1]) * Convert.ToDecimal(dt.Rows[i][2]);
}
else
{
totalPrice = totalPrice + Convert.ToDecimal(dt.Rows[i][2]) * totalLast;
break;
}
}
}
else
{
///如果总库存大于库存明细 取最新报价
string sqlprice = @"select top 1 Price from Supplier.PriceSheet a left join Supplier.PriceSheetDetail b
on a.PriceSheetID=b.PriceSheetID
where GoodsID='{0}' order by EndTime desc";
DataRow dr = _Sdbo.ExecuteDataRow(sqlprice, goodsID);
if (dr != null)
{
totalPrice = totalLast * Convert.ToDecimal(dr["Price"]);
}
else
{
totalPrice = 0;
}
}
return String.Format("{0:F}", totalPrice);//;
}
/// <summary>
/// 盘点日金额
/// </summary>
public string GetPanDianRiPrice(string goodsID, string deliveryID, decimal totalLast, string pandianDate)
{
//求出商品余量大于0的总和
pandianDate = Convert.ToDateTime(pandianDate).ToString("yyyy-MM-dd") + " 23:59:59";
string sql = @"select a.InventoryID,InvertoryLast,InvertoryPrice from Warehouse.InventoryDetail a left join Warehouse.Inventory b on a.InventoryID=b.InventoryID
where GoodsID='{0}' and DeliveryID='{1}' and [Type]='入库' and InvertoryLast>0 and InventoryTime < '{2}' order by InventoryTime asc ";
DataTable dt = _Sdbo.ExecuteDataTable(sql, goodsID, deliveryID, pandianDate);
decimal totalPrice = 0;
if (dt != null && dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
if (totalLast > Convert.ToDecimal(dt.Rows[i][1]))//如果输入的商品数量大于 该条库存的库存数量,则需往下循环领取
{
totalLast = totalLast - Convert.ToDecimal(dt.Rows[i][1]);
totalPrice = totalPrice + Convert.ToDecimal(dt.Rows[i][1]) * Convert.ToDecimal(dt.Rows[i][2]);
}
else
{
totalPrice = totalPrice + Convert.ToDecimal(dt.Rows[i][2]) * totalLast;
break;
}
}
}
else
{
///如果总库存大于库存明细 取最新报价
string sqlprice = @"select top 1 Price from Supplier.PriceSheet a left join Supplier.PriceSheetDetail b
on a.PriceSheetID=b.PriceSheetID
where GoodsID='{0}' order by EndTime desc";
DataRow dr = _Sdbo.ExecuteDataRow(sqlprice, goodsID);
if (dr != null)
{
totalPrice = totalLast * Convert.ToDecimal(dr["Price"]);
}
else
{
totalPrice = 0;
}
}
return String.Format("{0:F}", totalPrice);
}
public bool IsReusable
{
get
{
return false;
}
}
}