<?php
session_start(); 
ob_start();
include("../../pidbco/pidbjoin.php");

if(!isset($_SESSION['jay_proj_mngmnt']) && empty($_SESSION['jay_proj_mngmnt']))
{
    echo '<script type="text/javascript">alert("You Want To Login Now.."); window.location.href="../Login";</script>';
}


/*------------------- Add New Company -----------  */

if(isset($_POST['add_new_company'])){
 
 $ccompany = strip_tags($_POST['ccompany']);
 $cprefix = strip_tags($_POST['cprefix']);	
 $ccontact = strip_tags($_POST['ccontact']);		 
 $cmob = strip_tags($_POST['cmob']);
 $cemail = strip_tags($_POST['cemail']);
 $cstate = strip_tags($_POST['cstate']);
 $cdistrict = strip_tags($_POST['cdistrict']);
 
 $caddress = strip_tags($_POST['caddress']);
 $ccountry = strip_tags($_POST['ccountry']);
 
 $cstatus = strip_tags($_POST['cstatus']);
 $date = date('Y-m-d');
 
 $sq = mysqli_query($con,"SELECT MAX(`cid`) AS mxidntty FROM `p_company` ");
 $row = mysqli_fetch_assoc($sq);
 $comp_unqid = $row['mxidntty']+1; 
 
 $compinsert = mysqli_query($con,"INSERT INTO `p_company` (`c_identity` ,`c_comp`, `c_prefex`,`c_conpers` ,`c_mob` ,`c_email` ,`c_country`,`c_state` ,`c_district` ,
`c_address` ,`c_status` ,`c_date`)
VALUES ('$comp_unqid', '$ccompany', '$cprefix','$ccontact', '$cmob', '$cemail','$ccountry', '$cstate', '$cdistrict', '$caddress', '$cstatus', '$date')");
 
}


