/** * Create a consumable if a duplicate does not exist * * @author Daniel Melzter * @since 3.0 * @param $item array */ public function createConsumableIfNotExists(array $item) { $this->log("Creating Consumable"); foreach ($this->consumables as $tempconsumable) { if (strcasecmp($tempconsumable->name, $item["item_name"]) == 0) { $this->log("A matching consumable " . $item["item_name"] . " already exists"); //TODO: Adjust quantity if different maybe? return; } } $consumable = new Consumable(); $consumable->name = $item["item_name"]; if (!empty($item["purchase_date"])) { $consumable->purchase_date = $item["purchase_date"]; } else { $consumable->purchase_date = null; } if (!empty($item["purchase_cost"])) { $consumable->purchase_cost = number_format(e($item["purchase_cost"]), 2); } else { $consumable->purchase_cost = 0.0; } $consumable->location_id = $item["location"]->id; $consumable->user_id = $this->option('user_id'); $consumable->company_id = $item["company"]->id; $consumable->order_number = $item["order_number"]; $consumable->category_id = $item["category"]->id; // TODO:Implement //$consumable->notes= e($item_notes); $consumable->requestable = filter_var($item["requestable"], FILTER_VALIDATE_BOOLEAN); if ($item["quantity"] > -1) { $consumable->qty = $item["quantity"]; } else { $consumable->qty = 1; } if (!$this->option("testrun")) { if ($consumable->save()) { $this->log("Consumable " . $item["item_name"] . ' was created'); // $this->comment("Consumable " . $item["item_name"] . ' was created'); } else { $this->jsonError('Consumable', $consumable->getErrors()); } } else { $this->log('TEST RUN - Consumable ' . $item['item_name'] . ' not created'); } }
/** * Validate and store new consumable data. * * @author [A. Gianotto] [<*****@*****.**>] * @see ConsumablesController::getCreate() method that returns the form view * @since [v1.0] * @return Redirect */ public function postCreate() { $consumable = new Consumable(); $consumable->name = e(Input::get('name')); $consumable->category_id = e(Input::get('category_id')); $consumable->location_id = e(Input::get('location_id')); $consumable->company_id = Company::getIdForCurrentUser(Input::get('company_id')); $consumable->order_number = e(Input::get('order_number')); $consumable->min_amt = e(Input::get('min_amt')); $consumable->manufacturer_id = e(Input::get('manufacturer_id')); $consumable->model_no = e(Input::get('model_no')); $consumable->item_no = e(Input::get('item_no')); if (e(Input::get('purchase_date')) == '') { $consumable->purchase_date = null; } else { $consumable->purchase_date = e(Input::get('purchase_date')); } if (e(Input::get('purchase_cost')) == '0.00') { $consumable->purchase_cost = null; } else { $consumable->purchase_cost = e(Input::get('purchase_cost')); } $consumable->qty = e(Input::get('qty')); $consumable->user_id = Auth::user()->id; // Was the consumable created? if ($consumable->save()) { // Redirect to the new consumable page return redirect()->to("admin/consumables")->with('success', trans('admin/consumables/message.create.success')); } return redirect()->back()->withInput()->withErrors($consumable->getErrors()); }
/** * Create a consumable if a duplicate does not exist * * @author Daniel Melzter * @since 3.0 * @param $item array */ public function createConsumableIfNotExists(array $item) { $consumable = null; $editingConsumable = false; $this->log("Creating Consumable"); foreach ($this->consumables as $tempconsumable) { if (strcasecmp($tempconsumable->name, $item["item_name"]) == 0) { $this->log("A matching consumable " . $item["item_name"] . " already exists"); if (!$this->option('update')) { $this->log("Skipping consumable."); return; } $this->log('Updating matching consumable with new values'); $editingConsumable = true; $consumable = $tempconsumable; } } if (is_null($consumable)) { $this->log("No matching consumable, creating one"); $consumable = new Consumable(); } if (!$editingConsumable) { $consumable->name = $item["item_name"]; } if (!empty($item["purchase_date"])) { $consumable->purchase_date = $item["purchase_date"]; } else { $consumable->purchase_date = null; } if (!empty($item["purchase_cost"])) { $consumable->purchase_cost = Helper::ParseFloat($item["purchase_cost"]); } if ($item["location"]) { $consumable->location_id = $item["location"]->id; } $consumable->user_id = $this->option('user_id'); if ($item["company"]) { $consumable->company_id = $item["company"]->id; } if (!empty($item["order_number"])) { $consumable->order_number = $item["order_number"]; } if ($item["category"]) { $consumable->category_id = $item["category"]->id; } // TODO:Implement //$consumable->notes= e($item_notes); if (!empty($item["requestable"])) { $consumable->requestable = filter_var($item["requestable"], FILTER_VALIDATE_BOOLEAN); } if (!empty($item["quantity"])) { if ($item["quantity"] > -1) { $consumable->qty = $item["quantity"]; } else { $consumable->qty = 1; } } if (!$this->option("testrun")) { // dd($consumable); if ($consumable->save()) { $this->log("Consumable " . $item["item_name"] . ' was created'); // $this->comment("Consumable " . $item["item_name"] . ' was created'); } else { $this->jsonError('Consumable', $consumable->getErrors()); } } else { $this->log('TEST RUN - Consumable ' . $item['item_name'] . ' not created'); } }