#native_company# #native_desc#
#native_cta#

order by date difference in mysql

By Himadrish Laha
on November 28, 2003

Version: 1.4

Type: Function

Category: Databases

License: GNU General Public License

Description: We can used this function to work with form objects. When ever we want to change the logic just change this function.

<?
// This function created for using form and its propertise
//   Mainly used for select, radio, checkbox, textbox etc.
//You can used this line, but can not commit or remove authors comment
//	AUTHOR: Created on 30th DEcember,2002 by Himadrish Laha
//  MailId: [email protected]
function menu_item($txt, $txt_link, $bgcolor, $fgcolor)
{
    echo "<tr>
            <td align=left bgcolor="$bgcolor" 
				onMouseover	='LmOver(this, "$fgcolor", "$txt");'
				onMouseout	='LmOut(this, "$bgcolor");' 
				onMouseDown	='LmDown(this, "$bgcolor", "$txt");' 
				onMouseUp	='LmUp("".$txt_link."");'>
				<font size="2">".createlink($txt_link,$txt)."<br>
			</td>
	</tr>";
}

function createlink($location,$title, $misc="")
{
return "<A HREF="$location" onMouseOver="window.status='$title'; return true;" onMouseOut="window.status=''; return true;" class="navlink" $misc>$title</A>";
}

function createlink_img($location, $title, $img_src, $misc="")
{
	return "<A HREF="$location" onMouseOver="window.status='$title'; return true;" onMouseOut="window.status=''; return true;" class="navlink" $misc><IMG SRC="images/$img_src" align="absmiddle" ALT="$title" border=0 width="20" height="20"></A>";
}

function jswindow($location, $title, $width=640, $height=480, $scroll='0')
{
	return "<A HREF="JavaScript:sub=window.open('$location','','width=' + (screen.width - 10) + ',height=' + (screen.height - 59) + ',scrollbars=auto,status=no,location=no,menubar=no, left=0, top=0');  sub.parent.history.back();" onMouseOver="window.status='$title';return true;" onMouseOut="window.status='';" class="navlink">$title</a>";
}

function jswindow_img($location, $title, $img_src, $width=640, $height=480, $scroll='0')
{
	return "<A HREF="JavaScript:sub=window.open('$location','','width=' + (screen.width - 10) + ',height=' + (screen.height - 59) + ',scrollbars=auto,status=no,location=no,menubar=no, left=0, top=0');  sub.parent.history.back();" onMouseOver="window.status='$title';return true;" onMouseOut="window.status='';" class="navlink"><IMG SRC="images/$img_src" ALT="$title" border=0 align="absmiddle" width="20" height="20"></a>";
}

function font($class="plaintext", $txt)
{
	return "<FONT CLASS="$class">$txt</FONT>";
}


function navlink($url, $txt)
{
	return "<A HREF="$url" CLASS="navlink" onMouseOver="javascript:window.status='$txt';" onMouseOut="javascript:window.status='';">$txt</a>";
}


function form_input($name, $value, $class="cl-text", $size=50, $maxlength=100, $data_type="text", $jsscript="", $type="text")
{
	if($data_type == "int")
		$value = str_pad($value, $size-1, " ", STR_PAD_LEFT);
	else if($data_type == "float")
		$value = str_pad(number_format($value, 2), $size-2, " ", STR_PAD_LEFT);
		
	return "<INPUT TYPE="$type" NAME="$name" size="$size" maxlength="$maxlength" class="$class" VALUE="$value" $jsscript>";
}

function form_dummy($name, $value, $data_type, $size=12, $class="cl-text")
{
	//
	if($data_type != "text")
	{
		$value = number_format($value, 2);
		$value = str_pad($value, $size - 2,  " ", STR_PAD_LEFT);
	}
	return "<INPUT TYPE="TEXT" NAME="$name" class="$class" size=$size VALUE="$value" READONLY>";
}

