PageRenderTime 20ms CodeModel.GetById 12ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/beta/shopfloor/costs.asp

http://github.com/khaneh/Orders
ASP | 456 lines | 436 code | 19 blank | 1 comment | 100 complexity | a45a873208d4b566a28386562bc091fc MD5 | raw file
  1<%@LANGUAGE="VBSCRIPT" CODEPAGE="1256"%><%
  2'shopfloor (3)
  3PageTitle="���� ������"
  4SubmenuItem=7
  5if not Auth(3 , 7) then NotAllowdToViewThisPage()
  6%>
  7<!--#include file="top.asp" -->
  8<!--#include File="../include_farsiDateHandling.asp"-->
  9<!--#include File="../include_UtilFunctions.asp"-->
 10<STYLE>
 11	li{margin: 8px 10px 0 0;}
 12	.orderColor {background-color: black;color: yellow;}
 13	.quoteColor {background-color: #559;color: yellow;}
 14	.quoteColor td a:link{color: yellow;}
 15	.quoteColor td a:visited{color: #47FF00;}
 16	.quoteColor td a:hover{color: red;}
 17	.orderColor td a:link{color: yellow;}
 18	.orderColor td a:visited{color: #47FF00;}
 19	.orderColor td a:hover{color: red;}
 20	.grayColor{background-color: #ccc;}
 21	span.stName{padding: 0 5px;font-family: "b zar";font-weight: bold;font-size: 12px;color: #b04444}
 22</STYLE>
 23<script type="text/javascript">
 24$(document).ready(function(){
 25	$.ajaxSetup({
 26		cache: false
 27	});
 28	function dateDiff( str1, str2 ) {
 29	    var diff = Date( str2 ) - Date( str1 ); 
 30	    return isNaN( diff ) ? NaN : {
 31	        diff : diff,
 32	        ms : Math.floor( diff            % 1000 ),
 33	        s  : Math.floor( diff /     1000 %   60 ),
 34	        m  : Math.floor( diff /    60000 %   60 ),
 35	        h  : Math.floor( diff /  3600000 %   24 ),
 36	        d  : Math.floor( diff / 86400000        )
 37	    };
 38	}
 39	
 40	function checkBut(obj){
 41		var ret = true;
 42		if ($("#is_count").val()=="True"){
 43			if ($("#is_countinuous").val()=="True"){
 44				ret = ret && ($.isNumeric($("#startCounter").val()) && $.isNumeric($("#endCounter").val()) && $.isNumeric($("#order").val()))
 45			} else {
 46				ret = ret && ($.isNumeric($("#qtty").val()) && $.isNumeric($("#order").val()));
 47			}
 48		}
 49		if ($("#is_time").val()=="True"){
 50			if ($("#is_countinuous").val()=="True") {
 51				var lastTime = new Date($("#lastTime").val());
 52				var startTime = new Date($("#start_time").val());
 53				if (lastTime > startTime) {
 54					ret = false;
 55					$("#result").html("��� ���� �� ��� ���� ������� ���� ��������!");
 56					$("#startTime").val(lastTime.getHours()+':'+lastTime.getMinutes());
 57					$("#startDate").val($.format.date(lastTime,"yyyy/MM/dd"));
 58					$("#startDate").focus();
 59				}
 60			}
 61			if ($("#startDate").val()!="" && $("#startTime").val()!="" && $("#endDate").val()!="" && $("#endTime").val()!="") {
 62				var diff = dateDiff(Date($("#start_time").val()+":00"), Date($("#end_time").val()+":00"));
 63				if (diff.diff>0){
 64					var result = "������ ���: ";
 65					result += (diff.d>0)? diff.d + "��� ":"";
 66					result += (diff.h>0)? diff.h + "���� ":"";
 67					result += (diff.m>0)? diff.m + "����� ":"";
 68					if (obj.attr('id')!="order") 
 69						$("#result").html(result);
 70					//console.log(obj.attr('id'));
 71					if ($("#order_found").val()=="0"){
 72						ret = false;
 73					} else {
 74						ret = ret && true;
 75					}
 76				} else {
 77					if (obj.attr('id')!="order") 
 78						$("#result").html("����� � ���� ����� ���� �� ���� ��ѐ�� ����.");
 79					ret=false;
 80				}
 81			}
 82		}
 83		
 84		//console.log('checked!' + ret);
 85		if (ret)
 86			$("#save").prop("disabled", false);
 87		else
 88			$("#save").prop("disabled", true);
 89	}
 90	function acceptDate(obj){ 
 91		if (obj.val()=="") {
 92			$("#result").html("���� ����� �� ���� ����");
 93			obj.focus();
 94		}
 95		else if (obj.val()=="//") {
 96			var today = new Date();
 97			obj.val($.format.date(today,"yyyy/MM/dd"));
 98		} else {
 99			//var myRegExp = new RegExp("^(13)?[7-9][0-9]/[0-1]?[0-9]/[0-3]?[0-9]$");
100			var rege=/^(13)?[7-9][0-9]\/[0-1]?[0-9]\/[0-3]?[0-9]$/;
101
102			if( rege.test(obj.val()) ) {
103				var SP = obj.val().split("/");
104				if (SP[0].length == 2) SP[0] = "13" + SP[0] ;
105				if (SP[1].length == 1) SP[1] = "0"  + SP[1] ;
106				if (SP[2].length == 1) SP[2] = "0"  + SP[2] ;
107				obj.val(SP.join("/"));
108				if (obj.attr('id')=="startDate"){
109					$("#start_time").val($.jalaliCalendar.jalaliToGregorianStr($("#startDate").val()) + " " + $("#startTime").val());
110					checkBut(obj);
111				} else if (obj.attr('id')=="endDate"){
112					$("#end_time").val($.jalaliCalendar.jalaliToGregorianStr($("#endDate").val()) + " " + $("#endTime").val());
113					checkBut(obj);
114				}
115			}
116			if(!rege.test(obj.val())||( SP[0]<'1376' || SP[1]>'12' || SP[2]>'31' )) {
117				$("#result").html("���� ����� ���� YYYY/MM/DD ����.");
118				//obj.select();
119				obj.focus();
120			};
121		}
122		
123	}
124	function acceptTime(obj) {
125		if (obj.val()=="") {
126			$("#result").html("���� ���� �� ���� ����.");
127			obj.focus();
128		} else if (obj.val()==":"){
129			var now = new Date();
130			obj.val(now.getHours()+':'+now.getMinutes());
131			//var myRegExp = new RegExp("^[0-2]?[0-9]:[0-5]?[0-9]$");
132			var rege = /^[0-2]?[0-9]:[0-5]?[0-9]$/;
133			if( rege.test(obj.val()) ) {
134				var SP = obj.val().split(":");
135				if (SP[0].length == 1) SP[0] = "0" + SP[0] ;
136				if (SP[1].length == 1) SP[1] = "0"  + SP[1] ;
137				obj.val(SP.join(":"));
138	
139				if (obj.attr('id')=="startTime"){
140					$("#start_time").val($.jalaliCalendar.jalaliToGregorianStr($("#startDate").val()) + " " + $("#startTime").val());
141					checkBut(obj);
142				} else if (obj.attr('id')=="endTime"){
143					$("#end_time").val($.jalaliCalendar.jalaliToGregorianStr($("#endDate").val()) + " " + $("#endTime").val());
144					checkBut(obj);
145				}
146			}
147		} else {
148			//var myRegExp = new RegExp("^[0-2]?[0-9]:[0-5]?[0-9]$");
149			var rege = /^[0-2]?[0-9]:[0-5]?[0-9]$/;
150			if( rege.test(obj.val()) ) {
151				var SP = obj.val().split(":");
152				if (SP[0].length == 1) SP[0] = "0" + SP[0] ;
153				if (SP[1].length == 1) SP[1] = "0"  + SP[1] ;
154				obj.val(SP.join(":"));
155	
156				if (obj.attr('id')=="startTime"){
157					$("#start_time").val($.jalaliCalendar.jalaliToGregorianStr($("#startDate").val()) + " " + $("#startTime").val());
158					checkBut(obj);
159				} else if (obj.attr('id')=="endTime"){
160					$("#end_time").val($.jalaliCalendar.jalaliToGregorianStr($("#endDate").val()) + " " + $("#endTime").val());
161					checkBut(obj);
162				}
163			}
164			if(!rege.test(obj.val())||( SP[0]>23 || SP[1]>59)) {
165				$("#result").html("���� ���� ���� HH:MM ����.");
166				obj.focus();
167			};
168		}
169	}
170	if ($("#is_countinuous").val()=="True" && $("#is_count").val()=="True"){
171		$("#result").html(ajax_load);
172		$("#startCounter").ready(function(){
173			$.getJSON(loadUrl,
174				{act:"counter",operation_type:$("input[name=operation_type]:checked").val(),driver_id:$("#driver_id").val()},
175				function(json){
176					if (json.lastCounter>0) {
177						$("#result").html("����� ����� ���� ��");
178						$("#startCounter").val(json.lastCounter+1);
179						//$("#endCounter").focus();
180						$("#startCounter").focus();
181					} else{
182						$("#result").html("�������� �� ����� ����� ���� ���");
183						$("#startCounter").val(json.lastCounter);
184						$("#startCounter").focus();
185					}
186				}
187			);
188			
189		});
190	}  
191	if ($("#is_countinuous").val()=="True" && $("#is_time").val()=="True"){
192		$("#result").html(ajax_load);
193		$("#start_time").ready(function(){
194			$.getJSON(loadUrl,
195				{act:"time",operation_type:$("input[name=operation_type]:checked").val(),driver_id:$("#driver_id").val()},
196				function(json){
197					if (json.foundLastTime=='0') {
198						$("#result").html("��� ������ ���� ��� ���� ����� ����� ���� ���������!");
199						today =new Date();
200						//$("#start_time").val($.jalaliCalendar.gregorianToJalaliStr('2012/4/17'));
201						//$("#startDate").val($.jalaliCalendar.jalaliToGregorianStr('1391/1/29'));
202						
203						$("#startDate").val($.format.date(today,"yyyy/MM/dd"));
204						$("#start_time").val($.jalaliCalendar.jalaliToGregorianStr($("#startDate").val()));
205						$("#endDate").val($.format.date(today,"yyyy/MM/dd"));
206						$("#end_time").val($.jalaliCalendar.jalaliToGregorianStr($("#endDate").val()));
207						$("#startDate").focus();
208						//console.log('today');
209					} else{
210						if (json.isNewDay=='1'){
211							$("#result").html("�� ��� ���� �� ��� ��� ����� �� ���� ����ϡ ��� ���� ����� �����.");	
212							$("#startDate").focus();
213							$("#lastTime").val(json.lastTime.replace(RegExp('-','g'),'/'));
214							
215						} else {
216							$("#lastTime").val(json.lastTime.replace(RegExp('-','g'),'/'));
217							var lastTime = new Date($("#lastTime").val());
218							$("#startDate").val($.jalaliCalendar.gregorianToJalaliStr(json.lastTime));
219							$("#startTime").val(lastTime.getHours()+':'+lastTime.getMinutes());
220							$("#startTime").blur();
221							$("#endDate").focus();
222							$("#result").html("����� ���� ���� ��� �� ��� ���� ����� ������� <b>" +$("#startDate").val() + "</b> � �� ���� <b>" + $("#startTime").val() + "</b> ������ϡ ���� ���� ����� ��� ���� �� ���� ����");
223							
224						}
225						
226					}
227				}
228			);
229			//$("#endCounter").focus();
230			$("#startCounter").focus();
231		});
232	}
233	var loadUrl="/service/json_costCheck.asp";
234	var ajax_load = "<img src=\'/css/images/ajax-loader.gif\' width='20px' alt='Loading �'>";
235	$("#startCounter").blur(function(){
236		//$("#result").html(ajax_load).load(loadUrl,"act=counter");
237		if ($.isNumeric($("#startCounter").val()) && parseFloat($("#startCounter").val())>0){
238			//$("#endCounter").focus();
239			//console.log("endCounter");
240			;
241		} else {
242			$("#startCounter").val("");
243			$("#startCounter").focus();
244		}
245	});
246	$("#startDate").blur(function(){
247		acceptDate($(this));
248	});
249	$("#endDate").blur(function(){
250		acceptDate($(this));
251	});
252	$("#startTime").blur(function(){
253		acceptTime($(this));
254	});
255	$("#endTime").blur(function(){
256		acceptTime($(this));
257	});
258	$("#endCounter").blur(function(){
259		if ($(this).val()!=''){
260			if ($.isNumeric($(this).val())) {
261				var endCounter = parseFloat($("#endCounter").val()); 
262				var startCounter = parseFloat($("#startCounter").val());
263				if (startCounter >= endCounter){
264					$(this).val("");
265					$("#result").html("����� ����� ���� ��ѐ�� �� ����� ���� ����!");
266					$(this).focus();
267				} else {
268					var myCounter = parseFloat($("#endCounter").val()) - parseFloat($("#startCounter").val()); 
269					$("#result").html("������ ���: " + myCounter + " ����");
270					checkBut($(this));
271				}
272			} else {
273				$(this).focus();
274				$("#result").html("���� ��� ���� ����!");
275				$("#save").prop("disabled", true);
276			}
277		} else {
278			$(this).focus();
279		}
280	});
281	$("#order").blur(function(){
282		$("#result").html(ajax_load);
283		var orderID = Number($("#order").val());
284		if (!isNaN(orderID) && orderID!='') {
285			loadXMLDoc("/service/xml_getOrderProperty.asp?act=showHead&id=" + orderID, function(orderXML){
286				var isOrder = $(orderXML).find("status isOrder").text();
287				var isClosed = $(orderXML).find("status isClosed").text();
288				var isApproved = $(orderXML).find("status isApproved").text();
289				var step = $(orderXML).find("status step").text();
290				/*
291if (step=='40'){
292					$("#order_found").val("0");
293					alert("��� ���� ��� ����� ����� ���");
294				} else
295*/ if (parseInt(step)>0)
296					$("#order_found").val("1");
297				else
298					$("#order_found").val("0");
299				
300				TransformXml(orderXML, "/xsl.<%=version%>/orderShowHeader.xsl", function(result){
301					$("#result").html(result);	
302					checkBut($("#order"));
303					$('a#customerID').click(function(e){
304						window.open('../CRM/AccountInfo.asp?act=show&selectedCustomer='+$('a#customerID').attr("myID"), 'showCustomer');
305						e.preventDefault();
306					});
307				});
308			});
309			
310		} else {
311			$("#order_found").val("0");
312			$("#result").html("���� ������ ���� ���ϡ ���� ��� ����!");
313			$("#order").val("");
314			$("#order").focus();
315			$("#save").prop("disabled", true);
316		}
317		
318	});
319});
320</script>
321<br>
322<%
323if request("act")="" then 
324	mySQL="select cost_centers.name as centerName,cost_drivers.name as driverName,cost_drivers.ID from cost_drivers inner join cost_centers on cost_drivers.cost_center_id=cost_centers.id inner join cost_user_relations on cost_user_relations.driver_id=cost_drivers.id where cost_user_relations.user_id=" & session("id")
325	set rs=Conn.Execute(mySQL)
326	while not rs.eof
327	%>
328	<li><a href='costs.asp?act=add&ID=<%=rs("id")%>'><%="<b>" & rs("centerName") &"</b> - "& rs("driverName") %></a><br>
329	<%
330		rs.MoveNext
331	wend
332	rs.close
333elseif request("act")="add" then '-------------------------------- A D D
334	today=shamsiToday()
335	mySQL="select * from cost_drivers where id=" & request("id")
336	set rs=Conn.Execute(mySQL)
337	if rs.eof then 
338		msg="�� ����� ���� �� ����!"
339		response.redirect "?errmsg=" & Server.URLEncode(msg)
340	end if
341	mySQL = "select * from cost_operation_type where driver_id=" & request("id")
342	set rsOP=Conn.Execute(mySQL)
343	if rs.eof then 
344		msg="��� ������� ���� ��� ������ ��� ����"
345		response.redirect "?errmsg=" & Server.URLEncode(msg)
346	end if
347	currTime=now()
348	startTime=FormatDateTime(dateAdd("n",-30,currTime),4)
349	endDate=FormatDateTime(currTime,4)
350	%>
351<a href="costs.asp">��Ґ��</a><br>
352<form method="post" action="?act=insert">
353<b><%=rs("Name")%></b>
354<%
355i=0
356while not rsOP.eof
357	i=i+1
358%>
359	<input type="radio" name="operation_type" value="<%=rsOP("id")%>" <%if i=1 then response.write "checked='checked'"%>>
360	<span><%=rsOP("name")%></span>
361<%
362	rsOP.moveNext
363wend
364%>
365<br><br>
366
367	<input type="hidden" name="driver_id" value="<%=rs("id")%>" id='driver_id'>
368	<input type="hidden" name="is_count" id='is_count' value="<%=rs("is_count")%>">
369	<input type="hidden" name="is_time" id='is_time' value="<%=rs("is_time")%>">
370	<input type="hidden" name="is_direct" id='is_direct' value="<%=rs("is_direct")%>">
371	<input type="hidden" name="is_countinuous" id='is_countinuous' value="<%=rs("is_countinuous")%>">
372	<input type="hidden" name="lastTime" id='lastTime'>
373<%	if rs("is_count")="True" then 
374		if rs("is_countinuous")="True" then 
375	%>
376	<span>����� ����:</span>
377	<input type="text" name="startCounter" size="7" id='startCounter'>
378	<span>����� �����:</span>
379	<input type="text" name="endCounter" size="7" id='endCounter'><br>
380	<%	
381		else
382	%>
383	<span>����� �� ���� ����:</span>
384	<input type="text" name="qtty" size="3" id='qtty'><br>
385	<%
386		end if
387	end if 
388	if rs("is_time")="True" then 
389	%>
390	<input type="hidden" name="start_time" id='start_time'>
391	<input type="hidden" name="end_time" id='end_time'>
392	<span>����� ����:</span>
393	<input type="text" name="startDate" id='startDate' size="10" maxlength="10" value="" >
394	<span>���� ����:</span>
395	<input type="text" name="startTime" id='startTime' size="5" value="">
396	<span>����� �����:</span>
397	<input type="text" name="endDate" id='endDate' size="10" maxlength="10" value="">
398	<span>���� �����:</span>
399	<input type="text" name="endTime" id='endTime' size="5" value=""><br>
400	<%		
401	end if
402	if rs("is_direct")="True" then 
403	%>
404	<span>����� ����� �� ���� ����:</span>
405	<input type="text" name="order" id='order' size="6">
406	<input type="hidden" name="order_found" id='order_found' value="0">
407	<%
408	end if
409	%>
410	<br>
411	<span>�����: </span>
412	<input type="text" name="description">
413	<input type="submit" value="�����" disabled="disabled" id='save'>
414</form>
415<div id='result'></div>
416	<%
417	rs.close
418	rsOP.close
419elseif request("act")="edit" then '-------------------------------- E D I T
420
421elseif request("act")="insert" then '-------------------------------- I N S E R T
422	startCounter = "null"
423	endCounter = "null"
424	startTime = "null"
425	endTime = "null"
426	order = "null"
427	if request("startCounter")<>"" then startCounter=request("startCounter")
428	if request("endCounter")<>"" then endCounter=request("endCounter")
429	if request("start_time")<>"" then startTime= "'" & request("start_time") & "'"
430	if request("end_time")<>"" then endTime= "'" & request("end_time") & "'"
431	if request("order")<>"" then order=request("order")
432	if request("qtty")<>"" then 
433		startCounter = 0
434		endCounter = CDbl(request("qtty"))
435	end if
436	operationType = request("operation_type")
437	mySQL = "select * from cost_drivers where id=" & request("driver_id")
438	set rs=Conn.Execute(mySQL)
439	if not rs.eof then 
440		rate = CDbl(rs("rate"))
441		mySQL="INSERT INTO costs (operation_type, start_counter, end_counter, rate, start_time, end_time, [order], user_id, description) VALUES (" & operationType & ", " & startCounter & ", " & endCounter & ", " & rate & ", " & startTime & ", "& endTime &", " & order & ", " & session("id") & ", N'" & request("description") & "');"
442		response.write(mySQL)
443		Conn.Execute(mySQL)
444		response.redirect "?msg="&Server.URLEncode("�� ������� ��������� �� ���� �����")
445	else
446		response.redirect "?errmsg="&Server.URLEncode("�� ���� ������ �� ����� �� ����� ����� ����!!!")
447	end if
448	rs.close
449	set rs=nothing
450elseif request("act")="update" then '-------------------------------- U P D A T E
451end if
452
453%>
454
455
456<!--#include file="tah.asp" -->