/**
  * 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));
 }
Ejemplo n.º 2
0
 /**
 * Execute the command.
 *
 //	 * @return void
 */
 public function handle()
 {
     $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 . Order::getDocTypeName($this->docType))) {
         Storage::makeDirectory($whereAreClientDocuments . DIRECTORY_SEPARATOR . 'client_' . $this->order->user_id . DIRECTORY_SEPARATOR . Order::getDocTypeName($this->docType));
     }
     $clientFolder = $whereAreClientDocuments . DIRECTORY_SEPARATOR . 'client_' . $this->order->user_id . DIRECTORY_SEPARATOR . Order::getDocTypeName($this->docType);
     //(torg12/schetfactura)_{orderID}_{depoName}_date_{currentDate}
     $fileNameTemplate = $this->documentFor == Order::DOCUMENT_FOR_SERVICE ? $documents['client_service_document_template'] : $documents['client_document_template'];
     $fileNameTemplate = Utils::mb_str_replace('{docType}', Order::getDocTypeName($this->docType), $fileNameTemplate);
     $fileNameTemplate = Utils::mb_str_replace('{orderID}', $this->order->id, $fileNameTemplate);
     if ($this->documentFor == Order::DOCUMENT_FOR_SPARE_PART) {
         $depoName = $this->order->products_in_order[0]->stantion_name;
         $depoName = Utils::mb_str_replace(' ', '', $depoName);
         $depoName = Utils::translit($depoName);
         $fileNameTemplate = Utils::mb_str_replace('{depoName}', $depoName, $fileNameTemplate);
     }
     $fileNameTemplate = Utils::mb_str_replace('{currentDate}', time(), $fileNameTemplate);
     $extension = $this->file->getClientOriginalExtension();
     try {
         Storage::disk('local')->put($clientFolder . DIRECTORY_SEPARATOR . $fileNameTemplate . '.' . $extension, File::get($this->file));
     } catch (Exception $e) {
         Log::error('Ошибка загрузки файла ' . $fileNameTemplate . ' message - ' . $e->getMessage());
         return false;
     }
     return storage_path() . DIRECTORY_SEPARATOR . 'app' . $clientFolder . DIRECTORY_SEPARATOR . $fileNameTemplate . '.' . $extension;
 }