function form_text($name, $value, $class="cl-text", $rows=3, $cols=70)
{
	return "<TEXTAREA NAME="$name" CLASS="$class" rows="$rows" cols="$cols" wrap="virtual">$value</TEXTAREA>";
		
}

function form_button( $name, $value, $event)
{
	return "<INPUT TYPE="button" NAME="$name" VALUE="$value" OnClick="$event" class="cl-button">";
}


function form_select($data, $name, $selected, $jsscript="")
{
	$result = "<SELECT NAME="$name" $jsscript>";
	//*** Checking for duplicates
	while(list($dummy,$name) = each($data))
	{
		$title=$name[0];
		$id=$name[1];
		$result .= "ntttt<OPTION VALUE="$id"";
		$sel="";
		if($id==$selected) 
		{ 
			$sel=' SELECTED'; 
		} 
			$result .= $sel.">$title";
	}
	$result .= "nttt</SELECT>";
	return $result;
}

function form_yesno($var,$default)
{
	$data = array();
	array_push($data, array('Yes',1));
	array_push($data, array('No',0));
	return form_select($data,$var,$default);
}
		

function form_radio($name,$content, $selected=0)
{
	if($selected>0)
  		$checked="CHECKED";
	$result = "<INPUT TYPE="RADIO" class="cl-text" NAME="$name" VALUE="$content" $checked>n";
	return $result;
}

function form_checkbox($content,$name,$selected=0)
{
	if($selected>0)
  		$checked="CHECKED";
	$result = "<INPUT TYPE=CHECKBOX VALUE="$content" NAME="$name" CLASS="cl-text" $checked>n";
	return $result;
}

function form_hidden($name, $content="")
{
	if($content != "")
	{  
		$content=stripslashes($content);
		return "n<INPUT TYPE=HIDDEN NAME="$name" VALUE="$content">";
	}
	else 
		 return "n<INPUT TYPE=HIDDEN NAME="$name">";
}
	
function table_start($width="100%", $cellpadding="0", $cellspacing=0, $class='', $valign="TOP", $align="LEFT" )
{
	if($class!='')
		$class= "CLASS="".$class.""";
	return "n<TABLE WIDTH="$width" CELLPADDING="$cellpadding" CELLSPACING="$cellspacing" $class VALIGN="$valign" ALIGN="$align">";
}

function table_end()
{
	return "n</TABLE>";
}

function table_row($int=0, $txt='')
{
	if($int==0)
	{
		if($txt!=='')
		{
			return "nt<TR $txt>";
		}
		else
		{
			return "nt<TR>";
		}
	}
	else
		return "nt</tr>";
}

function table_item($txt='', $align="justify", $colspan=1, $valign="top", $misc="")
{
	if($txt != "" && $txt!="end")
		return "ntt<TD ALIGN="$align" VALIGN="$valign" COLSPAN="$colspan" $misc>nttt$txtntt</td>";
	else
		if($txt!="end")
			return  "ntt<TD ALIGN="$align" VALIGN="$valign" COLSPAN="$colspan" $misc>nttt";
		else
			return "ntt</TD>";
	
}

function table_data($i=0)
{
	if(!$i)
		return "ntt<TD>";
	else
		return "ntt</TD>";

}

function create_htaccess($dirname, $img=0)
{
	if($img==0)
 	{
		if(!file_exists($dirname."/.htaccess"))
		{
	 		if(($fd = fopen($dirname."/.htaccess", "w")))
			{
				fwrite($fd, "Order allow,denyndeny from alln");
				fclose($fd);
			}
		}
	}
	else
	{
		if(!file_exists($dirname."/images/.htaccess"))
		{
			if(($fd = fopen($dirname."/images/.htaccess", "w")))
			{
				fwrite($fd, "Order allow,denynallow from alln");
				fclose($fd);
			}
		}
	}
}

function format_date($date)
{
	if($date!="0000-00-00")
	{
		$fmt_date = explode("-", $date);
		return $fmt_date[2]."-".$fmt_date[1]."-".$fmt_date[0];
	}
	else
		return "-";
}

