/**
  * Execute the command.
  *
  * @return void
  */
 public function handle()
 {
     $documents = Config::get('documents');
     $whereAreClientDocuments = $documents['documents_folder'];
     //client_{id}
     if (!Storage::disk('local')->exists($whereAreClientDocuments . '/client_' . $this->firm->user->id)) {
         Storage::makeDirectory($whereAreClientDocuments . '/client_' . $this->firm->user->id);
     }
     //agreement
     if (!Storage::disk('local')->exists($whereAreClientDocuments . '/client_' . $this->firm->user->id . '/service_agreement')) {
         Storage::makeDirectory($whereAreClientDocuments . '/client_' . $this->firm->user->id . '/service_agreement');
     }
     //очищаем папку от всех файлов
     $files = Storage::files($whereAreClientDocuments . '/client_' . $this->firm->user->id . '/service_agreement');
     if (!empty($files)) {
         $agreementDocIds = Document::select('id')->where('type', Order::CONTRACT_TYPE)->where('user_id', $this->firm->user->id)->get();
         $agreementDocIdsArr = [];
         foreach ($agreementDocIds as $agreementDocId) {
             $agreementDocIdsArr[] = $agreementDocId->id;
         }
         Document::destroy($agreementDocIdsArr);
     }
     Storage::delete($files);
     //создаем новый файл
     $clientFolder = storage_path() . '/app' . $whereAreClientDocuments . '/client_' . $this->firm->user->id . '/service_agreement';
     //{docType}_contragent_{clientId}_date_{currentDate}.pdf
     $fileNameTemplate = $documents['client_service_agreement_template'];
     $fileNameTemplate = Utils::mb_str_replace('{docType}', Order::getDocTypeName(Order::CONTRACT_TYPE), $fileNameTemplate);
     $fileNameTemplate = Utils::mb_str_replace('{clientId}', $this->firm->user->id, $fileNameTemplate);
     $fileNameTemplate = Utils::mb_str_replace('{currentDate}', time(), $fileNameTemplate);
     //		$pdf->save($clientFolder.'/'.$fileNameTemplate);
     //********************************************************
     /*
     * Номер текущей страницы
     * если требуется сгенерировать несколько документов
     */
     //  $current_page = 1;
     //****************************************************
     //+++++++++++++++++++++++++++++++++++++++++++++++++++++
     $pdf = App::make('dompdf.wrapper');
     $pdf->loadView('documents.serviceAgreementTemplate', ['fullFirmName' => $this->firm->full_organisation_name, 'shortFirmName' => $this->firm->organisation_name, 'position' => $this->firm->rp_face_position, 'fio' => $this->firm->rp_face_fio, 'baseDocument' => $this->firm->rp_base_document, 'inn' => $this->firm->inn, 'kpp' => $this->firm->kpp, 'address' => $this->firm->place_address, 'rs' => $this->firm->rs, 'bank' => $this->firm->bank, 'ks' => $this->firm->ks, 'bik' => $this->firm->bik, 'phone' => $this->firm->phone, 'email' => $this->firm->user->email]);
     //+++++++++++++++++++++++++++++++++++++++++++++++
     //        $dom_pdf = $pdf->getDomPDF();
     //        $canvas = $dom_pdf->get_canvas();
     //        dd($canvas);
     //        $canvas->page_text(0, 0, "Page {PAGE_NUM} of {PAGE_COUNT}", null, 10, array(0, 0, 0));
     //--------------------------------------------
     $m = new Merger();
     $m->addRaw($pdf->output());
     //****************************************************
     //        $signs = array (
     //            'start-page' => $current_page);
     //
     //        // Замена меток в шаблоне их значениями
     //        foreach ($signs as $key => $value) {
     //            $template = str_replace('{' . $key . '}', $value, $template);
     //        }
     /*
      * Увеличили счетчик числа сгенерированных страниц
      * на число страниц текущего документа
      */
     //        $current_page = $current_page + $dom_pdf->get_canvas()->get_page_count();
     //********************************************************
     unset($pdf);
     $pdf = App::make('dompdf.wrapper');
     $pdf->setPaper('a4', 'landscape')->loadView('documents.serviceAgreementTemplate2');
     $m->addRaw($pdf->output());
     file_put_contents($clientFolder . '/' . $fileNameTemplate, $m->merge());
     $docs = new Document();
     $docs->type = Order::CONTRACT_TYPE;
     $docs->user_id = $this->firm->user->id;
     $docs->file_name = $clientFolder . '/' . $fileNameTemplate;
     $docs->sended = 1;
     $docs->save();
     $user = User::find($this->firm->user->id);
     $emailContent['userName'] = $user->name;
     $emailContent['email'] = $user->email;
     Bus::dispatch(new SendEmailWithServiceAgreement($emailContent, $clientFolder . '/' . $fileNameTemplate));
 }
Example #2
0
 public function store(Request $request, $user_as_merchant_model)
 {
     $merchant_id = $user_as_merchant_model['id'];
     /*
      * Get product last id from document table
      */
     $Document_id = Document::orderBy('id', 'desc')->take(1)->get();
     foreach ($Document_id as $DI) {
         $Did = $DI->id;
     }
     if (!isset($Did)) {
         $Did = 0;
     }
     $Did = $Did + 1;
     $documents = $request;
     // every key has an arr except merchant_id
     $files = $request->file('upload_attachment');
     for ($i = 0; $i < count($files); $i++) {
         $files_name = $files[$i]->getClientOriginalName();
         $destination = 'public/images/document/' . $Did . '/';
         if ($files[$i]->move($destination, $files_name)) {
             $doc = new Document();
             $doc->path = $destination . $files_name;
             $doc->save();
             $Merdoc = new merchantdocument();
             $Merdoc->merchant_id = $merchant_id;
             $Merdoc->document_id = $Did;
             $Merdoc->save();
             $Did = $Did + 1;
         }
     }
 }
Example #3
0
 /**
  * Create New Document
  *
  * @param String $name
  * @param Request $request
  * @return Response
  */
 public function postDocument($name, Request $request)
 {
     if (!$this->appKeyAvailable($request)) {
         return $this->notAuthorized($request);
     }
     if (!$this->setSessionUser($request)) {
         $this->setResultError("Not logged in", 401);
     } elseif (!$this->isCollection($name)) {
         $this->setResultError("Collection '{$name}' doesn't exist", 404);
     } else {
         $document = new Document();
         $data = $request->all();
         $document->data = json_encode($data);
         $document->user_id = $this->user->id;
         $document->collection_id = $this->readCollection($name)->id;
         $document->save();
         foreach ($data as $key => $value) {
             Data::create(['document_id' => $document->id, 'key' => $key, 'value' => $value]);
         }
         $this->setAllowed($document->id, null, $this->user->id, null, 'all');
         $this->setResultOk();
         $this->setDocumentData($document);
     }
     return $this->setResponse();
 }
Example #4
0
 public function actionCreate()
 {
     Document::deleteInactive();
     $document = new Document();
     $document->save();
     return $this->redirect(['update', 'id' => $document->id]);
 }
 /**
  * Creates a new Document model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Document();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['update', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Example #6
0
 public static function createDocument($application, $upload, $answer = null)
 {
     $document = new Document();
     $document->name = $upload['name'];
     $document->file = $upload['file'];
     $document->application_id = $application->id;
     $document->user_id = Auth::user()->id;
     if ($answer) {
         $document->answer_id = $answer->id;
     }
     $document->save();
     return $document;
 }
 /**
  * Execute the command.
  *
  * @return void
  */
 public function handle()
 {
     $selfFirmUser = User::with('firm')->where('role_id', User::ADMIN)->first();
     $clientCompany = User::with('firm')->where('id', $this->order->user_id)->first();
     $products = $this->order->products_in_order;
     $firm = $clientCompany->firm;
     $productsArr = [];
     foreach ($products as $product) {
         $productsArr[] = ['product_name' => $product->product_name, 'product_amount' => $product->product_amount, 'product_price' => $product->product_price];
     }
     $date = DateTime::createFromFormat('Y-m-d H:i:s', $this->order->created_at);
     $date = strtotime($date->format('d F Y'));
     $pdf = App::make('dompdf.wrapper');
     $viewType = null;
     if ($this->isTorg) {
         $viewType = 'documents.torg_12';
     } else {
         $viewType = 'documents.schet_factura';
     }
     $pdf->loadView($viewType, ['orderNumber' => $this->order->id, 'orderDate' => date('d.m.Y', $date), 'firm' => $firm, 'selfFirm' => $selfFirmUser->firm, 'products' => $productsArr]);
     //$pdf->setOrientation('landscape');
     $pdf->setPaper('A4', 'landscape');
     $documents = Config::get('documents');
     $whereAreClientDocuments = $documents['documents_folder'];
     //client_{id}
     if (!Storage::disk('local')->exists($whereAreClientDocuments . DIRECTORY_SEPARATOR . 'client_' . $this->order->user_id)) {
         Storage::makeDirectory($whereAreClientDocuments . DIRECTORY_SEPARATOR . 'client_' . $this->order->user_id);
     }
     //paymentDocs
     if (!Storage::disk('local')->exists($whereAreClientDocuments . DIRECTORY_SEPARATOR . 'client_' . $this->order->user_id . DIRECTORY_SEPARATOR . 'paymentDocs')) {
         Storage::makeDirectory($whereAreClientDocuments . DIRECTORY_SEPARATOR . 'client_' . $this->order->user_id . DIRECTORY_SEPARATOR . 'paymentDocs');
     }
     $clientFolder = storage_path() . DIRECTORY_SEPARATOR . 'app' . $whereAreClientDocuments . DIRECTORY_SEPARATOR . 'client_' . $this->order->user_id . DIRECTORY_SEPARATOR . 'paymentDocs';
     //(torg12/schetfactura)_{orderID}_{depoName}_date_{currentDate}
     $fileNameTemplate = $documents['client_invoice_template'];
     $fileNameTemplate = Utils::mb_str_replace('{docType}', Order::getDocTypeName($this->isTorg ? Order::AUCTION_12_TYPE : Order::INVOICE_ACCT_TYPE), $fileNameTemplate);
     $fileNameTemplate = Utils::mb_str_replace('{orderID}', $this->order->id, $fileNameTemplate);
     $depo = Stantion::find($this->order->products_in_order[0]->stantion_id);
     $depoName = Utils::mb_str_replace(' ', '', $depo->stantion_name);
     $depoName = Utils::translit($depoName);
     $fileNameTemplate = Utils::mb_str_replace('{depoName}', $depoName, $fileNameTemplate);
     $fileNameTemplate = Utils::mb_str_replace('{currentDate}', time(), $fileNameTemplate);
     $pdf->save($clientFolder . DIRECTORY_SEPARATOR . $fileNameTemplate);
     $docs = new Document();
     $docs->type = $this->isTorg ? Order::AUCTION_12_TYPE : Order::INVOICE_ACCT_TYPE;
     $docs->user_id = $this->order->user_id;
     $docs->order_id = $this->order->id;
     $docs->file_name = $clientFolder . DIRECTORY_SEPARATOR . $fileNameTemplate;
     $docs->save();
     Bus::dispatch(new SendEmailWithPaymentDocs($docs->file_name, $this->isTorg, $this->order));
 }
 /**
 * Execute the command.
 *
 	//	 * @return void
 */
 public function handle()
 {
     $documents = Config::get('documents');
     $whereAreClientDocuments = $documents['documents_folder'];
     //client_{id}
     if (!Storage::disk('local')->exists($whereAreClientDocuments . '/client_' . $this->firm->user->id)) {
         Storage::makeDirectory($whereAreClientDocuments . '/client_' . $this->firm->user->id);
     }
     //agreement
     if (!Storage::disk('local')->exists($whereAreClientDocuments . '/client_' . $this->firm->user->id . '/service_agreement')) {
         Storage::makeDirectory($whereAreClientDocuments . '/client_' . $this->firm->user->id . '/service_agreement');
     }
     $clientFilePath = $whereAreClientDocuments . '/client_' . $this->firm->user->id . '/service_agreement';
     $extension = $this->file->getClientOriginalExtension();
     //get all files from folder end delete them
     $files = Storage::files($clientFilePath);
     if (!empty($files)) {
         $agreementDocIds = Document::select('id')->where('type', Order::CONTRACT_TYPE)->where('user_id', $this->firm->user->id)->get();
         $agreementDocIdsArr = [];
         foreach ($agreementDocIds as $agreementDocId) {
             $agreementDocIdsArr[] = $agreementDocId->id;
         }
         Document::destroy($agreementDocIdsArr);
     }
     Storage::delete($files);
     $file = array_shift($files);
     $filePathBySlash = explode(DIRECTORY_SEPARATOR, $file);
     $fileName = end($filePathBySlash);
     $fileNameBy_ = explode('_', $fileName);
     $fileDateWithExtension = time() . '.' . $extension;
     array_pop($fileNameBy_);
     $fileNameBy_[] = $fileDateWithExtension;
     $fileName = implode('_', $fileNameBy_);
     array_pop($filePathBySlash);
     $filePathBySlash[] = $fileName;
     $file = implode(DIRECTORY_SEPARATOR, $filePathBySlash);
     try {
         Storage::disk('local')->put($file, File::get($this->file));
     } catch (Exception $e) {
         Log::error('Ошибка загрузки файла с договором оферты' . ' message - ' . $e->getMessage());
         return false;
     }
     $docs = new Document();
     $docs->type = Order::CONTRACT_TYPE;
     $docs->user_id = $this->firm->user->id;
     $docs->file_name = storage_path() . DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . $file;
     $docs->sended = 1;
     $docs->save();
     return storage_path() . DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . $file;
 }
