function generateTypeOptions($type, $empty, $value = '') { $return = $empty == true ? '<option value=""></option>' : ''; $factoryItem = Factory::createItem($type); $optArr = $factoryItem->generateTypeOptions($type); foreach ($optArr as $opt) { $selected = $opt[0] == $value ? ' selected' : ''; $return .= '<option value="' . $opt[0] . '"' . $selected . '>' . htmlspecialchars($opt[1], ENT_QUOTES | ENT_HTML5, 'UTF-8') . '</option>'; } return $return; }
Outputs: */ if ($_POST['action'] == 'deleteAttachment') { $return = ['status' => 'fail']; if (unlink('attachments/' . $_POST['subID'])) { $sth = $dbh->prepare('SELECT type, id, name, extension FROM attachments WHERE attachmentID = :attachmentID'); $sth->execute([':attachmentID' => $_POST['subID']]); $row = $sth->fetch(); $sth = $dbh->prepare('DELETE FROM attachments WHERE attachmentID = :attachmentID'); $sth->execute([':attachmentID' => $_POST['subID']]); $return = ['status' => 'success']; addChange($row['type'], $row['id'], $_SESSION['employeeID'], 'D', json_encode(['subType' => 'attachment', 'name' => $row['name'], 'extension' => $row['extension']])); } echo json_encode($return); } /* Function: customAjax Inputs: Outputs: */ if ($_POST['action'] == 'customAjax') { $data = $_POST; unset($data['action']); unset($data['type']); unset($data['id']); $factoryItem = Factory::createItem($_POST['type']); $return = $factoryItem->customAjax($_POST['id'], $data); echo json_encode($return); }
} //recurring expenseOthers $sth = $dbh->prepare('SELECT expenseID, name, unitPrice, quantity, recurringID, dayOfMonth FROM expenseOthers WHERE recurringID IS NOT NULL AND startDate <= :today AND endDate >= :today'); $sth->execute([':today' => $today]); while ($row = $sth->fetch()) { $day = date('j', $today); if ($day == $row['dayOfMonth']) { $sth2 = $dbh->prepare('INSERT INTO expenseOthers (expenseID, name, date, unitPrice, quantity, parentRecurringID) VALUES(:expenseID, :name, :date, :unitPrice, :quantity, :parentRecurringID)'); $sth2->execute([':expenseID' => $row['expenseID'], ':name' => $row['name'], ':date' => $today, ':unitPrice' => $row['unitPrice'], ':quantity' => $row['quantity'], ':parentRecurringID' => $row['recurringID']]); $expenseItem->updateAmountDue($row['expenseID']); } } $orderItem = Factory::createItem('order'); //recurring orders_products $sth = $dbh->prepare('SELECT orderProductID, orderID, productID, unitPrice, quantity, recurringID, dayOfMonth FROM orders_products WHERE recurringID IS NOT NULL AND startDate <= :today AND endDate >= :today'); $sth->execute([':today' => $today]); while ($row = $sth->fetch()) { $day = date('j', $today); if ($day == $row['dayOfMonth']) { $sth2 = $dbh->prepare('INSERT INTO orders_products (orderID, productID, date, unitPrice, quantity, parentRecurringID) VALUES(:orderID, :productID, :date, :unitPrice, :quantity, :parentRecurringID)'); $sth2->execute([':orderID' => $row['orderID'], ':productID' => $row['productID'], ':date' => $today, ':unitPrice' => $row['unitPrice'], ':quantity' => $row['quantity'], ':parentRecurringID' => $row['recurringID']]); $id = $dbh->lastInsertId(); //check for discounts on the item $sth2 = $dbh->prepare('SELECT discountID, discountType, discountAmount FROM orders_discounts