Skip to content

Commit

Permalink
refactor(Sale model): Update Sale model to accept id in updateSale me…
Browse files Browse the repository at this point in the history
…thod
  • Loading branch information
Hordunlarmy committed Feb 18, 2025
1 parent 0a2e9e2 commit 9c484b8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
4 changes: 0 additions & 4 deletions controllers/TradeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,6 @@ public function updateSales($saleId)
$data = $this->getRequestData();


if (!is_array($data['items']) || empty($data['items'])) {
$this->sendResponse('Items should be an array and not empty', 400);
}

$data['user_id'] = $_SESSION['user_id'];

try {
Expand Down
12 changes: 6 additions & 6 deletions models/Sale.php
Original file line number Diff line number Diff line change
Expand Up @@ -912,24 +912,24 @@ private function getTaxId($taxName)
return $stmt->fetchColumn();
}

public function updateSale($data)
public function updateSale($id, $data)
{
$this->db->beginTransaction();

try {
$this->updateSalesOrder($data);
$this->updateSalesOrderItems($data['sales_order_id'], $data['items']);
$this->updateSalesOrder($id, $data);
$this->updateSalesOrderItems($id, $data['items']);

$this->db->commit();

return $data['sales_order_id'];
return $id;
} catch (\Exception $e) {
$this->db->rollBack();
throw $e;
}
}

private function updateSalesOrder($data)
private function updateSalesOrder($id, $data)
{
$query = "
UPDATE sales_orders
Expand All @@ -954,7 +954,7 @@ private function updateSalesOrder($data)
$stmt = $this->db->prepare($query);

$stmt->execute([
':sales_order_id' => $data['sales_order_id'],
':sales_order_id' => $id,
':order_type' => $data['order_type'] ?? null,
':order_title' => $data['order_title'] ?? null,
':payment_term_id' => $data['payment_term_id'] ?? null,
Expand Down

0 comments on commit 9c484b8

Please sign in to comment.