Пример #1
0
 public function addDoubleLine($account_id, $oppt_account_id, $sum)
 {
     $round = new Transactions();
     $round->num = $this->num;
     $round->account_id = $account_id;
     $round->type = $this->type;
     $round->refnum1 = $this->refnum1;
     $round->refnum2 = $this->refnum2;
     $round->valuedate = $this->valuedate;
     $round->details = $this->details;
     $round->currency_id = $this->currency_id;
     $round->sum = $sum;
     $round->owner_id = $this->owner_id;
     $round->linenum = $this->linenum;
     $this->linenum++;
     $this->num = $round->save();
     $round = new Transactions();
     $round->num = $this->num;
     $round->account_id = $oppt_account_id;
     $round->type = $this->type;
     $round->refnum1 = $this->refnum1;
     $round->refnum2 = $this->refnum2;
     $round->valuedate = $this->valuedate;
     $round->details = $this->details;
     $round->currency_id = $this->currency_id;
     $round->sum = $sum * -1;
     $round->owner_id = $this->owner_id;
     $round->linenum = $this->linenum;
     $this->linenum++;
     $this->num = $round->save();
     return $this;
 }
Пример #2
0
 public function save()
 {
     //print_r($this->Deposit);
     $num = 0;
     $linenum = 1;
     $tranType = Settings::model()->findByPk('transactionType.chequedeposit')->value;
     if ($this->refnum == '' || $this->date == '' || !is_array($this->Deposit)) {
         return false;
     }
     $valuedate = date("Y-m-d H:m:s", CDateTimeParser::parse($this->date, Yii::app()->locale->getDateFormat('yiishort')));
     foreach ($this->Deposit as $line => $val) {
         list($a, $b) = explode(',', $line);
         $cheq = Doccheques::model()->findByPk(array("doc_id" => $a, "line" => $b));
         $oppt_acc = PaymentType::model()->findByPk($cheq->type)->oppt_account_id;
         //print_r($cheq);
         $accout = new Transactions();
         $accout->num = $num;
         $accout->account_id = $this->account_id;
         $accout->type = $tranType;
         $accout->refnum1 = $this->refnum;
         $accout->valuedate = $valuedate;
         //$accout->details=$this->company;
         $accout->currency_id = $cheq->currency_id;
         $accout->owner_id = Yii::app()->user->id;
         $accout->linenum = $linenum;
         $accout->sum = $cheq->sum * -1;
         $linenum++;
         $num = $accout->save();
         $oppt = new Transactions();
         $oppt->num = $num;
         $oppt->account_id = $oppt_acc;
         $oppt->type = $tranType;
         $oppt->refnum1 = $this->refnum;
         $oppt->valuedate = $valuedate;
         //$oppt->details=$this->company;
         $oppt->currency_id = $cheq->currency_id;
         $oppt->owner_id = Yii::app()->user->id;
         $oppt->linenum = $linenum;
         $oppt->sum = $cheq->sum * 1;
         $linenum++;
         $num = $oppt->save();
         $cheq->bank_refnum = $num;
         $cheq->save();
     }
     //Yii::app()->end();
     return $num;
 }
Пример #3
0
 public function actionOpenBalance()
 {
     $model = new Transactions();
     if (isset($_POST['account'])) {
         $year = $_POST['year'];
         $date = "{$year}-01-01 00:00:01";
         $accountArr = $_POST['account'];
         $balanceArr = $_POST['bal'];
         foreach ($accountArr as $index => $account) {
             $sum = $balanceArr[$index];
             if ($account) {
                 $submodel = new Transactions();
                 $submodel->date = $date;
                 $submodel->details = Yii::t('app', "Opening Balance");
                 $submodel->type = Yii::app()->user->settings['transactionType.openBalance'];
                 $submodel->currency_id = Yii::app()->user->settings['company.cur'];
                 $submodel->account_id = $account;
                 $submodel->sum = $sum;
                 $submodel->owner_id = Yii::app()->user->id;
                 $submodel->linenum = 1;
                 $submodel->save();
                 //$submodel->num;
                 $submodel1 = new Transactions();
                 $submodel1->num = $submodel->num;
                 $submodel1->date = $date;
                 $submodel1->details = Yii::t('app', "Opening Balance");
                 $submodel1->type = Yii::app()->user->settings['transactionType.openBalance'];
                 $submodel1->currency_id = Yii::app()->user->settings['company.cur'];
                 $submodel1->account_id = Yii::app()->user->settings['company.acc.openbalance'];
                 $submodel1->sum = $sum * -1.0;
                 $submodel1->owner_id = Yii::app()->user->id;
                 $submodel1->linenum = 2;
                 $submodel1->save();
             }
         }
         Yii::app()->user->setFlash('success', Yii::t('app', 'Open Balance saved'));
         //$this->redirect(array('OpenBalance'));
     }
     $this->render('opbalance', array('model' => $model));
 }
