コード例 #1
0
ファイル: stocks.php プロジェクト: nicarayz/linabiz
 function index_post()
 {
     $models = json_decode($this->post('models'));
     foreach ($models as $value) {
         $obj = new Stock(null, $this->entity);
         $obj->currency_id = $value->currency_id;
         $obj->bill_id = $value->bill_id;
         $obj->contact_id = $value->contact_id;
         $obj->product_id = $value->product_id;
         $obj->unit_id = $value->unit_id;
         $obj->quantity = $value->quantity;
         $obj->price = $value->price;
         $obj->issued_date = $value->issued_date;
         $obj->deleted = isset($value->deleted) ? $value->deleted : 0;
         if ($obj->save()) {
             $pl = new Price_list(null, $this->entity);
             $pl->where("product_id", $obj->product_id);
             $pl->where("unit_id", $obj->unit_id);
             $pl->get();
             $p = $obj->product->get();
             $p->on_hand = floatval($p->on_hand) - floatval($pl->unit_value);
             $p->save();
             //Respsone
             $data["results"][] = array("id" => $obj->id, "currency_id" => $obj->currency_id, "bill_id" => $obj->bill_id, "contact_id" => $obj->contact_id, "product_id" => $obj->product_id, "unit_id" => $obj->unit_id, "quantity" => $obj->quantity, "price" => $obj->price, "issued_date" => $obj->issued_date, "deleted" => $obj->deleted, "currency" => $obj->currency->get_raw()->result(), "contact" => $obj->contact->get_raw()->result(), "product" => $obj->product->get_raw()->result(), "unit" => $obj->unit->get()->name);
         }
     }
     $data["count"] = count($data["results"]);
     $this->response($data, 201);
 }
コード例 #2
0
ファイル: price_lists.php プロジェクト: nicarayz/linabiz
 function index_delete()
 {
     $models = json_decode($this->delete('models'));
     foreach ($models as $key => $value) {
         $obj = new Price_list(null, $this->entity);
         $obj->where("id", $value->id)->get();
         $data["results"][] = array("data" => $value, "status" => $obj->delete());
     }
     //Response data
     $this->response($data, 200);
 }