Ejemplo n.º 3
0
 /**
  * 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));
 }
 private static function getFileNameInParts($fileName, $type)
 {
     $tempFileNameArr = explode(DIRECTORY_SEPARATOR, $fileName);
     $onlyFileName = end($tempFileNameArr);
     $tempFileNameArr = explode('.', $onlyFileName);
     $extension = end($tempFileNameArr);
     $extension = strtolower($extension);
     $mime = null;
     if ($extension == 'pdf') {
         $mime = 'application/pdf';
     } else {
         $mime = 'image/' . $extension;
     }
     $fNameForUser = Order::getDocTypeName($type, true) . ' для заказа №';
     return ['fNameForUser' => $fNameForUser, 'mime' => $mime, 'extension' => $extension];
 }
                                        @if($document->type != $tempType)
                                            <td valign="middle" align="center">{{ \App\Models\Order::getDocTypeName($document->type, true) }}</td>
                                            <?php 
$tempType = $document->type;
?>
                                        @else
                                            <td></td>
                                        @endif
                                        <td valign="middle">
                                            <?php 
$shortFileName = explode(DIRECTORY_SEPARATOR, $document->file_name);
$shortFileName = end($shortFileName);
$tempFileName = explode('_', $shortFileName);
$tempFileName = explode('.', end($tempFileName));
$fileDate = date('d.m.Y', $tempFileName[0]);
$shownFileName = \App\Models\Order::getDocTypeName($document->type, true) . ' №' . $document->order->id . '.' . $tempFileName[1];
?>
                                            <div class="float-l withMarginTop5">
                                                {{ \App\Models\Order::getDocTypeName($document->type, true) }}, загруженный {{ $fileDate }}
                                            </div>
                                            <div class="float-r">
                                                {!! Form::open(['route' => 'downloadDoc', 'role' => 'form', 'class'=>'inlineForm']) !!}
                                                {!! Form::hidden('shortFileName', $shortFileName) !!}
                                                {!! Form::hidden('shownFileName', $shownFileName) !!}
                                                {!! Form::hidden('download', true) !!}
                                                {!! Form::submit('Скачать', ['class'=>'button-f*****g-1 withWidth']) !!}
                                                {!! Form::close() !!}
                                                &nbsp;
                                                {!! Form::open(['route' => 'downloadDoc', 'role' => 'form', 'class'=>'inlineForm']) !!}
                                                {!! Form::hidden('shortFileName', $shortFileName) !!}
                                                {!! Form::hidden('shownFileName', $shownFileName) !!}
Ejemplo n.º 6
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();
 }
Ejemplo n.º 7
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     $validationRules = ['oferta' => 'accepted', 'userID' => 'integer|required|in:' . Auth::user()->id];
     $v = Validator::make($request->all(), $validationRules);
     if ($v->fails()) {
         return redirect()->route('confirmOrder', ['user_id' => Auth::user()->id])->withErrors($v->errors());
         //            $newRequest = Request::create('confirmOrder/'.Auth::user()->id, 'POST', [], [], [], [],['blat'=>$v->errors()]);
         //            return Route::dispatch($newRequest)->getContent();
     }
     $userID = $request->userID;
     if (Auth::user()->id == (int) $userID) {
         $productsByDepoArr = [];
         $newProductsByDepoArr = [];
         $orderNumbers = [];
         DB::transaction(function () use($userID, &$productsByDepoArr, &$orderNumbers, &$newProductsByDepoArr) {
             $products = ProductCart::with('product.condition', 'price.stantion')->where('user_id', $userID)->get();
             foreach ($products as $productCart) {
                 $productsByDepoArr[$productCart->price->stantion[0]->id][] = [$productCart->product->name . '( состояние - ' . $productCart->product->condition->condition . ')', $productCart->product_count, $productCart->price->price, $productCart->price->id, $productCart->product->id, $productCart->price->stantion[0]->stantion_name, $productCart->price->nds];
                 $productCart->price->amount -= $productCart->product_count;
                 $productCart->price->save();
             }
             $userCompany = User::with('firm')->where('id', $userID)->first();
             $status = Status::where('is_first', Order::IS_FIRST)->first();
             foreach ($productsByDepoArr as $depoID => $productsArr) {
                 $order = new Order();
                 $order->status_id = $status->id;
                 $order->user_id = $userID;
                 $order->firm_id = $userCompany->firm->id;
                 $order->email = Auth::user()->email;
                 $order->save();
                 $orderNumbers[] = $order->id;
                 foreach ($productsArr as $product) {
                     $productsInOrder = new ProductsInOrder();
                     $productsInOrder->order_id = $order->id;
                     $productsInOrder->product_name = $product[0];
                     $productsInOrder->product_price = $product[2];
                     $productsInOrder->product_amount = $product[1];
                     $productsInOrder->stantion_id = $depoID;
                     $productsInOrder->price_id = $product[3];
                     $productsInOrder->product_id = $product[4];
                     $productsInOrder->stantion_name = $product[5];
                     $productsInOrder->nds = $product[6];
                     $productsInOrder->save();
                 }
                 $newProductsByDepoArr[$order->id] = $productsArr;
                 //Запускаем команду на формирование счета
                 Bus::dispatch(new CreateInvoice($order, Stantion::find($depoID)));
             }
             ProductCart::where('user_id', $userID)->delete();
         });
         $files = Document::where('user_id', Auth::user()->id)->where(function ($query) use($orderNumbers) {
             foreach ($orderNumbers as $number) {
                 $query->orWhere('file_name', 'like', '%' . Order::getDocTypeName(Order::INVOICE_TYPE) . '_' . $number . '_%');
             }
         })->get();
         $fileNames = [];
         foreach ($files as $file) {
             $fileNames[] = $file->file_name;
         }
         $messageParams = [];
         $messageParams['productByDepoWithOrderIdAsKey'] = $newProductsByDepoArr;
         //            //Запускаем команду на отправку email
         Bus::dispatch(new SendEmailWithInvoices($messageParams, $fileNames));
         //            Bus::dispatch(new SendWithTanksForOrder($messageParams));
         return view('orders.success', ['p' => 'purchases', 'ordersAmount' => count($productsByDepoArr)]);
     } else {
         return redirect('fatal_error')->with('alert-danger', 'Произошла ошибка в работе сайта. Мы уже исправляем эту проблему. Попробуйте через некоторое время.');
     }
 }
 public function showDocs()
 {
     $docs = Document::where('user_id', Auth::user()->id)->get();
     $docsByTypesArr = [];
     foreach ($docs as $q => $doc) {
         $shortFileName = explode(DIRECTORY_SEPARATOR, $doc->file_name);
         $shortFileName = end($shortFileName);
         $tempFileName = explode('_', $shortFileName);
         $tempFileName = explode('.', end($tempFileName));
         $fileDate = date('d.m.Y', $tempFileName[0]);
         $typeOfDoc = Order::getDocTypeName($doc->type, true);
         if (!$doc->service_order_id && !$doc->order_id) {
             $docId = null;
         } else {
             $docId = $doc->service_order_id ? $doc->service_order_id : $doc->order_id;
         }
         $extension = end($tempFileName);
         //$shownFileName = $typeOfDoc.' №'.$docId.'.'.$tempFileName[1];
         $temp = $docId ? ' №' . $docId : ' по оказанию услуг';
         $shownFileName = $typeOfDoc . $temp . '.' . $extension;
         $docsByTypesArr[$typeOfDoc][] = ['shortFileName' => $shortFileName, 'shownFileName' => $shownFileName, 'extension' => $extension, 'fileDate' => $fileDate, 'orderNumber' => $doc->order_id ? $doc->order_id : $doc->service_order_id, 'tempNumber' => $temp];
     }
     return view('documents.showDocs', ['p' => 'cabinet', 'documentsByTypes' => $docsByTypesArr]);
 }