Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New tk2408 3299 delete by line obj #504

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion htdocs/compta/facture/card-rec.php
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@
setEventMessages($mesg, null, 'errors');
} else {
// Insert line
$result = $object->addline($desc, $pu_ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, $idprod, $remise_percent, $price_base_type, $info_bits, '', $pu_ttc, $type, -1, $special_code, $label, $fk_unit, 0, $date_start_fill, $date_end_fill, $fournprice, $buyingprice);
$result = $object->addline($desc, $pu_ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, $idprod, $remise_percent, $price_base_type, $info_bits, '', $pu_ttc, $type, -1, $special_code, $label, $fk_unit, 0, $date_start_fill, $date_end_fill, $fournprice, $buyingprice, $array_options);

if ($result > 0) {
// Define output language and generate document
Expand Down
5 changes: 4 additions & 1 deletion htdocs/contrat/card.php
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,10 @@
$db->rollback();
}
} elseif ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->contrat->creer) {
$result = $object->deleteline(GETPOST('lineid', 'int'), $user);
$fk_line = GETPOSTINT('lineid');
$contratLigne = new ContratLigne($db);
$contratLigne->fetch($fk_line);
$result = $contratLigne->delete($user);

if ($result >= 0) {
header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
Expand Down
49 changes: 49 additions & 0 deletions htdocs/contrat/class/contrat.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -3662,4 +3662,53 @@ public function close_line($user, $date_end_real, $comment = '', $notrigger = 0)
return -1;
}
}

/**
* Delete line in database
*
* @param User $user Object user
* @param bool $notrigger Disable triggers
* @return int <0 if KO, >0 if OK
*/
public function delete(User $user, bool $notrigger = false): int
{
$error = 0;

$this->db->begin();

if (!$error) {
if (!$notrigger) {
$result = $this->call_trigger('LINECONTRACT_DELETE', $user);
if ($result < 0) {
$error++;
}
}
}

if (!$error) {
$result = $this->deleteExtraFields();
if ($result < 0) {
$error++;
}
}

if (!$error) {
$sql = "DELETE FROM " . $this->db->prefix() . $this->table_element . " WHERE rowid=" . intval($this->id);

$res = $this->db->query($sql);
if (!$res) {
$error++;
$this->errors[] = $this->db->lasterror();
}
}

if ($error) {
$this->db->rollback();
return -1;
} else {
$this->db->commit();
return 1;
}

}
}
Loading