/**
  * Delete order
  *
  * @param   int     $id         Order ID
  * 
  * @url     DELETE  order/{id}
  * 
  * @return  array
  */
 function delete($id)
 {
     if (!DolibarrApiAccess::$user->rights->commande->supprimer) {
         throw new RestException(401);
     }
     $result = $this->commande->fetch($id);
     if (!$result) {
         throw new RestException(404, 'Order not found');
     }
     if (!DolibarrApi::_checkAccessToResource('commande', $this->commande->id)) {
         throw new RestException(401, 'Access not allowed for login ' . DolibarrApiAccess::$user->login);
     }
     if (!$this->commande->delete(DolibarrApiAccess::$user)) {
         throw new RestException(500, 'Error when delete order : ' . $this->commande->error);
     }
     return array('success' => array('code' => 200, 'message' => 'Order deleted'));
 }
Beispiel #2
0
 /**
  * testCommandeDelete
  *
  * @param   int $id         Id of order
  * @return  void
  *
  * @depends testCommandeOther
  * The depends says test is run only if previous is ok
  */
 public function testCommandeDelete($id)
 {
     global $conf, $user, $langs, $db;
     $conf = $this->savconf;
     $user = $this->savuser;
     $langs = $this->savlangs;
     $db = $this->savdb;
     $localobject = new Commande($this->savdb);
     $result = $localobject->fetch($id);
     $result = $localobject->delete($user);
     print __METHOD__ . " id=" . $id . " result=" . $result . "\n";
     $this->assertLessThan($result, 0);
     return $result;
 }
        $row = $db->fetch_array($resql);
        $db->begin();
        $db->query("DELETE FROM " . MAIN_DB_PREFIX . "commandedet WHERE rowid = {$row['0']};");
        $db->commit();
    } else {
        $db->begin();
        $db->query("delete from " . MAIN_DB_PREFIX . "commandedet where rowid='{$id}'");
        $db->commit();
    }
    $sql = "SELECT count(*) FROM " . MAIN_DB_PREFIX . "commandedet where fk_commande={$placeid}";
    $resql = $db->query($sql);
    $row = $db->fetch_array($resql);
    if ($row[0] == 0) {
        $object = new Commande($db);
        $ret = $object->fetch($placeid);
        $result = $object->delete($user);
    }
}
if ($action == "q") {
    $db->begin();
    $db->query("update " . MAIN_DB_PREFIX . "commandedet set qty='{$number}', total_ht=subprice*qty, total_tva=total_ht*tva_tx/100, total_ttc=total_ht+total_tva where rowid='{$id}'");
    $db->commit();
}
if ($action == "p") {
    $db->begin();
    $db->query("update " . MAIN_DB_PREFIX . "commandedet set price='{$number}', remise=remise_percent*price/100, subprice=(price-remise)/(tva_tx/100+1), total_ht=subprice*qty, total_tva=total_ht*tva_tx/100, total_ttc=total_ht+total_tva where rowid='{$id}'");
    $db->commit();
}
if ($action == "d") {
    $db->begin();
    $db->query("update " . MAIN_DB_PREFIX . "commandedet set remise_percent='{$number}', remise=remise_percent*price/100, subprice=(price-remise)/(tva_tx/100+1), total_ht=subprice*qty, total_tva=total_ht*tva_tx/100, total_ttc=total_ht+total_tva where rowid='{$id}'");