Пример #4
0
 public function readBkmv()
 {
     //sort
     $this->sortBkmvFile();
     //skip for testing
     //
     //new company
     //get perm from ini
     //if (substr($line,395,1)=='2')
     //    $encoding="ibm862";
     //else
     $encoding = "windows-1255";
     //$encoding="ibm862";
     Yii::log('start Openimport', 'info', 'app');
     //$bkmv = $yiiBasepath."/files/".$configPath."/openformt/bkmvdata.txt-sorted";
     $bkmv = $this->bkmvFile . "-sorted";
     $suc = array();
     $suc['B110'] = 0;
     $suc['A100'] = 0;
     $suc['B100'] = 0;
     $suc['C100'] = 0;
     $suc['M100'] = 0;
     $suc['D110'] = 0;
     $suc['D120'] = 0;
     $suc['Z900'] = 0;
     $analze = array();
     $analze['B110'] = 0;
     $analze['A100'] = 0;
     $analze['B100'] = 0;
     $analze['C100'] = 0;
     $analze['M100'] = 0;
     $analze['D110'] = 0;
     $analze['D120'] = 0;
     $analze['Z900'] = 0;
     $accType = 200;
     //DELETE FROM `qwe_docCheques` WHERE 1;DELETE FROM `qwe_docDetails` WHERE 1;DELETE FROM `qwe_accounts` WHERE 1;DELETE FROM `qwe_items` WHERE 1;DELETE FROM `qwe_docs` WHERE 1;
     if ($fp = fopen($bkmv, 'r')) {
         while ($line = fgets($fp)) {
             @($line = iconv($encoding, "UTF-8//IGNORE", $line));
             //$line=utf8_encode($line);
             $type = substr($line, 0, 4);
             //$obj=$this->readline($line,$type);
             $obj = true;
             if (!$obj) {
                 //$suc[$type]--;
             } else {
                 //foreach ($obj as &$value)
                 //	if ($encoding=="ibm862")
                 //		$value = iconv("ISO-8859-8", "UTF-8", hebrev(iconv("UTF-8", "ISO-8859-8", $value)));
                 if ($type == 'B110') {
                     //Acc Haeder
                     /* Account Import */
                     $acc = new Accounts();
                     $acc->readLine($line, $type);
                     if (isset($this->accTypeIndex[$acc->type])) {
                         $this->accDesc[$acc->type] = $this->accDesc[$acc->type] . "," . $acc->name;
                     } else {
                         $this->accDesc[$acc->type] = $acc->name;
                         $this->accTypeIndex[$acc->type] = $accType;
                         $accType++;
                     }
                     $acc->type = $this->accTypeIndex[$acc->type];
                     $acc->save();
                     //get new acc index save old
                     unset($acc);
                     //*/
                 }
                 if ($type == 'M100') {
                     //Item In Stock
                     $item = new Item();
                     $item->category_id = 0;
                     $item->parent_item_id = 0;
                     $item->isProduct = 0;
                     $item->profit = 0;
                     $item->stockType = 0;
                     $item->readLine($line, $type);
                     $item->save();
                     unset($item);
                     //*/
                 }
                 if ($type == 'C100') {
                     //Doc Haeder
                     //return "done!";
                     //Yii::app()->end();
                     //find type
                     //global $DocOpenType;
                     $doc = new Docs();
                     $doc->readLine($line, $type);
                     $doc->status = 1;
                     //needtoChange
                     //Yii::log($doc,'info','app');
                     $doc->save();
                     unset($doc);
                     /*
                     					if ((isset($DocOpenType[$obj['doctype']])) && (isset($accIndex[$obj['account']]))){
                     						$obj['doctype']=$DocOpenType[$obj['doctype']];
                     						$doc=new document($obj['doctype']);
                     						$stype=$obj['doctype'];
                     						foreach($obj as $key=>$value){
                     							$doc->$key=$value;//print "$key <br />";
                     						}
                     						$doc->account=$accIndex[$doc->account];
                     						//search for old acc index
                     						if (isset($doc->rcptdetials)) unset($doc->rcptdetials);
                     						if (isset($doc->docdetials)) unset($doc->docdetials);
                     						
                     						if($check){
                     							if((strtotime($doc->issue_date)>$begindmy)&&(strtotime($doc->issue_date)<$enddmy))
                     								$docIndex[$stype.$obj["docnum"]]=$doc->newDocument();
                     							//print "we are chking!";
                     						}else{
                     							$docIndex[$stype.$obj["docnum"]]=$doc->newDocument();
                     						}
                     						//get new doc index save old
                     						unset($doc);
                     					}*/
                 }
                 if ($type == 'D110') {
                     //Doc Detial
                     $docdetial = new Docdetails();
                     $docdetial->readLine($line, $type);
                     //Yii::log($docdetial,'info','app');
                     $docdetial->save();
                     unset($docdetial);
                     /*
                     					global $DocOpenType;
                     					$stype=$DocOpenType[$obj['doctype']];
                     					if (isset($docIndex[$stype.$obj["num"]])){		
                     						$docdetial=new documentDetail;
                     						$docdetial->price=$obj['price'];
                     						unset($obj['doctype']);
                     						unset($obj['price']);
                     						
                     						foreach($obj as $key=>$value){
                     							$docdetial->{$key}=$value;//print "$key <br />";
                     							
                     						}
                     						
                     						$docdetial->num=$docIndex[$stype.$obj["num"]];	
                     						$docdetial->newDetial();
                     						
                     						//search for old doc index
                     						//die;
                     						//update to new index
                     						unset($docdetial);
                     					}//*/
                 }
                 if ($type == 'D120') {
                     //Kaballa Detial
                     $rcptdetial = new Doccheques();
                     $rcptdetial->readLine($line, $type);
                     Yii::log($rcptdetial, 'info', 'app');
                     $rcptdetial->save();
                     unset($rcptdetial);
                     /*
                     					global $DocOpenType;
                     					$stype=$DocOpenType[$obj['doctype']];
                     					if (isset($docIndex[$stype.$obj["refnum"]])){
                     						$rcptdetial=new receiptDetail();
                     						//$stype=$DocOpenType[$obj['doctype']];
                     						$rcptdetial->sum=(float)$obj['sum'];
                     						unset($obj['sum']);
                     						unset($obj['doctype']);
                     						foreach($obj as $key=>$value){
                     							$rcptdetial->$key=$value;
                     						}
                     						$rcptdetial->refnum=$docIndex[$stype.$obj["refnum"]];	
                     						$rcptdetial->newDetial();
                     						//search for old doc index
                     						//update to new index
                     						unset($rcptdetial);
                     					}*/
                 }
                 if ($type == 'B100') {
                     //Move Recored
                     $transaction = new Transactions();
                     $transaction->readLine($line, $type);
                     $transaction->save();
                     //Yii::log($transaction,'info','app');
                     unset($transaction);
                     /*
                     					//print $obj['value'].":".$obj['type'];
                     					global $openTransType;
                     					
                     					if (isset($accIndex[$obj['account']])){
                     						$bsum= $obj['sum'];
                     						if($obj['value']==1)
                     							$bsum= -1 * $obj['sum'];
                     						//print $bsum."<br />\n";
                     						$usum=$bsum*-1;
                     						
                     						$uaccount=$obj['account1'];
                     						$stype=$openTransType[$obj['type']];
                     						unset($obj['sum']);
                     						unset($obj['value']);
                     						unset($obj['account1']);
                     						//adam:! need to reset type of action!
                     						
                     						$transaction=new transaction;
                     						
                     						foreach($obj as $key=>$value){
                     							$transaction->$key=$value;//print "$key <br />";
                     						}
                     						$transaction->type=$stype;
                     						$transaction->sum=$bsum;
                     						$transaction->account=$accIndex[$obj['account']];
                     						
                     						if($check){
                     								if((strtotime($transaction->date)>$begindmy)&&(strtotime($transaction->date)<$enddmy)){
                     									// "gone";
                     									$transaction->newTransactions();
                     								}
                     								//print "gone2";	
                     							}else{
                     								//print "gone1";
                     								$transaction->newTransactions();
                     							}
                     						unset($transaction);
                     					}//*/
                 }
                 unset($obj);
                 $suc[$type]++;
             }
             $analze[$type]++;
             //if ($analze[$type]>100)	break;
         }
         Yii::log("End OpenImport", 'info', 'app');
         //print_r($docIndex);
         //end loop
         //print_r($accIndex);
     } else {
         print _("error cant open file!");
     }
 }
