Quantcast
Channel: Yii Framework Forum
Viewing all articles
Browse latest Browse all 18717

Duplicate Record In Transaction

$
0
0
Hi,
In my project there is some huge transaction,most of the time it is working fine but in some time it is replicating the data in my table.
please check my table content..


if you see, same Transaction , same time, same description, and same amount

ID Date Description Credit Debit Balance
30 07-Mar-2013 15:51:35 Description 20.00 0.00 34.10
30 07-Mar-2013 15:51:35 Description 20.00 0.00 34.10
30 07-Mar-2013 15:51:35 Description 20.00 0.00 34.10
30 07-Mar-2013 15:51:35 Description 20.00 0.00 34.10

pls find below my controller and model...


my controller

public function actionTransfer(){
	$mymodel= new Mymodel;
	if(isset($_POST['Mymodel'])){
		$mymodel->attributes = $_POST['Mymodel'];
		$amount = $_POST['Mymodel']['DepositeAmount'];
		$remarks =$_POST['Mymodel']['Description'];
        $typeoftransaction = 'Regular';                           
        $status = $mymodel->addTransfer($ownerID,$receiverid,$amount,1,2,$remarks,$typeoftransaction);
        if($status){
          // send mail..
       else{
         echo "trnsaction failed";
       }
	}
}


My model
 
public function addTransfer($ownerID,$receiverid,$amount,$senddesc,$recvdesc,$remarks,$type){ 
// for sender reccord....

$sender= new Mymodel;
                $transaction=$sender->dbConnection->beginTransaction();
                $status = false;
                try{
                    $totalbalance = 0;
                    $txnno = 0;
                    $sendelatestRec = $sender->getwalletAmount($ownerID);
                    $totalbalance = $sendelatestRec->TotalBalance;
                    $txnno =  $sendelatestRec->TxnID + 1;
                    $sender->OwnerID = $ownerID;
                    $sender->SenderID = $ownerID;
                    $sender->ReceiverID = $receiverid;
                   $sender->DepositeAmount = 0;
                    $sender->WithdrawAmount = round($amount,2);
                    $sender->TotalBalance = round($totalbalance - $amount,2);
                    $sender->Type = $type;
                    $sender->Date = time();
                    $sender->TxnID = $txnno;
                    $sender->RemarksID = $senddesc ;
                    $sender->Description = $remarks ;
                    if($sender->save()){
                        
                     // for receiver reccord....

                        $receiver = new Mymodel;
                        $txnno = 0;
                        $totalbalance = 0;
                        $sendelatestRec = $receiver ->getwalletAmount($receiverid);
                        $totalbalance = $sendelatestRec->TotalBalance;
                        $txnno =  $sendelatestRec->TxnID + 1;
                        $receiver ->OwnerID = $receiverid;
                        $receiver ->SenderID = $ownerID;
                        $receiver ->ReceiverID = $receiverid;
                        $receiver ->DepositeAmount = round($amount,2);
                        $receiver ->WithdrawAmount = 0;
                        $receiver ->TotalBalance = round($totalbalance + $amount,2);
                        $receiver ->Type = $type;
                        $receiver ->Date = time();
						 $receiver ->TxnID = $txnno;
                        $receiver ->RemarksID = $recvdesc;
                        $receiver ->Description = $remarks ;
                        $receiver ->save();                  
                        $status = true;
                    }else{
                         $status = false;
                    }
                       $transaction->commit();  
                       
                }
                catch(Exception $e){
                  $transaction->rollBack();
                   $status =  false;
                }
                return $status;
}


Please tell me how it will be happen with same code, but 99% working , 1% will get wrong result.

Please advise

Viewing all articles
Browse latest Browse all 18717

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>