Current File : /home/inlingua/public_html/noida/icentex/pg/ingl_material_main.main.php |
<?php
// Created on: 13-04-2013
session_start();
date_default_timezone_set('Asia/Calcutta');
/*
$loggedUserNo = $_SESSION['loggedUserNo'];
if ($loggedUserNo == "")
{ echo "Please <a href='index.php'>login</a> first.";
exit(0);
}
*/
// Include the database connection details
require('../dbConnection.php');
// Include common functions
require('../commonFunc.php');
// Include common functions
require('../globalVars.php');
// Setup table name, configuration and data entry form
$tableName = "ingl_invoice_main";
$tableConf = $tableName . ".conf.php";
$dataForm = "ingl_material_main.form.php";
$viewForm = $tableName . ".view.php";
// Include table configuration details
require($tableConf);
// Include the table handler class
require('../dbHandler.class.php');
$dbObject = new dbHandler();
$dbObject->setTableName($tableName);
$dbObject->setDbFieldList($dbFieldList);
$dbObject->setKeyFieldName("recNo");
$dbObject->connect();
// Retrieve parameters from request
$dbObject->getDbFieldsFromRequest();
//Table2
// Setup table name, configuration and data entry form
$tableName1 = "ingl_invoice_detail";
$tableConf1 = $tableName1 . ".conf.php";
// Include table configuration details
require($tableConf1);
$dbObject1 = new dbHandler();
$dbObject1->setTableName($tableName1);
$dbObject1->setDbFieldList($dbFieldList1);
$dbObject1->setKeyFieldName("recNo");
$dbObject1->connect();
// Retrieve parameters from request
$dbObject1->getDbFieldsFromRequest();
//////////////////////////////////////////
//Table3
// Setup table name, configuration and data entry form
$tableName3 = "ingl_invoice_payment";
$tableConf3 = $tableName3 . ".conf1.php";
// Include table configuration details
require($tableConf3);
$dbObject3 = new dbHandler();
$dbObject3->setTableName($tableName3);
$dbObject3->setDbFieldList($dbFieldList3);
$dbObject3->setKeyFieldName("recNo");
$dbObject3->connect();
// Retrieve parameters from request
$dbObject3->getDbFieldsFromRequest();
//////////////////////////////////////////
$tableName4="ingl_invoice_reg";
$tableConf4=$tableName4.".conf.php";
// Include table configuration details
require($tableConf4);
$dbObject4 = new dbHandler();
$dbObject4->setTableName($tableName4);
$dbObject4->setDbFieldList($dbFieldList4);
$dbObject4->setKeyFieldName("recNo");
$dbObject4->connect();
// Retrieve parameters from request
$dbObject4->getDbFieldsFromRequest();
//////////////////////////////////////////
$currentMode = "";
$formPrompt = "";
$succFailMesg = "";
$showResult = "N";
isset($_REQUEST['aC'])?$action =$_REQUEST['aC']:$action ='';
//$action = $_REQUEST['aC'];
if (($action == "") || ($action == "sA"))
{ // Set 'Add' mode in dataform
$dbObject->setDbField("student_id",$_REQUEST['student_id']);
$queryS="select * from ingl_admission where ref_No='".$_REQUEST['student_id']."'";
$resultS=mysqli_query($conn,$queryS);
$numS=mysqli_fetch_array($resultS);
$dbObject->setDbField("student_name","".$numS['firstName']." ".$numS['lastName']."");
$dbObject->setDbField("student_address","".$numS['address']."");
$queryB="select * from timesheet_location where location='".$_SESSION['branch']."' order by location";
$resultB=mysqli_query($conn,$queryB);
$numB=mysqli_fetch_array($resultB);
$dbObject->setDbField("centre","".$numB['recNo']."");
$dbObject->setDbField("createDate",date("Y-m-d"));
$currentMode = "Add";
$succFailMesg = "<b>Add entry</b> [<a href='javascript:history.back()'>Back</a>]<br>";
}
else if ($action == "Add")
{ $currentMode = "Add";
// Perform check for duplicate entry
if($dbObject->Exists("recNo", $_REQUEST["recNo"]))
{ $succFailMesg = "<font color='#da0000'><b>Could not add. entry with this key already exists.</b></font><br>";
$showResult = "N"; // Show dataentry form again
}
else if($_REQUEST['category'][0]=="0" || $_REQUEST['product'][0]=="0")
{
$succFailMesg = "<font color='#da0000'><b>Could not add. Please select at least one item.</b></font><br>";
$showResult = "N"; // Show dataentry form again
}
else
{ //$today = date("Y-m-d");
$query_setId="ALTER TABLE ingl_invoice_main auto_increment = 1";
$result=mysqli_query($conn,$query_setId);
$queryB="select * from timesheet_location where recNo='".$_REQUEST['centre']."'";
$resultB=mysqli_query($conn,$queryB);
$numB=mysqli_fetch_array($resultB);
$financial_year_to = (date('m') > 03) ? date('Y') +1 : date('Y');
$year = $financial_year_to - 1;
$query="select count(recNo) as maxid from ingl_invoice_main where centre='".$_REQUEST['centre']."' and type ='M' and financialyear='".$year."' ";
$result=mysqli_query($conn,$query);
$num=mysqli_fetch_array($result);
$roll=$num['maxid']+1+36;
if(strlen($roll)=="1")
{
$rid=$year."000".$roll."";
}
else if(strlen($roll)=="2")
{
$rid=$year."00".$roll."";
}
else if(strlen($roll)=="3")
{
$rid=$year."0".$roll."";
}
else
{
$rid=$year."".$roll."";
}
$rid="".$numB['code_prefix']."-M-".$rid."";
//echo $rid ; exit();
$dbObject->setDbField("invoice_no","".$rid."");
$dbObject->setDbField("createdBy","".$_SESSION['id']."");
$dbObject->setDbField("createDate",date("Y-m-d H:i:s"));
$dbObject->setDbField("status_delete",0);
$dbObject->setDbField("financialyear",$year);
$dbObject->setDbField("type","M");
$insert_1=$dbObject->Save();
//For Reg
if($insert_1>0)
{
$product_Regid=$_REQUEST['product'][0];
if($product_Regid==61||$product_Regid==62||$product_Regid==63)
{
//$Reg_Cate1=$_REQUEST['reg_category1'];
$Reg_Cate2=$_REQUEST['reg_category2'];
//$Reg_Cate3=$_REQUEST['reg_category3'];
$Reg_product1=$_REQUEST['reg_product1'];
$Reg_product2=$_REQUEST['reg_product2'];
$Reg_product3=$_REQUEST['reg_product3'];
if($Reg_product1!=0)
{
$dbObject4->setDbField("reg_category1",$Reg_Cate2);
$dbObject4->setDbField("reg_product1",$Reg_product1);
}
else
{
$dbObject4->setDbField("reg_category1","0");
$dbObject4->setDbField("reg_product1","0");
}
if($Reg_product2!=0)
{
$dbObject4->setDbField("reg_category2",$Reg_Cate2);
$dbObject4->setDbField("reg_product2",$Reg_product2);
}
else
{
$dbObject4->setDbField("reg_category2","0");
$dbObject4->setDbField("reg_product2","0");
}
if($Reg_product3!=0)
{
$dbObject4->setDbField("reg_category3",$Reg_Cate2);
$dbObject4->setDbField("reg_product3",$Reg_product3);
}
else
{
$dbObject4->setDbField("reg_category3","0");
$dbObject4->setDbField("reg_product3","0");
}
$dbObject4->setDbField("recNo",$insert_1);
$dbObject4->setDbField("invice_no",$rid);
$dbObject4->setDbField("level",$product_Regid);
if($insert_1>0)
{
$dbObject4->Save();
}
}
//end Of Reg
$des_array=$_REQUEST['category'];
/*echo"<pre>";
print_r($des_array);
print_r($_REQUEST);
exit;*/
if(is_array($des_array))
{
foreach($des_array as $key1=>$val1)
{
$category_id=$_REQUEST['category'][$key1];
$product_id=$_REQUEST['product'][$key1];
$queryD="select bill_details from ingl_billing_main where bill_category='".$product_id."'";
$resultD=mysqli_query($conn,$queryD);
$numD=mysqli_fetch_array($resultD);
$product_desc=$numD['bill_details'];
$rates=$_REQUEST['rates'][$key1];
$tax_rates=$_REQUEST['tax_s'][$key1];
$quantity=$_REQUEST['quan'][$key1];
$amount=$_REQUEST['total'][$key1];
$tax_amount=$_REQUEST['tax'][$key1];
$remarks=$_REQUEST['description'][$key1];
$CourseID=$_REQUEST['CourseID'][$key1];
$Discount=$_REQUEST['Discount'][$key1];
if($rates==''){
$rates='0.00';
}
if($tax_rates==''){
$tax_rates='0.00';
}
if($tax_amount==''){
$tax_amount='0.00';
}
$dbObject1->setDbField("main_id",$insert_1);
$dbObject1->setDbField("invoice_no",$rid);
$dbObject1->setDbField("category_id",$category_id);
$dbObject1->setDbField("product_id",$product_id);
$dbObject1->setDbField("product_desc",$product_desc);
$dbObject1->setDbField("rates",$rates);
$dbObject1->setDbField("tax_rates",$tax_rates);
$dbObject1->setDbField("quantity",$quantity);
$dbObject1->setDbField("amount",$amount);
$dbObject1->setDbField("tax_amount",$tax_amount);
$dbObject1->setDbField("remarks",$remarks);
$dbObject1->setDbField("Course_id",$CourseID);
$dbObject1->setDbField("Discount",$Discount);
if($category_id>0 && $product_id>0 && $insert_1>0)
{
$dbObject1->Save();
}
}
}
//$arrayAlpha=array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z");
$queryR="select count(a.recNo) as maxid from ingl_invoice_payment a left join ingl_invoice_main b on b.recNo=a.invice_no
where b.centre='".$_REQUEST['centre']."' and type ='M' and financialyear='".$year."'";
$resultR=mysqli_query($conn,$queryR);
$numR=mysqli_fetch_array($resultR);
$idR=$numR['maxid']+1+36;
if(strlen($idR)=="1")
{
$idR=$year."000".$idR."";
}
else if(strlen($idR)=="2")
{
$idR=$year."00".$idR."";
}
else if(strlen($idR)=="3")
{
$idR=$year."0".$idR."";
}
else
{
$idR=$year."".$idR."";
}
$idR1="".$numB['code_prefix']."-M-".$idR."";
$dbObject3->setDbField("invice_no",$insert_1);
$dbObject3->setDbField("rcpt_id","".$idR1."");
/*$dbObject3->setDbField("amount",$_REQUEST['rcpt_amount']);
$dbObject3->setDbField("payment_mode",$_REQUEST['rcpt_payment_mode']);
$dbObject3->setDbField("cheque_no",$_REQUEST['rcpt_cheque_no']);
$dbObject3->setDbField("favour_of",$_REQUEST['rcpt_favour_of']);
$dbObject3->setDbField("createDate",$_REQUEST['createDate']);
$dbObject3->setDbField("created_by","".$_SESSION['id']."");
$dbObject3->setDbField("product_id",$_REQUEST['product'][0]);*/
$dbObject3->setDbField("amount",$_POST['total'][0]);
$dbObject3->setDbField("payment_mode",$_REQUEST['rcpt_payment_mode']);
$dbObject3->setDbField("cheque_no",$_REQUEST['rcpt_cheque_no']);
$dbObject3->setDbField("favour_of",$_REQUEST['rcpt_favour_of']);
$dbObject3->setDbField("createDate",date("Y-m-d H:i:s"));
$dbObject3->setDbField("created_by","".$_SESSION['id']."");
$dbObject3->setDbField("product_id",$_REQUEST['product'][0]);
if($insert_1>0)
{
$insertpay=$dbObject3->Save();
}
//$insertpay=mysqli_insert_id();
$sql="Select dt.*,main.bill_details,adm.mobile,adm.firstName from ingl_invoice_detail dt inner join ingl_billing_main main on dt.product_id=main.recNo
inner join ingl_invoice_main invmain on invmain.invoice_no=dt.invoice_no inner join ingl_admission adm on adm.ref_No=invmain.student_id where dt.invoice_no='".$idR1."' order by recNo";
$selected = $dbObject->Select($sql);
if($selected)
{
$objectData=$dbObject->SelectNext();
$productdt .= $objectData['bill_details'].",";
$totalamt=$totalamt+$objectData['amount'];
$fname=$objectData['firstName'];
$product=str_replace(" ","%20",$productdt);
$product=$product."%20Amount%20".$totalamt."%20INR";
$studentid=trim(str_replace(" ","%20",$_REQUEST['student_id']));
$sms="Dear%20".$fname."%20We%20have%20received%20your%20payment%20towards%20".$product.".%20Your%20receipts%20No.%20is%20".$idR1."%20and%20student%20ID%20is%20".$studentid.".%20Wishing%20you%20the%20best!%20Inlingua%20".$_SESSION['branch'].".";
//$dbObject->send_sms($objectData['mobile'],$sms);
//exit;
}
$succFailMesg = "<b>Entry added successfully</b><br>";
}
$showResult = "Y"; // Goto result part in dataform
$succFailMesg = "<b>Could not Add entry. Contact system administrator</b><br>";
$_SESSION['dispMesg'] = array(date("U"), $succFailMesg);
$goUrl = "ingl_material_main.main.php?aC=sV&kV=".$insert_1."";
header('Location: '.$goUrl);
}
}
else if ($action == "sM")
{ // Set 'Update' mode in dataform
$currentMode = "Update";
$succFailMesg = "<b>Modify entry</b> [<a href='javascript:history.back()'>Back</a>]<br>";
// Retrieve record first
if ($dbObject->Retrieve("recNo",$_REQUEST["kV"]))
{ ; }
else
{ $succFailMesg = "<font color='#da0000'><b>Recipt Not Generate Try Again.</b></font> [<a href='javascript:history.back()'>Back</a>]<br>";
$showResult = "Y"; // Goto result part in dataform
}
}
else if ($action == "Update")
{ $currentMode = "Update";
$showResult = "Y"; // Goto result part in dataform
$dbObject->setDbField("createdBy","".$_SESSION['id']."");
$dbObject->setDbField("modifyDate",date("Y-m-d"));
$dbObject->setDbField("refunded_date",date("Y-m-d"));
if ($dbObject->Update("recNo",$_REQUEST["kV"]))
{
//For Reg
$product_Regid=$_REQUEST['product'][0];
if($product_Regid==61||$product_Regid==62||$product_Regid==63)
{
//$Reg_Cate1=$_REQUEST['reg_category1'];
$Reg_Cate2=$_REQUEST['reg_category2'];
//$Reg_Cate3=$_REQUEST['reg_category3'];
$Reg_product1=$_REQUEST['reg_product1'];
$Reg_product2=$_REQUEST['reg_product2'];
$Reg_product3=$_REQUEST['reg_product3'];
if( $Reg_product1!=0)
{
$dbObject4->setDbField("reg_category1",$Reg_Cate2);
$dbObject4->setDbField("reg_product1",$Reg_product1);
}
else
{
$dbObject4->setDbField("reg_category1","0");
$dbObject4->setDbField("reg_product1","0");
}
if($Reg_product2!=0)
{
$dbObject4->setDbField("reg_category2",$Reg_Cate2);
$dbObject4->setDbField("reg_product2",$Reg_product2);
}
else
{
$dbObject4->setDbField("reg_category2","0");
$dbObject4->setDbField("reg_product2","0");
}
if($Reg_product3!=0)
{
$dbObject4->setDbField("reg_category3",$Reg_Cate2);
$dbObject4->setDbField("reg_product3",$Reg_product3);
}
else
{
$dbObject4->setDbField("reg_category3","0");
$dbObject4->setDbField("reg_product3","0");
}
$dbObject4->setDbField("recNo",$_REQUEST["kV"]);
$dbObject4->setDbField("invice_no",$_REQUEST["Invoice"]);
$dbObject4->setDbField("level",$product_Regid);
$dbObject4->Update("recNo",$_REQUEST["kV"]);
}
//end Of Reg
$amount="select amount from ingl_invoice_detail where invoice_no='".$_REQUEST['Invoice']."'";
$resultAM=mysqli_query($conn,$amount);
$tamount=mysqli_fetch_array($resultAM);
$dbObject1->Delete("main_id",$_REQUEST["kV"]);
$query_setId="ALTER TABLE ingl_invoice_detail auto_increment = 1";
$result=mysqli_query($conn,$query_setId);
$invoice=$_REQUEST['Invoice'];
$des_array=$_REQUEST['category'];
if(is_array($des_array))
{
$j=0;
foreach($des_array as $key1=>$val1)
{
if($tamount[$j]>0){
$category_id=$_REQUEST['category'][$key1];
$product_id=$_REQUEST['product'][$key1];
$queryD="select bill_details from ingl_billing_main where bill_category='".$product_id."'";
$resultD=mysqli_query($conn,$queryD);
$numD=mysqli_fetch_array($resultD);
$product_desc=$numD['bill_details'];
$rates='0.00';
$tax_rates='0.00';
$quantity=$_REQUEST['quan'][$key1];
$amount=$tamount[$j];
$tax_amount=$_REQUEST['tax'][$key1];
$remarks=$_REQUEST['description'][$key1];
$CourseID=$_REQUEST['CourseID'][$key1];
$Discount=$_REQUEST['Discount'][$key1];
$dbObject1->setDbField("recNo",0);
$dbObject1->setDbField("main_id",$_REQUEST["kV"]);
$dbObject1->setDbField("invoice_no",$invoice);
$dbObject1->setDbField("category_id",$category_id);
$dbObject1->setDbField("product_id",$product_id);
$dbObject1->setDbField("product_desc",$product_desc);
$dbObject1->setDbField("rates",$rates);
$dbObject1->setDbField("tax_rates",$tax_rates);
$dbObject1->setDbField("quantity",$quantity);
$dbObject1->setDbField("amount",$amount);
$dbObject1->setDbField("tax_amount",$tax_amount);
$dbObject1->setDbField("remarks",$remarks);
$dbObject1->setDbField("Course_id",$CourseID);
$dbObject1->setDbField("Discount",$Discount);
if($category_id>0 && $product_id>0)
{
$dbObject1->Save();
}
}
$j++;
}
}
$succFailMesg = "<b>Entry modified successfully</b><br>";
$_SESSION['dispMesg'] = array(date("U"), $succFailMesg);
$goUrl = "ingl_material_main.main.php?aC=sV&kV=".$_REQUEST['kV']."";
header('Location: '.$goUrl);
}
else
{ $succFailMesg = "<font color='#da0000'><b>Could not modify entry. Contact system administrator</b></font> [<a href='javascript:history.back()'>Back</a>]<br>" ;
}
}
else if ($action == "sD")
{ $currentMode = "Delete"; $succFailMesg = "<b>Delete entry</b> [<a href='javascript:history.back()'>Back</a>]<br>";
// Retrieve record first
if ($dbObject->Retrieve("recNo",$_REQUEST["kV"]))
{ ; }
else
{ $succFailMesg = "<font color='#da0000'><b>Recipt Not Generate Try Again. </b></font> [<a href='javascript:history.back()'>Back</a>]<br>";
$showResult = "Y"; // Goto result part in dataform
}
}
else if ($action == "Delete")
{ $showResult = "Y"; // Goto result part in dataform
$dbObject->setDbField("status_delete",1);
if ($dbObject->Update("recNo",$_REQUEST["kV"]))
{
$succFailMesg = "<b>Entry Cancelled successfully</b><br>";
$_SESSION['dispMesg'] = array(date("U"), $succFailMesg);
$goUrl = "ingl_invoice_main.select.php";
header('Location: '.$goUrl);
}
else{
$succFailMesg = "<font color='#da0000'><b>Could not Cancel entry. Contact System administrator</b></font> [<a href='javascript:history.back()'>Back</a>]<br>" ;
}
/*if ($dbObject->Delete("recNo",$_REQUEST["kV"]))
{
$dbObject1->Delete("main_id",$_REQUEST["kV"]);
$succFailMesg = "<b>Entry deleted successfully</b><br>";
$_SESSION['dispMesg'] = array(date("U"), $succFailMesg);
$goUrl = "ingl_invoice_main.select.php";
header('Location: '.$goUrl);
}
else
{ $succFailMesg = "<font color='#da0000'><b>Could not delete entry. Contact System administrator</b></font> [<a href='javascript:history.back()'>Back</a>]<br>" ; }
*/
}
else if ($action == "sDel")
{
if ($dbObject->Delete("recNo",$_REQUEST["kV"]))
{
$dbObject4->Delete("recNo",$_REQUEST["kV"]);
$dbObject1->Delete("main_id",$_REQUEST["kV"]);
$query_del="delete from ingl_invoice_payment where invice_no='".$_REQUEST["kV"]."'";
$resul_del=mysqli_query($conn,$query_del) or die(mysql_error($conn));
$succFailMesg = "<b>Entry deleted successfully</b><br>";
$_SESSION['dispMesg'] = array(date("U"), $succFailMesg);
$goUrl = "ingl_invoice_main.select.php";
header('Location: '.$goUrl);
}
else
{ $succFailMesg = "<font color='#da0000'><b>Could not delete entry. Contact System administrator</b></font> [<a href='javascript:history.back()'>Back</a>]<br>" ; }
}
else if ($action == "sV")
{ // Set 'View' mode
$currentMode = "View";
/*$goUrl = "rcpt_pdf.php?kV=".$_REQUEST["kV"]."";
header('Location: '.$goUrl);*/
//$succFailMesg = "<b>Invoice (<a href='invoice_pdf.php?kV=".$_REQUEST["kV"]."' target='_blank'>Print</a>)</b> <b>(<a href='ingl_invoice_payment.select.php?kV=".$_REQUEST["kV"]."' target='_blank'>Receipts</a>)</b> [<a href='javascript:history.back()'>Back</a>]<br>";
$succFailMesg = "<aside class='contentbox-head'> <span class='title'>Invoice (<span class='status-row'><a style='color:white;' href='invoice_pdf.php?kV=".$_REQUEST["kV"]."' target='_blank' title='Add entry'>Print</a></span>
)</span>
<span style='float:right;' class='title'> <span class='status-row'><!--<a style='color:white;' target='_blank' href='ingl_invoice_payment.main.php?invice_no=".$_REQUEST["kV"]."'' title='Add entry'>Make Payment</a>--> </span>
</aside>";
$dataForm = $viewForm;
// Retrieve record first
if ($dbObject->Retrieve("recNo",$_REQUEST["kV"]))
{ ; }
else
{ $succFailMesg = "<font color='#da0000'><b>Recipt Not Generate Try Again.</b></font> [<a href='javascript:history.back()'>Back</a>]<br>";
$showResult = "Y"; // Goto result part in dataform
}
}
else
{ echo "Nothing to do !";
return;
}
// Load the data entry or view entry form
require($dataForm);
$dbObject->CloseConnection();
return;
?>