Пример #1
0
 public function post_enter_prices($qr_id, $qid = null)
 {
     $quote_request = QuoteRequest::Find($qr_id);
     // Reset chosen supplier for quotes
     $quote_request->quote_id = 0;
     $quote_request->save();
     if ($qid == null) {
         $quote = $quote_request->first_quote();
     } else {
         $quote = Quote::Find($qid);
     }
     $input = request::all();
     // Invert form array
     $input = array_except($input, ['_token', 'quote_request_id', 'qid']);
     $keys = array_keys($input);
     $first_key = $keys[0];
     $count = count($input[$first_key]);
     $output = [];
     foreach (range(0, $count - 1) as $i) {
         foreach ($keys as $key) {
             $output[$i][$key] = $input[$key][$i];
         }
     }
     foreach ($output as $item) {
         $id = $item["id"];
         if ($id == "") {
             // Create new
             QuoteItem::create($item);
         } else {
             $qi = QuoteItem::find($id);
             $qi->update($item);
         }
     }
     // delete Quote PDF if exists
     $path = 'quotes/' . $qr_id . '.pdf';
     if (file_exists($path)) {
         unlink($path);
     }
     $quote_request_lines = $quote_request->qris;
     return view('quotes.enter_prices', compact('quote_request', 'quote', 'quote_request_lines'))->with('message', 'Supplier Prices have been Updated');
 }