public function show($id) { $quotation = Quotation::find($id); if ($quotation) { //return $quotation; return view('quotations.retrieve', compact('id', 'quotation')); } else { return view('quotations.create', compact('id', 'quotation')); } }
/** * Execute the console command. * * @return mixed */ public function handle() { // Get quotations that are still fresh. $quotes = Quotation::where('State', '=', 'fresh')->get(); // Now check them. foreach ($quotes as $quote) { if (date('Y-m-d', strtotime($quote->Created) + 86400 * $quote->Life) < date('Y-m-d')) { $quote->State = 'expired'; $quote->save(); } } }
public function __construct() { $A_authors = Author::all(); view()->share('A_authors', $A_authors); $A_projects = Project::all(); view()->share('A_projects', $A_projects); $A_blogs = Blog::all(); view()->share('A_blogs', $A_blogs); $A_newsletters = Newsletter::all(); view()->share('A_newsletters', $A_newsletters); $A_quotations = Quotation::all(); view()->share('A_quotations', $A_quotations); $quotations = Quotation::all(); //dump($quotations); $quotations = count($quotations) > 1 ? $quotations->random(2) : $quotations; view()->share('quotations', $quotations); }
public function show_devis() { $title = 'Devis'; $quotations = Quotation::all(); $cars = Car::all(); $customers = Customer::all(); /* return view('Mail/mail_devis',[ 'finition'=>$request->finition, 'basic_price'=>$request->basic_price, 'tva'=>$request->tva, 'frais_imm'=>$request->frais_imm, 'tme'=>$request->tme, 'frais_timbre'=>$request->frais_timbre, 'prix_tot'=>$request->prix_total_voiture, 'options'=>$options, 'prix_options'=>$request->prix_options, 'name'=>$customer->name, 'last_name'=>$customer->last_name, 'datetime'=>$datetime] );*/ }
/** * Function that makes a quotation. * * @return Response */ public function makeQuotation() { // Validate Input. $validator = Validator::make(Input::all(), array('items' => 'required', 'institution' => 'required', 'discount' => 'required')); if ($validator->fails()) { return response()->json(['error' => 'No se envio la informacion completa!']); } // Check that user is part of authorized staff. if (Auth::user()->Type != 1) { // If they are unauthorized no point in returning anything. return response()->json(['state' => 'Unauthorized']); } // Get user branch. $worker = Worker::find(Auth::user()->TypeId); $userBranch = $worker->BranchId; $quotePrice = 0; $branch = Branch::find($userBranch); // Check discount is not greater than what user is allowed. $permissions = json_decode(UserLevel::find(Auth::user()->UserLevel)->Permissions); if (Input::get('discount') > $permissions->permissions->sales->discount->limit) { // Check if we have an auth code we can use. if (Input::get('authCode') == 0) { $response['state'] = 'Error'; $response['error'] = 'No tiene permiso para otorgar este descuento!'; return response()->json($response); } $request = Request::find(Input::get('authCode')); if ($request->Used == 1) { $response['state'] = 'Error'; $response['error'] = 'No tiene permiso para otorgar este descuento!'; return response()->json($response); } if ($request->Amount != Input::get('discount')) { $response['state'] = 'Error'; $response['error'] = 'No tiene permiso para otorgar este descuento!'; return response()->json($response); } $request->Used = 1; $request->save(); } // Get client. $client = Client::where('Cedula', '=', Input::get('client'))->first(); // Get institution if defined. $institution; if (Input::get('institution') != 0) { $institution = Institution::find(Input::get('institution')); if (!$institution) { $response['state'] = 'Error'; $response['error'] = 'La institucion definida no fue encontrada en el sistema!'; return response()->json($response); } } // Loop through products and services and get prices. $items = json_decode(Input::get('items')); foreach ($items as $code => $info) { // Check if it is a product. $product = Stock::where('Code', '=', $code)->where('BranchId', '=', $userBranch)->first(); if (!$product) { // Check if it is a service. $service = Service::where('Code', '=', $code)->where('BranchId', '=', $userBranch)->first(); if (!$service) { $response['state'] = 'Error'; $response['error'] = 'No se reconocio uno de los productos o servicios!'; return response()->json($response); } // Add price to total of quotation. $quotePrice += $service->Price * $info->quantity; } else { // Add price to total of quotation. $quotePrice += $product->Price * $info->quantity; } } $subTotal = $quotePrice; $discount = $quotePrice * (Input::get('discount') / 100); // Give discount. $quotePrice = $quotePrice * (1 - Input::get('discount') / 100); // Calculate tax if required. $tax = 0; if (json_decode($branch->DefaultExpenses)->regimen == 'cuotageneral') { if (Input::get('institution') != 0) { if (!$institution->Excempt) { $tax = $salePrice * 0.15; } } else { if (!$client || !$client->Excempt) { $tax = $salePrice * 0.15; } } } // Save client information. $clientInfo = array(); if (Input::get('institution') != 0) { // Save institution information. $clientInfo = array('Name' => $institution->Name, 'Address' => $institution->Address, 'Id' => $institution->RUC); } else { // Save institution information. if ($client) { $clientInfo = array('Name' => $client->Name, 'Address' => $client->Address, 'Id' => $client->Cedula); } } // Get quote life span. $config = Configuration::find(0); // Make Quotation. $quotation; if (Input::get('institution') != 0) { // Creditor Type 1 = Client, 2 = Institution. $quotation = Quotation::create(array('WorkerId' => $worker->Id, 'Value' => $quotePrice, 'Discount' => Input::get('discount'), 'Tax' => $tax, 'CreditorId' => Input::get('institution'), 'CreditorType' => 2, 'State' => 'fresh', 'Life' => $config->QuoteLife)); } else { if (!$client) { $quotation = Quotation::create(array('WorkerId' => $worker->Id, 'Value' => $quotePrice, 'Discount' => Input::get('discount'), 'Tax' => $tax, 'CreditorId' => 0, 'CreditorType' => 1, 'State' => 'fresh', 'Life' => $config->QuoteLife)); } else { $quotation = Quotation::create(array('WorkerId' => $worker->Id, 'Value' => $quotePrice, 'Discount' => Input::get('discount'), 'Tax' => $tax, 'CreditorId' => $client->Id, 'CreditorType' => 1, 'State' => 'fresh', 'Life' => $config->QuoteLife)); } } // Loop through items and add them to Quotation Breakdown. foreach ($items as $code => $info) { // Check if product. $product = Stock::where('Code', '=', $code)->where('BranchId', '=', $userBranch)->first(); if (!$product) { // Get service cost. $service = Service::where('Code', '=', $code)->where('BranchId', '=', $userBranch)->first(); QuotationBreakdown::create(array('QuotationId' => $quotation->Id, 'Code' => $code, 'Quantity' => $info->quantity, 'Price' => $service->Price)); } else { QuotationBreakdown::create(array('QuotationId' => $quotation->Id, 'Code' => $code, 'Quantity' => $info->quantity, 'Price' => $product->Price)); } } // Return success message and return quotation information. $response['state'] = 'Success'; $response['quoteInfo'] = array('SubTotal' => $subTotal, 'Discount' => $discount, 'Tax' => $tax, 'Total' => $quotePrice + $tax, 'QuoteId' => $quotation->Id, 'Date' => date('d/m/Y'), 'Life' => $config->QuoteLife); $response['clientInfo'] = $clientInfo; return response()->json($response); }
public function deleteQuotation($id) { $quotation = Quotation::findOrFail($id); return $id; //return view('administration.blog.showBlog')->with('blog', $blog); }