Example #9
0
 /**
  * Execute the command.
  *
  * @return void
  */
 public function handle()
 {
     $selfFirmUser = User::with('firm')->where('role_id', User::ADMIN)->first();
     $userCompany = User::with('firm')->where('id', $this->order->user_id)->first();
     $products = $this->order->products_in_order;
     $firm = $userCompany->firm;
     $productsArr = [];
     foreach ($products as $product) {
         $productsArr[$this->depo->id][] = ['product_name' => $product->product_name, 'product_amount' => $product->product_amount, 'product_price' => $product->product_price, 'product_nds' => Product::getVAT_calculationByKey($product->nds), 'product_nds_as_str' => Product::getAllVAT_rateByKey($product->nds)];
     }
     $date = DateTime::createFromFormat('Y-m-d H:i:s', $this->order->created_at);
     $date = strtotime($date->format('d F Y'));
     if (!$firm->rp_face_fio) {
         $faceFioArr = explode(' ', $firm->face_fio);
         $lastName = isset($faceFioArr[0]) ? $faceFioArr[0] : '';
         $name = isset($faceFioArr[1]) ? $faceFioArr[1] : '';
         $secondName = isset($faceFioArr[2]) ? $faceFioArr[2] : '';
         $petrovich = new Petrovich();
         $petrovich->gender = $petrovich->detectGender($secondName);
         if ($petrovich->gender == Petrovich::FAIL_MIDDLEWARE) {
             $fio = $firm->face_fio;
         } else {
             $fio = $petrovich->lastname($lastName, Petrovich::CASE_GENITIVE) . ' ' . $petrovich->firstname($name, Petrovich::CASE_GENITIVE) . ' ' . $petrovich->middlename($secondName, Petrovich::CASE_GENITIVE);
             $firm->rp_face_fio = $fio;
             $firm->save();
         }
     } else {
         $fio = $firm->rp_face_fio;
     }
     if (!$firm->rp_face_position) {
         $facePosition = Utils::getGenitiveCase($firm->face_position);
         if ($facePosition != $firm->face_position) {
             $firm->rp_face_position = $facePosition;
             $firm->save();
         }
     } else {
         $facePosition = $firm->rp_face_position;
     }
     if (!$firm->rp_base_document) {
         $baseDocument = Utils::getGenitiveCase($firm->base_document);
         if ($baseDocument != $firm->base_document) {
             $firm->rp_base_document = $baseDocument;
             $firm->save();
         }
     } else {
         $baseDocument = $firm->rp_base_document;
     }
     $pdf = App::make('dompdf.wrapper');
     $pdf->loadView('documents.invoice', ['orderNumber' => $this->order->id, 'orderDate' => date('d.m.Y', $date), 'firm' => $firm, 'firmRpFio' => $fio, 'firmFacePosition' => $facePosition, 'firmBaseDocument' => $baseDocument, 'selfFirm' => $selfFirmUser->firm, 'products' => $productsArr, 'depoId' => $this->depo->id, 'depoName' => $this->depo->stantion_name]);
     //$whereAreClientDocuments = storage_path().'/app'.Config::get('documents')['documents_folder'];
     $documents = Config::get('documents');
     $whereAreClientDocuments = $documents['documents_folder'];
     //client_{id}
     if (!Storage::disk('local')->exists($whereAreClientDocuments . '/client_' . Auth::user()->id)) {
         Storage::makeDirectory($whereAreClientDocuments . '/client_' . Auth::user()->id);
     }
     //invoices
     if (!Storage::disk('local')->exists($whereAreClientDocuments . '/client_' . Auth::user()->id . '/invoices')) {
         Storage::makeDirectory($whereAreClientDocuments . '/client_' . Auth::user()->id . '/invoices');
     }
     $clientFolder = storage_path() . '/app' . $whereAreClientDocuments . '/client_' . Auth::user()->id . '/invoices';
     //invoice_{orderID}_{depoName}_date_{currentDate}
     $fileNameTemplate = $documents['client_invoice_template'];
     $fileNameTemplate = Utils::mb_str_replace('{docType}', Order::getDocTypeName(Order::INVOICE_TYPE), $fileNameTemplate);
     $fileNameTemplate = Utils::mb_str_replace('{orderID}', $this->order->id, $fileNameTemplate);
     $depoName = Utils::mb_str_replace(' ', '', $this->depo->stantion_name);
     $depoName = Utils::translit($depoName);
     $fileNameTemplate = Utils::mb_str_replace('{depoName}', $depoName, $fileNameTemplate);
     $fileNameTemplate = Utils::mb_str_replace('{currentDate}', time(), $fileNameTemplate);
     $pdf->save($clientFolder . '/' . $fileNameTemplate);
     $docs = new Document();
     $docs->type = Order::INVOICE_TYPE;
     $docs->user_id = Auth::user()->id;
     $docs->order_id = $this->order->id;
     $docs->file_name = $clientFolder . '/' . $fileNameTemplate;
     $docs->sended = 1;
     $docs->save();
 }
 public function uploadDocument(Document $document, Requests\UploadDocument $request)
 {
     if ($request->document_for == Order::DOCUMENT_FOR_SERVICE) {
         $order = ServiceOrder::find($request->order_id);
     } else {
         $order = Order::find($request->order_id);
     }
     $file = $request->file('docFileName');
     //Сам файл
     if ($pathToFile = Bus::dispatch(new UploadDocument($file, $order, $request->docType, $request->document_for))) {
         $document->type = $request->docType;
         $document->user_id = $order->user_id;
         if ($request->document_for == Order::DOCUMENT_FOR_SERVICE) {
             $document->service_order_id = $request->order_id;
         } else {
             $document->order_id = $request->order_id;
         }
         $document->file_name = $pathToFile;
         $document->save();
         return redirect()->back()->with('alert-success', 'Файл загружен.');
     } else {
         return redirect()->back()->withInput()->with('alert-danger', 'Ошибка загрузки файла. Файл не загружен.');
     }
 }
Example #11
0
 /**
  * save document
  * @param DocumentModal $document
  * @return bool
  */
 public function store(DocumentModal $document)
 {
     return $document->save();
 }