public function backupDB() { $dumper = new dbMaster(); $sql = $dumper->getDump(false); $file = new Files(); $file->name = "DB Backup " . date("d-m-Y_H_i") . ".sql"; $file->path = '.'; $file->save(); $file->writeFile($sql); $this->DBback = $file->id; }
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; }
public function make($cid) { $this->id = rand(0, 999999); //$this->iniArr=array('b110'=>0,'b100'=>0,'m100'=>0,'c100'=>0,'d100'=>0,'d110'=>0,'d120'=>0,); //$this->docArr=array(0=>0,305=>0,300=>0,); $bkmv = ''; //$this->line=1; //$yiidatetimesec=Yii::$app->locale->getDateFormat('yiidatetimesec'); //$phpdbdatetime=Yii::$app->locale->getDateFormat('phpdbdatetime'); $from_date = $this->from_date . " 00:00:00"; $to_date = $this->to_date . " 23:59:59"; //$types=array(3,4,9,11,13,14); //accounts $accounts = Accounts::find()->All(); $record = array('id' => 'B110', 'name' => OpenFormatType::getDesc('B110'), 'count' => 0); foreach ($accounts as $account) { $this->line++; $bkmv .= $account->openfrmt($this->line, $from_date, $to_date); $record['count']++; } $this->iniArr[] = $record; //items $items = Item::find()->All(); $record = array('id' => 'M100', 'name' => OpenFormatType::getDesc('M100'), 'count' => 0); foreach ($items as $item) { $this->line++; $bkmv .= $item->openfrmt($this->line, $from_date, $to_date); $record['count']++; } $this->iniArr[] = $record; // //transactions $transactions = Transactions::find()->where(['BETWEEN', 'valuedate', $from_date, $to_date])->All(); $record = array('id' => 'B100', 'name' => OpenFormatType::getDesc('B100'), 'count' => 0); foreach ($transactions as $transaction) { $this->line++; $bkmv .= $transaction->openfrmt($this->line, $from_date, $to_date); $record['count']++; } $this->iniArr[] = $record; //docs $docs = Docs::find()->where(['BETWEEN', 'due_date', $from_date, $to_date])->All(); //OpenFormatType::getDesc('C100') $record = array('id' => 'C100', 'name' => OpenFormatType::getDesc('C100'), 'count' => 0); $d110 = array('id' => 'D110', 'name' => OpenFormatType::getDesc('D110'), 'count' => 0); $d120 = array('id' => 'D120', 'name' => OpenFormatType::getDesc('D120'), 'count' => 0); foreach ($docs as $doc) { if ($doc->docType->openformat != '0') { $this->line++; $bkmv .= $doc->openfrmt($this->line, $from_date, $to_date); foreach ($doc->docDetailes as $detial) { $this->line++; $bkmv .= $detial->openfrmt($this->line, $from_date, $to_date); $d110['count']++; } foreach ($doc->docCheques as $detial) { $this->line++; $bkmv .= $detial->openfrmt($this->line, $from_date, $to_date); $d120['count']++; } $type = $doc->OpenfrmtType(); $this->docArr[$type] = isset($this->docArr[$type]) ? $this->docArr[$type] + 1 : 0; $this->docSumArr[$type] = isset($this->docSumArr[$type]) ? $this->docSumArr[$type] + $doc->total : $doc->total; $record['count']++; } } $this->iniArr[] = $record; $this->iniArr[] = $d110; $this->iniArr[] = $d120; $company = \app\models\Settings::findOne(['company.name']); //A100 $bkmv = $company->a100(1, $this->id, $from_date, $to_date) . $bkmv; //Z900 $bkmv = $bkmv . $company->z900($this->line + 1, $this->id, $this->line + 1); $bkmvFile = new Files(); $bkmvFile->name = 'bkmvdata.txt'; $bkmvFile->path = 'openformat/'; // $bkmvFile->expire = 360; $bkmvFile->save(); $bkmvFile->writeFile($bkmv); $this->bkmvId = $bkmvFile->id; //A000 $ini = $company->a000(1, $this->id, $this->line + 1, $from_date, $to_date); foreach ($this->iniArr as $line) { $ini .= $line['id'] . sprintf("%015d", $line['count']) . "\r\n"; } //Z $iniFile = new Files(); $iniFile->name = 'ini.txt'; $iniFile->path = 'openformat/'; // $iniFile->expire = 360; $iniFile->save(); $iniFile->writeFile($ini); $this->iniId = $iniFile->id; return $this->id; }