0byt3m1n1
Path:
C:
/
wamp64
/
www
/
cpms_new
/
USER
/
[
Home
]
File: edit_payment_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']; $paymentdb_id=$_GET['id']; $sql="select * from payment where user_id='$u_id' and project_id='$p_id' and payment_id ='$paymentdb_id'"; $sql1=mysql_query($sql); while($row=mysql_fetch_array($sql1)) { //1 $voucher=$row['voucher']; $payment_date=$row['p_date']; $account_name=$row['account_Name']; $amount=$row['amount']; $discount=$row['discount']; $description=$row['description']; list($payment_yy, $payment_mm, $payment_dd) = split('[/.-]', $payment_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; $payment_id_restore=@$_POST['txtrpaymentid']; $voucher_restore=@$_POST['txtvoucher']; $amount_restore=@$_POST['txtamount']; $discount_restore=@$_POST['txtdiscount']; $description_restore=@$_POST['txtdes']; $payment_mm_restore=@$_POST['cmbpaymentmm']; $payment_dd_restore=@$_POST['cmbpaymentdd']; $payment_yy_restore=@$_POST['txtpaymentyy']; $payment_date_restore= $payment_yy_restore."-".$payment_mm_restore."-".$payment_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 ($payment_date_restore < $verify_date and $verify_date!='') { $message="Cannot submit transactions before verification date"; $error_flag=1; } //verify date......................... if (!is_numeric(@$_POST['txtpaymentyy'])) { $error['payment_date']="Please enter valid year"; $error_flag=1; } if($amount_restore=="") { $error['amount_null']="Please Enter Filename"; $error_flag=1; } if (!is_numeric(@$_POST['txtamount'])) { $error['amount_numeric']="Please enter valid year"; $error_flag=1; } if($discount_restore!="") { if (!is_numeric(@$_POST['txtdiscount'])) { $error['discount_numeric']="Please enter valid year"; $error_flag=1; } } if($payment_yy_restore=="") { $error['payment_yy_null']="Please Enter year"; $error_flag=1; } /*if($description_restore=="") { $error['description_null']="Please Enter Description"; $error_flag=1; }*/ if($voucher_restore!="") { $sql="select `voucher` from payment where user_id='$u_id' and project_id='$p_id' and voucher='$voucher_restore' and payment_id <>'$payment_id_restore'" ; mysql_query($sql); if (mysql_affected_rows()>0) { $error['Voucher_number']="voucher number exists."; $error_flag=1; } } $acc_group="Expenses"; $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"; $error_flag=1; } if($error_flag==1) { /*$url=$server_ip."/USER/edit_payment.php?message=$message"; echo "<script>window.location='$url'</script>";*/ include "edit_payment.php"; exit(); } else { $ledgertype="Payment"; ////////// //-----------------Discount Recieved --------------- $p_id=@$_SESSION['project_id']; $u_id=@$_SESSION['user_id']; $sql="select discount from payment where user_id='$u_id' and project_id='$p_id' and payment_id ='$payment_id_restore'"; $sql1=mysql_query($sql); while($row=mysql_fetch_array($sql1)) { //1 $discount=$row['discount']; }//1 $groupname="Discount Received"; 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`='".$payment_date_restore."' , `debit`='0',`credit`='$discount_restore' ,`description`='".$description_restore."' where `ledger_type`='".$ledgertype."' and `type_id`='".$payment_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 Received",$acc_name,$payment_date_restore,"Payment",$payment_id_restore,0,$discount_restore,$description_restore); Financial::createAccount($u_id,$p_id,"Discount Received",$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 Received' and type_id ='$payment_id_restore'"; mysql_query($sql); } //------------------------------------------------------------ $groupname="Expenses"; $sql= "update `payment` set `voucher`= '".$voucher_restore."', `account_Name`='".$acc_name."', `p_date`='".$payment_date_restore."' , `amount`='".$amount_restore."',`discount`='".$discount_restore."' ,`description`='".$description_restore."' where `payment_id`='".$payment_id_restore."' "; $result= Financial::updateReceipt($sql); $sql1= " update `ledger` set `account_name`='".$acc_name."', `date`='".$payment_date_restore."' , `debit`='".$amount_restore."',`credit`= '0',`description`='".$description_restore."' where `ledger_type`='".$ledgertype."' and `type_id`='".$payment_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_payment.php?message=$message"; echo "<script>window.location='$url'</script>"; } else { $message="Updation Failed.Invalid charactors found"; $url=$server_ip."/USER/search_payment.php?message=$message"; echo "<script>window.location='$url'</script>"; } }//112 }//2 ?>