/* ------- Edit Company ------------- */
if(isset($_POST['edit_new_company'])){
	
 $ccompany = strip_tags($_POST['ccompany']);
 $cprefix = strip_tags($_POST['cprefix']);	
 $ccontact = strip_tags($_POST['ccontact']);		 
 $cmob = strip_tags($_POST['cmob']);
 $cemail = strip_tags($_POST['cemail']);
 $cstate = strip_tags($_POST['cstate']);
 $cdistrict = strip_tags($_POST['cdistrict']);
 $caddress = strip_tags($_POST['caddress']);
 $ccountry = strip_tags($_POST['ccountry']);
 $cstatus = strip_tags($_POST['cstatus']);
 $hidvall = strip_tags($_POST['hidvall']);
 
 $upp= mysqli_query($con, "UPDATE `p_company` SET `c_comp` = '$ccompany',
`c_prefex` = '$cprefix',`c_conpers` = '$ccontact',`c_mob` = '$cmob',`c_email` = '$cemail',`c_country` = '$ccountry',`c_state` = '$cstate',
`c_district` = '$cdistrict',`c_address` = '$caddress',`c_status` = '$cstatus' WHERE `cid` ='$hidvall'");
 	
}

/* ----------- Delete Company ------- */
if(isset($_POST['btn_delete_company'])){
	
	$id = strip_tags(base64_decode($_POST['id']));
	$sqdel = mysqli_query($con, "DELETE FROM `p_company` WHERE `cid` = '$id'");
}



/* ---------- Add New Business Category ------ */
if(isset($_POST['add_new_business'])){
	$buscat = strip_tags($_POST['buscat']);
	$busststaus = strip_tags($_POST['busststaus']);
	$date= date('Y-m-d');
	
	$binsert = mysqli_query($con,"INSERT INTO `p_business` (`b_business` ,`bstatus` ,`bdate`) VALUES ( '$buscat', '$busststaus', '$date') ");
	
}



/* --------------  Add New Branch -------- */
if(isset($_POST['add_new_branch'])){
	
	$bcompany = strip_tags($_POST['bcompany']);
	$brname = strip_tags($_POST['brname']);
	$brmob = strip_tags($_POST['brmob']);
	$bremail = strip_tags($_POST['bremail']);
	$braddres = strip_tags($_POST['braddres']);
	$brcountry = strip_tags($_POST['brcountry']);
	$bstate = strip_tags($_POST['bstate']);
	$bdistrict= strip_tags($_POST['bdistrict']);
	$bstatus = strip_tags($_POST['bstatus']);
	$dat = date('Y-m-d');
	
 $sq = mysqli_query($con,"SELECT MAX(`bid`) AS mxidntty FROM `p_branch` ");
 $row = mysqli_fetch_assoc($sq);
 $bra_unqid = $row['mxidntty']+1; 
	
	$brainsert = mysqli_query($con,"INSERT INTO `p_branch` (`b_identity` ,`b_comp` ,`b_branchna` ,`b_email` ,`b_mob` ,`b_addrs` ,`b_countr` ,`b_state` ,
`b_distri` ,`b_status` ,`b_date`) VALUES ('$bra_unqid', '$bcompany', '$brname', '$bremail', '$brmob', '$braddres', '$brcountry', '$bstate', 
'$bdistrict', '$bstatus', '$dat')");	
	
}

/* ------------ Edit Branch ----------- */

if(isset($_POST['edit_new_branch'])){
	
    $bcompany = strip_tags($_POST['bcompany']);
	$brname = strip_tags($_POST['brname']);
	$brmob = strip_tags($_POST['brmob']);
	$bremail = strip_tags($_POST['bremail']);
	$braddres = strip_tags($_POST['braddres']);
	$brcountry = strip_tags($_POST['brcountry']);
	$bstate = strip_tags($_POST['bstate']);
	$bdistrict= strip_tags($_POST['bdistrict']);
	$bstatus = strip_tags($_POST['bstatus']);
	
	$hidvall = strip_tags($_POST['hidvall']);
	
	$upbra = mysqli_query($con, "UPDATE `p_branch` SET `b_comp` = '$bcompany',
`b_branchna` = '$brname',`b_email` = '$bremail',`b_mob` = '$brmob',`b_addrs` = '$braddres',`b_countr` = '$brcountry',`b_state` = '$bstate',`b_distri` = '$bdistrict',
`b_status` = '$bstatus' WHERE `bid` = '$hidvall'");
		
}

/* ---------- Delete Branch -------------- */

if(isset($_POST['btn_delete_branch'])){
	
	$id = strip_tags(base64_decode($_POST['id']));
	$sqdel = mysqli_query($con, "DELETE FROM `p_branch` WHERE `bid` = '$id'");
		
}



/* --------------------------- Delete Business --------- */

if(isset($_POST['btn_delete_business'])){
	
    $id = strip_tags(base64_decode($_POST['id']));
	$sqdel = mysqli_query($con, "DELETE FROM `p_business` WHERE `bid` = '$id'");	
}

/* ----------- Edit Business Category ----------- */

if(isset($_POST['edit_business_cat'])){
		
	$buscat = strip_tags($_POST['buscat']);
	$busststaus = strip_tags($_POST['busststaus']);
	$hidvall = strip_tags($_POST['hidvall']);
	
	$upp = mysqli_query($con, "UPDATE `p_business` SET `b_business` = '$buscat',`bstatus` = '$busststaus' WHERE `bid` = '$hidvall'");
	
}
/* -------- Add New Tax ------------ */
if(isset($_POST['btn_add_tax'])){
	
	$taxname = strip_tags($_POST['taxname']);
	$tax = strip_tags($_POST['tax']);
	$tinsert= mysqli_query($con,"INSERT INTO `tax_master` (`tax_name` ,`tax_per`)
 VALUES ('$taxname', '$tax')");	

}

/* -------- Add New Vender ------------ */

if(isset($_POST['add_new_vendor'])){
	
	$vcompany = strip_tags($_POST['vcompany']);
	$vcontact = strip_tags($_POST['vcontact']);
	$vmob = strip_tags($_POST['vmob']);
	$vemail = strip_tags($_POST['vemail']);
	$vcountry= strip_tags($_POST['vcountry']);
	$vstate = strip_tags($_POST['vstate']);
	$vdistrict = strip_tags($_POST['vdistrict']);
	$vstatus = strip_tags($_POST['vstatus']);
	$vdate = date('Y-m-d');
	$vpin = strip_tags($_POST['vpin']);
	$vaddress = strip_tags($_POST['vaddress']);
	$vmob2 = strip_tags($_POST['vmob2']);
	$vemail2 = strip_tags($_POST['vemail2']);
	$vcurrent = strip_tags($_POST['vcurrent']);
	$gstNo = strip_tags($_POST['gstNo']);
	$cred_deb = strip_tags($_POST['cred_deb']);
	
    $sq = mysqli_query($con,"SELECT MAX(`vid`) AS mxidntty FROM `p_vendor` ");
    $row = mysqli_fetch_assoc($sq);
    $vn_unqid = $row['mxidntty']+1; 
 
$vinsert= mysqli_query($con,"INSERT INTO `p_vendor` (`v_identity` ,`v_company` ,`v_contact` ,`v_mob` ,`v_email` ,`v_country` ,`v_state` ,`v_district` ,`v_curntbal`,`v_type`,`v_status` ,`v_date`,`v_email2` ,`v_mob2` ,`v_addres` ,`v_pin`,`v_gs)
 VALUES ('$vn_unqid', '$vcompany', '$vcontact', '$vmob', '$vemail', '$vcountry', '$vstate', '$vdistrict', '$vcurrent','$cred_deb', '$vstatus', '$vdate', '$vemail2', '$vmob2', '$vaddress', '$vpin')");	

}
 /* ------- Delete Vendor ------ */

if(isset($_POST['btn_delete_vendor'])){
    	
    $id = strip_tags(base64_decode($_POST['id']));
	$sqdel = mysqli_query($con, "DELETE FROM `p_vendor` WHERE `vid` = '$id'");	
	
}

/* ---------- tt Vendor ---------*/

if(isset($_POST['edit_new_vendor'])){

	$vcompany = strip_tags($_POST['vcompany']);
	$vcontact = strip_tags($_POST['vcontact']);
	$vmob = strip_tags($_POST['vmob']);
	$vemail = strip_tags($_POST['vemail']);
	$vcountry= strip_tags($_POST['vcountry']);
	$vstate = strip_tags($_POST['vstate']);
	$vdistrict = strip_tags($_POST['vdistrict']);
	$vstatus = strip_tags($_POST['vstatus']);
	$hidvall = strip_tags($_POST['hidvall']);
	$vcurrent = strip_tags($_POST['vcurrent']);
	$vpin = strip_tags($_POST['vpin']);
	$vaddress = strip_tags($_POST['vaddress']);
	$vmob2 = strip_tags($_POST['vmob2']);
	$vemail2 = strip_tags($_POST['vemail2']);
	$gstNo = strip_tags($_POST['gstNo']);
	$cred_deb = strip_tags($_POST['cred_deb']);
		
	$upp = mysqli_query($con, "UPDATE `p_vendor` SET `v_company` = '$vcompany', `v_contact` = '$vcontact',
`v_mob` = '$vmob', `v_email` = '$vemail', `v_country` = '$vcountry', `v_state` = '$vstate',
`v_district` = '$vdistrict', `v_curntbal`='$vcurrent', `v_type`='$cred_deb',`v_status` = '$vstatus',`v_pin` = '$vpin',`v_addres` = '$vaddress',`v_mob2` = '$vmob2',`v_email2` = '$vemail2',`v_gstno` = '$gstNo' WHERE `vid` ='$hidvall'");
	
}

/* ----- Branch Chnage ----- */

if(isset($_GET['comp_idd'])){
	
$comidd = $_GET['comp_idd']; ?>
	 <option value="">Branch</option>
<?php	 
$bran = mysqli_query($con, "SELECT 	b_branchna FROM `p_branch` WHERE `b_comp`='$comidd' ");
while($result = mysqli_fetch_assoc($bran)){ ?>
	<option value="<?php echo $result['b_branchna']; ?>"><?php echo $result['b_branchna']; ?></option>		
<?php }		
	
}


/* -------------- State Change ------ */

if(isset($_GET['state_idd'])){
  $state_idd = strip_tags($_GET['state_idd']); ?>
	<option value="">District</option>
<?php	 
$bran = mysqli_query($con, "SELECT * FROM `cities` WHERE `state_name`='$state_idd' ");
while($result = mysqli_fetch_assoc($bran)){ ?>
	<option value="<?php echo $result['cities_name']; ?>"><?php echo $result['cities_name']; ?></option>		
<?php }		
	
}


/* ----------- New Order Registration ----------- */
if(isset($_POST['add_new_orders']))
{
$replace_str = array("`", "'");	
$ocompny = strip_tags($_POST['ocompny']);
$rbranch = strip_tags($_POST['rbranch']);
$orderty = strip_tags($_POST['orderty']);
$ocustomer = strip_tags($_POST['ocustomer']);
$ordramnt = strip_tags($_POST['ordramnt']);
$ordate = strip_tags($_POST['ordate']);
$compltdate = strip_tags($_POST['compltdate']);
$disamount = strip_tags($_POST['disamount']);
$netamount = strip_tags($_POST['netamount']);
$ordertax = strip_tags($_POST['ordertax']);
$orderbdo = strip_tags($_POST['orderbdo']);
$hidvall   = strip_tags($_POST['hidvall']);
$bill_head = str_replace( $replace_str, "", $_POST['bill_head']);
$dat = date('Y-m-d');
$order_status = strip_tags($_POST['order_status']);
$total = strip_tags($_POST['total']);

$custsq = mysqli_query($con, "SELECT cmob,cname FROM `p_customers` WHERE `cid`='$ocustomer' ");
$custres = mysqli_fetch_array($custsq);
$cmob = $custres['cmob'];
$cname = $custres['cname'];


$sq = mysqli_query($con,"SELECT MAX(`oid`) AS mxidntty FROM `p_orders` ");
$row = mysqli_fetch_array($sq);
$ordr_unqid = $row['mxidntty']+1;
if($hidvall !='' && $orderty==9){
mysqli_query($con, "INSERT INTO `p_orders` (`order_id` ,`ocomp` ,`obranch` ,`ordr_type` ,`ocustm` ,`ordr_amt` ,`dis_amnt`,`net_amnt`,`ordr_date` ,
`compl_date` ,`or_tax`,`or_bdo`, `ostatus`,`bill_head`,`odate`,`total_amnt`)
VALUES ('$hidvall', '$ocompny', '$rbranch', '$orderty', '$ocustomer', '$ordramnt', '$disamount', '$netamount', '$ordate', '$compltdate', '$ordertax', '$orderbdo', '$order_status', '$bill_head','$dat', '$total')");
}
else{
$sqq = mysqli_query($con, "INSERT INTO `p_orders` (`order_id` ,`ocomp` ,`obranch` ,`ordr_type` ,`ocustm` ,`ordr_amt` ,`dis_amnt`,`net_amnt`,`ordr_date` ,
`compl_date` ,`or_tax`,`or_bdo`, `ostatus`,`bill_head`,`odate`,`total_amnt`)
VALUES ('$ordr_unqid', '$ocompny', '$rbranch', '$orderty', '$ocustomer', '$ordramnt', '$disamount', '$netamount', '$ordate', '$compltdate', '$ordertax', '$orderbdo', '$order_status', '$bill_head','$dat', '$total')");
}

$ddomain = strip_tags($_POST['ddomain']);
$downer = strip_tags($_POST['downer']);
$dprovider = strip_tags($_POST['dprovider']);
$dregdate = strip_tags($_POST['dregdate']);
$drenewel = strip_tags($_POST['drenewel']);
$dexpdate = strip_tags($_POST['dintimatn']);
$damount = strip_tags($_POST['damount']);
$dtax = strip_tags($_POST['dtax']);
$dredirectn = strip_tags($_POST['dredirectn']);
$duser = strip_tags($_POST['duser']);
$dpass = strip_tags($_POST['dpass']);
$damount = strip_tags($_POST['damount']);
$gstno = strip_tags($_POST['gstno']);
$daccess = strip_tags($_POST['daccess']);
$dremarks = str_replace( $replace_str, "", $_POST['dremarks']);
$dom_credentl = strip_tags($_POST['dom_credentl']);


if($ddomain != ''){                       
$dominsert = mysqli_query($con, "INSERT INTO `p_domain` (`dorder` ,`dcust`,`d_domain` ,`d_owner` ,`d_provider` ,`d_regdate` ,`d_renewel` ,`d_expdate` ,
`d_amnt` ,`d_tax` ,`d_redirectn` ,`d_user` ,`d_pass` ,`d_access` ,`d_credential`,`d_remarks`,`GstNo`,`d_netamount`)
VALUES ('$ordr_unqid', '$ocustomer', '$ddomain', '$downer', '$dprovider', '$dregdate', '$drenewel', '$dexpdate', '$damount', '$dtax', '$dredirectn',
 '$duser', '$dpass', '$daccess', '$dom_credentl', '$dremarks','$gstno','$damount')");
}
 
 $sercomp = strip_tags($_POST['sercomp']);
 $opertsystm = strip_tags($_POST['opertsystm']);
 $servalc = strip_tags($_POST['servalc']);
 $srstartdat = strip_tags($_POST['srstartdat']);
 $srenddate = strip_tags($_POST['srenddate']);
 $sramount = strip_tags($_POST['sramount']);
 $srtax = strip_tags($_POST['srtax']);
 $srremarks= str_replace( $replace_str, "", $_POST['srremarks']);
 $srowner = strip_tags($_POST['srowner']);
 $sr_credentl = strip_tags($_POST['sr_credentl']);
 $srspace = $_POST['srspace'];
 
 
 if($sercomp != ''){
 $serverinsert = mysqli_query($con, "INSERT INTO `p_server` (`s_order` ,`s_comp` ,`s_os` ,`s_alc` ,`s_start` ,`s_end` ,`s_amnt` ,`s_tax` ,`s_owner`, `s_credential` ,`s_remarks`,`s_space`)
VALUES ('$ordr_unqid', '$sercomp', '$opertsystm', '$servalc', '$srstartdat', '$srenddate', '$sramount', '$srtax','$srowner','$sr_credentl', '$srremarks','$srspace')");                  
 }
   
 $alcalc = strip_tags($_POST['alcalc']);
 $alcprovided = strip_tags($_POST['alcprovided']);
 $alcstart = strip_tags($_POST['alcstart']);
 $alcend = strip_tags($_POST['alcend']);
 $alcamount = strip_tags($_POST['alcamount']);
 $alctax = strip_tags($_POST['alctax']);
 $alcremarks = str_replace( $replace_str, "", $_POST['alcremarks']);

 
 if($alcalc != ''){
 $alcinsert = mysqli_query($con, "INSERT INTO `p_alc` (`al_order` ,`al_alc` ,`al_provided` ,`al_start` ,`al_end` ,`al_amnt` ,`al_tax` , `al_remarks`)
VALUES ('$ordr_unqid', '$alcalc', '$alcprovided', '$alcstart', '$alcend', '$alcamount', '$alctax', '$alcremarks')");
 } 


 $amcdomain = strip_tags($_POST['amcdomain']);
 $amc_per = strip_tags($_POST['amc_per']);
 $amcsdate = strip_tags($_POST['amcsdate']);
 $amcedate = strip_tags($_POST['amcedate']);
 $amcamount = strip_tags($_POST['amcamount']);
 

 
 if($amcdomain != ''){
 $amcinsert = mysqli_query($con, "INSERT INTO `p_amc` (`amc_order` ,`amc_domain` ,`amc_per` ,`netamount` ,`sdate` ,`edate`)
VALUES ('$ordr_unqid', '$amcdomain', '$amc_per', '$amcamount', '$amcsdate', '$amcedate')");
 } 


$smsdomain = strip_tags($_POST['smsdomain']);
$smsaccess = strip_tags($_POST['smsaccess']);
$smscount = strip_tags($_POST['smscount']);
$smsperrat = strip_tags($_POST['smsperrat']);
$smsrenewel = strip_tags($_POST['smsrenewel']);
$smsamount = strip_tags($_POST['smsamount']);
$smsserv_prov = strip_tags($_POST['smsserv_prov']);
$smsserderid = strip_tags($_POST['smsserderid']);
$smstype = strip_tags($_POST['smstype']);
$smsutility = strip_tags($_POST['smsutility']);
$smsmanaged = strip_tags($_POST['smsmanaged']);
$smsmainadm = strip_tags($_POST['smsmainadm']);
$smsmainuser = strip_tags($_POST['smsmainuser']);
$smsmainpass = strip_tags($_POST['smsmainpass']);
$smscust = strip_tags($_POST['smscust']);
$smscustuser = strip_tags($_POST['smscustuser']);
$smscustpass = strip_tags($_POST['smscustpass']);
if($smsdomain != ''){
$smsinsert = mysqli_query($con, "INSERT INTO `p_sms` (`sm_order` ,`sm_domain` ,`sm_access` ,`sm_count` ,`sm_perrate` ,`sm_renewel` ,`sm_amnt` ,
`sm_service` ,`sm_senderid` ,`sm_type` ,`sm_utility` ,`sm_managed` ,`sm_main` ,`sm_muser` ,`sm_mpass` ,`sm_user` ,`sm_uuser` ,`sm_upass`)
VALUES ('$ordr_unqid', '$smsdomain', '$smsaccess', '$smscount', '$smsperrat', '$smsrenewel', '$smsamount', '$smsserv_prov', '$smsserderid',
 '$smstype', '$smsutility', '$smsmanaged', '$smsmainadm', '$smsmainuser', '$smsmainpass', '$smscust', '$smscustuser', '$smscustpass')");
}

$emdomain = strip_tags($_POST['emdomain']);
$emservice = strip_tags($_POST['emservice']);
$emcount = strip_tags($_POST['emcount']);
$emcost = strip_tags($_POST['emcost']);
$emtax = strip_tags($_POST['emtax']);
$emexpiry = strip_tags($_POST['emexpiry']);
$emtype = strip_tags($_POST['emtype']);
$emrenewel = strip_tags($_POST['emrenewel']);
$emmanaged = strip_tags($_POST['emmanaged']);
$emdetails = str_replace( $replace_str, "", $_POST['emdetails']);
if($emdomain != ''){
$eminsert = mysqli_query($con, "INSERT INTO `p_email` (`em_orderid` ,`em_domain` ,`em_service` ,`em_noemail` ,`em_cost` ,`em_tax` ,`em_expiry` ,
`em_type` ,`em_renewel` ,`em_managed` ,`em_details`)
VALUES ('$ordr_unqid', '$emdomain', '$emservice', '$emcount', '$emcost', '$emtax', '$emexpiry', '$emtype', '$emrenewel', '$emmanaged', '$emdetails')");
}

$seodomain = strip_tags($_POST['seodomain']);
$seosergment = strip_tags($_POST['seosergment']);
$seoresult1 = strip_tags($_POST['seoresult1']);
$seoresult2 = strip_tags($_POST['seoresult2']);
$seoresult3 = strip_tags($_POST['seoresult3']);
$seoengine = strip_tags($_POST['seoengine']);
$seoamount = strip_tags($_POST['seoamount']);
$seokeyword = str_replace( $replace_str, "", $_POST['seokeyword']);
if($seodomain != ''){
	$seoinsert = mysqli_query($con, "INSERT INTO `p_seo` (`se_order` ,`se_domain` ,`se_segment` ,`se_rank1` ,`se_rank2` ,`se_rank3` ,`se_engine` ,
`se_amount` ,`se_keywords`)
VALUES ('$ordr_unqid', '$seodomain', '$seosergment', '$seoresult1', '$seoresult2', '$seoresult3', '$seoengine', '$seoamount', '$seokeyword')");
}

   $custsmssent = $_POST['custsmssent'];
   if($custsmssent == '1'){
     $dat = date('Y-m-d');
	 $tim = date("h:i a");
	 $ipp = $_SERVER['REMOTE_ADDR'];
     $cmobile = $cmob;
	 $message = urlencode("Greetings From Programers, Your Order No.#$ordr_unqid has been Processed Successfully, Thank you,9447151442 ");
	 $pushid = @file_get_contents("http://programerssms.com/rest/services/sendSMS/sendGroupSms?AUTH_KEY=e57023ed682d83a41d25acb650c877da&message=$message&senderId=PROGRA&routeId=1&mobileNos=$cmobile&smsContentType=english ");

	 
	 $sq1 = mysqli_query($con, "INSERT INTO `p_sms_history` (`sm_cust`,`sm_mob` ,`sm_sms` ,`sm_date` ,`sm_time` ,`sm_ip`)
     VALUES ('$cname','$cmob', 'ORDER CREATED', '$dat', '$tim', '$ipp')");

   }
	
}








/* ----------- Edit New Orders ------------------- */
if(isset($_POST['edit_new_orders'])){
	
$replace_str = array("`", "'");
$ocompny   = strip_tags($_POST['ocompny']);
$rbranch   = strip_tags($_POST['rbranch']);
$orderty   = strip_tags($_POST['orderty']);
$ocustomer = strip_tags($_POST['ocustomer']);
$ordramnt  = strip_tags($_POST['ordramnt']);
$ordate    = strip_tags($_POST['ordate']);
$compltdate = strip_tags($_POST['compltdate']);
$disamount = strip_tags($_POST['disamount']);
$netamount = strip_tags($_POST['netamount']);
$bill_head = str_replace( $replace_str, "", $_POST['bill_head']);
$ordertax  = strip_tags($_POST['ordertax']);
$orderbdo  = strip_tags($_POST['orderbdo']);
$hidvall   = strip_tags($_POST['hidvall']);
$total   = strip_tags($_POST['total']);

$order_status = strip_tags($_POST['order_status']);


$up1 = mysqli_query($con, "UPDATE `p_orders` SET `ocomp` = '$ocompny',`obranch` = '$rbranch',`ordr_type` = '$orderty',
`ocustm` = '$ocustomer',`ordr_amt` = '$ordramnt',`dis_amnt` = '$disamount',`net_amnt` = '$netamount',
`ordr_date` = '$ordate',`compl_date` = '$compltdate', `or_tax`='$ordertax', `or_bdo`='$orderbdo', `ostatus`='$order_status', `bill_head`='$bill_head', `total_amnt`='$total' WHERE `order_id` ='$hidvall'");

$ddomain = strip_tags($_POST['ddomain']);
$downer = strip_tags($_POST['downer']);
$dprovider = strip_tags($_POST['dprovider']);
$dregdate = strip_tags($_POST['dregdate']);
$drenewel = strip_tags($_POST['drenewel']);
$dintimatn = strip_tags($_POST['dintimatn']);
$damount = strip_tags($_POST['damount']);
$dtax = strip_tags($_POST['dtax']);
$dredirectn = strip_tags($_POST['dredirectn']);
$duser = strip_tags($_POST['duser']);
$dpass = strip_tags($_POST['dpass']);
$daccess = strip_tags($_POST['daccess']);
$dremarks = str_replace( $replace_str, "", $_POST['dremarks']);
$dom_credentl = strip_tags($_POST['dom_credentl']);

$sel = mysqli_query($con, "SELECT * FROM `p_domain` WHERE `dorder`='$hidvall' ");
$count1 = mysqli_num_rows($sel);
if($ddomain != ''){
if($count1 != '0'){
	
$up2 = mysqli_query($con, "UPDATE `p_domain` SET `d_domain` = '$ddomain',`d_owner` = '$downer',`d_provider` = '$dprovider',
`d_regdate` = '$dregdate',`d_renewel` = '$drenewel',`d_expdate` = '$dintimatn',`d_amnt` = '$damount',
`d_tax` = '$dtax',`d_redirectn` = '$dredirectn',`d_user` = '$duser',`d_pass` = '$dpass',
`d_access` = '$daccess', `d_credential`='$dom_credentl',`d_remarks` = '$dremarks' WHERE `dorder` = '$hidvall'");

	
} else {
	
$ins2 = mysqli_query($con, "INSERT INTO `p_domain` (`dorder` ,`d_domain` ,`d_owner` ,`d_provider` ,`d_regdate` ,`d_renewel` ,`d_expdate` ,
`d_amnt` ,`d_tax` ,`d_redirectn` ,`d_user` ,`d_pass` ,`d_access` , `d_credential`,`d_remarks`)
VALUES ('$hidvall', '$ddomain', '$downer', '$dprovider', '$dregdate', '$drenewel', '$dintimatn', '$damount', '$dtax', '$dredirectn',
 '$duser', '$dpass', '$daccess', '$dom_credentl', '$dremarks')");
} }

 $sercomp    = strip_tags($_POST['sercomp']);
 $opertsystm = strip_tags($_POST['opertsystm']);
 $servalc    = strip_tags($_POST['servalc']);
 $srstartdat = strip_tags($_POST['srstartdat']);
 $srenddate  = strip_tags($_POST['srenddate']);
 $sramount   = strip_tags($_POST['sramount']);
 $srtax      = strip_tags($_POST['srtax']);
 $srremarks  = str_replace( $replace_str, "", $_POST['srremarks']);
 $srowner    = strip_tags($_POST['srowner']);
 $sr_credentl = strip_tags($_POST['sr_credentl']);
 $srspace = $_POST['srspace'];
 
 $sel2 = mysqli_query($con, "SELECT * FROM `p_server` WHERE `s_order`='$hidvall' ");
 $count2 = mysqli_num_rows($sel2);
 if($sercomp != ''){
 if($count2 != '0'){
 	$up3 = mysqli_query($con, "UPDATE `p_server` SET `s_comp` = '$sercomp',
`s_os` = '$opertsystm',`s_alc` = '$servalc',`s_start` = '$srstartdat',`s_end` = '$srenddate',
`s_amnt` = '$sramount',`s_tax` = '$srtax', `s_owner`='$srowner', `s_credential`='$sr_credentl' , `s_remarks` = '$srremarks', `s_space`='$srspace' WHERE `s_order` = '$hidvall'");
 	 

 } else {
 	$ins3 = mysqli_query($con, "INSERT INTO `p_server` (`s_order` ,`s_comp` ,`s_os` ,`s_alc` ,`s_start` ,`s_end` ,`s_amnt` ,`s_tax` ,`s_owner`,`s_credential`,`s_remarks`,`s_space`)
VALUES ('$hidvall', '$sercomp', '$opertsystm', '$servalc', '$srstartdat', '$srenddate', '$sramount', '$srtax', '$srowner','$sr_credentl', '$srremarks','$srspace')"); 
 } }
 
  $amcdomain = strip_tags($_POST['amcdomain']);
 $amc_per = strip_tags($_POST['amc_per']);
 $amcsdate = strip_tags($_POST['amcsdate']);
 $amcedate = strip_tags($_POST['amcedate']);
 $amcamount = strip_tags($_POST['amcamount']);

$sel9 = mysqli_query($con, "SELECT * FROM `p_amc` WHERE `amc_order`='$hidvall' ");
 $count9 = mysqli_num_rows($sel9);
 if($amcdomain != ''){
 if($count9 != '0'){
  	$up9 = mysqli_query($con, "UPDATE `p_amc` SET `amc_domain` = '$amcdomain',`amc_per` = '$amc_per',`netamount` = '$amcamount',
`sdate` = '$amcsdate',`edate` = '$amcedate' WHERE `amc_order` = '$hidvall' ");	
  } else {
   $amcinsert = mysqli_query($con, "INSERT INTO `p_amc` (`amc_order` ,`amc_domain` ,`amc_per` ,`netamount` ,`sdate` ,`edate`)
VALUES ('$ordr_unqid', '$amcdomain', '$amc_per', '$amcamount', '$amcsdate', '$amcedate')");	
  }	
 } 

 $alcalc      = strip_tags($_POST['alcalc']);
 $alcprovided = strip_tags($_POST['alcprovided']);
 $alcstart    = strip_tags($_POST['alcstart']);
 $alcend      = strip_tags($_POST['alcend']);
 $alcamount   = strip_tags($_POST['alcamount']);
 $alctax      = strip_tags($_POST['alctax']);
 $alcremarks  = str_replace( $replace_str, "", $_POST['alcremarks']);
 
 $sel3 = mysqli_query($con, "SELECT * FROM `p_alc` WHERE `al_order`='$hidvall' ");
 $count3 = mysqli_num_rows($sel3);
 if($alcalc != ''){
 if($count3 != '0'){
  	$up4 = mysqli_query($con, "UPDATE `p_alc` SET `al_alc` = '$alcalc',`al_provided` = '$alcprovided',`al_start` = '$alcstart',
`al_end` = '$alcend',`al_amnt` = '$alcamount',`al_tax` = '$alctax',`al_remarks` = '$alcremarks' WHERE `al_order` = '$hidvall' ");	
  } else {
   $alcinsert = mysqli_query($con, "INSERT INTO `p_alc` (`al_order` ,`al_alc` ,`al_provided` ,`al_start` ,`al_end` ,`al_amnt` ,`al_tax` ,`al_remarks`)
VALUES ('$hidvall', '$alcalc', '$alcprovided', '$alcstart', '$alcend', '$alcamount', '$alctax', '$alcremarks')");	
  }	
 }
 
 
 $smsdomain  = strip_tags($_POST['smsdomain']);
$smsaccess   = strip_tags($_POST['smsaccess']);
$smscount    = strip_tags($_POST['smscount']);
$smsperrat   = strip_tags($_POST['smsperrat']);
$smsrenewel  = strip_tags($_POST['smsrenewel']);
$smsamount   = strip_tags($_POST['smsamount']);
$smsserv_prov = strip_tags($_POST['smsserv_prov']);
$smsserderid = strip_tags($_POST['smsserderid']);
$smstype = strip_tags($_POST['smstype']);
$smsutility = strip_tags($_POST['smsutility']);
$smsmanaged = strip_tags($_POST['smsmanaged']);
$smsmainadm = strip_tags($_POST['smsmainadm']);
$smsmainuser = strip_tags($_POST['smsmainuser']);
$smsmainpass = strip_tags($_POST['smsmainpass']);
$smscust = strip_tags($_POST['smscust']);
$smscustuser = strip_tags($_POST['smscustuser']);
$smscustpass = strip_tags($_POST['smscustpass']);
$sel4 = mysqli_query($con, "SELECT * FROM `p_sms` WHERE `sm_order`='$hidvall' ");
$count4 = mysqli_num_rows($sel4);
if($smsdomain != ''){
 if($count4 != '0')	{
 	$up5 = mysqli_query($con, "UPDATE `p_sms` SET 
`sm_domain` = '$smsdomain',`sm_access` = '$smsaccess',`sm_count` = '$smscount',`sm_perrate` = '$smsperrat',
`sm_renewel` = '$smsrenewel',`sm_amnt` = '$smsamount',`sm_service` = '$smsserv_prov',`sm_senderid` = '$smsserderid',
`sm_type` = '$smstype',`sm_utility` = '$smsutility',`sm_managed` = '$smsmanaged',`sm_main` = '$smsmainadm',
`sm_muser` = '$smsmainuser',`sm_mpass` = '$smsmainpass',`sm_user` = '$smscust',`sm_uuser` = '$smscustuser',`sm_upass` = '$smscustpass' WHERE `sm_order` = '$hidvall'");
 } else {
 	$smsinsert = mysqli_query($con, "INSERT INTO `p_sms` (`sm_order` ,`sm_domain` ,`sm_access` ,`sm_count` ,`sm_perrate` ,`sm_renewel` ,`sm_amnt` ,
`sm_service` ,`sm_senderid` ,`sm_type` ,`sm_utility` ,`sm_managed` ,`sm_main` ,`sm_muser` ,`sm_mpass` ,`sm_user` ,`sm_uuser` ,`sm_upass`)
VALUES ('$hidvall', '$smsdomain', '$smsaccess', '$smscount', '$smsperrat', '$smsrenewel', '$smsamount', '$smsserv_prov', '$smsserderid',
 '$smstype', '$smsutility', '$smsmanaged', '$smsmainadm', '$smsmainuser', '$smsmainpass', '$smscust', '$smscustuser', '$smscustpass')");
 }
}


$emdomain = strip_tags($_POST['emdomain']);
$emservice = strip_tags($_POST['emservice']);
$emcount = strip_tags($_POST['emcount']);
$emcost = strip_tags($_POST['emcost']);
$emtax = strip_tags($_POST['emtax']);
$emexpiry = strip_tags($_POST['emexpiry']);
$emtype = strip_tags($_POST['emtype']);
$emrenewel = strip_tags($_POST['emrenewel']);
$emmanaged = strip_tags($_POST['emmanaged']);
$emdetails = str_replace( $replace_str, "", $_POST['emdetails']);
$sel5 = mysqli_query($con, "SELECT * FROM `p_email` WHERE `em_orderid`='$hidvall' ");
$count5 = mysqli_num_rows($sel5);
if($emdomain != ''){
   if($count5 != '0'){
   	$up6 = mysqli_query($con, "UPDATE `p_email` SET `em_domain` = '$emdomain',`em_service` = '$emservice',`em_noemail` = '$emcount',
   	`em_cost` = '$emcost',`em_tax` = '$emtax',`em_expiry` = '$emexpiry',`em_type` = '$emtype',`em_renewel` = '$emrenewel',`em_managed` = '$emmanaged',
`em_details` = '$emdetails' WHERE `em_orderid` ='$hidvall'");	
   	} else {
   	$eminsert = mysqli_query($con, "INSERT INTO `p_email` (`em_orderid` ,`em_domain` ,`em_service` ,`em_noemail` ,`em_cost` ,`em_tax` ,`em_expiry` ,
`em_type` ,`em_renewel` ,`em_managed` ,`em_details`)
VALUES ('$hidvall', '$emdomain', '$emservice', '$emcount', '$emcost', '$emtax', '$emexpiry', '$emtype', '$emrenewel', '$emmanaged', '$emdetails')");	
   	}	
 }

$seodomain   = strip_tags($_POST['seodomain']);
$seosergment = strip_tags($_POST['seosergment']);
$seoresult1  = strip_tags($_POST['seoresult1']);
$seoresult2  = strip_tags($_POST['seoresult2']);
$seoresult3  = strip_tags($_POST['seoresult3']);
$seoengine   = strip_tags($_POST['seoengine']);
$seoamount   = strip_tags($_POST['seoamount']);
$seokeyword  = str_replace( $replace_str, "", $_POST['seokeyword']);
$sel6 = mysqli_query($con, "SELECT * FROM `p_seo` WHERE `se_order`='$hidvall' ");
$count6 = mysqli_num_rows($sel6);
if($seodomain != ''){
  if($count6 != '0'){
  	$up7 = mysqli_query($con, "UPDATE `p_seo` SET `se_domain` = '$seodomain',
`se_segment` = '$seosergment',`se_rank1` = '$seoresult1',`se_rank2` = '$seoresult2',`se_rank3` = '$seoresult3',
`se_engine` = '$seoengine',`se_amount` = '$seoamount',`se_keywords` = '$seokeyword' WHERE `se_order` ='$hidvall'");
  }	else {
  	$seoinsert = mysqli_query($con, "INSERT INTO `p_seo` (`se_order` ,`se_domain` ,`se_segment` ,`se_rank1` ,`se_rank2` ,`se_rank3` ,`se_engine` ,
`se_amount` ,`se_keywords`)
VALUES ('$hidvall', '$seodomain', '$seosergment', '$seoresult1', '$seoresult2', '$seoresult3', '$seoengine', '$seoamount', '$seokeyword')");
  }
}

}



/* ----------- Add New Account Head --------------- */
if(isset($_POST['add_new_main_cat']))
{

$maincat = strip_tags($_POST['maincat']);
$mainstatus = strip_tags($_POST['mainstatus']);	
	
$insert = mysqli_query($con, "INSERT INTO `p_accnt_head` (`ma_cat` ,`ma_status`) VALUES ('$maincat', '$mainstatus')");
	
}
/* ---------- Edit Account Head --------- */

if(isset($_POST['edit_new_main_cat'])){
    $maincat = strip_tags($_POST['maincat']);
    $mainstatus = strip_tags($_POST['mainstatus']);	
    $hidcat = strip_tags($_POST['hidcat']);

    $upaccnt = mysqli_query($con,"UPDATE `p_accnt_head` SET `ma_cat` = '$maincat',`ma_status` = '$mainstatus' WHERE `mid` = '$hidcat'");  		
}
/* ---------------- Delete Main Category -------- */
if(isset($_POST['btn_delete_macat'])){

    $id = strip_tags(base64_decode($_POST['id']));
	$sqdel = mysqli_query($con, "DELETE FROM `p_accnt_head` WHERE `mid` = '$id'");		
	
}

/* --------- Add New Sub Category ------------ */

if(isset($_POST['add_new_sub_cat'])){
	
	$submain = strip_tags($_POST['submain']);
	$subcat = strip_tags($_POST['subcat']);
	$substatus = strip_tags($_POST['substatus']);
	
	$insertsub = mysqli_query($con, "INSERT INTO `p_sub_head` (`main_id` ,`sub_cat` ,`sub_status`) VALUES ('$submain', '$subcat', '$substatus')");
	
}

/* ------ Edit Sub Category --------- */

if(isset($_POST['edit_new_sub_cat'])){
	
	$submain = strip_tags($_POST['submain']);
	$subcat = strip_tags($_POST['subcat']);
	$substatus = strip_tags($_POST['substatus']);
	$hiddsubcat = strip_tags($_POST['hiddsubcat']);
	$upsubcat = mysqli_query($con, "UPDATE `p_sub_head` SET `main_id` = '$submain',`sub_cat` = '$subcat',`sub_status` = '$substatus' WHERE `sid` = '$hiddsubcat'");
}

/* ---------- Delete Sub Category -------- */

if(isset($_POST['btn_delete_subcat'])){
	
    $id = strip_tags(base64_decode($_POST['id']));
	$sqdel = mysqli_query($con, "DELETE FROM `p_sub_head` WHERE `sid` = '$id'");		
}

/* --------- Add Second Sub Category ------------ */

if(isset($_POST['add_new_subsub_cat'])){
		
	$ssubmain = strip_tags($_POST['ssubmain']);
	$ssubsub = strip_tags($_POST['ssubsub']);
	$subsubcat = strip_tags($_POST['subsubcat']);
	$subsubstatus = strip_tags($_POST['subsubstatus']);
	
	$insert3 = mysqli_query($con,"INSERT INTO `p_sub_head2` (`sbmain` ,`sbsub` ,`secndsub` ,`sb_status`) VALUES ('$ssubmain', '$ssubsub', '$subsubcat', '$subsubstatus')");
}


/* ------ Edit Sub Category  ------ */

if(isset($_POST['edit_new_subsub_cat'])){
	$ssubmain = strip_tags($_POST['ssubmain']);
	$ssubsub = strip_tags($_POST['ssubsub']);
	$subsubcat = strip_tags($_POST['subsubcat']);
	$subsubstatus = strip_tags($_POST['subsubstatus']);
	$hiddsubsub = strip_tags($_POST['hiddsubsub']);
	
	$upp = mysqli_query($con, "UPDATE `p_sub_head2` SET `sbmain` = '$ssubmain',
`sbsub` = '$ssubsub',`secndsub` = '$subsubcat',`sb_status` = '$subsubstatus' WHERE `sbid` ='$hiddsubsub'");
}

/* ---------- Delete Second Sub Category ------ */

if(isset($_POST['btn_del_subsubcat'])){
	
	$id = strip_tags(base64_decode($_POST['id']));
	$sqdel = mysqli_query($con, "DELETE FROM `p_sub_head2` WHERE `sbid` = '$id'");	
}











/* ------------  MAin Category Change --------  */

if(isset($_GET['main_idd']))
{
 $main_idd = strip_tags($_GET['main_idd']); ?>
	<option value="">Sub Category</option>
<?php	 
$bran = mysqli_query($con, "SELECT * FROM `p_sub_head` WHERE `main_id`='$main_idd' ");
while($result = mysqli_fetch_assoc($bran)){ ?>
	<option value="<?php echo $result['sid']; ?>"><?php echo $result['sub_cat']; ?></option>	
<?php }	
}


/* -------- Customers Orders ----------------- */

if(isset($_GET['cust_idd'])){

  $cust_idd = $_GET['cust_idd']; ?>
  <option value="">Orders</option>
  <?php	 
    $bran = mysqli_query($con, "SELECT * FROM `p_orders` WHERE `ocustm`='$cust_idd' ");
    while($result = mysqli_fetch_assoc($bran)){ ?>
	     <option value="<?php echo $result['order_id']; ?>"><?php echo $result['ordr_type']."-".$result['order_id']; ?></option>	
  <?php }
}




/*---------- Order Amount Auto Change -----*/

if(isset($_GET['order_amnt_auto'])){
$order_amnt_auto = $_GET['order_amnt_auto'];
		
$sqry = mysqli_query($con, "SELECT * FROM `p_orders` WHERE `order_id`='$order_amnt_auto' ");	
$sres = mysqli_fetch_array($sqry);
?>
<div class="col-md-2"  style=" padding-left: 2px; padding-right: 0px; ">			
<div class="form-group">
     <input name="ramount" id="ramount" class="form-control" placeholder="Amount" value="<?php echo $sres['ordr_amt']; ?>" >
</div></div>


<div class="col-md-2" >					
<div class="form-group">
    <input name="rdiscount" id="rdiscount" class="form-control" placeholder="Discount Amount" value="<?php echo $sres['dis_amnt']; ?>" >
</div></div>


<div class="col-md-2" >					
<div class="form-group">
    <input name="rnet" id="rnet" class="form-control" placeholder="Net Amount" value="<?php echo $sres['net_amnt']; ?>" >
</div></div>
	
<?php }


/* ----------- Vender Purchase No. ------- */

if(isset($_GET['vendr_idd'])){
$vendid = $_GET['vendr_idd']; ?>
<option value="">Purchase No.</option>
<?php	 
$bran = mysqli_query($con, "SELECT * FROM `p_purchase` WHERE `p_vendor`='$vendid' ");
while($result = mysqli_fetch_assoc($bran)){ ?>
	<option value="<?php echo $result['pid']; ?>"><?php echo $result['p_identity']; ?></option>	
<?php }		
		
}


/* ----------- Add New Receipts ------------- */

if(isset($_POST['add_new_receipts'])){

$replace_str = array("`", "'");		
$rcompany  = strip_tags($_POST['rcompany']);
$rbranch   = strip_tags($_POST['rbranch']);
$rcust     = strip_tags($_POST['rcust']);			
$recorders = strip_tags($_POST['recorders']);
$ramnt_type = strip_tags($_POST['ramnt_type']);
$ramount   = strip_tags($_POST['ramount']);
$rcheque   = strip_tags($_POST['rcheque']);
$rbank     = strip_tags($_POST['rbank']);
$rdate     = strip_tags($_POST['rdate']);
$rremarks  = str_replace( $replace_str, "", $_POST['rremarks']);

   $date = date('Y-m-d');

    $sqcus = mysqli_query($con, "SELECT cname,cmob FROM `p_customers` WHERE `cid`='$rcust' "); 
	$rscus = mysqli_fetch_array($sqcus);
	$cname = $rscus['cname'];
	$cmob = $rscus['cmob']; 

$sq = mysqli_query($con,"SELECT MAX(`rid`) AS mxidntty FROM `p_receipts` ");
$row = mysqli_fetch_assoc($sq);
$rec_no = $row['mxidntty']+1;

$binsert = mysqli_query($con,"INSERT INTO `p_receipts` (`ridentity` ,`rcomp` ,`rbran` ,`rcust` ,`rorder` ,`ramnt_type` ,`ramount` ,`rcheque` ,
`rbank` ,`rcheq_date` ,`rremarks` ,`rdate`)
VALUES ( '$rec_no', '$rcompany', '$rbranch', '$rcust', '$recorders', '$ramnt_type', '$ramount', '$rcheque', '$rbank', '$rdate', '$rremarks', '$date')");

	$custsmssent = $_POST['custsmssent'];
	if($custsmssent != '0'){
	 	
	 $dat = date('Y-m-d');
	 $tim = date("h:i a");
	 $ipp = $_SERVER['REMOTE_ADDR'];
     $cmobile = $cmob;
	 $message = urlencode("Thank you for Receiving Your Payment. Your Receipt No. #$rec_no ");
	 $pushid = @file_get_contents("http://programerssms.com/rest/services/sendSMS/sendGroupSms?AUTH_KEY=e57023ed682d83a41d25acb650c877da&message=$message&senderId=PROGRA&routeId=1&mobileNos=$cmobile&smsContentType=english ");
	 
	 $sq1 = mysqli_query($con, "INSERT INTO `p_sms_history` (`sm_cust`,`sm_mob` ,`sm_sms` ,`sm_date` ,`sm_time` ,`sm_ip`)
VALUES ('$cname','$cmob', 'INVOICE GENERATED', '$dat', '$tim', '$ipp')");
			
		
	}
	
}

/* --------- Add New Voucher ---------- */

if(isset($_POST['add_new_voucher'])){

$rcompany = strip_tags($_POST['rcompany']);
$rbranch = strip_tags($_POST['rbranch']);
$vvendr = strip_tags($_POST['vvendr']);			
$purch_num = strip_tags($_POST['purch_num']);
$ramnt_type = strip_tags($_POST['ramnt_type']);
$vamount = strip_tags($_POST['vamount']);
$rcheque = strip_tags($_POST['rcheque']);
$rbank = strip_tags($_POST['rbank']);
$rdate = strip_tags($_POST['rdate']);
$vremarks = strip_tags($_POST['vremarks']);

$vaccounth = strip_tags($_POST['vaccounth']);
$vsubhead1 = strip_tags($_POST['vsubhead1']);
$vsubhead2 = strip_tags($_POST['vsubhead2']);

$date = date('Y-m-d');

$sq = mysqli_query($con,"SELECT MAX(`vid`) AS mxidntty FROM `p_voucher` ");
$row = mysqli_fetch_assoc($sq);
$vouchr_no = $row['mxidntty']+1;

$vinsert = mysqli_query($con,"INSERT INTO `p_voucher` (`videntity` ,`vcomp` ,`vbranch` , `vaccnt_head1`,`vaccnt_head2`,`vaccnt_head3` ,`vvendr` ,`vpurch_no` ,`vamnt_type` ,`vamnt` ,`vcheque` ,
`vbank` ,`vcheq_date` ,`vremarks` ,`vdate`)
VALUES ( '$vouchr_no', '$rcompany', '$rbranch', '$vaccounth', '$vsubhead1', '$vsubhead2', '$vvendr', '$purch_num', '$ramnt_type', '$vamount', '$rcheque', '$rbank', '$rdate', '$vremarks', '$date')");

		
	
}

/* ------ Update Voucher ----- */

if(isset($_POST['update_new_voucher'])){

$replace_str = array("`", "'");		
$rcompany = strip_tags($_POST['rcompany']);
$rbranch = strip_tags($_POST['rbranch']);
$vvendr = strip_tags($_POST['vvendr']);			
$purch_num = strip_tags($_POST['purch_num']);
$ramnt_type = strip_tags($_POST['ramnt_type']);
$vamount = strip_tags($_POST['vamount']);
$rcheque = strip_tags($_POST['rcheque']);
$rbank = strip_tags($_POST['rbank']);
$rdate = strip_tags($_POST['rdate']);
$vremarks = str_replace( $replace_str, "", $_POST['vremarks']); 

$vaccounth = strip_tags($_POST['vaccounth']);
$vsubhead1 = strip_tags($_POST['vsubhead1']);
$vsubhead2 = strip_tags($_POST['vsubhead2']);
$hidvall = strip_tags($_POST['hidvall']);
$upp = mysqli_query($con,"UPDATE `p_voucher` SET `vcomp` = '$rcompany',
 `vbranch` = '$rbranch',`vaccnt_head1` = '$vaccounth',`vaccnt_head2` = '$vsubhead1',`vaccnt_head3` = '$vsubhead2',
 `vvendr` = '$vvendr',`vpurch_no` = '$purch_num',`vamnt_type` = '$ramnt_type',`vamnt` = '$vamount',
 `vcheque` = '$rcheque',`vbank` = '$rbank',`vcheq_date` = '$rdate',`vremarks` = '$vremarks' WHERE `vid` ='$hidvall'"); 

}


if(isset($_POST['account_subhead'])){
	 ?>
	
 <div class="col-md-2" style="padding-left: 2px; padding-right: 0px;">					
  <div class="form-group">
	<select class="form-control" id="vsubhead1" name="vsubhead1" onchange="sub_head(this.value);">
		<option value="" disabled selected="selected">Sub Head</option>
	<?php
	$account_idd = $_POST['type'];
	$accselect = mysqli_query($con, "SELECT * FROM `p_sub_head` WHERE `main_id`='$account_idd' ");
	while($resacc = mysqli_fetch_array($accselect)) {  ?>
	  <option value="<?php echo $resacc['sid']; ?>"><?php echo $resacc['sub_cat']; ?></option>	
	<?php } ?>	
	</select>
 </div></div>
 	
<?php }


if(isset($_POST['account_subhead2']))
{
	$account_idd = $_POST['type2'];
	$accselect = mysqli_query($con, "SELECT * FROM `p_sub_head2` WHERE `sbsub`='$account_idd' ");
	$rwcount = mysqli_num_rows($accselect);
	if($rwcount != 0){
?>	
<div class="col-md-3" style="padding-left: 2px; padding-right: 0px;">					
  <div class="form-group">
	<select class="form-control" id="vsubhead2" name="vsubhead2">
		<option value="" disabled selected="selected">Sub Head</option>
	<?php
	
	while($resacc = mysqli_fetch_array($accselect)) {  ?>
	  <option value="<?php echo $resacc['sbid']; ?>"><?php echo $resacc['secndsub']; ?></option>	
	<?php } ?>	
	</select>
 </div></div>
	
<?php 
}
}



/* ---------- Purchase Register ---------  */

if(isset($_POST['purchase_register'])){
	
	$replace_str = array("`", "'");
	$rcompany  = strip_tags($_POST['rcompany']);
	$rbranch   = strip_tags($_POST['rbranch']);
	$billno    = strip_tags($_POST['billno']);
	$purchs_date = strip_tags($_POST['purchs_date']);
	$accnt_name  = strip_tags($_POST['accnt_name']);
	$prodnam     = str_replace( $replace_str, "", $_POST['prodnam']);
	$vvendr      = strip_tags($_POST['vvendr']);
	$pamount     = strip_tags($_POST['pamount']);
	$pdiscount   = strip_tags($_POST['pdiscount']);
	$pnet        = strip_tags($_POST['pnet']);
	$pdescrptn   = str_replace( $replace_str, "", $_POST['pdescrptn']);
		
	$dat = date('Y-m-d');
	$pageaddress=$_SERVER['HTTP_REFERER'];
    $allowedExts = array("png","JPEG","jpg","jpeg");
	
	 if($_FILES["image"]["name"] != '') {
				    $temp = explode(".", $_FILES["image"]["name"]);
				    $extension = end($temp);
				    if(!in_array($extension, $allowedExts)){
				     echo '<script type="text/javascript">alert("File Format does not Support");window.location.href="' . $pageaddress . '";</script>';
	                 exit();
				     }
				     $file_info = getimagesize($_FILES["image"]["tmp_name"]);
	                 if(empty($file_info)) // No Image?
	                 {	
	                 echo '<script type="text/javascript">alert("File Format does not Support");window.location.href="' . $pageaddress . '";</script>';
	                 exit();
	                 }
					 if($_FILES["image"]["size"] > 1806814) { 
				     echo '<script type="text/javascript">alert("File Format does not Support");window.location.href="' . $pageaddress . '";</script>';
	                 exit();
				     }
					 $rand=md5(uniqid());
				     $extension = explode('.', $_FILES['image']['name']);
				     $extension = $extension[count($extension)-1];
				     $photo = $rand . '.' . $extension;
				     $tmp_photo = $_FILES['image']['tmp_name'];
	                 move_uploaded_file($tmp_photo, 'Bill/'.$photo);
		 }	
		 
$sq = mysqli_query($con,"SELECT MAX(`pid`) AS mxidntty FROM `p_purchase` ");
$row = mysqli_fetch_assoc($sq);
$purch_no = $row['mxidntty']+1;
		
	$sqq = mysqli_query($con, "INSERT INTO `p_purchase` (`p_identity` ,`p_vendor` ,`p_comp` ,`p_bran` ,`p_billno` ,`p_purdat` ,`p_acount` ,
	`prod_nam` ,`p_amnt` ,`p_discnt` ,`p_netamnt` ,`p_descre` ,`p_bill` ,`p_dat`)
VALUES ('$purch_no', '$vvendr', '$rcompany', '$rbranch', '$billno', '$purchs_date', '$accnt_name', '$prodnam', 
'$pamount', '$pdiscount', '$pnet', '$pdescrptn', '$photo', '$dat')");	 
		 
}

/* ------------- Delete Purchase --------- */

if(isset($_POST['btn_delete_purchase'])){
	$id = strip_tags(base64_decode($_POST['id']));
	$sqdel = mysqli_query($con, "DELETE FROM `p_purchase` WHERE `pid` = '$id'");
}

/* ---------- edit Purchase ----------- */

if(isset($_POST['purchase_register_edit'])){
	
	$rcompany = strip_tags($_POST['rcompany']);
	$rbranch = strip_tags($_POST['rbranch']);
	$billno = strip_tags($_POST['billno']);
	$purchs_date = strip_tags($_POST['purchs_date']);
	$accnt_name = strip_tags($_POST['accnt_name']);
	$prodnam = strip_tags($_POST['prodnam']);
	$vvendr = strip_tags($_POST['vvendr']);
	$pamount = strip_tags($_POST['pamount']);
	$pdiscount = strip_tags($_POST['pdiscount']);
	$pnet = strip_tags($_POST['pnet']);
	$pdescrptn = strip_tags($_POST['pdescrptn']);
	$hidvall = strip_tags($_POST['hidvall']);
			
	$dat = date('Y-m-d');
	$pageaddress=$_SERVER['HTTP_REFERER'];
    $allowedExts = array("png","JPEG","jpg","jpeg");
	
	 if($_FILES["image"]["name"] != '') {
				    $temp = explode(".", $_FILES["image"]["name"]);
				    $extension = end($temp);
				    if(!in_array($extension, $allowedExts)){
				     echo '<script type="text/javascript">alert("File Format does not Support");window.location.href="' . $pageaddress . '";</script>';
	                 exit();
				     }
				     $file_info = getimagesize($_FILES["image"]["tmp_name"]);
	                 if(empty($file_info)) // No Image?
	                 {	
	                 echo '<script type="text/javascript">alert("File Format does not Support");window.location.href="' . $pageaddress . '";</script>';
	                 exit();
	                 }
					 if($_FILES["image"]["size"] > 1806814) { 
				     echo '<script type="text/javascript">alert("File Format does not Support");window.location.href="' . $pageaddress . '";</script>';
	                 exit();
				     }
					 $rand=md5(uniqid());
				     $extension = explode('.', $_FILES['image']['name']);
				     $extension = $extension[count($extension)-1];
				     $photo = $rand . '.' . $extension;
				     $tmp_photo = $_FILES['image']['tmp_name'];
	                 move_uploaded_file($tmp_photo, 'Bill/'.$photo);
	                $imag =", `p_bill` = '$photo' "; 
		 } else {
		 	        $imag ="";
		 }
		 
		$upp = mysqli_query($con, "UPDATE `p_purchase` SET `p_vendor` = '$vvendr',
`p_comp` = '$rcompany',`p_bran` = '$rbranch', `p_billno` = '$billno',`p_purdat` = '$purchs_date',
`p_acount` = '$accnt_name',`prod_nam` = '$prodnam', `p_amnt` = '$pamount',`p_discnt` = '$pdiscount',
`p_netamnt` = '$pnet',`p_descre` = '$pdescrptn'
 $imag WHERE `pid` = '$hidvall'");
		 
}


/* -------- Delete Voucher ---------- */

if(isset($_POST['btn_delete_voucher'])) {
			
	$id = strip_tags(base64_decode($_POST['id']));
	$sqdel = mysqli_query($con, "DELETE FROM `p_voucher` WHERE `vid` = '$id'");
	
}

/* ----------- Delete Receipt ---------- */

if(isset($_POST['btn_delete_receipt'])){
	
	$id = strip_tags(base64_decode($_POST['id']));
	$sqdel = mysqli_query($con, "DELETE FROM `p_receipts` WHERE `rid` = '$id'");
}

/* --------- Update Receipts ----------- */

if(isset($_POST['edit_new_receipts'])){
	
	$replace_str = array("`", "'");
	$rcompany  = strip_tags($_POST['rcompany']);
	$rbranch   = strip_tags($_POST['rbranch']);
	$rcust     = strip_tags($_POST['rcust']);
	$recorders = strip_tags($_POST['recorders']);
	$ramnt_type = strip_tags($_POST['ramnt_type']);
	$ramount   = strip_tags($_POST['ramount']);
	$rcheque   = strip_tags($_POST['rcheque']);
	$rbank     = strip_tags($_POST['rbank']);
	$rdate     = strip_tags($_POST['rdate']);
	$rremarks  = str_replace( $replace_str, "", $_POST['rremarks']);
	$hidvall   = strip_tags($_POST['hidvall']);
	
 $up = mysqli_query($con, "UPDATE `p_receipts` SET `rcomp` = '$rcompany',
`rbran` = '$rbranch',`rcust` = '$rcust',`rorder` = '$recorders',`ramnt_type` = '$ramnt_type',`ramount` = '$ramount',`rcheque` = '$rcheque',
`rbank` = '$rbank',`rcheq_date` = '$rdate',`rremarks` = '$rremarks' WHERE `rid` ='$hidvall'");	
}


/* ---------- New Sale & Billing ----  */

if(isset($_POST['add_new_billing'])){
	
	$replace_str = array("`", "'");
	$rcompany  = strip_tags($_POST['rcompany']);
	$rbranch   = strip_tags($_POST['rbranch']);
	$rcust     = strip_tags($_POST['rcust']);
	$recorders = strip_tags($_POST['recorders']);
	$ramount   = strip_tags($_POST['ramount']);
	$rdiscount = strip_tags($_POST['rdiscount']);
	$rnet      = strip_tags($_POST['rnet']);
	$rremarks  = str_replace( $replace_str, "", $_POST['rremarks']);
	$dat=date('Y-m-d');
     
	$sqcus = mysqli_query($con, "SELECT cname,cmob FROM `p_customers` WHERE `cid`='$rcust' "); 
	$rscus = mysqli_fetch_array($sqcus);
	$cname = $rscus['cname'];
	$cmob  = $rscus['cmob']; 
	 	
    $sq      = mysqli_query($con,"SELECT MAX(`bid`) AS mxidntty FROM `p_billing` ");
    $row     = mysqli_fetch_assoc($sq);
    $bill_no = $row['mxidntty']+1;
	
	$sqq= mysqli_query($con, "INSERT INTO `p_billing` (`bill_no` ,`bcomp` ,`bbranch` ,`bcust` ,`border_no` ,`bamnt` ,`bdiscount` ,
`bnet` ,`bremarks` ,`bdate`)
VALUES ('$bill_no', '$rcompany', '$rbranch', '$rcust', '$recorders', '$ramount', '$rdiscount', '$rnet', '$rremarks', '$dat')");
	
	$custsmssent = $_POST['custsmssent'];
	if($custsmssent != '0'){
	 	
	 $dat = date('Y-m-d');
	 $tim = date("h:i a");
	 $ipp = $_SERVER['REMOTE_ADDR'];
     $cmobile = $cmob;
	 $message = urlencode("Thank you for Choosing Programers, Your Invoice No. #$bill_no has been generated. Will be Delivered to your Email ");
	 $pushid = @file_get_contents("http://programerssms.com/rest/services/sendSMS/sendGroupSms?AUTH_KEY=e57023ed682d83a41d25acb650c877da&message=$message&senderId=PROGRA&routeId=1&mobileNos=$cmobile&smsContentType=english ");
	 
	 $sq1 = mysqli_query($con, "INSERT INTO `p_sms_history` (`sm_cust`,`sm_mob` ,`sm_sms` ,`sm_date` ,`sm_time` ,`sm_ip`)
VALUES ('$cname','$cmob', 'INVOICE GENERATED', '$dat', '$tim', '$ipp')");
			
		
	}	
}

/* -------- Edit Sale & Billing ----------- */

if(isset($_POST['edit_new_billing'])){
	
	$rcompany = strip_tags($_POST['rcompany']);
	$rbranch = strip_tags($_POST['rbranch']);
	$rcust = strip_tags($_POST['rcust']);
	$recorders = strip_tags($_POST['recorders']);
	$ramount = strip_tags($_POST['ramount']);
	$rdiscount = strip_tags($_POST['rdiscount']);
	$rnet = strip_tags($_POST['rnet']);
	$rremarks = strip_tags($_POST['rremarks']);
	$hidvall = strip_tags($_POST['hidvall']);
	
	$upbill = mysqli_query($con, "UPDATE `p_billing` SET `bcomp` = '$rcompany',
`bbranch` = '$rbranch',`bcust` = '$rcust',`border_no` = '$recorders',`bamnt` = '$ramount',`bdiscount` = '$rdiscount',`bnet` = '$rnet',
`bremarks` = '$rremarks' WHERE `bid` ='$hidvall'");
	
}

/* --------------- Delete Orders ------------ */

if(isset($_POST['btn_delete_orders'])){
	
	$id = strip_tags(base64_decode($_POST['id']));
	
	$sqdel = mysqli_query($con, "DELETE FROM `p_orders` WHERE `oid` = '$id'");
	
	$sqdel2 = mysqli_query($con, "DELETE FROM `p_domain2` WHERE `dorder` = '$id'");
	
	$sqdel3 = mysqli_query($con, "DELETE FROM `p_alc` WHERE `al_order` = '$id'");
	
	$sqdel4 = mysqli_query($con, "DELETE FROM `p_server2` WHERE `s_order` = '$id'");
	
}


/* ----------- Add New Customer ------------- */
if(isset($_POST['add_new_customer'])){
	
	$replace_str = array("`", "'");
	$vcompany = str_replace( $replace_str, "", $_POST['vcompany']);
	$vtype = $_POST['vtype'];
	$vcontact = $_POST['vcontact'];
	$vdesignatn = $_POST['vdesignatn'];	
	$vmob = $_POST['vmob'];
	$vmob2 = $_POST['vmob2'];
	$vemail = $_POST['vemail'];
	$vemail2 = $_POST['vemail2'];	
	$vland1 = $_POST['vland1'];
	$vland2 = $_POST['vland2'];
	$vmob3 = $_POST['vmob3'];
	$vemail3 = $_POST['vemail3'];	
	$permantaddrs = $_POST['permantaddrs'];
	$commnctnaddrs = $_POST['commnctnaddrs'];
	
	$vdistrict = $_POST['vdistrict'];
	$vstate    = $_POST['vstate'];
	$vcountry = $_POST['vcountry'];
	$vpincode = $_POST['vpincode'];
	$vremarks = $_POST['vremarks'];	
	
	$vreferred = $_POST['vreferred'];
	$vsource   = $_POST['vsource'];	
	$vgoogle = $_POST['vgoogle'];
	$vstatus = $_POST['vstatus'];
	$gstNo = $_POST['gstNo'];
	$allowedExts = array("png","JPEG","jpg","jpeg");
	$dat = date('d/m/Y');
	if($_FILES["image1"]["name"] != '') {
				    $temp = explode(".", $_FILES["image1"]["name"]);
				    $extension = end($temp);
				    if(!in_array($extension, $allowedExts)){
				     echo 'File Format does not Support';
	                 exit();
				     }
				     $file_info = getimagesize($_FILES["image1"]["tmp_name"]);
	                 if(empty($file_info)) // No Image?
	                 {	
	                 echo 'File Format does not Support';
	                 exit();
	                 }
					 if($_FILES["image1"]["size"] > 1806814) { 
				     echo 'File Format does not Support';
	                 exit();
				     }
					 $rand=md5(uniqid());
				     $extension = explode('.', $_FILES['image1']['name']);
				     $extension = $extension[count($extension)-1];
				     $photo = $rand . '.' . $extension;
				     $tmp_photo = $_FILES['image1']['tmp_name'];
	                 move_uploaded_file($tmp_photo, 'Bill/logo/'.$photo);
		 }	
		if($_FILES["image2"]["name"] != '') {
				    $temp = explode(".", $_FILES["image2"]["name"]);
				    $extension = end($temp);
				    if(!in_array($extension, $allowedExts)){
				     echo 'File Format does not Support';
	                 exit();
				     }
				     $file_info = getimagesize($_FILES["image2"]["tmp_name"]);
	                 if(empty($file_info)) // No Image?
	                 {	
	                 echo 'File Format does not Support';
	                 exit();
	                 }
					 if($_FILES["image2"]["size"] > 1806814) { 
				     echo 'File Format does not Support';
	                 exit();
				     }
					 $rand=md5(uniqid());
				     $extension = explode('.', $_FILES['image2']['name']);
				     $extension = $extension[count($extension)-1];
				     $photo2 = $rand . '.' . $extension;
				     $tmp_photo = $_FILES['image2']['tmp_name'];
	                 move_uploaded_file($tmp_photo, 'Bill/business/'.$photo2);
		 } 
	
	$sq = mysqli_query($con,"SELECT MAX(`cid`) AS mxidntty FROM `p_customers` ");
    $row = mysqli_fetch_assoc($sq);
    $cust_no = $row['mxidntty']+1;
	
	$custinsert = mysqli_query($con, "INSERT INTO `p_customers` (`cidentity`, `cname`, `ctype`, `ccontact`, `cdesignatn`,`cmob`, `cmob2`, `cemail`, `cemail2`, `cphone1`, `cphone2`, `perm_addr`, `comm_addr`, `ccountry`, `cstate`, `cdistrict`, `cpincode`, `cremarks`,`crefered`, `csource`, `clogo`, `cbusiness`, `cgoogle`, `cstatus`, `cdate`, `cmob3`, `cemail3`, `gstNo`)
	  VALUES ('$cust_no', '$vcompany', '$vtype', '$vcontact', '$vdesignatn', '$vmob', '$vmob2', '$vemail', '$vemail2', '$vland1', '$vland2','$permantaddrs', '$commnctnaddrs', '$vcountry', '$vstate', '$vdistrict', '$vpincode', '$vremarks','$vreferred', '$vsource', '$photo', '$photo2', '$vgoogle', '$vstatus', '$dat', '$vmob3', '$vemail3','$gstNo')");


if ($custinsert==true)
{
	echo "0|";
	$custsel = mysqli_query($con, "SELECT `cid`,`cname` FROM `p_customers` WHERE `cname` != '' GROUP BY `cname` ");
    while($custres = mysqli_fetch_array($custsel)){
      if($data['ocustm'] == $custres['cid']){  ?>
         <option value="<?php echo ($custres['cid']); ?>" selected><?php echo $custres['cname']; ?></option>
    <?php }
      else if($_GET['customerid'] == $custres['cid']){  ?>
         <option value="<?php echo ($custres['cid']); ?>" selected><?php echo $custres['cname']; ?></option>
    <?php }
     else {  ?>
         <option value="<?php echo ($custres['cid']); ?>"><?php echo $custres['cname']; ?></option>
    <?php } }
}
else
{
	echo "1|";
	$custsel = mysqli_query($con, "SELECT `cid`,`cname` FROM `p_customers` WHERE `cname` != '' GROUP BY `cname` ");
    while($custres = mysqli_fetch_array($custsel)){
      if($data['ocustm'] == $custres['cid']){  ?>
         <option value="<?php echo ($custres['cid']); ?>" selected><?php echo $custres['cname']; ?></option>
    <?php }
      else if($_GET['customerid'] == $custres['cid']){  ?>
         <option value="<?php echo ($custres['cid']); ?>" selected><?php echo $custres['cname']; ?></option>
    <?php }
     else {  ?>
         <option value="<?php echo ($custres['cid']); ?>"><?php echo $custres['cname']; ?></option>
    <?php } }
}


	
}




/* ----------  Delete Customer ----------- */
if(isset($_POST['btn_delete_customers'])){
	$id = strip_tags(base64_decode($_POST['id']));
	$sqdel = mysqli_query($con, "DELETE FROM `p_customers` WHERE `cid` = '$id'");
}

/* ------------- Edit Customer ------------ */

if(isset($_POST['edit_new_customer'])){
	
	$replace_str = array("`", "'");
	$vcompany = str_replace( $replace_str, "", $_POST['vcompany']);
	$hidvall   = strip_tags($_POST['hidvall']);
	
	$vtype = $_POST['vtype'];
	$vcontact = $_POST['vcontact'];
	$vdesignatn = $_POST['vdesignatn'];	
	$vmob = $_POST['vmob'];
	$vmob2 = $_POST['vmob2'];
	$vemail = $_POST['vemail'];
	$vemail2 = $_POST['vemail2'];	
	$vland1 = $_POST['vland1'];
	$vland2 = $_POST['vland2'];	

	$vmob3 = $_POST['vmob3'];
	$vemail3 = $_POST['vemail3'];
	$permantaddrs = $_POST['permantaddrs'];
	$commnctnaddrs = $_POST['commnctnaddrs'];
	
	$vdistrict = $_POST['vdistrict'];
	$vstate    = $_POST['vstate'];
	$vcountry = $_POST['vcountry'];
	$vpincode = $_POST['vpincode'];
	$vremarks = $_POST['vremarks'];	
	
	$vreferred = $_POST['vreferred'];
	$vsource   = $_POST['vsource'];	
	$vgoogle = $_POST['vgoogle'];
	$vstatus = $_POST['vstatus'];
	$gstNo = $_POST['gstNo'];
	$allowedExts = array("png","JPEG","jpg","jpeg");
	$dat = date('d/m/Y');
	if($_FILES["image1"]["name"] != '') {
				    $temp = explode(".", $_FILES["image1"]["name"]);
				    $extension = end($temp);
				    if(!in_array($extension, $allowedExts)){
				     echo 'File Format does not Support';
	                 exit();
				     }
				     $file_info = getimagesize($_FILES["image1"]["tmp_name"]);
	                 if(empty($file_info)) // No Image?
	                 {	
	                 echo 'File Format does not Support';
	                 exit();
	                 }
					 if($_FILES["image1"]["size"] > 1806814) { 
				     echo 'File Format does not Support';
	                 exit();
				     }
					 $rand=md5(uniqid());
				     $extension = explode('.', $_FILES['image1']['name']);
				     $extension = $extension[count($extension)-1];
				     $photo = $rand . '.' . $extension;
				     $tmp_photo = $_FILES['image1']['tmp_name'];
	                 move_uploaded_file($tmp_photo, 'Bill/logo/'.$photo);
					 $pic1 = " `clogo` = '$photo', ";
		 }	else {
		 	 $pic1 = "";
		 }
		if($_FILES["image2"]["name"] != '') {
				    $temp = explode(".", $_FILES["image2"]["name"]);
				    $extension = end($temp);
				    if(!in_array($extension, $allowedExts)){
				     echo 'File Format does not Support';
	                 exit();
				     }
				     $file_info = getimagesize($_FILES["image2"]["tmp_name"]);
	                 if(empty($file_info)) // No Image?
	                 {	
	                 echo 'File Format does not Support';
	                 exit();
	                 }
					 if($_FILES["image2"]["size"] > 1806814) { 
				     echo 'File Format does not Support';
	                 exit();
				     }
					 $rand=md5(uniqid());
				     $extension = explode('.', $_FILES['image2']['name']);
				     $extension = $extension[count($extension)-1];
				     $photo2 = $rand . '.' . $extension;
				     $tmp_photo = $_FILES['image2']['tmp_name'];
	                 move_uploaded_file($tmp_photo, 'Bill/business/'.$photo2);
					 $pic2 = " `cbusiness` = '$photo2', ";
		 } else {
		 	 $pic2 = "";
		 }
		
		
		$uppcust =  mysqli_query($con, "UPDATE `p_customers` SET `cname` = '$vcompany',`ctype` = '$vtype',`ccontact` = '$vcontact',`cdesignatn` = '$vdesignatn',
`cmob` = '$vmob',`cmob2` = '$vmob2',`cemail` = '$vemail',`cemail2` = '$vemail2',
`cphone1` = '$vland1',`cphone2` = '$vland2',`perm_addr` = '$permantaddrs',`comm_addr` = '$commnctnaddrs',
`ccountry` = '$vcountry',`cstate` = '$vstate',`cdistrict` = '$vdistrict',`cpincode` = '$vpincode',
`cremarks` = '$vremarks',`crefered` = '$vreferred',`csource` = '$vsource',
`cgoogle` = '$vgoogle',`cstatus` = '$vstatus',`cmob3` = '$vmob3',`cemail3` = '$vemail3' , `gstNo`='$gstNo' WHERE `cid`='$hidvall'");
	
	
}


/* ------------  Delete Sales -----------*/

if(isset($_POST['btn_delete_sales'])){
	
	$id = strip_tags(base64_decode($_POST['id']));
	$sqdel = mysqli_query($con, "DELETE FROM `p_billing` WHERE `bid` = '$id'");
}


/* --------- Add Task Register  -------- */

if(isset($_POST['add_new_taskreg'])){
	
	$taskfrom = strip_tags($_POST['taskfrom']);
	$taskto = strip_tags($_POST['taskto']);
	$taskaction = strip_tags($_POST['taskaction']);
	$taskstatus = strip_tags($_POST['taskstatus']);
	$dat = date('Y-m-d');
	$tim = date("h:i a");
	$taskadd = mysqli_query($con, "INSERT INTO `p_task` (`t_from` ,`t_to` ,`t_action` , `t_status`, `t_time`,`t_dat`) VALUES ('$taskfrom', '$taskto', '$taskaction', '$taskstatus', '$tim', '$dat')");
	
}
/* -------- Delete Task Register ------- */

if(isset($_POST['btn_delete_taskk'])){
	$id = strip_tags(base64_decode($_POST['id']));
	$sqdel = mysqli_query($con, "DELETE FROM `p_task` WHERE `tid` = '$id'");	
}
/* ------ Edit Task Register  ------ */

if(isset($_POST['edit_new_taskreg'])){
    $taskfrom = strip_tags($_POST['taskfrom']);
	$taskto = strip_tags($_POST['taskto']);
	$taskaction = strip_tags($_POST['taskaction']);
	$taskstatus = strip_tags($_POST['taskstatus']);
	$transferto = strip_tags($_POST['transferto']);
	$taskreport = strip_tags($_POST['taskreport']);
	
	if($transferto != ''){
	   $dat = date('Y-m-d');
	   $tim = date("h:i a");
	   $taskadd2 = mysqli_query($con, "INSERT INTO `p_task` (`t_from` ,`t_to` ,`t_action` , `t_status`, `t_time`,`t_dat`) 
	   VALUES ('$taskto', '$transferto', '$taskaction', '0', '$tim', '$dat')");	
	}
	
	if($taskstatus != 0) {
	   $close_dat = date('Y-m-d');
	}
	if($taskstatus == 2){
		$taskstatus =1;
	}
	$hidvall = strip_tags($_POST['hidvall']);
	$tasksign = $_POST['tasksign'];
	
	$upp = mysqli_query($con, "UPDATE `p_task` SET `t_from` = '$taskfrom',
`t_to` = '$taskto',`t_action` = '$taskaction',`t_status` = '$taskstatus',`t_sign` = '$tasksign', `t_closedat`='$close_dat', `t_transfer`='$transferto',`task_report`='$taskreport' WHERE `tid` = '$hidvall' ");
	 
}


/*  --- Add InterConnected Task Register  --- */
if(isset($_POST['add_new_interconct'])){
		
	$interconnect = $_POST['interconnect'];	
	$idd = $_POST['idd'];
	$sq1 = mysqli_query($con, "UPDATE `p_task` SET `t_connect` = '$interconnect' WHERE `tid` = '$idd'");
}


if(isset($_POST['btn_change_pass'])){
	
   $pwd_old = strip_tags(sha1($_POST['pwd_old']));
   $pwd_new = strip_tags(sha1($_POST['pwd_new']));
   
   $sqq= mysqli_query($con, "SELECT * FROM `pi_log_data` WHERE `pass`='$pwd_old' ");
   $rss= mysqli_num_rows($sqq);
      if($rss != 0){
           $sq = mysqli_query($con,"UPDATE `pi_log_data` SET `pass` = '$pwd_new' WHERE `pass` = '$pwd_old'");
           echo "Password Changed Successfully";
      } else {
	       echo "Invalid Password";
      }
 }
 
	 
	 
	 
	 
 
 /* -------- Renewel letter ------ */
 
 if(isset($_POST['dom_renewel_prin'])){
 	
	$domsort      = $_POST['domsort'];
	$domain_val   = $_POST['domain_val'];
	$domain_sub   = $_POST['domain_sub'];
	$domain_grand = $_POST['domain_grand'];
	$server_val   = $_POST['server_val'];
	$server_sub   = $_POST['server_sub'];
	$server_grand = $_POST['server_grand'];
	$pop_val      = $_POST['pop_val'];
	$pop_sub      = $_POST['pop_sub'];
	$pop_grand    = $_POST['pop_grand'];
	$host_val     = $_POST['host_val'];
	$host_sub     = $_POST['host_sub'];
	$host_grand   = $_POST['host_grand'];
	$dsn_val      = $_POST['dsn_val'];
	$dsn_sub      = $_POST['dsn_sub'];
	$dsn_grand    = $_POST['dsn_grand'];
	$prog_val     = $_POST['prog_val'];
	$prog_sub     = $_POST['prog_sub'];
	$prog_grand   = $_POST['prog_grand'];
	$redir_val    = $_POST['redir_val'];
	$redir_sub    = $_POST['redir_sub'];
	$redir_grand  = $_POST['redir_grand'];
	$site_val     = $_POST['site_val'];
	$site_sub     = $_POST['site_sub'];
	$site_grand   = $_POST['site_grand'];
	$others_val   = $_POST['others_val'];
	$others_sub   = $_POST['others_sub'];
	$others_grand = $_POST['others_grand'];
	$dat = date('d/m/Y');
	$tim = date('h:i a');
	
  
  $reninsert = mysqli_query($con, "INSERT INTO `p_domain_renwl` (`d_domain`, `dom_val`, `dom_sub`, `dom_grand`, `server_val`, `server_sub`, `server_grand`, `email_val`, `email_sub`, `email_grand`, `host_val`, `host_sub`, `host_grand`, `db_val`, `db_sub`, `db_grand`, `program_val`, `program_sub`, `program_grand`, `redir_val`, `redir_sub`, `redir_grand`, `redign_val`, `redign_sub`, `redign_grand`, `other_val`, `other_sub`, `other_grand`, `d_dat`, `d_tim`) 
  VALUES ( '$domsort', '$domain_val', '$domain_sub', '$domain_grand', '$server_val', '$server_sub', '$server_grand', '$pop_val', '$pop_sub', '$pop_grand', '$host_val', '$host_sub', '$host_grand',
   '$dsn_val', '$dsn_sub', '$dsn_grand', '$prog_val', '$prog_sub', '$prog_grand', '$redir_val', '$redir_sub', '$redir_grand', '$site_val', '$site_sub', '$site_grand', '$others_val', '$others_sub', '$others_grand', '$dat', '$tim');");	
	

 }
 
  
?>