0byt3m1n1
Path:
C:
/
wamp64
/
www
/
cpms_new
/
USER
/
[
Home
]
File: advance_settelment_entry_ctrl.php
<?php require_once "../lib/config.php"; require_once BASE_DIR."/lib/db/connection.php"; include("../model/financial_mdl.php"); include("../model/financial_report_mdl.php"); //include("../model/defaultValues_mdl.php"); $u_id= @$_SESSION['user_id']; $p_id=@$_SESSION['project_id']; $sql="select * from advance_taken_entry where user_id='$u_id' and project_id='$p_id' or project_id=0"; $sql=mysql_query($sql); $i=0; while($row=mysql_fetch_array($sql)) { $taken_entry_no_db=$row['advance_id']; $i=$i+1; $taken_entry_no_array[$i]=$taken_entry_no_db; } $taken_entry_no=@$_POST['cmbtaken_entry_no']; $taken_entry_no_var=$taken_entry_no_array[$taken_entry_no]; if(isset($_POST['showbtn'])) { $sql1="select * from advance_taken_entry where user_id='$u_id' and advance_id='$taken_entry_no_var' "; $sql1=mysql_query($sql1); while($row1=mysql_fetch_array($sql1)) { $taken_entry_date_db=$row1['date']; $taken_entry_name_db=$row1['name']; $taken_entry_amount_db=$row1['amount']; $taken_entry_type_db=$row1['advance_impresed']; $closed=$row1['closed']; } } if(isset($_POST['savebtn'])) { $sql1="select * from advance_taken_entry where user_id='$u_id' and advance_id='$taken_entry_no_var' "; $sql1=mysql_query($sql1); while($row1=mysql_fetch_array($sql1)) { $taken_entry_date_db=$row1['date']; $taken_entry_name_db=$row1['name']; $taken_entry_amount_db=$row1['amount']; $taken_entry_type_db=$row1['advance_impresed']; $closed=$row1['closed']; } $error_flag=0; $advance_taken_id=@$_POST['cmbtaken_entry_no']; $type_of_item=@$_POST['txttypeofitem']; $vender_name=@$_POST['txtvender_name']; $invoice_no=@$_POST['txtinvoice_no']; $date_mm= @$_POST['cmbinvoicemm']; $date_dd=@$_POST['cmbinvoicedd']; $date_yy=@$_POST['txtinvoice_yy']; $closed_restore=@$_POST['chkclosed']; $date=$date_yy."-".$date_mm."-".$date_dd; $bill_amount=@$_POST['txtbill_amount']; $description=@$_POST['txtdesc']; //verify date.......................... $u_id= @$_SESSION['user_id']; $p_id=@$_SESSION['project_id']; $sql="select verify_date from addproject where user_id='$u_id' and project_id='$p_id'"; $sql=mysql_query($sql); while($row=mysql_fetch_array($sql)) { $verify_date=$row['verify_date']; } if ($date < $verify_date and $verify_date!='') { $message="Cannot submit transactions before verification date"; $error_flag=1; } //verify date......................... if (!is_numeric(@$_POST['txtbill_amount'])) { $error['numeric']="Only allow numbers"; $error_flag=1; } /*$sql1="select * from advance_taken_entry where user_id='$u_id' and advance_id='$taken_entry_no_var' "; $sql1=mysql_query($sql1); while($row1=mysql_fetch_array($sql1)) { $closed=$row1['closed']; } */ if ($closed == 1) { $message="This Advance/Imprest is closed. You cannot enter settlement for this. For enter further settlement, please edit to unclosed state."; $error_flag=1; } if (!is_numeric(@$_POST['txtinvoice_yy'])) { $error['invoicedate']="Only allow numbers"; $error_flag=1; } if($type_of_item=="") { $error['type_of_item_null']="Please Enter number of type_of_item"; $error_flag=1; } if($date=="") { $error['invoice_date_null']="Please Enter number of type_of_item"; $error_flag=1; } //if($vender_name=="") // { // $error['vender_name_null']="Please Enter vender_name"; // $error_flag=1; // } // // if($invoice_no=="") // { // $error['invoice_no_null']="Please Enter invoice_no"; // $error_flag=1; // } if($bill_amount=="") { $error['bill_amount']="Please Enter bill_amount"; $error_flag=1; } if($error_flag==1) { //88 /*echo "<script>window.location='http://localhost/CPFMS/USER/stockentry.php</script>";*/ include("advance_settelment_entry.php"); exit(); } //8 else { //88 try { // 89 $sql="select * from advance_taken_entry where user_id='$u_id' and advance_id='$taken_entry_no_var'"; $sql=mysql_query($sql); $i=0; while($row=mysql_fetch_array($sql)) { $acc_name_db=$row['account_name']; $project_id_db=$row['project_id']; $advance_impresed_db=$row['advance_impresed']; $advance_amt=$row['amount']; } //Calculate settlement ammount//////////////////// $bill_amt=0; if($closed_restore== "on") { $sql="select bill_amount from advance_settelment where advance_taken_entry_no ='$taken_entry_no_var'"; $sql1=mysql_query($sql); while($row=mysql_fetch_array($sql1)) { //1 $bill_amt = $bill_amt + $row['bill_amount']; } $settlement_amt = $advance_amt - $bill_amt; } else { $settlement_amt = 0; } //Calculate settlement ammount//////////////////// $table_id=Common::getTableID("advance_settelment","settelment_id"); $table_id=$table_id+1; $voucher_no=Common::voucherno("advance_settelment","voucher_no",$taken_entry_no_var); $voucher_no=$voucher_no+1; $u_id=@$_SESSION['user_id']; $p_id=@$_SESSION['project_id']; $sql="INSERT INTO `advance_settelment`( `settelment_id`, `voucher_no`, `advance_taken_entry_no`, `type_of_item`, `vender_name`, `invoice_no`, `invoice_date`, `bill_amount`, `description` ) VALUES ( '$table_id','$voucher_no','$taken_entry_no_var','$type_of_item','$vender_name','$invoice_no','$date','$bill_amount','$description' ) "; mysql_query($sql); if (mysql_affected_rows()>0) { } else { $message= "Submission Failed.Invalid charactors found"; $url=$server_ip."/USER/advance_settelment_entry.php?message=$message"; echo "<script>window.location='$url'</script>"; //include("advance_settelment_entry.php"); exit(); } //closing advance/imprest if ($closed_restore=="on") { $sql= " update `advance_taken_entry` set `closed`= 1, `balance`='$settlement_amt' where `advance_id`='".$taken_entry_no_var."' "; mysql_query($sql); } $ledgertype="AI Settlement"; $groupname="Expenses"; $ledg_id_table=Common::getTableID("ledger","ledg_id"); $ledg_id_table=$ledg_id_table+1; if($advance_impresed_db=="Imprest") { //131 //"Expenses",$acc_name_db,$date,"Advance/Imprest",$table_id,$bill_amount,0,$description $p_id_ledger=0; $sql="INSERT INTO `ledger` ( `ledg_id` , `user_id` , `project_id` , `group_name`, `account_name` , `date`, `ledger_type` , `type_id` , `debit`, `credit`, `description` ) VALUES ( '$ledg_id_table','$u_id','$p_id_ledger','$groupname','Imprest','$date', '$ledgertype', '$table_id', '$bill_amount',0,'$description' ) "; Financial::createAccount($u_id,$p_id_ledger,$groupname,$acc_name_db); } //131 else // Advance { //131 $sql="INSERT INTO `ledger` ( `ledg_id` , `user_id` , `project_id` , `group_name`, `account_name` , `date`, `ledger_type` , `type_id` , `debit`, `credit`, `description` ) VALUES ( '$ledg_id_table','$u_id','$p_id','$groupname','$acc_name_db','$date','$ledgertype', '$table_id', '$bill_amount',0,'$description' ) "; Financial::createAccount($u_id,$p_id,$groupname,$acc_name_db); } //131 mysql_query($sql); if (mysql_affected_rows()>0) { $message="Submission Completed successfully.."; $url=$server_ip."/USER/advance_settelment_entry.php?message=$message"; echo "<script>window.location='$url'</script>"; /*include("advance_settelment_entry.php"); exit(); */ } else { $message= "Submission Failed.Invalid charactors found"; $url=$server_ip."/USER/advance_settelment_entry.php?message=$message"; echo "<script>window.location='$url'</script>"; //include("advance_settelment_entry.php"); exit(); } }//89 catch( Exception $ex) { //89 echo $ex-> getMessage(); return null; } //89 } //88 } ?>