Пример #5
0
 public function pay()
 {
     $this->dates();
     $yiidatetimesec = Yii::app()->locale->getDateFormat('yiidatetimesec');
     $phpdbdatetime = Yii::app()->locale->getDateFormat('phpdbdatetime');
     $date = date($phpdbdatetime, CDateTimeParser::parse($this->to_date, $yiidatetimesec));
     /*
               $tnum = Transaction(0, TRAN_PRETAX, IRS, $ref1, $ref2, $date, $details, $this->tax_sum);
               $tnum = Transaction($tnum, TRAN_PRETAX, PRETAX, $ref1, $ref2, $date, $details, $this->tax_sum * -1.0);
               $tnum = Transaction($tnum, TRAN_PRETAX, IRS, $ref1, $ref2, $date, $details, $this->custtax_total);
               $tnum = Transaction($tnum, TRAN_PRETAX, CUSTTAX, $ref1, $ref2, $date, $details, $this->custtax_total * -1.0);
     */
     $irs = Yii::app()->user->settings['company.acc.irs'];
     $pretax = Yii::app()->user->settings['company.acc.pretax'];
     $custtax = Yii::app()->user->settings['company.acc.custtax'];
     $cur = Yii::app()->user->settings['company.cur'];
     $owner = Yii::app()->user->id;
     $line = 1;
     $accout = new Transactions();
     $accout->account_id = $irs;
     //IRS
     $accout->type = 14;
     //$accout->refnum1 = $this->from_date;
     //$accout->refnum2 = $this->to_date;
     $accout->valuedate = $date;
     $accout->details = Yii::t('app', 'tax') . " " . $this->from_month . "-" . $this->to_month . "/" . $this->year;
     $accout->currency_id = $cur;
     $accout->owner_id = $owner;
     $accout->linenum = $line;
     $accout->sum = $this->tax_sum;
     $line++;
     $num = $accout->save();
     $accout = new Transactions();
     $accout->account_id = $pretax;
     //PRETAX
     $accout->type = 14;
     $accout->num = $num;
     //$accout->refnum1 = $this->from_date;
     //$accout->refnum2 = $this->to_date;
     $accout->valuedate = $date;
     $accout->details = Yii::t('app', 'tax') . " " . $this->from_month . "-" . $this->to_month . "/" . $this->year;
     $accout->currency_id = $cur;
     $accout->owner_id = $owner;
     $accout->linenum = $line;
     $accout->sum = $this->tax_sum * -1;
     $line++;
     $accout->save();
     $accout = new Transactions();
     $accout->account_id = $irs;
     //IRS
     $accout->type = 14;
     $accout->num = $num;
     //$accout->refnum1 = $this->from_date;
     //$accout->refnum2 = $this->to_date;
     $accout->valuedate = $date;
     $accout->details = Yii::t('app', 'tax') . " " . $this->from_month . "-" . $this->to_month . "/" . $this->year;
     $accout->currency_id = $cur;
     $accout->owner_id = $owner;
     $accout->linenum = $line;
     $accout->sum = $this->custtax_total;
     $line++;
     $accout->save();
     $accout = new Transactions();
     $accout->account_id = $custtax;
     //CUSTTAX
     $accout->type = 14;
     $accout->num = $num;
     //$accout->refnum1 = $this->from_date;
     //$accout->refnum2 = $this->to_date;
     $accout->valuedate = $date;
     $accout->details = Yii::t('app', 'tax') . " " . $this->from_month . "-" . $this->to_month . "/" . $this->year;
     $accout->currency_id = $cur;
     $accout->owner_id = $owner;
     $accout->linenum = $line;
     $accout->sum = $this->custtax_total * -1.0;
     $line++;
     $accout->save();
 }
Пример #6
0
 public function processed()
 {
     $aggregator = $this->_aggregator;
     // Проверка необходимых параметров
     $aggregator->checkParams();
     // Проверка подписи
     $aggregator->checkSignature();
     if ($aggregator->isSms()) {
         $paymentSystem = $this->_aggregator_id == self::PAYMENT_SYSTEM_UNITPAY ? self::PAYMENT_SYSTEM_UNITPAY_SMS : self::PAYMENT_SYSTEM_WAYTOPAY_SMS;
         if ($paymentSystem == self::PAYMENT_SYSTEM_UNITPAY_SMS) {
             $transactionId = $aggregator->getId();
             /** @var Transactions $transaction */
             $transaction = Transactions::model()->findByPk($transactionId);
             if (!$transaction) {
                 throw new Exception('Транзакция не найдена.');
             } elseif ($transaction->isPaid()) {
                 throw new Exception('Транзакция уже обработана.');
             } elseif ($transaction->getSum() != $aggregator->getSum()) {
                 throw new Exception('Сумма не совпадает.');
             }
             $gsModel = Gs::model()->findByPk($transaction->gs_id);
             if (!$gsModel) {
                 throw new Exception('Сервер не найден.');
             }
             $tr = db()->beginTransaction();
             try {
                 $transaction->status = Transactions::STATUS_SUCCESS;
                 $transaction->save(FALSE, array('status', 'updated_at'));
                 $this->recharge($transaction->user_id, $aggregator->getSum(), $gsModel->deposit_course_payments);
                 $tr->commit();
             } catch (Exception $e) {
                 $tr->rollback();
                 Yii::log($e->getMessage(), CLogger::LEVEL_ERROR, 'modules.deposit.extensions.Deposit.' . __LINE__);
                 throw new Exception('Ошибка');
             }
         } elseif ($paymentSystem == self::PAYMENT_SYSTEM_WAYTOPAY_SMS) {
             $userId = $aggregator->getId();
             $gsId = $aggregator->getGsId();
             $userModel = Users::model()->findByPk($userId);
             if (!$userModel) {
                 throw new Exception('Аккаунт не найден.');
             }
             $gsModel = Gs::model()->findByPk($gsId);
             if (!$gsModel) {
                 throw new Exception('Сервер не найден.');
             }
             $count = floor($aggregator->getProfit() / $gsModel->deposit_course_payments);
             $tr = db()->beginTransaction();
             try {
                 $transaction = new Transactions();
                 $transaction->payment_system = $paymentSystem;
                 $transaction->user_id = $userId;
                 $transaction->sum = (double) $aggregator->getProfit();
                 $transaction->count = $count;
                 $transaction->status = Transactions::STATUS_SUCCESS;
                 $transaction->params = serialize($_REQUEST);
                 $transaction->gs_id = $gsId;
                 $transaction->save(FALSE);
                 $gsModel = Gs::model()->findByPk($gsId);
                 if (!$gsModel) {
                     throw new Exception('Сервер не найден.');
                 }
                 $this->recharge($userId, $aggregator->getSum(), $gsModel->deposit_course_payments);
                 $tr->commit();
             } catch (Exception $e) {
                 $tr->rollback();
                 Yii::log($e->getMessage(), CLogger::LEVEL_ERROR, 'modules.deposit.extensions.Deposit.' . __LINE__);
                 throw new Exception('Ошибка');
             }
         }
     } else {
         $transactionId = $aggregator->getId();
         $transaction = Transactions::model()->findByPk($transactionId);
         if (!$transaction) {
             throw new Exception('Транзакция не найдена.');
         }
         if ($transaction->isPaid()) {
             throw new Exception('Транзакция уже обработана.');
         } elseif ($transaction->getSum() != $aggregator->getSum()) {
             throw new Exception('Сумма не совпадает.');
         }
         $transaction->status = Transactions::STATUS_SUCCESS;
         $gsModel = Gs::model()->findByPk($transaction->gs_id);
         if (!$gsModel) {
             throw new Exception('Сервер не найден.');
         }
         $tr = db()->beginTransaction();
         try {
             $transaction->save(FALSE, array('status', 'updated_at'));
             $this->recharge($transaction->user_id, $aggregator->getSum(), $gsModel->deposit_course_payments);
             $tr->commit();
         } catch (Exception $e) {
             $tr->rollback();
             throw new Exception($e->getMessage());
         }
     }
     return $transaction;
 }
Пример #7
0
 public function transaction()
 {
     if ($this->validate()) {
         $valuedate = date("Y-m-d H:m:s", CDateTimeParser::parse($this->date, Yii::app()->locale->getDateFormat('yiishort')));
         $num = 0;
         $line = 1;
         $tranType = Yii::app()->user->settings["transactionType.supplierPayment"];
         $tran = new Transactions();
         $opt_tran = new Transactions();
         $tran->num = $num;
         $tran->account_id = $this->account_id;
         $tran->type = $tranType;
         $tran->refnum1 = $this->refnum_ids;
         $tran->valuedate = $valuedate;
         $tran->details = $this->details;
         $tran->currency_id = $this->currency_id;
         $tran->owner_id = Yii::app()->user->id;
         $tran->linenum = $line;
         $tran->sum = $this->sum * -1;
         $line++;
         $num = $tran->save();
         $opt_tran->num = $num;
         //$vat->account_id=Yii::app()->user->settings['company.acc.vatacc'];
         $opt_tran->account_id = $this->opp_account_id;
         $opt_tran->type = $tranType;
         $opt_tran->refnum1 = $this->refnum_ids;
         $opt_tran->valuedate = $valuedate;
         $opt_tran->details = $this->details;
         $opt_tran->currency_id = $this->currency_id;
         $opt_tran->owner_id = Yii::app()->user->id;
         $opt_tran->linenum = $line;
         $opt_tran->sum = $this->sum * 1;
         $line++;
         //print_r($vat->attributes);
         $num = $opt_tran->save();
         if ((int) $this->src_tax != 0) {
             $tran->num = $num;
             $tran->account_id = $this->account_id;
             $tran->type = $tranType;
             $tran->refnum1 = $this->refnum_ids;
             $tran->valuedate = $valuedate;
             $tran->details = $this->details;
             $tran->currency_id = $this->currency_id;
             $tran->owner_id = Yii::app()->user->id;
             $tran->linenum = $line;
             $tran->sum = $this->src_tax * -1;
             $line++;
             $num = $tran->save();
             $opt_tran->num = $num;
             //$vat->account_id=Yii::app()->user->settings['company.acc.vatacc'];
             $opt_tran->account_id = 5;
             //company.acc.supliertax
             $opt_tran->type = $tranType;
             $opt_tran->refnum1 = $this->refnum_ids;
             $opt_tran->valuedate = $valuedate;
             $opt_tran->details = $this->details;
             $opt_tran->currency_id = $this->currency_id;
             $opt_tran->owner_id = Yii::app()->user->id;
             $opt_tran->linenum = $line;
             $opt_tran->sum = $this->src_tax * 1;
             $line++;
             //print_r($vat->attributes);
             $num = $opt_tran->save();
         }
         $this->saveRef($num, $this->sum);
         return true;
     }
     return false;
 }
Пример #8
0
 public function pay()
 {
     $this->dates();
     $yiidatetimesec = Yii::app()->locale->getDateFormat('yiidatetimesec');
     $phpdbdatetime = Yii::app()->locale->getDateFormat('phpdbdatetime');
     $this->payvat_acc = Yii::app()->user->settings['company.acc.payvat'];
     $date = date($phpdbdatetime, CDateTimeParser::parse($this->to_date, $yiidatetimesec));
     $cur = Yii::app()->user->settings['company.cur'];
     $owner = Yii::app()->user->id;
     $line = 1;
     $accout = new Transactions();
     $accout->account_id = $this->selvat_acc;
     $accout->type = 6;
     //$accout->refnum1 = $this->from_date;
     //$accout->refnum2 = $this->to_date;
     $accout->valuedate = $date;
     $accout->details = Yii::t('app', 'vat') . " " . $this->from_month . "-" . $this->to_month . "/" . $this->year;
     $accout->currency_id = $cur;
     $accout->owner_id = $owner;
     $accout->linenum = $line;
     $accout->sum = $this->selvat_total * -1.0;
     $line++;
     $num = $accout->save();
     $accout = new Transactions();
     $accout->account_id = $this->payvat_acc;
     $accout->type = 6;
     $accout->num = $num;
     //$accout->refnum1 = $this->from_date;
     //$accout->refnum2 = $this->to_date;
     $accout->valuedate = $date;
     $accout->details = Yii::t('app', 'vat') . " " . $this->from_month . "-" . $this->to_month . "/" . $this->year;
     $accout->currency_id = $cur;
     $accout->owner_id = $owner;
     $accout->linenum = $line;
     $accout->sum = $this->selvat_total;
     $line++;
     $accout->save();
     $accout = new Transactions();
     $accout->account_id = $this->buyvat_acc;
     $accout->type = 6;
     $accout->num = $num;
     //$accout->refnum1 = $this->from_date;
     //$accout->refnum2 = $this->to_date;
     $accout->valuedate = $date;
     $accout->details = Yii::t('app', 'vat') . " " . $this->from_month . "-" . $this->to_month . "/" . $this->year;
     $accout->currency_id = $cur;
     $accout->owner_id = $owner;
     $accout->linenum = $line;
     $accout->sum = $this->buyvat_total;
     $line++;
     $accout->save();
     $accout = new Transactions();
     $accout->account_id = $this->payvat_acc;
     $accout->type = 6;
     $accout->num = $num;
     //$accout->refnum1 = $this->from_date;
     //$accout->refnum2 = $this->to_date;
     $accout->valuedate = $date;
     $accout->details = Yii::t('app', 'vat') . " " . $this->from_month . "-" . $this->to_month . "/" . $this->year;
     $accout->currency_id = $cur;
     $accout->owner_id = $owner;
     $accout->linenum = $line;
     $accout->sum = $this->buyvat_total * -1.0;
     $line++;
     $accout->save();
     $accout = new Transactions();
     $accout->account_id = $this->assetvat_acc;
     $accout->type = 6;
     $accout->num = $num;
     //$accout->refnum1 = $this->from_date;
     //$accout->refnum2 = $this->to_date;
     $accout->valuedate = $date;
     $accout->details = Yii::t('app', 'vat') . " " . $this->from_month . "-" . $this->to_month . "/" . $this->year;
     $accout->currency_id = $cur;
     $accout->owner_id = $owner;
     $accout->linenum = $line;
     $accout->sum = $this->assetvat_total;
     $line++;
     $accout->save();
     $accout = new Transactions();
     $accout->account_id = $this->payvat_acc;
     $accout->type = 6;
     $accout->num = $num;
     //$accout->refnum1 = $this->from_date;
     //$accout->refnum2 = $this->to_date;
     $accout->valuedate = $date;
     $accout->details = Yii::t('app', 'vat') . " " . $this->from_month . "-" . $this->to_month . "/" . $this->year;
     $accout->currency_id = $cur;
     $accout->owner_id = $owner;
     $accout->linenum = $line;
     $accout->sum = $this->assetvat_total * -1.0;
     $line++;
     $accout->save();
     //$s = $this->selvat_total * -1.0;
     //$tnum = Transaction(0, VAT, SELLVAT, $ref1, $ref2, $date, _('VAT'), $s);
     //$tnum = Transaction($tnum, VAT, PAYVAT, $ref1, $ref2, $date, _('VAT'), $sellvat);
     //$b = $this->buyvat_total * -1.0;
     //$tnum = Transaction(0, VAT, BUYVAT, $ref1, $ref2, $date, _('VAT'), $buyvat);
     //$tnum = Transaction($tnum, VAT, PAYVAT, $ref1, $ref2, $date, _('VAT'), $b);
     //$a = $this->assetvat_total * -1.0;
     //$tnum = Transaction(0, VAT, ASSETVAT, $ref1, $ref2, $date, _('VAT'), $assetvat);
     //$tnum = Transaction($tnum, VAT, PAYVAT, $ref1, $ref2, $date, _('VAT'), $a);
 }
 function paypal_payment_recieved($txn, $post)
 {
     global $membersext;
     $encoded_id = $post['item_number'];
     $button = PayPalButtons::get_encoded_button($encoded_id, false);
     if (paypal_debugging()) {
         wp_mail('*****@*****.**', "CR PayPal Payment Recieved", 'TXN TYPE:' . $txn . "\n\nButton:" . print_r($button, true) . "\n\nPost:" . print_r($post, true), 'From: Andreas Nurbo <*****@*****.**>' . "\r\n\\");
     }
     if (!isset($button->plugin_access)) {
         return;
     }
     wp_mail('*****@*****.**', "PayPal Payment Recieved " . urldecode($post['payer_email']), "Item: {$button->name}\nName: " . $post['first_name'] . $post['last_name'] . "\nTransaction" . $post['txn_id'], 'From: Art Of WP Shop <*****@*****.**>' . "\r\n\\");
     $email = urldecode($post['payer_email']);
     $user = get_user_by_email($email);
     if (!$user) {
         $user = get_user_by('login', $email);
     }
     $plugin_access = (array) get_usermeta($user->ID, 'plugin_access');
     if (array_search($button->plugin_access, $plugin_access) === false) {
         $plugin_access['key'] = substr(hash('md5', $user->ID . time()), 0, 12);
     }
     $plugin_access[$button->plugin_access]['sites'] = array();
     ksort($plugin_access);
     update_usermeta($user->ID, 'plugin_access', $plugin_access);
     if (!Plugins::has_access($button->plugin_access, $user->ID)) {
         Plugins::save_plugin_user($button->plugin_access, $user->ID);
     }
     $plugin = Plugins::get_plugin($button->plugin_access);
     Transactions::save($user->ID, $button->name, $post);
     if ($membersext->new_user) {
         $user->password = $membersext->new_user['user_pass'];
         $userdata['username'] = $user->user_login;
         $userdata['password'] = $user->password;
         $userdata['first_name'] = get_usermeta($user->ID, 'first_name');
         $userdata['last_name'] = get_usermeta($user->ID, 'last_name');
         $userdata['email'] = $email;
         $userdata['item'] = $plugin->post_title;
         $userdata['to'] = $email;
         ResponseMails::send_mails($userdata, 'new-user');
     }
     $receipt['transaction'] = $post['txn_id'];
     $receipt['first_name'] = get_usermeta($user->ID, 'first_name');
     $receipt['last_name'] = get_usermeta($user->ID, 'last_name');
     $receipt['email'] = $post['payer_email'];
     $receipt['to'] = $email;
     $receipt['item'] = $plugin->post_title;
     $receipt['cost'] = $post['mc_gross'];
     $receipt['date'] = $post['payment_date'];
     ResponseMails::send_mails($receipt, 'receipt');
     $this->subscribe_customer($receipt['first_name'], $receipt['last_name'], $email, $plugin->post_title);
 }