PK

ADDRLIN : /home/anibklip/aaravpest.in/
FLL :
Current File : /home/anibklip/aaravpest.in/create_invoice.php

<?php
include "templatic/head.php";
include "templatic/header.php";
?>
<div class="box">
	<div style="padding:0px 10px;">
		<?php
		if (isset($_POST['sbmt_btn'])) {
			//Invoice
			$clntid = $_POST['clntid'];
			$ajtname = $_POST['ajtname'];
			$date = $_POST['issuedate'];
			$certid=$_POST[certid];
			$amt = $_POST['amount'];
			$stax = $_POST['srtax'];
			$grtotal = $_POST['finalone'];
			$particular = $_POST['particular'];

			if($amt){
				if($_GET[invid]){
					$sqlinvoice="update invoices set
						clnid='$clntid',
						ajtid='$ajtname',
						container='$_POST[container]',
						quantitydeclared='$_POST[quantitydeclared]',
						portcountry='$_POST[portcountry]',
						cert_typ='$_POST[cert_typ]',
						dtd='$date',
						amount='$amt',
						servicetax='$stax',
						grandtotal='$grtotal',
						particular='$particular',
						invstatus='pending',
						travel_exp='$_POST[travel_exp]',
						other_exp='$_POST[other_exp]',
						gst_combine='$_POST[gst_combine]',
						qty='$_POST[qty]'
						where invid='$_GET[invid]'
					";
					$msg="Invoice Updated successfully.";
				}else{
					$sqlinvoice="INSERT INTO invoices set
						user_id='$_SESSION[user_id]',
						clnid='$clntid', 
						ajtid='$ajtname',
						certid='$certid',
						container='$_POST[container]',
						portcountry='$_POST[portcountry]',
						cert_typ='$_POST[cert_typ]',
						dtd='$date', 
						amount='$amt', 
						servicetax='$stax',
						grandtotal='$grtotal',
						particular='$particular',
						invstatus='pending',
						travel_exp='$_POST[travel_exp]',
						other_exp='$_POST[other_exp]',
						gst_combine='$_POST[gst_combine]',
						qty='$_POST[qty]'
					";
					$msg="Invoice Created successfully.";
				}
				//echo "<pre>$sqlinvoice </pre>";
				mysql_query($sqlinvoice) or die(mysql_error().' - Error in creating Invoice');

				$arr=explode(",",$certid);
				foreach($arr as $k=>$v){
					$q="update certificates set inv_done=1 where certificateno='$v' ";
					//echo "$q <br>";
					mysql_query($q) or die(mysql_error());
					//$invno=mysql_insert_id();
				}
			}else{
				$arr=explode(",",$certid);
				foreach($arr as $k=>$v){
					$q="update certificates set inv_done=1 where certificateno='$v' ";
					//echo "$q <br>";
					mysql_query($q) or die(mysql_error());
					//$invno=mysql_insert_id();
				}
				$msg="Invoice status changed successfully.";
			}
			print "<h1 align='center'>$msg<br /><br /></h1>";
		}else{
			if(!$_GET[invid]){
				foreach($_POST[chk] as $k=>$v){
					$whr.=" certificateno='$v' or ";
				}
				$whr=substr($whr,0,-3);
				$sqlu1="SELECT * FROM certificates WHERE $whr";
				$resultu1=mysql_query($sqlu1) or die('error in fetch');
				while($cert_row=mysql_fetch_array($resultu1)){
					$certid.=$cert_row[certificateno].",";
					if($cert_row['certypo']=="a"){
						$ctype="AQIS";
					}elseif($cert_row['certypo']=="b"){
						$ctype="AUS";
					}elseif($cert_row['certypo']=="c"){
						$ctype="PPQ";
					}elseif($cert_row['certypo']=="d"){
						$ctype="AUS-BK";
					}elseif($cert_row['certypo']=="e"){
						$ctype="PPQ-BK";
					}

					$certno.=$ctype."/".$cert_row[certno]." | ";
					$conslinkno.=$cert_row[conslinkno]." | ";
					$quantitydeclared.=$cert_row[quantitydeclared]." | ";
					//$portcountry.=$cert_row[countrydes]." | ";

					if($cert_row[certypo]=="b"){
						$portcountry.=$cert_row[countrydes]." | ";
					}else{
						$portcountry.=$cert_row[declentry]." | ";
					}
					
					$nameaddress=str_replace("<br>","xxxxx",$cert_row[nameaddress]);
					//echo $cert_row[nameaddress]."-<br><br>-".$nameaddress;
					$parr=explode(",",$nameaddress);

					$qq="SELECT * from certificates where parent_cert='$cert_row[certificateno]' ";
					$qq=mysql_query($qq) or die('Error in getting Certificates');
					while($r1=mysql_fetch_array($qq, MYSQL_ASSOC)){
						$cert_no=getColumn("certificates","certificateno", $r1['parent_cert'],"certno");
						
						if($r1['sub_certno']==1){
							$sub_certno="/A";
						}elseif($r1['sub_certno']==2){
							$sub_certno="/B";
						}elseif($r1['sub_certno']==3){
							$sub_certno="/C";
						}elseif($r1['sub_certno']==4){
							$sub_certno="/D";
						}elseif($r1['sub_certno']==5){
							$sub_certno="/E";
						}elseif($r1['sub_certno']==6){
							$sub_certno="/F";
						}elseif($r1['sub_certno']==7){
							$sub_certno="/G";
						}elseif($r1['sub_certno']==8){
							$sub_certno="/H";
						}

						$certno.=$ctype."/".$cert_no.$sub_certno." | ";
						$conslinkno.=$r1[conslinkno]." | ";
						$quantitydeclared.=$r1[quantitydeclared]." | ";
						$portcountry.=$r1[portcountry]." | ";
						$parr="";//explode(",",$r1[nameaddress]);
					}
					$party.=$cert_row[nameaddress]." | ";
					//$party=$parr[0].",".$parr[1].",".$parr[2]." ".$parr[3]." ".$parr[4]." ".$parr[3];
				}

				$certno=substr($certno,0,-3);
				$conslinkno=substr($conslinkno,0,-3);
				$quantitydeclared=substr($quantitydeclared,0,-3);
				$party=substr($party,0,-3);
				
				$portcountry=substr($portcountry,0,-3);
				$certid=substr($certid,0,-1);
			}else{
				$qi="select * from invoices where invid='$_GET[invid]'";
				$qi=mysql_query($qi) or die(mysql_error());
				if($inv_row=mysql_fetch_array($qi)){
					$arr=explode(",",$inv_row[certid]);
					foreach($arr as $k=>$v){
						$whr.=" certificateno='$v' or ";
					}
					$whr=substr($whr,0,-3);
					$sqlu1="SELECT * FROM certificates WHERE $whr";
					$resultu1=mysql_query($sqlu1) or die('error in fetch');
					while($cert_row=mysql_fetch_array($resultu1)){
						$certid.=$cert_row[certificateno].",";
						if($cert_row['certypo']=="a"){
							$ctype="AQIS";
						}elseif($cert_row['certypo']=="b"){
							$ctype="AUS";
						}elseif($cert_row['certypo']=="c"){
							$ctype="PPQ";
						}elseif($cert_row['certypo']=="d"){
							$ctype="AUS-BK";
						}elseif($cert_row['certypo']=="e"){
							$ctype="PPQ-BK";
						}

						$certno.=$ctype."/".$cert_row[certno]." | ";

						$party.=$cert_row[nameaddress].",";
					}
					$certno=substr($certno,0,-3);
					$party=substr($party,0,-1);

					$certid=$inv_row[certid];
					if($inv_row['certypo']=="a"){
						$ctype="AQIS";
					}elseif($inv_row['certypo']=="b"){
						$ctype="AUS";
					}elseif($inv_row['certypo']=="c"){
						$ctype="PPQ";
					}

					$certno.=$ctype."/".$inv_row[certno];
					$conslinkno.=$inv_row[container];
					$quantitydeclared.=$inv_row[quantitydeclared];
					$portcountry.=$inv_row[portcountry];
					if($inv_row[clnid]){
						$party=$inv_row[clnid];
					}
				}
			}
			?>
			<form action="" method="post" onsubmit="return checkform(this);">
				<input type="hidden" name="certid" value="<?php echo $certid; ?>">
				<input type="hidden" name="cert_typ" value="<?php echo $ctype; ?>">

				<table align="center" width="100%" border="0" cellpadding="0" cellspacing="0">
					<tr>
						<td align="center" colspan="6">
							<center><h3> Create Invoice</h3> </center>
						</td>
					</tr>
					<!-- <tr>
						<td colspan="4"><strong>Create Invoice:</strong></td>
					</tr> -->
					<tr>
						<td colspan="2" align="right"><strong>Certificate No</strong> :</td>
						<td colspan="2"><?php echo $certno?></td>
					</tr>
					<?php
					//if($inv_row[ajtid]=="")
					{
						?>
						<tr>
							<td colspan="2" align="right"><strong>Party A/C</strong> :</td>
							<td colspan="2">
								<!-- <textarea name="clntid" rows="3" cols="90"><?php echo $party?></textarea> -->
								<?php
								$arr=explode(",",$party);
								array_unique($arr);
								$whr="";
								foreach($arr as $k=>$v){
									$whr.=" headid='$v' or ";
								}
								$whr=substr($whr,0,-3);
								$qc="select headid, headname, headaddress from parties where $whr ";
								//echo "$qc <br>";
								$rsp = mysql_query($qc) or die(mysql_error());
								while($rp = mysql_fetch_array($rsp, MYSQL_ASSOC) ){
									echo "<b>$rp[headname]</b> <br />";//<br>$rp[headaddress]
								}
								//echo $party;
								?>
								<!-- <input type="text" size="110" name="party_name" id="party_name" value="<?php echo $party?>"/> -->
							</td>
						</tr>
						<?php
					}
					?>
					<tr>
						<td colspan="2" align="right"><strong>Container No</strong> :</td>
						<td colspan="2"><input type="text" size="110" name="container" id="container" value="<?php echo $conslinkno?>"/></td>
					</tr>
					<tr>
						<td colspan="2" align="right"><strong>Quantity Declared</strong> :</td>
						<td colspan="2"><?php echo $quantitydeclared?><!-- <input type="text" size="110" name="quantitydeclared" id="quantitydeclared" value="<?php echo $quantitydeclared?>"/> --></td>
					</tr>
					<tr>
						<td colspan="2" align="right"><strong>Port</strong> :</td>
						<td colspan="2"><?php echo $portcountry?><!-- <input type="text" size="110" name="portcountry" id="portcountry" value="<?php echo $portcountry?>"/> --></td>
					</tr>
					<tr>
						<td colspan="2" align="right"><strong>Certificate Type</strong> :</td>
						<td colspan="2"><?php echo $ctype?></td>
					</tr>
					<tr>
						<td colspan="2" align="right"><strong>Date of Issue</strong> :</td>
						<td colspan="2">
							<input type="text" id="issuedate" name="issuedate" class="datepicker" value="<?php echo date('Y-m-d'); ?>" />
							<script>
								$(".datepicker").datepicker({
									dateFormat: 'yy-mm-dd'
								});
							</script>
						</td>
					</tr>
					<tr>
						<td colspan="2" align="right">For Agent:</td>
						<td colspan="2">
							<input type="text" size="60" name="ajtname" id="agentslist" value="<?php echo $inv_row[ajtid]?>" />
						</td>
					</tr>
					<tr>
						<td colspan="2" align="right"><strong>Amount</strong> :</td>
						<td colspan="2">
							<input type="text" size="7" name="amount" value="<?php echo $inv_row[amount]?>" >/- INR</td>
					</tr>
					<!-- <tr>
						<td colspan="2" align="right"> Discount:<em>(in %age)</em></td>
						<td colspan="2"><input type="text" name="discount" size="3" value="0" onfocus="this.value=''">%</td>
					</tr> -->
					<tr>
						<td colspan="2" align="right">GST :</td>
						<td colspan="4"><input type="text" name="srtax" value="18" size="4">%</td>
					</tr>

					<!-- <tr>
						<td colspan="2" align="right">Quantity:</td>
						<td colspan="4"><input type="text" name="qty" size="4" /></td>
					</tr> -->
					<tr>
						<td colspan="2" align="right">Is this IGST? :</td>
						<td colspan="4"><input type="checkbox" name="gst_combine" value="1" /></td>
					</tr>

					<!-- <tr>
						<td colspan="2" align="right">Name of Product/Service:</td>
						<td colspan="4"><input type="text" name="product" size="100"></td>
					</tr> -->
					<tr>
						<td colspan="2" align="right">Lashing Charges of container  :</td>
						<td colspan="4"><input type="text" name="travel_exp" value="<?php echo $inv_row[travel_exp]?>" size="40"></td>
					</tr>
					<tr>
						<td colspan="2" align="right">Visiting Charges :</td>
						<td colspan="4"><input type="text" name="other_exp" value="<?php echo $inv_row[other_exp]?>" size="40"></td>
					</tr>
					<tr>
						<td colspan="2" align="right" valign="middle">Particulars</td>
						<td colspan="2"><textarea name="particular" rows="3" cols="90"><?php echo $inv_row[particular]?></textarea></td>
					</tr>
					<tr>
						<td colspan="6">
							<center>
								<input type="submit" name="sbmt_btn" value="&raquo; <?php echo($_GET[invid]?"Update":"Create")?> Invoice &raquo;" class="amo-submit">
							</center>
						</td>
					</tr>
				</table>
				
			</form>
			<?php
		}
		?>
	</div>
</div>
<?php
include "templatic/footer.php";
?>


PK 99