Пример #1
0
 public static function pdfDoc($model)
 {
     $yiiBasepath = Yii::$app->basePath;
     $yiiUser = \app\helpers\Linet3Helper::getUserId();
     //$configPath = app\helpers\Linet3Helper::getSetting("company.path");
     $user = User::findOne($yiiUser);
     if (!$user->hasCert()) {
         //create new
         $settings = array('commonName' => $user->username, 'emailAddress' => $user->email);
         if (\app\helpers\Linet3Helper::getSetting('company.en.city') != '') {
             $settings['localityName'] = \app\helpers\Linet3Helper::getSetting('company.en.city');
         }
         if (\app\helpers\Linet3Helper::getSetting('company.en.name') != '') {
             $settings['organizationName'] = \app\helpers\Linet3Helper::getSetting('company.en.name');
         }
         $ssl = new \app\helpers\SSLHelper($settings);
         $filename = $user->getCertFilePath();
         \app\helpers\Linet3Helper::setSetting('company.' . $yiiUser . '.certpasswd', $ssl->createUserCert($filename));
         //$user->save();
     }
     $configCertpasswd = \app\helpers\Linet3Helper::getSetting('company.' . $yiiUser . '.certpasswd');
     $name = $model->docType->name . "-" . "{$model->docnum}.pdf";
     $file = PrintDoc::findFile($model, $name);
     if (!$file) {
         $model->preview = 2;
         $docfile = PrintDoc::printMe($model);
         /*//adam
           $file = new Files();
           $file->name = $name;
           $file->path = "docs/";
           $file->parent_type = get_class($model);
           $file->parent_id = $model->id;
           $file->hidden = 1;
           $file->public = 0;
           $file->save();
           $file->writeFile($docfile);
           exit;
           //adam*/
         //$mPDF1 = new Pdf;
         //$mPDF1->execute(['WriteHTML' => $docfile]);
         $pdf = new Pdf(['mode' => Pdf::MODE_UTF8, 'format' => Pdf::FORMAT_A4, 'orientation' => Pdf::ORIENT_PORTRAIT, 'methods' => ['SetFooter' => ['Linet 3.1 Accounting Software']]]);
         $mpdf = $pdf->api;
         //$mpdf->fonttrans['freeserif'] = 'freeserif2';
         //$mpdf->PDFAauto = true;
         $mpdf->WriteHtml($docfile);
         $file = new Files();
         $file->name = $name;
         $file->path = "docs/";
         $file->parent_type = get_class($model);
         $file->parent_id = $model->id;
         $file->hidden = 1;
         $file->public = 0;
         $file->save();
         //var_dump($file->getErrors());
         //exit;
         $file->writeFile($mpdf->output("bla", "S"));
     }
     $name = $model->docType->name . "-" . "{$model->docnum}-signed.pdf";
     $doc_file = PrintDoc::findFile($model, $name);
     if (!$doc_file) {
         //'digi';//
         $cerfile = User::getCertFilePath($yiiUser);
         //loads a sample PDF file
         Yii::$classMap['Farit_Pdf'] = $yiiBasepath . '/vendor/Farit/Pdf.php';
         Yii::$classMap['Farit_Pdf_ElementRaw'] = $yiiBasepath . '/vendor/Farit/ElementRaw.php';
         Yii::$classMap['Zend_Memory'] = $yiiBasepath . '/vendor/Zend/Memory.php';
         Yii::$classMap['Zend_Memory_Manager'] = $yiiBasepath . '/vendor/Zend/Memory/Manager.php';
         Yii::$classMap['Zend_Memory_Container'] = $yiiBasepath . '/vendor/Zend/Memory/Container.php';
         Yii::$classMap['Zend_Memory_Container_Interface'] = $yiiBasepath . '/vendor/Zend/Memory/Container/Interface.php';
         Yii::$classMap['Zend_Memory_Container_Locked'] = $yiiBasepath . '/vendor/Zend/Memory/Container/Locked.php';
         Yii::$classMap['Zend_Pdf'] = $yiiBasepath . '/vendor/Zend/Pdf.php';
         Yii::$classMap['Zend_Pdf_Parser'] = $yiiBasepath . '/vendor/Zend/Pdf/Parser.php';
         Yii::$classMap['Zend_Pdf_Page'] = $yiiBasepath . '/vendor/Zend/Pdf/Page.php';
         Yii::$classMap['Zend_Pdf_UpdateInfoContainer'] = $yiiBasepath . '/vendor/Zend/Pdf/UpdateInfoContainer.php';
         Yii::$classMap['Zend_Pdf_Target'] = $yiiBasepath . '/vendor/Zend/Pdf/Target.php';
         Yii::$classMap['Zend_Pdf_Destination'] = $yiiBasepath . '/vendor/Zend/Pdf/Destination.php';
         Yii::$classMap['Zend_Pdf_Destination_Zoom'] = $yiiBasepath . '/vendor/Zend/Pdf/Destination/Zoom.php';
         Yii::$classMap['Zend_Pdf_Destination_Explicit'] = $yiiBasepath . '/vendor/Zend/Pdf/Destination/Explicit.php';
         Yii::$classMap['Zend_Pdf_RecursivelyIteratableObjectsContainer'] = $yiiBasepath . '/vendor/Zend/Pdf/RecursivelyIteratableObjectsContainer.php';
         Yii::$classMap['Zend_Pdf_StringParser'] = $yiiBasepath . '/vendor/Zend/Pdf/StringParser.php';
         Yii::$classMap['Zend_Pdf_ElementFactory'] = $yiiBasepath . '/vendor/Zend/Pdf/' . 'ElementFactory' . '.php';
         Yii::$classMap['Zend_Pdf_ElementFactory_Interface'] = $yiiBasepath . '/vendor/Zend/Pdf/ElementFactory/' . 'Interface' . '.php';
         Yii::$classMap['Zend_Pdf_ElementFactory_Proxy'] = $yiiBasepath . '/vendor/Zend/Pdf/ElementFactory/Proxy.php';
         Yii::$classMap['Zend_Pdf_Element_Reference_Table'] = $yiiBasepath . '/vendor/Zend/Pdf/Element/Reference/Table.php';
         Yii::$classMap['Zend_Pdf_Element_Reference_Context'] = $yiiBasepath . '/vendor/Zend/Pdf/Element/Reference/Context.php';
         Yii::$classMap['Zend_Pdf_Element_Dictionary'] = $yiiBasepath . '/vendor/Zend/Pdf/Element/Dictionary.php';
         Yii::$classMap['Zend_Pdf_Element'] = $yiiBasepath . '/vendor/Zend/Pdf/Element.php';
         Yii::$classMap['Zend_Pdf_Element_Object'] = $yiiBasepath . '/vendor/Zend/Pdf/Element/Object.php';
         Yii::$classMap['Zend_Pdf_Element_Null'] = $yiiBasepath . '/vendor/Zend/Pdf/Element/Null.php';
         Yii::$classMap['Zend_Pdf_Element_Name'] = $yiiBasepath . '/vendor/Zend/Pdf/Element/Name.php';
         Yii::$classMap['Zend_Pdf_Element_Numeric'] = $yiiBasepath . '/vendor/Zend/Pdf/Element/Numeric.php';
         Yii::$classMap['Zend_Pdf_Element_Reference'] = $yiiBasepath . '/vendor/Zend/Pdf/Element/Reference.php';
         Yii::$classMap['Zend_Pdf_Element_Array'] = $yiiBasepath . '/vendor/Zend/Pdf/Element/Array.php';
         Yii::$classMap['Zend_Pdf_Element_String'] = $yiiBasepath . '/vendor/Zend/Pdf/Element/String.php';
         Yii::$classMap['Zend_Pdf_Element_String_Binary'] = $yiiBasepath . '/vendor/Zend/Pdf/Element/String/Binary.php';
         Yii::$classMap['Zend_Pdf_Trailer'] = $yiiBasepath . '/vendor/Zend/Pdf/Trailer.php';
         Yii::$classMap['Zend_Pdf_Trailer_Keeper'] = $yiiBasepath . '/vendor/Zend/Pdf/Trailer/Keeper.php';
         $pdf = \Farit_Pdf::load($file->getFullFilePath());
         if (file_exists($cerfile)) {
             $certificate = file_get_contents($cerfile);
             if (empty($certificate)) {
                 throw new \Exception('Cannot open the certificate file');
             }
             $pdf->attachDigitalCertificate($certificate, $configCertpasswd);
             $docfile = $pdf->render();
             $doc_file = new Files();
             $doc_file->name = $name;
             $doc_file->path = "docs/";
             $doc_file->parent_type = get_class($model);
             $doc_file->parent_id = $model->id;
             $doc_file->public = 1;
             $doc_file->hidden = 0;
             $doc_file->save();
             $doc_file->writeFile($docfile);
         } else {
             $link = "";
             $text = Yii::t('app', "Error! <br />\nIt is not possible to create a digitally signed PDF file and/or send it by mail without having certificate file located at current users' configuration page.\nYou should make a certificate file with third party software and import it through 'certificate file' field, separately for each user, within configuration zone of the user. You also should input the password for the certificate file in 'password for digital signature certificate' field in the above mentioned user configuration page.\nYou can find instructions for making self signed certificate file with Acrobat reader (One of the options. There are many applications able to make such a certificate out there)  here: ");
             throw new \Exception($text);
             //Yii::$app->end();
         }
     }
     return $doc_file;
 }
