Esempio n. 1
0
 public function transaction()
 {
     if ($this->validate()) {
         $num = 0;
         $line = 1;
         $tranType = \app\helpers\Linet3Helper::getSetting("transactionType.supplierPayment");
         $tran = new Transactions();
         $tran->num = $num;
         $tran->type = $tranType;
         $tran->refnum1 = $this->refnum_ids;
         $tran->refnum2 = '';
         $tran->valuedate = $this->date;
         $tran->details = $this->details;
         $tran->currency_id = $this->currency_id;
         $tran->owner_id = Yii::$app->user->id;
         $tran->linenum = $line;
         $trans = Yii::$app->db->beginTransaction(\yii\db\Transaction::READ_UNCOMMITTED);
         //-shuld start transaction here so lets lock down
         try {
             $tran->addSingleLine($this->account_id, $this->sum * -1);
             $tran->addSingleLine($this->opp_account_id, $this->sum * 1);
             if ((int) $this->src_tax != 0) {
                 $tran->addDoubleLine(5, $this->account_id, $this->src_tax);
             }
             //commit it here
             $trans->commit();
         } catch (\Exception $e) {
             $trans->rollBack();
             $message = $e->getMessage();
             $this->addError('details', $message);
             return false;
         }
         $this->saveRef($num, $this->sum);
         return true;
     }
     return false;
 }