summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/containers/WaybillForm.tsx36
-rw-r--r--src/containers/WaybillPanel.tsx20
-rw-r--r--src/services.js4
3 files changed, 37 insertions, 23 deletions
diff --git a/src/containers/WaybillForm.tsx b/src/containers/WaybillForm.tsx
index fedc9c4..2167d17 100644
--- a/src/containers/WaybillForm.tsx
+++ b/src/containers/WaybillForm.tsx
@@ -1,10 +1,17 @@
-import React from 'react';
+import React, { useState } from 'react';
import { Form, FormikProps } from 'formik';
+import _ from 'lodash';
import Input from '../components/Input';
+import Button from '../components/Button';
import Select from '../components/Select';
+import Paper from '../components/Paper';
import useOptions from '../hooks/useOptions';
const WaybillForm: React.FC<FormikProps> = ({ setFieldValue, values }) => {
+ const [recordsNumber, setRecordsNumber] = useState<number>(values.records.length);
+
+ const handleAddRecord = () => setRecordsNumber(v => v + 1);
+
const contractorOptions = useOptions('contractors', 'contractorId', values, setFieldValue);
const productOptions = useOptions('products', 'productId', values, setFieldValue);
@@ -16,11 +23,6 @@ const WaybillForm: React.FC<FormikProps> = ({ setFieldValue, values }) => {
options={contractorOptions}
/>
<Select
- name="productId"
- label="Товар"
- options={productOptions}
- />
- <Select
name="operation"
label="Операция"
options={[
@@ -28,7 +30,27 @@ const WaybillForm: React.FC<FormikProps> = ({ setFieldValue, values }) => {
{ key: 'out', label: 'Расход' },
]}
/>
- <Input name="quantity" type="number" label="Количество" />
+ <Button onClick={handleAddRecord}>+</Button>
+ {_.times(recordsNumber).map(index => (
+ <Paper>
+ <Select
+ name={`records.${index}.productId`}
+ label="Товар"
+ options={productOptions}
+ />
+ <Input
+ name={`records.${index}.price`}
+ type="number"
+ label="Цена, $"
+ />
+ <Input
+ name={`records.${index}.quantity`}
+ type="number"
+ label="Количество"
+ />
+ {values.records[index]?.price * values.records[index]?.quantity || 0}
+ </Paper>
+ ))}
</Form>
);
};
diff --git a/src/containers/WaybillPanel.tsx b/src/containers/WaybillPanel.tsx
index ca40169..397b16b 100644
--- a/src/containers/WaybillPanel.tsx
+++ b/src/containers/WaybillPanel.tsx
@@ -3,35 +3,29 @@ import { useHistory } from 'react-router-dom';
import Input from '../components/Input';
import Button from '../components/Button';
import Paper from '../components/Paper';
-import { post } from '../requests';
+import { patch } from '../requests';
import { PanelProps } from './Service/ServiceContext';
const WaybillPanel: React.FC<PanelProps> = ({ item }) => {
const history = useHistory();
- const handleExecute = () => post(`/waybills/${item._id}/execute`)
+ const handleExecute = () => patch(`/waybills/${item._id}`, { status: 'executed' })
.then(() => history.push('/waybills'));
- const handleCancel = () => post(`/waybills/${item._id}/cancel`)
+ const handleCancel = () => patch(`/waybills/${item._id}`, { status: 'cancelled' })
.then(() => history.push('/waybills'));
const executed = item.status === 'executed';
- const total = item.product.price * item.quantity;
return (
<div className="m-4 p-4 pl-16 border-l flex flex-col">
<p className="text-lg">
- Итоговая сумма: ${total}
+ Итоговая сумма: ${item.total}
</p>
- <div>
- <Button route={`/contractors/${item.contractorId}`} variant="outlined">
- Перейти к контрагенту
- </Button>
- <Button route={`/products/${item.productId}`} variant="outlined">
- Перейти к продукту
- </Button>
- </div>
+ <Button route={`/contractors/${item.contractorId}`} variant="outlined">
+ Перейти к контрагенту
+ </Button>
{
executed
? <Button onClick={handleCancel}>Откатить</Button>
diff --git a/src/services.js b/src/services.js
index f8e27cf..3e53c14 100644
--- a/src/services.js
+++ b/src/services.js
@@ -50,13 +50,11 @@ const services: ServiceParams[] = [
tableFields: [
{ key: 'status', label: 'Статус', transform: status => waybillStatusNames[status] },
{ key: 'operation', label: 'Операция', transform: op => operationNames[op] },
- { key: 'product.name', label: 'Товар' },
{ key: 'contractor.name', label: 'Контрагент' },
- { key: 'quantity', label: 'Количество' },
],
default: {
operation: 'in',
- quantity: 1,
+ records: [],
},
},
];