Index: src/stock-adjustment-mobile/edit-product-page/edit-product-page.jsx
===================================================================
diff -u -N -r0514582c6e1fc7c5f7832ba3d4be2bc09d2ec2b0 -r3bb65537bb15684ded22951a91c362f7f7a208d8
--- src/stock-adjustment-mobile/edit-product-page/edit-product-page.jsx (.../edit-product-page.jsx) (revision 0514582c6e1fc7c5f7832ba3d4be2bc09d2ec2b0)
+++ src/stock-adjustment-mobile/edit-product-page/edit-product-page.jsx (.../edit-product-page.jsx) (revision 3bb65537bb15684ded22951a91c362f7f7a208d8)
@@ -26,13 +26,13 @@
import SelectField from '../../react-components/form-fields/select-field';
import ReadOnlyField from '../../react-components/form-fields/read-only-field';
import confirmAlertCustom from '../../react-components/modals/confirm';
-import { formatLot, formatDate, formatDateISO, toastProperties, isQuantityNotFilled, formatProductName } from '../format-utils';
+import { formatLot, formatDate, formatDateISO, toastProperties, isQuantityNotFilled } from '../format-utils';
import AddButton from '../../react-components/buttons/add-button';
import { setAdjustment } from '../reducers/adjustment';
import { setToastList } from '../reducers/toasts';
-const EditProductPage = ({}) => {
+const EditProductPage = ({ offlineService }) => {
const history = useHistory();
const location = useLocation();
const dispatch = useDispatch();
@@ -47,25 +47,35 @@
const toastList = useSelector(state => state.toasts.toasts);
const [quantityCurrentState, setQuantityCurrentState] = useState(null);
const [reasonCurrentState, setReasonCurrentState] = useState(null);
+ const [lotCodeCurrentState, setLotCodeCurrentState] = useState(null);
+ const menu = document.getElementsByClassName("header ng-scope")[0];
+
useEffect(() => {
+ menu.style.display = "none";
+ }, [menu]);
+
+ useEffect(() => {
setProductToEdit(location.state.productToEdit);
setIndexOfProductToEdit(location.state.indexOfProductToEdit);
setQuantityCurrentState(location.state.productToEdit.quantity);
setReasonCurrentState(location.state.productToEdit.reason.name);
+ setLotCodeCurrentState(location.state.productToEdit?.lot?.lotCode ?? null);
}, [location]);
const decorator = useMemo(() => createDecorator({
- field: /product/,
+ field: /product|lot/,
updates: {
stockOnHand: (productVal, itemsVal) => {
const orderable = itemsVal.items[0]?.product ?? [];
- if (itemsVal.items[0].hasOwnProperty('lot')) {
- let copiedItemData = Object.assign({}, itemsVal.items[0]);
- delete copiedItemData.lot;
- itemsVal = update(itemsVal.items, { [0] : {$set: copiedItemData} });
- }
- const lotCode = null;
+ const lotCode = itemsVal.items[0]?.lot?.lotCode ?? null;
+ if ( lotCode === null ) {
+ if (itemsVal.items[0].hasOwnProperty('lot')) {
+ let copiedItemData = Object.assign({}, itemsVal.items[0]);
+ delete copiedItemData.lot;
+ itemsVal.items = update(itemsVal.items, { [0] : {$set: copiedItemData} });
+ }
+ }
return getStockOnHand(orderable, lotCode);
}
}
@@ -134,7 +144,12 @@
const deleteProduct = () => {
const adjustmentLength = adjustment.length;
dispatch(setAdjustment(update(adjustment, { $splice: [[indexOfProductToEdit, 1]] } )));
- showToast('success');
+ if (offlineService.isOffline()) {
+ showToast('offline');
+ }
+ else{
+ showToast('success')
+ }
if (adjustmentLength > 1) {
history.goBack();
}
@@ -166,7 +181,8 @@
const onSubmit = (values) => {
values = updateAdjustmentList(values);
- if (values.quantity === quantityCurrentState && values.reason.name === reasonCurrentState) {
+ const lotCode = values?.lot?.lotCode ?? null;
+ if (values.quantity === quantityCurrentState && values.reason.name === reasonCurrentState && lotCode === lotCodeCurrentState) {
onSubmitWithoutChanges();
} else {
onSubmitWithChanges(values);
@@ -175,7 +191,12 @@
const onSubmitWithChanges = (values) => {
dispatch(setAdjustment(update(adjustment, { [indexOfProductToEdit] : {$set: values} })));
- showToast('success');
+ if (offlineService.isOffline()) {
+ showToast('offline');
+ }
+ else{
+ showToast('success')
+ }
history.push("/makeAdjustmentAddProducts/submitAdjustment");
};
@@ -198,11 +219,10 @@
return (
);
@@ -249,8 +269,8 @@