0byt3m1n1
Path:
C:
/
wamp64
/
www
/
cpms_new
/
USER
/
[
Home
]
File: edit_receipt_ctrl.php
<?php include( "../lib/config.php"); include_once("../model/defaults_mdl.php"); require_once BASE_DIR."/lib/db/connection.php"; require_once "../model/defaultValues_mdl.php"; include("../model/financial_mdl.php"); include("../model/financial_report_mdl.php"); $p_id=@$_SESSION['project_id']; $u_id=@$_SESSION['user_id']; $receiptdb_id=$_GET['id']; $sql="select * from reciept where user_id='$u_id' and project_id='$p_id' and receipt_id ='$receiptdb_id'"; $sql1=mysql_query($sql); while($row=mysql_fetch_array($sql1)) { //1 $voucher=$row['voucher']; $receipt_date=$row['r_date']; $account_name=$row['account_Name']; $amount=$row['amount']; $discount=$row['discount']; $description=$row['description']; list($receipt_yy, $receipt_mm, $receipt_dd) = split('[/.-]', $receipt_date); }//1 $sql="select distinct(account_name) from account where user_id='$u_id' and project_id='$p_id' "; $sql=mysql_query($sql); $i=0; while($row=mysql_fetch_array($sql)) { $accdb_name=$row['account_name']; $i=$i+1; $acc_name_array[$i]=$accdb_name; } $for_var_i=$i; $account_name_restore=@$_POST['cmbaccname']; $acc_name=$acc_name_array[$account_name_restore]; if(isset($_POST['Update'])) { //35 $error_flag=0; $receipt_id_restore=@$_POST['txtreceiptid']; $voucher_restore=@$_POST['txtvoucher']; $amount_restore=@$_POST['txtamount']; $discount_restore=@$_POST['txtdiscount']; $description_restore=@$_POST['txtdes']; $receipt_mm_restore=@$_POST['cmbreceiptmm']; $receipt_dd_restore=@$_POST['cmbreceiptdd']; $receipt_yy_restore=@$_POST['txtreceiptyy']; $receipt_date_restore= $receipt_yy_restore."-".$receipt_mm_restore."-".$receipt_dd_restore; //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 ($receipt_date_restore < $verify_date and $verify_date!='') { $message="Cannot submit transactions before verification date"; $error_flag=1; } //verify date......................... if (!is_numeric(@$_POST['txtreceiptyy'])) { $error['receipt_date']="Please enter valid year"; $message=$error['receipt_date']; $error_flag=1; } if($amount_restore=="") { $error['amount_null']="Please Enter amount"; $message=$error['amount_null']; $error_flag=1; } if (!is_numeric(@$_POST['txtamount'])) { $error['amount_numeric']="Please enter valid amount"; $message=$error['amount_numeric']; $error_flag=1; } if($discount_restore!="") { if (!is_numeric(@$_POST['txtdiscount'])) { $error['discount_numeric']="Please enter valid amount"; $message=$error['discount_numeric']; $error_flag=1; } } if($receipt_yy_restore=="") { $error['receipt_yy_null']="Please Enter year"; $message=$error['receipt_yy_null']; $error_flag=1; } /*if($description_restore=="") { $error['description_null']="Please Enter Description"; $message=$error['description_null']; $error_flag=1; }*/ if($voucher_restore!="") { $sql="select `voucher` from reciept where user_id='$u_id' and project_id='$p_id' and voucher='$voucher_restore' and receipt_id <>'$receipt_id_restore'" ; mysql_query($sql); if (mysql_affected_rows()>0) { $error['Voucher_number']="voucher number exists."; $message=$error['Voucher_number']; $error_flag=1; } } $acc_group="Income"; $sql="select * from account where user_id='$u_id' and project_id='$p_id' and group_name='$acc_group' and account_name='$acc_name'"; mysql_query($sql); if (mysql_affected_rows()<=0) { $error['account_exist']="Account not exist. Plz add account first"; $message=$error['account_exist']; $error_flag=1; } //if($voucher_restore!="") // { // $result=Financial::rvoucherNumbercheck($voucher_restore); // if($result=="True") // { // $error_flag=1; // $error['Voucher_number']="voucher number exists."; // } // } if($error_flag==1) { $url=$server_ip."/USER/search_receipt.php?message=$message"; echo "<script>window.location='$url'</script>"; /* echo "<script>window.location='http://localhost/CPFMS/USER/edit_receipt.php</script>"; */ //include("edit_receipt.php"); exit(); } else { $ledgertype="Receipt"; ///////------------------------------------------------ $p_id=@$_SESSION['project_id']; $u_id=@$_SESSION['user_id']; $receiptdb_id=@$_POST['txtreceiptid']; $sql="select * from reciept where user_id='$u_id' and project_id='$p_id' and receipt_id ='$receiptdb_id'"; $sql1=mysql_query($sql); while($row=mysql_fetch_array($sql1)) { //1 $discount=$row['discount']; }//1 $groupname="Discount Paid" ; if($discount_restore >0 and $discount >0) //$discount_restore == new discount ; $discount == old discount ; means , already a discount is present and an updation in ledger is required. { $sql= " update `ledger` set `account_name`='".$acc_name."', `date`='".$receipt_date_restore."' , `debit`='".$discount_restore."',`credit`='0' ,`description`='".$description_restore."' where `ledger_type`='".$ledgertype."' and `type_id`='".$receipt_id_restore."' and `group_name`= '".$groupname."' "; $result_ledger= Reports::updateLedger($sql); } if($discount_restore >0 and $discount ==0) //$discount_restore == new discount ; $discount == old discount ; means , old discount is 0, no entry in ledger and a new entry required in ledger) { $resultledger=Reports::Ledger("Discount Paid",$acc_name,$receipt_date_restore,"Receipt",$receipt_id_restore,$discount_restore,0,$description_restore); Financial::createAccount($u_id,$p_id,"Discount Paid",$acc_name); //create account } if($discount_restore ==0 and $discount > 0) //$discount_restore == new discount ; $discount == old discount ; means , old discount is there, but the updated discount is 0. So we have to delete the discount entry from ledger) { $sql="delete from ledger where user_id='$u_id' and project_id ='$p_id' and ledger_type='$ledgertype' and group_name='Discount Paid' and type_id ='$receipt_id_restore'"; mysql_query($sql); } //--------------------------------------------- //recipt table $groupname="Income"; $sql= " update `reciept` set `voucher`= '".$voucher_restore."', `account_Name`='".$acc_name."', `r_date`='".$receipt_date_restore."' , `amount`='".$amount_restore."',`discount`='".$discount_restore."' ,`description`='".$description_restore."' where `receipt_id`='".$receipt_id_restore."' "; $result= Financial::updateReceipt($sql); $sql1= " update `ledger` set `account_name`='".$acc_name."', `date`='".$receipt_date_restore."' , `debit`='0',`credit`='".$amount_restore."' ,`description`='".$description_restore."' where `ledger_type`='".$ledgertype."' and `type_id`='".$receipt_id_restore."' and `group_name`= '".$groupname."' "; $result_ledger= Reports::updateLedger($sql1); if ($result =="True"&& $result_ledger=="True") { $message="Updation Completed successfully.."; $url=$server_ip."/USER/search_receipt.php?message=$message"; echo "<script>window.location='$url'</script>"; exit(); } else { $message="Updation Failed.Invalid charactors found"; $url=$server_ip."/USER/search_receipt.php?message=$message"; echo "<script>window.location='$url'</script>"; exit(); } }//112 }//2 ?>