Пример #2
0
 private function newNum()
 {
     if ($this->num == 0) {
         //$model=Yii::$app->user->settings['company.transaction'];
         $transaction = \app\helpers\Linet3Helper::getSetting('company.transaction');
         \app\helpers\Linet3Helper::setSetting('company.transaction', $transaction + 1);
         //$model = Settings::findOne('company.transaction');
         //$model->value = (int) $model->value + 1;
         //Yii::$app->user->settings['company.transaction']=$model->value;
         //$model->save();
         return (int) $transaction;
         //adam: has to go
     } else {
         return (int) $this->num;
     }
 }
Пример #3
0
 private function saveSetting($key, $value)
 {
     return \app\helpers\Linet3Helper::setSetting($key, $value);
 }
Пример #4
0
 public function save($runValidation = true, $attributes = NULL)
 {
     $a = parent::save($runValidation, $attributes);
     if ($this->prefix == '') {
         $this->string = Yii::$app->dbMain->dsn;
         //$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
         $this->prefix = "CA" . $this->id . "_";
         //got prefix
         $a = parent::save($runValidation, $attributes);
     }
     //if tables config notexsits
     Yii::$app->db->close();
     Yii::$app->db->dsn = $this->string;
     Yii::$app->db->tablePrefix = $this->prefix;
     Yii::$app->db->open();
     //needs to clear accounts
     if (Yii::$app->db->schema->getTableSchema('{{config}}') === null) {
         //
         //create tables
         $this->createDb();
         Yii::$app->db->close();
         Yii::$app->db->dsn = $this->string;
         Yii::$app->db->tablePrefix = $this->prefix;
         Yii::$app->db->open();
         \app\helpers\Linet3Helper::setSetting('company.path', $this->prefix);
         //update path by prefix
         //$yiiBasepath = Yii::$app->basePath;
         //add permisstions
     } else {
         //else
         //table version
         //upgrade
     }
     $perm = new DatabasesPerm();
     $perm->user_id = Yii::$app->user->id;
     $perm->database_id = $this->id;
     $perm->level_id = 1;
     $perm->save();
     return $a;
 }