/**
  * create form of a purchase
  * 
  * 1. Get Previous data and page setting
  * 2. Initialize data
  * 3. Generate breadcrumb
  * 4. Generate view
  * @param id
  * @return Object View
  */
 public function create($id = null)
 {
     //1. Get Previous data and page setting
     if (is_null($id)) {
         $data = null;
         $breadcrumb = ['Baru' => route('shop.buy.create')];
         $this->page_attributes->subtitle = 'Baru';
     } else {
         $APIPurchase = new APIPurchase();
         $data = ['data' => $APIPurchase->getShow($id)['data']];
         //explode description saved in json
         $breadcrumb = [$data['data']['ref_number'] => route('shop.buy.show', ['id' => $data['data']['id']]), 'Edit' => route('shop.buy.create', ['id' => $data['data']['id']])];
         $this->page_attributes->subtitle = $data['data']['ref_number'];
     }
     //2. Initialize data
     if (Input::get('pid') && Input::get('vid')) {
         $APIProduct = new APIProduct();
         $product = $APIProduct->getShow(Input::get('pid'))['data'];
         foreach ($product['varians'] as $key => $value) {
             if (Input::get('vid') == $value['id']) {
                 $product['varians'] = ['0' => $value];
             }
         }
         if (count($product['varians']) == 0) {
             App::abort(404, 'data not found');
         }
         $data['data'] = ['id' => null, 'user_id' => null, 'supplier_id' => null, 'voucher_id' => null, 'ref_number' => null, 'type' => 'buy', 'transact_at' => null, 'unique_number' => null, 'shipping_cost' => null, 'voucher_discount' => null, 'amount' => null, 'status' => null, 'transactionlogs' => [], 'supplier' => [], 'transactiondetails' => ['0' => ['id' => null, 'transaction_id' => null, 'varian_id' => $product['varians'][0]['id'], 'quantity' => null, 'price' => null, 'discount' => null, 'varian' => ['id' => $product['varians'][0]['id'], 'product_id' => $product['varians'][0]['product_id'], 'sku' => $product['varians'][0]['sku'], 'size' => $product['varians'][0]['size'], 'product' => ['id' => $product['id'], 'name' => $product['name']]]]]];
         $data['src'] = 'dashboard';
     }
     $this->page_attributes->data = $data;
     //3. Generate breadcrumb
     $this->page_attributes->breadcrumb = array_merge($this->page_attributes->breadcrumb, $breadcrumb);
     //4. Generate view
     $this->page_attributes->source = $this->page_attributes->source . 'create';
     return $this->generateView();
 }
 /**
  * Delete a varian
  * 
  * @param pid, id
  * @return function
  */
 public function destroy($pid = null, $id = null)
 {
     //cek auth
     //get data
     $APIProduct = new APIProduct();
     $product = $APIProduct->getShow($pid);
     $varian = $this->VarianFindData($product['data']['varians'], $id);
     //delete varian
     unset($product['data']['varians'][$varian['key']]);
     //save
     $result = $APIProduct->postData($product['data']);
     //response
     if ($result['status'] != 'success') {
         $this->errors = $result['message'];
     }
     //return view
     $this->page_attributes->success = "Data Varian Telah Dihapus";
     return $this->generateRedirectRoute('goods.product.show', ['id' => $pid]);
 }
 /**
  * create form of a product
  * 
  * 1. Get Previous data and page setting
  * 2. Initialize data
  * 3. Generate breadcrumb
  * 4. Generate view
  * @param id
  * @return Object View
  */
 public function create($id = null)
 {
     //1. Get Previous data and page setting
     if (is_null($id)) {
         $data = null;
         $breadcrumb = ['Data Baru' => route('goods.product.create')];
         $this->page_attributes->subtitle = 'Data Baru';
     } else {
         $APIProduct = new APIProduct();
         $data = ['data' => $APIProduct->getShow($id)['data']];
         //explode description saved in json
         $tmp = json_decode($data['data']['description'], true);
         $data['data']['description'] = $tmp['description'];
         $data['data']['fit'] = $tmp['fit'];
         $data['data']['care'] = isset($tmp['care']) ? $tmp['care'] : '';
         $data['data']['price_start'] = \Carbon\Carbon::parse($data['data']['price_start'])->format('d-m-Y H:i');
         $breadcrumb = [$data['data']['name'] => route('goods.product.show', ['id' => $data['data']['id']]), 'Edit' => route('goods.product.create', ['id' => $data['data']['id']])];
         $this->page_attributes->subtitle = $data['data']['name'];
     }
     //2. Initialize data
     $this->page_attributes->data = $data;
     //3. Generate breadcrumb
     $this->page_attributes->breadcrumb = array_merge($this->page_attributes->breadcrumb, $breadcrumb);
     //4. Generate view
     $this->page_attributes->source = $this->page_attributes->source . 'create';
     return $this->generateView();
 }