where('caisse_id', $id)->first(); } public function updateCaisse($data) { try { $id = 1; if ($this->update($id, $data)) { return true; } return false; } catch (\Exception $e) { log_message('error', 'Erreur lors de la mise à jour de la caisse : ' . $e->getMessage()); return false; } } public function updateCaissePerRecouvrement($montant) { try { $this->transStart(); $this->set('caisse_espece', 'caisse_espece + ' . (float)$montant, false); $this->where('caisse_id', 1); $this->update(); $this->set('caisse_mvola', 'caisse_mvola - ' . (float)$montant, false); $this->where('caisse_id', 1); $this->update(); if ($this->transStatus() === false) { $this->transRollback(); return false; } $this->transComplete(); return true; } catch (\Exception $e) { $this->transRollback(); log_message('error', 'Erreur lors de la mise à jour de la caisse : ' . $e->getMessage()); return false; } } public function updateCaissePerOrders($p1, $p2, $operation = '+', $p3 = null, $destination = 'banque') { $caisse = $this->where('caisse_id', 1)->first(); if (!$caisse) { return false; } $data = [ 'caisse_total' => $caisse['caisse_total'] + $p1, ]; if ($operation == '+') { $data['caisse_mvola'] = $caisse['caisse_mvola'] + $p2; } elseif ($operation == '-') { $data['caisse_mvola'] = $caisse['caisse_mvola'] - $p2; } if ($p3 !== null) { if ($destination === 'banque') { $data['caisse_banque'] = $caisse['caisse_banque'] + $p3; } elseif ($destination === 'espece') { $data['caisse_espece'] = $caisse['caisse_espece'] + $p3; } } // Exécuter la mise à jour return $this->update(1, $data); } }