public function addOrder($data) { if ($data['mode'] == 'save') { $draft = 0; } else { $draft = 1; } $stock_order = StockOrder::addNew(['amount' => $data['amount'], 'stock_id' => $this->id, 'branch_id' => $data['branch_id'], 'creator_id' => Auth::user()->id, 'urgent' => $data['urgent'], 'required_at' => $data['required_date'], 'draft' => $draft, 'send_reminder' => $data['send_reminder'], 'reminder_days' => $data['reminder_days'], 'comments' => $data['comments']]); return $stock_order; }
public static function addNew($data) { $stock_order = new StockOrder(); if ($data['required_at']) { $required_at = Carbon::createFromFormat('d/m/Y', $data['required_at']); $required_at->hour = 8; $required_at->minute = 0; $required_at->second = 0; } $stock_order->amount = $data['amount']; $stock_order->stock_id = $data['stock_id']; $stock_order->branch_id = $data['branch_id']; $stock_order->creator_id = $data['creator_id']; $stock_order->urgent = $data['urgent'] ? 1 : 0; $stock_order->required_at = $required_at; $stock_order->draft = $data['draft'] ? 1 : 0; $stock_order->send_reminder = $data['send_reminder'] ? 1 : 0; $stock_order->reminder_days = $data['reminder_days'] ? $data['reminder_days'] : 0; $stock_order->comments = $data['comments']; $stock_order->save(); return $stock_order; }