Current File : /home/inlingua/public_html/faridabad/icentex/admin_fd/ingl_invoice_main.main.php |
<?php
// Created on: 13-04-2013
session_start();
/*
$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 = $tableName . ".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();
//////////////////////////////////////////
$currentMode = "";
$formPrompt = "";
$succFailMesg = "";
$showResult = "N";
$action = $_REQUEST['aC'];
if (($action == "") || ($action == "sA"))
{ // Set 'Add' mode in dataform
$dbObject->setDbField("student_id",$_REQUEST['sid']);
$queryS="select * from ingl_admission where recNo='".$_REQUEST['sid']."'";
$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);
$query="select count(recNo) as maxid from ingl_invoice_main where centre='".$_REQUEST['centre']."'";
$result=mysqli_query($conn,$query);
$num=mysqli_fetch_array($result);
$roll=$num['maxid']+1;
if(strlen($roll)=="1")
{
$rid="000".$roll."";
}
else if(strlen($roll)=="2")
{
$rid="00".$roll."";
}
else if(strlen($roll)=="3")
{
$rid="0".$roll."";
}
else
{
$rid="".$roll."";
}
$rid="".$numB['code_prefix']."".$rid."";
$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->Save();
$insert_1=mysqli_insert_id();
$des_array=$_REQUEST['category'];
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];
$dbObject1->setDbField("main_id",$insert_1);
$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);
if($category_id>0 && $product_id>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']."'";
$resultR=mysqli_query($conn,$queryR);
$numR=mysqli_fetch_array($resultR);
$idR=$numR['maxid']+1;
if(strlen($idR)=="1")
{
$idR="000".$idR."";
}
else if(strlen($idR)=="2")
{
$idR="00".$idR."";
}
else if(strlen($idR)=="3")
{
$idR="0".$idR."";
}
else
{
$idR="".$idR."";
}
$idR1="".$numB['code_prefix']."".$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->Save();
$succFailMesg = "<b>Entry added successfully</b><br>";
$showResult = "Y"; // Goto result part in dataform
$_SESSION['dispMesg'] = array(date("U"), $succFailMesg);
$goUrl = "ingl_invoice_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>Could not retrieve entry. Contact system administrator</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"));
if ($dbObject->Update("recNo",$_REQUEST["kV"]))
{
$dbObject1->Delete("main_id",$_REQUEST["kV"]);
$query_setId="ALTER TABLE ingl_invoice_detail auto_increment = 1";
$result=mysqli_query($conn,$query_setId);
$des_array=$_REQUEST['category'];
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];
$dbObject1->setDbField("recNo",0);
$dbObject1->setDbField("main_id",$_REQUEST["kV"]);
$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);
if($category_id>0 && $product_id>0)
{
$dbObject1->Save();
}
}
}
$succFailMesg = "<b>Entry modified successfully</b><br>";
$_SESSION['dispMesg'] = array(date("U"), $succFailMesg);
$goUrl = "ingl_invoice_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>Could not retrieve entry. Contact system administrator</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 == "sV")
{ // Set 'View' mode
$currentMode = "View"; $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>";
$dataForm = $viewForm;
// Retrieve record first
if ($dbObject->Retrieve("recNo",$_REQUEST["kV"]))
{ ; }
else
{ $succFailMesg = "<font color='#da0000'><b>Could not retrieve entry. Contact system administrator</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;
?>