| 70 | |
| 71 | |
| 72 | |
| 73 | = Трансакции |
| 74 | |
| 75 | {{{ |
| 76 | const db = require('./db'); |
| 77 | |
| 78 | exports.getAll = (cb) => { |
| 79 | db.query('SELECT * FROM procurement', cb); |
| 80 | }; |
| 81 | |
| 82 | exports.getDetailedTransactions = (cb) => { |
| 83 | const query = ` |
| 84 | SELECT p.TransactionID, c.CustomerName, c.CustomerSurName, pr.Model, t.Type, t.Duration, t.MonthlyPay, t.TotalPrice, p.ProcurementDate |
| 85 | FROM procurement p |
| 86 | JOIN customer c ON p.CustomerID = c.CustomerID |
| 87 | JOIN product pr ON p.ProductID = pr.ProductID |
| 88 | JOIN t_type t ON p.TransactionID = t.TransactionID`; |
| 89 | db.query(query, cb); |
| 90 | }; |
| 91 | |
| 92 | exports.add = (data, cb) => { |
| 93 | const { TransactionID, EmployeeID, CustomerID, ProductID, ProcurementDate, Quantity } = data; |
| 94 | db.query('INSERT INTO procurement VALUES (?, ?, ?, ?, ?, ?)', [TransactionID, EmployeeID, CustomerID, ProductID, ProcurementDate, Quantity], cb); |
| 95 | }; |
| 96 | }}} |