Example #1
0
 public function action_index($id = null)
 {
     $items = null;
     $count = 0;
     $ship = \Model_Ship::find('first', ['related' => ['parts' => ['related' => ['auctions' => ['related' => ['vendor']]]]], 'where' => ['shipNumber' => $id]]);
     if ($ship) {
         $ship_count = DB::select(DB::expr('SUM(item_count) as count'))->from('auctions')->join('parts', 'LEFT')->on('parts.id', '=', 'auctions.part_id')->where('ship_number', $id)->execute()->as_array();
         $count = $ship_count[0]['count'];
         $items = $ship->parts;
     }
     $this->template->title = "Shipped";
     $this->template->content = View::forge('admin/list', ['ships' => \Model_Ship::find('all'), 'items' => $items, 'ship_id' => $id, 'count_in_part' => $count]);
 }
Example #2
0
 public function action_index()
 {
     if (Input::method() == 'POST') {
         $val = \Model_Ship::validate('default');
         $values['sell_id'] = \Input::post('sell_id');
         if ($val->run($values)) {
             $ship = \Model_Ship::forge();
             $parts = Model_Part::find('all', ['where' => ['status' => \Config::get('my.status.ship.id')]]);
             try {
                 \DB::start_transaction();
                 $ship->shipAuctionID = $val->validated('sell_id');
                 $ship->partStatus = 4;
                 if (!$ship->save()) {
                     throw new Exception("Could not create ship", 1);
                 }
                 foreach ($parts as $p) {
                     $p->status = \Config::get('my.status.shipped.id');
                     $p->ship_number = $ship->shipNumber;
                     if (!$p->save()) {
                         throw new Exception("Could not save part ID:" . $p->id, 1);
                     }
                 }
                 \DB::commit_transaction();
                 Session::set_flash('alert', ['status' => 'success', 'message' => 'Ship was successfully created']);
             } catch (\Exception $e) {
                 DB::rollback_transaction();
                 Session::set_flash('alert', ['status' => 'danger', 'message' => $e->getMessage()]);
             }
         } else {
             Session::set_flash('alert', ['status' => 'danger', 'message' => 'Check sell ID']);
         }
     }
     $data['items'] = Model_Part::find('all', ['where' => ['status' => \Config::get('my.status.ship.id')], 'related' => ['auctions' => ['related' => ['vendor']]]]);
     $ship_count = DB::select(DB::expr('SUM(item_count) as count'))->from('auctions')->join('parts', 'LEFT')->on('parts.id', '=', 'auctions.part_id')->where('status', Config::get('my.status.ship.id'))->execute()->as_array();
     $data['ship_count'] = $ship_count[0]['count'];
     $this->template->title = "Ship";
     $this->template->content = View::forge('admin/list', $data);
 }