function deformat_date($date)
{
	if ($date != "00-00-0000") 
	{
		$fmt_date = explode("-", $date);
		return $fmt_date[2]."-".$fmt_date[1]."-".$fmt_date[0];
	}
	else
		return "-";
}

function space($ctr=0)
{
	
	for($i=0; $i<$ctr; $i++)
		$spcs .= " ";
	return $spcs;
}

function goodsrcd_bal($contact=0)
{
	include_once("config.php");
	global $dbname, $dbconn;
	$sel_goodsrcd_qty = "select sum(goods_rcd.goodsrcpt_qty) from goods_rcd";
	
	if($contact)
	{ 
		$sel_goodsrcd_qty .= " where goods_rcd.contact_id = "$contact"";
	}
	
	$res = mysql_db_query($dbname, $sel_goodsrcd_qty, $dbconn);
	list($input) = mysql_fetch_row($res);
	return $input;
}

function challan_bal($contact=0)
{
	include_once("config.php");
global $dbname, $dbconn;

	$sel_challan_qty = "select sum(challan.challan_qty) from challan";
	if($contact)
		$sel_challan_qty .= " where challan.contact_id = "$contact"";
		
	$res = mysql_db_query($dbname, $sel_challan_qty, $dbconn);
	list($output) = mysql_fetch_row($res);
	return $output;
}

function loan_interest($loan_pay_amount, $dd1, $mm1, $yy1, $dd2, $mm2, $yy2)
{
	include_once("datediff.php");
	
			$jun_amt=$sep_amt=$oct_amt=0.00;
			$flag=true;
			if(checkdate($mm2, $dd2, $yy2))
			{							
				if (datecmp($dd2, $mm2, $yy2, 30, 6, $yy2)<=0) 
				{
				    $jun_amt = datediff(($dd1+0), ($mm1+0), ($yy1+0), 30, 6, $yy1)*$loan_pay_amount*0.21/365;
				}
				else  
				{
					$flag=false;
					$jun_amt = datediff(($dd1+0), ($mm1+0), ($yy1+0), ($dd2+0), ($mm2+0), ($yy2+0))*$loan_pay_amount*0.21/365;
				}
				
				if ($flag) 
				{
					if (datecmp($dd2, $mm2, $yy2, 30, 9, $yy1)<=0) 
					{
					    $sep_amt = datediff(1,7,($yy1+0), 30, 9, $yy1)*(($loan_pay_amount+$jun_amt))*0.21/365;
					}
					else  
					{
						$flag=false;
						$sep_amt = datediff(1, 7, ($yy1+0), ($dd2+0), ($mm2+0), ($yy2+0))*(($loan_pay_amount+$jun_amt))*0.21/365; 
					}
					
					if ($flag) 
					{
						if (datecmp($dd2, $mm2, $yy2, 15, 10, $yy1)<=0) 
						{
						    $oct_amt = datediff(1, 10,($yy1+0), 15, 10, ($yy1+0))*(($loan_pay_amount+$jun_amt+$sep_amt))*0.21/365;
						}
						else  
						{
							$oct_amt = datediff(1, 10, ($yy1+0), ($dd2+0), ($mm2+0), ($yy2+0))*(($loan_pay_amount+$jun_amt+$sep_amt))*0.21/365; 
						}
					}
				}
			}
						
			$loan_repay_amount = $loan_pay_amount + $jun_amt + $sep_amt + $oct_amt;
			
			$loan_repay = array();
			$loan_repay[0] = number_format($jun_amt,2);
			$loan_repay[1] = number_format($sep_amt,2);
			$loan_repay[2] = number_format($oct_amt,2);
			$loan_repay[3] = number_format($loan_repay_amount,2);
			return $loan_repay; 

}

function dfmt_date($date)
{

     $dt = explode("-", $date);

     $ret_date = $dt[2] . "-" . $dt[1] . "-" . substr($dt[0], 2);

     return $ret_date;

    
}
?>