Skip to content

Instantly share code, notes, and snippets.

@rasulsh
Created October 6, 2024 12:12
Show Gist options
  • Select an option

  • Save rasulsh/b491e500f065af9f56279229d23e40fb to your computer and use it in GitHub Desktop.

Select an option

Save rasulsh/b491e500f065af9f56279229d23e40fb to your computer and use it in GitHub Desktop.

Revisions

  1. rasulsh created this gist Oct 6, 2024.
    33 changes: 33 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    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);
    }
    }