コード例 #1
0
 /**
  * Add transaction and return the new transaction id
  *
  * @param arr $data - array(
  *                        'accounting_date' => 'YYYY-MM-DD',                OPTIONAL
  *                        'transfer_date'   => 'YYYY-MM-DD',
  *                        'description'     => 'text',                      OPTIONAL
  *                        'journal_id'      => int or NULL                  OPTIONAL
  *                        'vat'             => amount of money, 0 or above  OPTIONAL
  *                        'sum'             => amount of money, above 0
  *                        'employee_id'     => int or NULL                  OPTIONAL
  *                    )
  * @return int
  **/
 private function add($data)
 {
     if (!isset($data['accounting_date'])) {
         $data['accounting_date'] = $data['transfer_date'];
     }
     if (!isset($data['description'])) {
         $data['description'] = '';
     }
     if (!isset($data['journal_id'])) {
         $data['journal_id'] = NULL;
     }
     if (!isset($data['vat'])) {
         $data['vat'] = 0;
     }
     if (!isset($data['employee_id'])) {
         $data['employee_id'] = NULL;
     }
     if (self::$prepared_insert == NULL) {
         self::$prepared_insert = $this->pdo->prepare('INSERT INTO transactions (accounting_date, transfer_date, description, journal_id, vat, sum, employee_id) VALUES(?,?,?,?,?,?,?)');
     }
     self::$prepared_insert->execute(array($data['accounting_date'], $data['transfer_date'], $data['description'], $data['journal_id'], $data['vat'], $data['sum'], $data['employee_id']));
     return $this->pdo->lastInsertId();
 }