Esempio n. 1
0
 /**
  * Validates and stores the license form data submitted from the new
  * license form.
  *
  * @author [A. Gianotto] [<*****@*****.**>]
  * @see LicensesController::getCreate() method that provides the form view
  * @since [v1.0]
  * @return Redirect
  */
 public function postCreate()
 {
     // get the POST data
     $new = Input::all();
     // create a new model instance
     $license = new License();
     if (e(Input::get('purchase_cost')) == '') {
         $license->purchase_cost = null;
     } else {
         $license->purchase_cost = e(Input::get('purchase_cost'));
     }
     if (e(Input::get('supplier_id')) == '') {
         $license->supplier_id = null;
     } else {
         $license->supplier_id = e(Input::get('supplier_id'));
     }
     if (e(Input::get('maintained')) == '') {
         $license->maintained = 0;
     } else {
         $license->maintained = e(Input::get('maintained'));
     }
     if (e(Input::get('reassignable')) == '') {
         $license->reassignable = 0;
     } else {
         $license->reassignable = e(Input::get('reassignable'));
     }
     if (e(Input::get('purchase_order')) == '') {
         $license->purchase_order = '';
     } else {
         $license->purchase_order = e(Input::get('purchase_order'));
     }
     // Save the license data
     $license->name = e(Input::get('name'));
     $license->serial = e(Input::get('serial'));
     $license->license_email = e(Input::get('license_email'));
     $license->license_name = e(Input::get('license_name'));
     $license->notes = e(Input::get('notes'));
     $license->order_number = e(Input::get('order_number'));
     $license->seats = e(Input::get('seats'));
     $license->purchase_date = e(Input::get('purchase_date'));
     $license->purchase_order = e(Input::get('purchase_order'));
     $license->depreciation_id = e(Input::get('depreciation_id'));
     $license->company_id = Company::getIdForCurrentUser(Input::get('company_id'));
     $license->expiration_date = e(Input::get('expiration_date'));
     $license->user_id = Auth::user()->id;
     if ($license->purchase_date == "" || $license->purchase_date == "0000-00-00") {
         $license->purchase_date = null;
     }
     if ($license->expiration_date == "" || $license->expiration_date == "0000-00-00") {
         $license->expiration_date = null;
     }
     if ($license->purchase_cost == "" || $license->purchase_cost == "0.00") {
         $license->purchase_cost = null;
     }
     // Was the license created?
     if ($license->save()) {
         $insertedId = $license->id;
         // Save the license seat data
         DB::transaction(function () use(&$insertedId, &$license) {
             for ($x = 0; $x < $license->seats; $x++) {
                 $license_seat = new LicenseSeat();
                 $license_seat->license_id = $insertedId;
                 $license_seat->user_id = Auth::user()->id;
                 $license_seat->assigned_to = null;
                 $license_seat->notes = null;
                 $license_seat->save();
             }
         });
         // Redirect to the new license page
         return redirect()->to("admin/licenses")->with('success', trans('admin/licenses/message.create.success'));
     }
     return redirect()->back()->withInput()->withErrors($license->getErrors());
 }