Skip to content

Instantly share code, notes, and snippets.

@rasulsh
Created October 6, 2024 12:12
Show Gist options
  • Save rasulsh/b491e500f065af9f56279229d23e40fb to your computer and use it in GitHub Desktop.
Save rasulsh/b491e500f065af9f56279229d23e40fb to your computer and use it in GitHub Desktop.
add document method
public function addDocument($data = array()) {
$user_id = $this->user->getId();
$user_selected_date = call_function($this->language->get('function_jtg'), $this->db->escape($data['user_selected_date']));
$document_note = strip_tags(trim($data['document_note']));
$this->db->query("INSERT INTO `" . DB_PREFIX . "finance_document` SET `user_id` = '" . $this->db->escape($user_id) . "', `user_selected_date` = '" . $this->db->escape($user_selected_date) . "', `document_note` = '" . $this->db->escape($document_note) . "'");
$document_id = $this->db->getLastId();
$values = [];
foreach ($data['document_items'] as $item) {
// عدد مثبت بستانکار
// عدد منفی بدهکار
$value = 0;
if (empty($item['debtor'])) {
$value = $item['creditor'];
} else {
$value = $item['debtor'] * (-1);
}
$item_note = strip_tags(trim($item['item_note']));
$values[] = "('" . $document_id . "', '" . $this->db->escape($item['contact_id']) . "', '" . $this->db->escape($value) . "', '" . $this->db->escape($item_note) . "')";
}
if (!empty($values)) {
$sql = "INSERT INTO `" . DB_PREFIX . "finance_document_item` (`document_id`, `contact_id`, `value`, `item_note`) VALUES " . implode(", ", $values);
$this->db->query($sql);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment