Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

yii-auth with db transaction #112

Open
dadinugroho opened this issue Apr 27, 2018 · 0 comments
Open

yii-auth with db transaction #112

dadinugroho opened this issue Apr 27, 2018 · 0 comments

Comments

@dadinugroho
Copy link

Hi All,

I have an issue with this extension (might be) and db transaction. When I login as superuser, I can call unpost method (and other method with db transaction) without any problem. But, when I login as other user, I got an error that said, There is no active transaction!

Can anyone help me with this?

Below is the method:
`
public function actionUnpost($id) {
if (Yii::app()->request->isPostRequest) {
$model = $this->loadModel($id);
$qtyCheck = array();

        $transaction = Yii::app()->db->beginTransaction(); // Transaction begin

        try {
            // If unpost this will resulting in negative remaining quantity, we should cancel this unpost!!!
            foreach ($model->formDetails as $detail) {

                if (isset($qtyCheck[$detail->id])) {
                    $qtyCheck[$detail->id] -= ($detail->quantity * $detail->type);
                } else {
                    $qtyCheck[$detail->id] = Journal::model()->getRemReceivingQty($detail->id, $detail->locationFk) - ($detail->quantity * $detail->type);
                }

                // remaining has normal balance positif, so check the remaining should not be less than 0
                if (0 > $qtyCheck[$detail->id]) {
                    throw new CDbException('Stok barang ' . $detail->item->name . ' menjadi negatif, FB tidak bisa diunposting!');
                }

                // Delete journal entries
                foreach ($detail->journalEntries as $entry) {
                    $entry->delete();
                }
            }

            $model->postingStatus = FormHeader::UNPOSTED;
            $model->save(false);

            $transaction->commit();
            Yii::app()->user->setFlash('success', "FB $model->headerNo telah berhasil diunposting.");
        } catch (Exception $e) {
            $transaction->rollBack();
            Yii::app()->user->setFlash('error', $e->getMessage());
        }

        $this->redirect(array('view', 'id' => $model->id));
    } else {
        throw new CHttpException(400, 'Invalid request. Please do not repeat this request again!');
    }
}

`

TIA
Daniel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant