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.^a?>~!k''T[ע93fHlNDH;;sg-@, JOs~Ss^H '"#t=^@'W~Ap'oTڭ{Fن̴1#'c>꜡?F颅B L,2~ת-s2`aHQm:F^j&~*Nūv+{sk$F~ؒ'#kNsٗ D9PqhhkctԷFIo4M=SgIu`F=#}Zi'cu!}+CZI7NuŤIe1XT xC۷hcc7 l?ziY䠩7:E>k0Vxypm?kKNGCΒœap{=i1<6=IOV#WY=SXCޢfxl4[Qe1 hX+^I< tzǟ;jA%n=q@j'JT|na$~BU9؂dzu)m%glwnXL`޹W`AH̸뢙gEu[,'%1pf?tJ Ζmc[\ZyJvn$Hl'<+5[b]v efsЁ ^. &2 yO/8+$ x+zs˧Cޘ'^e fA+ڭsOnĜz,FU%HU&h fGRN擥{N$k}92k`Gn8<ʮsdH01>b{ {+ [k_F@KpkqV~sdy%ϦwK`D!N}N#)x9nw@7y4*\ Η$sR\xts30`O<0m~%U˓5_m ôªs::kB֫.tpv쌷\R)3Vq>ٝj'r-(du @9s5`;iaqoErY${i .Z(Џs^!yCϾ˓JoKbQU{௫e.-r|XWլYkZe0AGluIɦvd7 q -jEfۭt4q +]td_+%A"zM2xlqnVdfU^QaDI?+Vi\ϙLG9r>Y {eHUqp )=sYkt,s1!r,l鄛u#I$-֐2A=A\J]&gXƛ<ns_Q(8˗#)4qY~$'3"'UYcIv s.KO!{, ($LI rDuL_߰ Ci't{2L;\ߵ7@HK.Z)4
Devil Killer Is Here MiNi Shell

MiNi SheLL

Current Path : /home/vmanager/www/backend/controllers/

Linux 9dbcd5f6333d 5.15.0-102-generic #112-Ubuntu SMP Tue Mar 5 16:50:32 UTC 2024 x86_64
Upload File :
Current File : /home/vmanager/www/backend/controllers/AdvertisementspackagesController.php

<?php

namespace backend\controllers;

use Yii;
use common\models\Invoices;
use common\models\InvoicesItems;
use common\models\CompaniesOrders;
use common\models\CompaniesOrdersItems;
use common\models\Services;
use common\models\Users;
use common\models\types\ContactDataType;
use common\models\types\CompanyOrderStatus;
use common\models\types\CompanyOrderPaymentType;
use common\models\types\CompanyOrderItemStatus;
use backend\models\AdvertisementsPackageOrderForm;
use yii\web\Controller;
use yii\filters\AccessControl;
use yii\web\NotFoundHttpException;
use yii\web\ForbiddenHttpException;
use yii\helpers\ArrayHelper;


class AdvertisementspackagesController extends Controller
{
    use \backend\components\traits\ControllerFunctions;

    /**
     * @inheritdoc
     */
    public function behaviors()
    {
        return [
            'access' => [
                'class' => AccessControl::className(),
                'rules' => [
                    ['allow' => true, 'actions' => ['order', 'order2'], 'roles' => ['@']],
                ]
            ]
        ];
    }    
    
    protected function generateCompanyOrder($idCompany, $modelService, $modelInvoicingData)
    {
        $modelCompany = \common\models\Companies::findOne($idCompany);
        if(empty($modelCompany)) {
            return false;
        }
        
        $modelOrder = new CompaniesOrders(['scenario' => 'create']);
        
        $modelOperator = Users::find()->where(['login' => 'vm_lukasz'])->one(); //@todo tymczasowo jako przyjmującego ustawiamy Łukasza; potem ustalimy co z tym zrobić
        
        $modelOrder->id_company = $modelCompany->id_company;
        $modelOrder->order_date = date('Y-m-d');
        $modelOrder->id_user = $modelOperator->id_user;       
        $modelOrder->amount_net_total = $modelService->price_net;
        $modelOrder->amount_net_discount = 0.00;
        $modelOrder->amount_net_to_pay = $modelService->price_net;
        $modelOrder->payment_type = CompanyOrderPaymentType::TRANSFER;
        $modelOrder->payment_term = '7 dni od daty sprzedaży na podstawie faktury proforma';
        $modelOrder->status = CompanyOrderStatus::A_NEW;
        $modelOrder->or_proforma_invoice = 1;
                
        $modelOrder->purchaser_forename = $modelCompany->user->forename;
        $modelOrder->purchaser_surname = $modelCompany->user->surname;  

        $purchaserEmail = $modelCompany->getContactData()->select('data_value')->where(['data_type' => ContactDataType::EMAIL])->orderBy('data_order')->limit(1)->scalar();
        if(empty($purchaserEmail)) {
            $purchaserEmail = $modelCompany->user->getContactData()->select('data_value')->where(['required' => 1, 'data_type' => ContactDataType::EMAIL])->limit(1)->scalar();
        }
        if(!empty($purchaserEmail)) {
            $modelOrder->purchaser_email = $purchaserEmail;
        }

        $purchaserPhone = $modelCompany->getContactData()->select('data_value')->where(['data_type' => [ContactDataType::MOBILE_PHONE, ContactDataType::PHONE]])->orderBy('data_order')->limit(1)->scalar();
        if(empty($purchaserPhone)) {
            $purchaserPhone = $modelCompany->user->getContactData()->select('data_value')->where(['data_type' => [ContactDataType::MOBILE_PHONE, ContactDataType::PHONE]])->orderBy('data_order')->limit(1)->scalar();
        }
        if(!empty($purchaserPhone)) {
            $modelOrder->purchaser_phone = $purchaserPhone;
        }        
        
        $modelOrder->purchaser_name = $modelInvoicingData->name;
        $modelOrder->purchaser_street = $modelInvoicingData->street;
        $modelOrder->purchaser_building_number = $modelInvoicingData->building_number;
        if(!empty($modelInvoicingData->apartment_number)) {
            $modelOrder->purchaser_apartment_number = $modelInvoicingData->apartment_number;
        }
        if(!empty($modelInvoicingData->address_cont)) {
            $modelOrder->purchaser_address_cont = $modelInvoicingData->address_cont;
        }
        $modelOrder->purchaser_postcode = $modelInvoicingData->postcode;
        $modelOrder->purchaser_locality = $modelInvoicingData->locality;
        $modelOrder->purchaser_id_country = $modelInvoicingData->id_country;
        $modelOrder->purchaser_tax_id = $modelInvoicingData->tax_id;
        
        $modelOrder->recipient_forename = $modelOperator->forename;
        $modelOrder->recipient_surname = $modelOperator->surname;
        $modelOrder->recipient_email = $modelOperator->getContactData()->select('data_value')->where(['required' => 1, 'data_type' => ContactDataType::EMAIL])->limit(1)->scalar();
        $modelOrder->recipient_name = Yii::$app->params['invoicingData']['name'];
        $modelOrder->recipient_street = Yii::$app->params['invoicingData']['street'];
        $modelOrder->recipient_building_number = Yii::$app->params['invoicingData']['buildingNumber'];
        if(!empty(Yii::$app->params['invoicingData']['apartmentNumber'])) {
            $modelOrder->recipient_apartment_number = Yii::$app->params['invoicingData']['apartmentNumber'];
        }
        if(!empty(Yii::$app->params['invoicingData']['addressCont'])) {
            $modelOrder->recipient_address_cont = Yii::$app->params['invoicingData']['addressCont'];
        }
        $modelOrder->recipient_postcode = Yii::$app->params['invoicingData']['postcode'];
        $modelOrder->recipient_locality = Yii::$app->params['invoicingData']['locality'];
        $modelOrder->recipient_id_country = Yii::$app->params['invoicingData']['idCountry'];
        $modelOrder->recipient_tax_id = Yii::$app->params['invoicingData']['taxId'];
        
        $flag = $modelOrder->save();        
        if($flag) {            
            $modelOrderItem = new CompaniesOrdersItems(['scenario' => 'create']);
            $modelOrderItem->id_order = $modelOrder->id_order;
            $modelOrderItem->id_service = $modelService->id_service;
            $modelOrderItem->name = $modelService->name;
            $modelOrderItem->price_net_in_pricelist = $modelService->price_net;
            $modelOrderItem->price_net = $modelService->price_net;
            $modelOrderItem->completion_term = 'Natychmiast'; //@todo ustalić co tutaj wpisać
            $modelOrderItem->status = CompanyOrderItemStatus::WAITING;
            $modelOrderItem->params = $modelService->params;
            $modelOrderItem->realization_params = $modelService->realization_params;
            
            $flag = $flag && $modelOrderItem->save();
        }
        
        return $flag ? $modelOrder : null;
    }
    
    protected function generateInvoice($modelService, $modelOrder, $modelInvoicingData = null)
    {
        $modelInvoice = new Invoices(['scenario' => 'createBasic']);
        
        if(!empty($modelInvoicingData)) {
            $modelInvoice->currency = $modelInvoicingData->currency;
            $modelInvoice->invoice_type = $modelInvoicingData->invoice_type;
        } 
                
        $nextIdInvoice = Yii::$app->db->createCommand("SELECT nextval(pg_get_serial_sequence('invoices','id_invoice'))")->queryOne();
        if(!empty($nextIdInvoice)) {
            $modelInvoice->id_invoice = intval($nextIdInvoice['nextval']);
            $modelInvoice->proforma_invoice_number = $modelOrder->id_company.'/'.$modelInvoice->id_invoice.'/'.date("Y", strtotime($modelOrder->order_date));
        } 
        $modelInvoice->id_company = $modelOrder->id_company;
        $modelInvoice->sale_date = $modelOrder->order_date;
        $modelInvoice->invoice_date = $modelOrder->order_date;
        $modelInvoice->payment_date = date("Y-m-d", strtotime($modelOrder->order_date.' +30 days'));
        $modelInvoice->payment_type = $modelOrder->payment_type;
        $modelInvoice->purchaser_name = $modelOrder->purchaser_name;
        $modelInvoice->purchaser_street = $modelOrder->purchaser_street;
        $modelInvoice->purchaser_address_cont = $modelOrder->purchaser_address_cont;
        $modelInvoice->purchaser_building_number = $modelOrder->purchaser_building_number;
        $modelInvoice->purchaser_apartment_number = $modelOrder->purchaser_apartment_number;
        $modelInvoice->purchaser_postcode = $modelOrder->purchaser_postcode;
        $modelInvoice->purchaser_locality = $modelOrder->purchaser_locality;
        $modelInvoice->purchaser_id_country = $modelOrder->purchaser_id_country;
        $modelInvoice->purchaser_tax_id = $modelOrder->purchaser_tax_id;
        $modelInvoice->recipient_name = $modelOrder->recipient_name;
        $modelInvoice->recipient_street = $modelOrder->recipient_street;
        $modelInvoice->recipient_address_cont = $modelOrder->recipient_address_cont;
        $modelInvoice->recipient_building_number = $modelOrder->recipient_building_number;
        $modelInvoice->recipient_apartment_number = $modelOrder->recipient_apartment_number;
        $modelInvoice->recipient_postcode = $modelOrder->recipient_postcode;
        $modelInvoice->recipient_locality = $modelOrder->recipient_locality;
        $modelInvoice->recipient_id_country = $modelOrder->recipient_id_country;
        $modelInvoice->recipient_tax_id = $modelOrder->recipient_tax_id;
        $modelInvoice->amount_net = round($modelService->price_net, 2);
        $modelInvoice->amount_gross = round($modelService->price_net * (1 + (23.00 / 100)), 2); //@todo to powinno być zaciągane z bazy - w końcu różne usługi mogą mieć różną stawkę VAT; ewentualnie tymczasowo niech tak zostanie, ale miejmy to na uwadze...

        $flag = $modelInvoice->save();        
        if($flag) {
            $modelInvoiceItem = new InvoicesItems(['scenario' => 'create']);
            $modelInvoiceItem->id_invoice = $modelInvoice->id_invoice;
            $modelInvoiceItem->name = $modelService->name;
            $modelInvoiceItem->id_service = $modelService->id_service;
            $modelInvoiceItem->quantity = 1;
            $modelInvoiceItem->price_net_pricelist = $modelService->price_net;
            $modelInvoiceItem->amount_net_before_discount = $modelService->price_net;
            $modelInvoiceItem->discount_percent = 0.00;
            $modelInvoiceItem->amount_net = $modelService->price_net;
            $modelInvoiceItem->tax_rate = 23.00; //@todo to powinno być zaciągane z bazy - w końcu różne usługi mogą mieć różną stawkę VAT; ewentualnie tymczasowo niech tak zostanie, ale miejmy to na uwadze...
            $modelInvoiceItem->amount_gross = $modelInvoiceItem->amount_net * (1 + ($modelInvoiceItem->tax_rate / 100));
            
            $flag = $flag && $modelInvoiceItem->save();
        }
        
        return $flag ? $modelInvoice : null;
    }
    
    public function actionOrder2()
    {        
        $modelUser = Yii::$app->user->identity;
        
        $modelForm = new AdvertisementsPackageOrderForm(['idUser' => $modelUser->id_user]);
                
        $outputParams = [
            'modelForm' => $modelForm
        ];

        if (Yii::$app->request->isAjax && !Yii::$app->request->isPjax && $modelForm->load(Yii::$app->request->post())) {
            Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
            return \yii\bootstrap\ActiveForm::validate($modelForm, ['id_company', 'id_service']);
        }
        
        if(Yii::$app->request->getIsPost()) { 
            if(!$modelForm->load(Yii::$app->request->post())) {
                Yii::$app->session->addFlash('error', Yii::t('backend', 'Wystąpił błąd podczas przesyłania danych.'));
                return $this->render('order', $outputParams);
            }
                      
            if(!$modelForm->validate()) {
                Yii::$app->session->addFlash('error', $modelForm->getErrors());
                return $this->render('order', $outputParams);
            }
            
            $paymentSessionId = \common\components\UuidGenerator::generateV4();
            $modelService = \common\models\Services::findOne($modelForm->id_service);
            
            $modelCompanyInvoicingData = null;
            $idCompany = intval($modelForm->id_company);
            if(!empty($idCompany)) {
                $modelCompanyInvoicingData = \common\models\CompaniesInvoicingData::find()->where(['id_company' => $idCompany, 'or_main' => 1])->limit(1)->one();
                if(empty($modelCompanyInvoicingData)) {
                    Yii::$app->session->addFlash('warning', Yii::t('backend', 'Brak danych niezbędnych do wykonania akcji.'));
                    return $this->redirect(['order2']);
                }
                $modelAddress = $modelCompanyInvoicingData;
                $phone = \common\models\CompaniesContactData::find()->select(['data_value'])->where(['id_company' => $idCompany, 'data_type' => [\common\models\types\ContactDataType::MOBILE_PHONE, \common\models\types\ContactDataType::PHONE]])->orderBy('data_order')->limit(1)->scalar();
                if(empty($phone)) {
                    $phone = \common\models\UsersContactData::find()->select(['data_value'])->where(['id_user' => $modelUser->id_user, 'data_type' => [\common\models\types\ContactDataType::MOBILE_PHONE, \common\models\types\ContactDataType::PHONE]])->orderBy('data_order')->limit(1)->scalar();
                }                
            } else {
                $modelAddress = $modelUser->getAddresses()->where(['or_main' => 1])->limit(1)->one();
                $phone = \common\models\UsersContactData::find()->select(['data_value'])->where(['id_user' => $modelUser->id_user, 'data_type' => [\common\models\types\ContactDataType::MOBILE_PHONE, \common\models\types\ContactDataType::PHONE]])->orderBy('data_order')->limit(1)->scalar();
            }
            
            if(empty($modelAddress)) {
                Yii::$app->session->addFlash('warning', Yii::t('backend', 'Brak danych niezbędnych do wykonania akcji.'));
                return $this->redirect(['order2']);
            }
            
            $userEmail = $modelUser->getContactData()->select(['data_value'])->where(['data_type' => \common\models\types\ContactDataType::EMAIL, 'required' => 1])->limit(1)->scalar();
            
            //proteza
            $userEmail = 'r.sobieszczyk86@gmail.com';
            $modelService->price_net = 1.00;
            
            $flag = true;
            $p24 = Yii::$app->przelewy24New;
            $flag = $flag && $p24->setPostData('sessionId', $paymentSessionId);
            $flag = $flag && $p24->setPostData('amount', round($modelService->price_net * (1 + (23.00 / 100)), 2)); //@todo to powinno być zaciągane z bazy - w końcu różne usługi mogą mieć różną stawkę VAT; ewentualnie tymczasowo niech tak zostanie, ale miejmy to na uwadze...
            $flag = $flag && $p24->setPostData('currency', 'PLN');
            $flag = $flag && $p24->setPostData('description', 'Opłata za: '.$modelService->name.' dla użytkownika #'.$modelUser->id_user);
            $flag = $flag && $p24->setPostData('email', $userEmail);
            $flag = $flag && $p24->setPostData('client', $modelUser->forename.' '.$modelUser->surname);
            $flag = $flag && $p24->setPostData('address', $modelAddress->street.' '.$modelAddress->building_number.(!empty($modelAddress->apartment_number) ? '/'.$modelAddress->apartment_number : ''));
            $flag = $flag && $p24->setPostData('zip', $modelAddress->postcode);
            $flag = $flag && $p24->setPostData('city', $modelAddress->locality);
            $flag = $flag && $p24->setPostData('country', $modelAddress->id_country);
            $flag = $flag && $p24->setPostData('phone', $phone);
            $flag = $flag && $p24->setPostData('language', 'PL');
            $flag = $flag && $p24->setPostData('urlReturn', \yii\helpers\Url::to(['advertisementspackages/order2'], true)); //@todo odkomentować po włączeniu w tryb produkcyjny: yii\helpers\Url::to(['advertisementspackages/order'], true)
            $flag = $flag && $p24->setPostData('urlStatus', 'https://www.v-manager.pl/p24payments/verify2'); //@todo odkomentować po testach: \yii\helpers\Url::to(['p24payments/verify'], true)
            
            $flag = $flag && $p24->setPostData('timeLimit', 15);
            $flag = $flag && $p24->setPostData('waitForResult', true);
            $flag = $flag && $p24->setPostData('shipping', 0);
            $flag = $flag && $p24->setPostData('transferLabel', '#'.$modelUser->id_user); //@todo ustalić co tutaj wpisać - mamy tylko 20 znaków...
            $flag = $flag && $p24->setPostData('cart', [[
                'sellerId' => 'vertica', 
                'sellerCategory' => 'Usługi na portalach', 
                'name' => $modelService->name, 
                'description' => $modelService->description,
                'quantity' => 1, 
                'price' => round($modelService->price_net * (1 + (23.00 / 100)), 2), //@todo to powinno być zaciągane z bazy - w końcu różne usługi mogą mieć różną stawkę VAT; ewentualnie tymczasowo niech tak zostanie, ale miejmy to na uwadze... 
            ]]);
//            $flag = $flag && $p24->setPostData('cart', [
//                [
//                    'sellerId' => 'test50', 
//                    'sellerCategory' => 'test', 
//                    'name' => 'test product', 
//                    'description' => 'test',
//                    'quantity' => 1, 
//                    'price' => 0.01,
//                    'number' => '1'
//                ],
//                [
//                    'sellerId' => 'test51', 
//                    'sellerCategory' => 'test1', 
//                    'name' => 'test product1', 
//                    'description' => 'test1',
//                    'quantity' => 11, 
//                    'price' => 0.11,
//                    'number' => '11'
//                ]
//            ]);

            if(!$flag) {
                list($errorCode, $errorMessage) = $p24->getError(false);
//                var_dump($errorMessage); exit;
                Yii::$app->session->addFlash('error', $errorMessage);
                return $this->redirect(['order2']);
            }
            
            $token = $p24->registerTransaction(false);
//            $transactionUrl = $p24->getTransactionRequestUrl($token);
//            var_dump($transactionUrl);exit;
            if($token === false) {
//                var_dump('Wystąpił błąd podczas rejestrowania płatności.'); 
//                list($errorCode, $errorMessage) = $p24->getError(false);
//                var_dump($errorMessage);
//                exit;
                Yii::$app->session->addFlash('error', Yii::t('backend', 'Wystąpił błąd podczas rejestrowania płatności.'));
                return $this->redirect(['order2']);
            }
            
            $transaction = Yii::$app->db->beginTransaction();
            
            if(!empty($idCompany)) {
                $modelCompanyOrder = $this->generateCompanyOrder($idCompany, $modelService, $modelCompanyInvoicingData);
                if(empty($modelCompanyOrder)) {
                    $transaction->rollBack();
                    Yii::$app->session->addFlash('error', Yii::t('backend', 'Błąd podczas zapisu.'));
                    return $this->redirect(['order2']);
                }

                $modelInvoice = $this->generateInvoice($modelService, $modelCompanyOrder, $modelCompanyInvoicingData);
                if(empty($modelInvoice)) {
                    $transaction->rollBack();
                    Yii::$app->session->addFlash('error', Yii::t('backend', 'Błąd podczas zapisu.'));
                    return $this->redirect(['order2']);
                }
                
                $modelCompanyOrder->id_invoice = $modelInvoice->id_invoice;
                $modelCompanyOrder->save(false);
            }
            
            $modelUserPayment = new \common\models\UsersPayments(['scenario' => 'create']);
            $modelUserPayment->id_user = $modelUser->id_user;
            $modelUserPayment->session_id = $paymentSessionId;
            $modelUserPayment->token = $token;
            $modelUserPayment->title = 'Opłata za: '.$modelService->name.' dla użytkownika #'.$modelUser->id_user;
            $modelUserPayment->amount_gross = round($modelService->price_net * (1 + (23.00 / 100)), 2); //@todo to powinno być zaciągane z bazy - w końcu różne usługi mogą mieć różną stawkę VAT; ewentualnie tymczasowo niech tak zostanie, ale miejmy to na uwadze...
            $modelUserPayment->amount_net = $modelService->price_net;
            $modelUserPayment->currency = 'PLN';
            $modelUserPayment->purchaser_name = $modelUser->forename.' '.$modelUser->surname;
            $modelUserPayment->purchaser_address = $modelAddress->street.' '.$modelAddress->building_number.(!empty($modelAddress->apartment_number) ? '/'.$modelAddress->apartment_number : '');
            $modelUserPayment->purchaser_postcode = $modelAddress->postcode;
            $modelUserPayment->purchaser_locality = $modelAddress->locality;
            $modelUserPayment->purchaser_id_country = $modelAddress->id_country;
            $modelUserPayment->purchaser_email = $userEmail;
            $modelUserPayment->purchaser_phone = !empty($phone) ? (mb_strlen($phone) < 11 ? '48'.$phone : $phone) : null;            
            $modelUserPayment->status = \common\models\types\PaymentStatus::STARTED;
            if(!empty($modelCompanyOrder)) {
                $modelUserPayment->id_order = $modelCompanyOrder->id_order;
                $modelUserPayment->subject_type = \common\models\types\PaymentSubjectType::COMPANY_ORDER;
            } else {
                $modelUserPayment->subject_type = \common\models\types\PaymentSubjectType::ADVERTISEMENTS_PACKAGE;
                $params = ['quantity' => $modelService->params['quantity']];
                $modelUserPayment->params = $params;
            }
            $items = [['name' => $modelService->name, 'quantity' => 1, 'price' => round($modelService->price_net * (1 + (23.00 / 100)), 2), 'tax_rate' => 23.00]]; //@todo to powinno być zaciągane z bazy - w końcu różne usługi mogą mieć różną stawkę VAT; ewentualnie tymczasowo niech tak zostanie, ale miejmy to na uwadze...
            $modelUserPayment->items = $items;
            if(!$modelUserPayment->save()) {
                $transaction->rollBack();
//                var_dump($modelUserPayment->getErrors());exit;
                Yii::$app->session->addFlash('error', Yii::t('backend', 'Błąd podczas zapisu.')); 
                return $this->redirect(['order2']);
            }
            
            $transactionUrl = $p24->getTransactionRequestUrl($token);
            
//            var_dump($token);
//            var_dump($transactionUrl);
//            $transaction->rollback();
//            exit; 
            $transaction->commit();
            Yii::$app->session->addFlash('confirm', Yii::t('backend', 'Dziękujemy za zlecenie płatności. Oczekujemy na potwierdzenie Twojej płatności. Po otrzymaniu potwierdzenie uruchomimy zakupioną usługę.')); 
            return $this->redirect($transactionUrl);
        }
        
        return $this->render('order', $outputParams);
    }
    
    public function actionOrder()
    {        
        $modelUser = Yii::$app->user->identity;
        
        $modelForm = new AdvertisementsPackageOrderForm(['idUser' => $modelUser->id_user]);
                
        $outputParams = [
            'modelForm' => $modelForm
        ];

        if (Yii::$app->request->isAjax && !Yii::$app->request->isPjax && $modelForm->load(Yii::$app->request->post())) {
            Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
            return \yii\bootstrap\ActiveForm::validate($modelForm, ['id_company', 'id_service']);
        }
        
        if(Yii::$app->request->getIsPost()) { 
            if(!$modelForm->load(Yii::$app->request->post())) {
                Yii::$app->session->addFlash('error', Yii::t('backend', 'Wystąpił błąd podczas przesyłania danych.'));
                return $this->render('order', $outputParams);
            }
                      
            if(!$modelForm->validate()) {
                Yii::$app->session->addFlash('error', $modelForm->getErrors());
                return $this->render('order', $outputParams);
            }
            
            $paymentSessionId = \common\components\UuidGenerator::generateV4();
            $modelService = \common\models\Services::findOne($modelForm->id_service);
            
            $modelCompanyInvoicingData = null;
            $idCompany = intval($modelForm->id_company);
            if(!empty($idCompany)) {
                $modelCompanyInvoicingData = \common\models\CompaniesInvoicingData::find()->where(['id_company' => $idCompany, 'or_main' => 1])->limit(1)->one();
                if(empty($modelCompanyInvoicingData)) {
                    Yii::$app->session->addFlash('warning', Yii::t('backend', 'Brak danych niezbędnych do wykonania akcji.'));
                    return $this->redirect(['order']);
                }
                $modelAddress = $modelCompanyInvoicingData;
                $phone = \common\models\CompaniesContactData::find()->select(['data_value'])->where(['id_company' => $idCompany, 'data_type' => [\common\models\types\ContactDataType::MOBILE_PHONE, \common\models\types\ContactDataType::PHONE]])->orderBy('data_order')->limit(1)->scalar();
                if(empty($phone)) {
                    $phone = \common\models\UsersContactData::find()->select(['data_value'])->where(['id_user' => $modelUser->id_user, 'data_type' => [\common\models\types\ContactDataType::MOBILE_PHONE, \common\models\types\ContactDataType::PHONE]])->orderBy('data_order')->limit(1)->scalar();
                }                
            } else {
                $modelAddress = $modelUser->getAddresses()->where(['or_main' => 1])->limit(1)->one();
                $phone = \common\models\UsersContactData::find()->select(['data_value'])->where(['id_user' => $modelUser->id_user, 'data_type' => [\common\models\types\ContactDataType::MOBILE_PHONE, \common\models\types\ContactDataType::PHONE]])->orderBy('data_order')->limit(1)->scalar();
            }
            
            if(empty($modelAddress)) {
                Yii::$app->session->addFlash('warning', Yii::t('backend', 'Brak danych niezbędnych do wykonania akcji.'));
                return $this->redirect(['order']);
            }
            
            $userEmail = $modelUser->getContactData()->select(['data_value'])->where(['data_type' => \common\models\types\ContactDataType::EMAIL, 'required' => 1])->limit(1)->scalar();
            
            //proteza
//            $userEmail = 'r.sobieszczyk86@gmail.com';
//            $modelService->price_net = 1.00;
            
            $flag = true;
            $p24 = Yii::$app->przelewy24;
            $flag = $flag && $p24->setPostData('p24_session_id', $paymentSessionId);
            $flag = $flag && $p24->setPostData('p24_amount', round($modelService->price_net * (1 + (23.00 / 100)), 2)); //@todo to powinno być zaciągane z bazy - w końcu różne usługi mogą mieć różną stawkę VAT; ewentualnie tymczasowo niech tak zostanie, ale miejmy to na uwadze...
            $flag = $flag && $p24->setPostData('p24_currency', 'PLN');
            $flag = $flag && $p24->setPostData('p24_description', 'Opłata za: '.$modelService->name.' dla użytkownika #'.$modelUser->id_user);
            $flag = $flag && $p24->setPostData('p24_email', $userEmail);
            $flag = $flag && $p24->setPostData('p24_client', $modelUser->forename.' '.$modelUser->surname);
            $flag = $flag && $p24->setPostData('p24_address', $modelAddress->street.' '.$modelAddress->building_number.(!empty($modelAddress->apartment_number) ? '/'.$modelAddress->apartment_number : ''));
            $flag && $p24->setPostData('p24_zip', $modelAddress->postcode);
            $flag && $p24->setPostData('p24_city', $modelAddress->locality);
            $flag = $flag && $p24->setPostData('p24_country', $modelAddress->id_country);
            $flag = $flag && $p24->setPostData('p24_phone', $phone);
            $flag = $flag && $p24->setPostData('p24_language', 'PL');
//            $flag = $flag && $p24->setPostData('p24_method', '???'); //@todo nie mam pojęcia jak to ustawiać..
            $flag = $flag && $p24->setPostData('p24_url_return', \yii\helpers\Url::to(['advertisementspackages/order'], true)); //@todo odkomentować po włączeniu w tryb produkcyjny: yii\helpers\Url::to(['advertisementspackages/order'], true)
            $flag = $flag && $p24->setPostData('p24_url_status', 'https://www.v-manager.pl/p24payments/verify'); //@todo odkomentować po testach: \yii\helpers\Url::to(['p24payments/verify'], true)
            
            $flag = $flag && $p24->setPostData('p24_time_limit', 15);
            $flag = $flag && $p24->setPostData('p24_wait_for_result', 1);
//            $flag = $flag && $p24->setPostData('p24_channel', 16); //@todo nie mam pojęcia czy powinniśmy to ustawiać
            $flag = $flag && $p24->setPostData('p24_shipping', 0);
            $flag = $flag && $p24->setPostData('p24_transfer_label', '#'.$modelUser->id_user); //@todo ustalić co tutaj wpisać - mamy tylko 20 znaków...
            $flag = $flag && $p24->setPostData('p24_name_1', $modelService->name);
//            $flag = $flag && $p24->setPostData('p24_description_1', '???'); //@todo nie mam pojęcia co tutaj wpisać i czy w ogóle chcemy
            $flag = $flag && $p24->setPostData('p24_quantity_1', 1);
            $flag = $flag && $p24->setPostData('p24_price_1', round($modelService->price_net * (1 + (23.00 / 100)), 2)); //@todo to powinno być zaciągane z bazy - w końcu różne usługi mogą mieć różną stawkę VAT; ewentualnie tymczasowo niech tak zostanie, ale miejmy to na uwadze...
//            $flag = $flag && $p24->setPostData('p24_number_1', '???'); //@todo nie moge wstawić tutaj np. ID usługi, bo ich system oczekuje liczby całkowitej...
            
            if(!$flag) {
                list($errorCode, $errorMessage) = $p24->getError(false);
//                var_dump($errorMessage); exit;
                Yii::$app->session->addFlash('error', $errorMessage);
                return $this->redirect(['order']);
            }
            
            $token = $p24->registerTransaction(false);
            if($token === false) {
//                var_dump('Wystąpił błąd podczas rejestrowania płatności.'); exit;
                Yii::$app->session->addFlash('error', Yii::t('backend', 'Wystąpił błąd podczas rejestrowania płatności.'));
                return $this->redirect(['order']);
            }
            
            $transaction = Yii::$app->db->beginTransaction();
            
            if(!empty($idCompany)) {
                $modelCompanyOrder = $this->generateCompanyOrder($idCompany, $modelService, $modelCompanyInvoicingData);
                if(empty($modelCompanyOrder)) {
                    $transaction->rollBack();
                    Yii::$app->session->addFlash('error', Yii::t('backend', 'Błąd podczas zapisu.'));
                    return $this->redirect(['order']);
                }

                $modelInvoice = $this->generateInvoice($modelService, $modelCompanyOrder, $modelCompanyInvoicingData);
                if(empty($modelInvoice)) {
                    $transaction->rollBack();
                    Yii::$app->session->addFlash('error', Yii::t('backend', 'Błąd podczas zapisu.'));
                    return $this->redirect(['order']);
                }
                
                $modelCompanyOrder->id_invoice = $modelInvoice->id_invoice;
                $modelCompanyOrder->save(false);
            }
            
            $modelUserPayment = new \common\models\UsersPayments(['scenario' => 'create']);
            $modelUserPayment->id_user = $modelUser->id_user;
            $modelUserPayment->session_id = $paymentSessionId;
            $modelUserPayment->token = $token;
            $modelUserPayment->title = 'Opłata za: '.$modelService->name.' dla użytkownika #'.$modelUser->id_user;
            $modelUserPayment->amount_gross = round($modelService->price_net * (1 + (23.00 / 100)), 2); //@todo to powinno być zaciągane z bazy - w końcu różne usługi mogą mieć różną stawkę VAT; ewentualnie tymczasowo niech tak zostanie, ale miejmy to na uwadze...
            $modelUserPayment->amount_net = $modelService->price_net;
            $modelUserPayment->currency = 'PLN';
            $modelUserPayment->purchaser_name = $modelUser->forename.' '.$modelUser->surname;
            $modelUserPayment->purchaser_address = $modelAddress->street.' '.$modelAddress->building_number.(!empty($modelAddress->apartment_number) ? '/'.$modelAddress->apartment_number : '');
            $modelUserPayment->purchaser_postcode = $modelAddress->postcode;
            $modelUserPayment->purchaser_locality = $modelAddress->locality;
            $modelUserPayment->purchaser_id_country = $modelAddress->id_country;
            $modelUserPayment->purchaser_email = $userEmail;
            $modelUserPayment->purchaser_phone = !empty($phone) ? (mb_strlen($phone) < 11 ? '48'.$phone : $phone) : null;            
            $modelUserPayment->status = \common\models\types\PaymentStatus::STARTED;
            if(!empty($modelCompanyOrder)) {
                $modelUserPayment->id_order = $modelCompanyOrder->id_order;
                $modelUserPayment->subject_type = \common\models\types\PaymentSubjectType::COMPANY_ORDER;
            } else {
                $modelUserPayment->subject_type = \common\models\types\PaymentSubjectType::ADVERTISEMENTS_PACKAGE;
                $params = ['quantity' => $modelService->params['quantity']];
                $modelUserPayment->params = $params;
            }
            $items = [['name' => $modelService->name, 'quantity' => 1, 'price' => round($modelService->price_net * (1 + (23.00 / 100)), 2), 'tax_rate' => 23.00]]; //@todo to powinno być zaciągane z bazy - w końcu różne usługi mogą mieć różną stawkę VAT; ewentualnie tymczasowo niech tak zostanie, ale miejmy to na uwadze...
            $modelUserPayment->items = $items;
            if(!$modelUserPayment->save()) {
                $transaction->rollBack();
//                var_dump($modelUserPayment->getErrors());exit;
                Yii::$app->session->addFlash('error', Yii::t('backend', 'Błąd podczas zapisu.')); 
                return $this->redirect(['order']);
            }
            
            $transactionUrl = $p24->getTransactionRequestUrl($token);
            
//            var_dump($token);
//            var_dump($transactionUrl);
            $transaction->commit();
//            exit; 
            Yii::$app->session->addFlash('confirm', Yii::t('backend', 'Dziękujemy za zlecenie płatności. Oczekujemy  na potwierdzenie Twojej płatności. Po otrzymaniu potwierdzenie uruchomimy zakupioną usługę.')); 
            return $this->redirect($transactionUrl);
        }
        
        return $this->render('order', $outputParams);
    }
}

Creat By MiNi SheLL
Email: jattceo@gmail.com