if ($success && copy($dir . $ds . '00000.png', $dir . $ds . $fileName)) { $dbquery = $db->prepare('UPDATE products SET image="/img/products/' . $fileName . '" where id=' . $id); $dbquery->execute(); $product['id'] = $id; $product['image'] = '/img/products/' . $fileName; } echoResponse(200, array('success' => $success, 'product' => $product)); } else { $error = 'Unable to save product with invalid params: ' . join(', ', $invalids); echoResponse(400, null, array('error' => $error, 'params' => $product)); } }); $app->put('/product/:id', function ($id) use($app, $db) { Security::RestictedAccess('admin'); $product = $app->request->put(); $invalids = validateProduct($product); if (empty($invalids)) { $queryValues = array('id' => $id, 'categoryId' => $product['categoryId'], 'name' => $product['name'], 'amount' => $product['amount'], 'price' => $product['price']); $dbquery = $db->prepare('UPDATE products SET categoryId=:categoryId, name=:name, amount=:amount, price=:price where id=:id'); $success = $dbquery->execute($queryValues); echoResponse(200, array('success' => $success, 'product' => $product)); } else { $error = 'Unable to save product with invalid params: ' . join(', ', $invalids); echoResponse(400, null, array('error' => $error, 'params' => $product)); } }); $app->delete('/product/:id', function ($id) use($app, $db) { Security::RestictedAccess('admin'); $dbquery = $db->prepare('UPDATE products SET active=0 WHERE id=:id'); $dbquery->execute(array('id' => $id)); echoResponse(200, array('success' => true));
private function _addInvoiceDetails($data, $user = NULL) { $client_id = $data['client_id']; $pending = $data['pending']; unset($data['client_id']); unset($data['pending']); foreach ($data['product_id'] as $key => $val) { $ins_data = array('product_id' => $val, 'invoice_id' => $data['inv_id'], 'product_name' => $data['product_name'][$key], 'price' => $data['price'][$key], 'quantity' => $data['qty'][$key], 'product_description' => $data['description'][$key], 'tax_type_id' => 1, 'tax_type_name' => 'No_Vat', 'tax_type_percentage' => 0, 'product_total' => $data['price'][$key] * $data['qty'][$key] * (0 / 100 + 1)); //adding cache $cache_data = array('client_id' => $client_id, 'invoice_id' => $data['inv_id'], 'product_id' => $val, 'pending' => $ins_data['product_total']); $this->invoice_lib->cache_invoice($cache_data); // pr($data); if (validateProduct($val, TRUE)) { $this->db->insert('tblstock', array('company_id' => $this->comp_id, 'product_id' => $val, 'quantity' => $data['qty'][$key], 'movement' => STOCK_OUT, 'invoice_id' => $data['inv_id'])); $this->add_stock_cache($val); } $this->db->insert('tblinvoice_details', $ins_data); } return true; }