/* eslint-disable react/jsx-no-useless-fragment */
/* eslint-disable react/jsx-key */
/* eslint-disable react/destructuring-assignment */
/* eslint-disable compat/compat */
/* eslint-disable react/jsx-props-no-spreading */
import React, { useState } from 'react';
import {
  Grid,
  Paper,
  TextField,
  Button,
  FormControl,
  Switch,
  Autocomplete,
} from '@mui/material';
import { makeStyles } from '@mui/styles';
import Typography from '@mui/material/Typography';
import { observer } from 'mobx-react';
import { ipcRenderer } from 'electron';
import { useTranslation } from 'react-i18next';
import { useNavigate } from 'react-router-dom';
import NumberFormat from 'react-number-format';
import { getRootStore } from '../../../models/root-store';
import Log from '../../../models/Logs/Log';

const useStyles = makeStyles({
  dataGrid: {
    border: 0,
    color: 'white',
  },
  content: {
    alignItems: 'center',
  },
  root: {
    flexGrow: 1,
  },
  paper: {
    backgroundColor: '#95A5A6',
    textAlign: 'center',
  },
  paperInput: {
    backgroundColor: '#666666',
    alignItems: 'center',
    justifyContentItems: 'baseline',
    padding: 10,
    margin: 10,
    minHeight: 70,
  },
  paperInputNested: {
    backgroundColor: '#7d7d7d',
    alignItems: 'center',
    justifyContentItems: 'baseline',
    padding: 10,
    margin: 10,
    minHeight: 70,
  },
  button: {
    backgroundColor: '#3E3E3E',
    height: '90%',
    width: '90%',
    margin: 25,
    padding: 25,
    textAlign: 'center',
  },
  typo: {
    fontSize: 'auto',
  },
  paperTop: {
    alignItems: 'center',
    padding: 10,
    marginTop: 15,
    margin: 15,
  },
  input: {
    color: 'white',
    fontSize: '1.1em',
    padding: '5px',
    width: 'auto',
  },
  inputLabel: {
    color: 'black',
    fontSize: '20px',
  },
  inputNumbers: {
    color: 'white',
    fontSize: '1.2em',
    padding: '5px',
    width: 'auto',
  },
});

interface NumberFormatPriceProps {
  inputRef: (instance: NumberFormat | null) => void;
  onChange: (event: { target: { name: string; value: string } }) => void;
  name: string;
}

const safe = (v: any) => (v == null ? '' : String(v));

function logEmv(
  rootStore: any,
  name: string,
  reasonLines: Array<string | undefined>,
  user = 'Operator',
  type = 'Application',
  subType = 'EMV'
) {
  rootStore.logs.addLog(
    new Log({
      type,
      subType,
      name,
      reason: reasonLines.filter(Boolean).map(safe).join(' | '),
      user,
    })
  );
}

function NumberFormatPrice(props: NumberFormatPriceProps) {
  const { inputRef, onChange, ...other } = props;

  return (
    <NumberFormat
      {...other}
      getInputRef={inputRef}
      onValueChange={(values) => {
        onChange({
          target: {
            name: props.name,
            value: values.value,
          },
        });
      }}
      thousandSeparator
      fixedDecimalScale
      decimalScale={2}
      prefix="€"
    />
  );
}

const ExitUnitPayAdvanced = observer(() => {
  const classes = useStyles();
  const [rootStore] = useState(() => getRootStore());
  const [selectedSerialPort, setSelectedSerialPort] = React.useState(
    rootStore.settings.getSerialByPath(rootStore.settings.serialPortPath)
  );
  const [errorLogin, setErrorLogin] = useState(false);
  const [errorNoAccount, setErrorNoAccount] = useState(false);
  const [progressZones, setProgressZones] = useState(-1); // When not loaded yet it's -1, when starting to load it's 0
  const history = useNavigate();
  const { t } = useTranslation();

  const runFetchLoginLocal = async () => {
    if (typeof rootStore.acs01List?.defaultAcs01 === 'undefined') {
      return new Error();
    }
    const fetchData: any = await fetch(
      `http://${rootStore.acs01List?.defaultAcs01.localUrl}/apiv1/auth/login`,
      {
        method: 'POST',
        body: JSON.stringify({
          username: rootStore.acs01List?.defaultAcs01.username,
          password: rootStore.acs01List?.defaultAcs01.password,
        }),
      }
    )
      .then((response: any) => {
        if (response.status !== 200) {
          return new Error(response.status);
        }
        return response.json();
      })
      .then((json: any) => {
        console.log('local', json);
        return json;
      })
      .catch((error) => {
        console.log('non local');
        return error;
      });
    rootStore.acs01List.setLoginStatus(rootStore.acs01List.loginStatus + 1);

    return fetchData;
  };

  const runFetchGetPassageById = async () => {
    if (typeof rootStore.acs01List?.defaultAcs01 === 'undefined') {
      return new Error();
    }
    const fetchData: any = await fetch(
      `http://${rootStore.acs01List?.defaultAcs01.localUrl}/apiv1/passage/${rootStore.passageList?.defaultPassageId}`,
      {
        method: 'GET',
      }
    )
      .then((response: any) => {
        if (response.status !== 200) {
          return new Error(response.status);
        }
        return response.json();
      })
      .then((json: any) => {
        console.log('passage by id', json);
        return json;
      })
      .catch((error) => {
        console.log('passage by id');
        return error;
      });
    return fetchData;
  };

  const runFetchGetPrinterById = async () => {
    if (typeof rootStore.acs01List?.defaultAcs01 === 'undefined') {
      return new Error();
    }
    const fetchData: any = await fetch(
      `http://${rootStore.acs01List?.defaultAcs01.localUrl}/apiv1/printer/${rootStore.printerList?.defaultPrinterId}`,
      {
        method: 'GET',
      }
    )
      .then((response: any) => {
        if (response.status !== 200) {
          return new Error(response.status);
        }
        return response.json();
      })
      .then((json: any) => {
        console.log('passage by id', json);
        return json;
      })
      .catch((error) => {
        console.log('passage by id');
        return error;
      });
    return fetchData;
  };

  const runFetchGetAuxById = async () => {
    if (typeof rootStore.acs01List?.defaultAcs01 === 'undefined') {
      return new Error();
    }
    const fetchData: any = await fetch(
      `http://${rootStore.acs01List?.defaultAcs01.localUrl}/apiv1/io_connection/${rootStore.auxList?.defaultLoopId}`,
      {
        method: 'GET',
      }
    )
      .then((response: any) => {
        if (response.status !== 200) {
          return new Error(response.status);
        }
        return response.json();
      })
      .then((json: any) => {
        console.log('passage by id', json);
        return json;
      })
      .catch((error) => {
        console.log('passage by id');
        return error;
      });
    return fetchData;
  };

  const runFetchGetScenarioById = async () => {
    if (typeof rootStore.acs01List?.defaultAcs01 === 'undefined') {
      return new Error();
    }
    const fetchData: any = await fetch(
      `http://${rootStore.acs01List?.defaultAcs01.localUrl}/apiv1/scenario/${rootStore.scenarioList?.defaultScenarioId}`,
      {
        method: 'GET',
      }
    )
      .then((response: any) => {
        if (response.status !== 200) {
          return new Error(response.status);
        }
        return response.json();
      })
      .then((json: any) => {
        console.log('scenario by id', json);
        return json;
      })
      .catch((error) => {
        console.log('scenario by id');
        return error;
      });
    return fetchData;
  };

  const authenticate = async () => {
    if (typeof rootStore.acs01List.defaultAcs01 === 'undefined') {
      setErrorNoAccount(true);
      return new Error();
    }
    setErrorNoAccount(false);
    setErrorLogin(false);
    // Authenticate on the Acs01 locally
    const loginLocal = await ipcRenderer.invoke(
      'loginLocal',
      rootStore.acs01List?.defaultAcs01.localUrl
    );

    if (loginLocal?.role === 100) {
      rootStore.acs01List.setLocalStatus(1);
      if (
        typeof rootStore.passageList.defaultPassageId !== 'undefined' &&
        rootStore.passageList.defaultPassageId !== ''
      ) {
        setProgressZones(50);
        const getPassage = await ipcRenderer.invoke('passageById', [
          rootStore.acs01List?.defaultAcs01.localUrl,
          rootStore.passageList?.defaultPassageId,
        ]);
        if (getPassage) {
          rootStore.passageList.setDefault(getPassage);
          setProgressZones(100);
        } else setErrorLogin(true);
      }
      if (
        typeof rootStore.auxList.defaultLoopId !== 'undefined' &&
        typeof rootStore.auxList.defaultLoop !== 'undefined' &&
        rootStore.auxList.defaultLoopId !== ''
      ) {
        const getAux = await ipcRenderer.invoke('auxById', [
          rootStore.acs01List?.defaultAcs01.localUrl,
          rootStore.auxList?.defaultLoopId,
        ]);
        if (getAux) rootStore.auxList.setDefault(getAux);
        else setErrorLogin(true);
      }
      if (
        typeof rootStore.printerList.defaultPrinterId !== 'undefined' &&
        typeof rootStore.printerList.defaultPrinter !== 'undefined' &&
        rootStore.printerList.defaultPrinterId !== ''
      ) {
        const getPrinter = await ipcRenderer.invoke('printerById', [
          rootStore.acs01List?.defaultAcs01.localUrl,
          rootStore.printerList?.defaultPrinterId,
        ]);
        if (getPrinter) rootStore.printerList.setDefaultPrinter(getPrinter);
        else setErrorLogin(true);
      }
      if (
        typeof rootStore.scenarioList.defaultScenarioId !== 'undefined' &&
        typeof rootStore.scenarioList.defaultScenario !== 'undefined' &&
        rootStore.scenarioList.defaultScenarioConfigured
      ) {
        const getScenario = await ipcRenderer.invoke('scenarioById', [
          rootStore.acs01List?.defaultAcs01.localUrl,
          rootStore.scenarioList?.defaultScenarioId,
        ]);
        if (getScenario) rootStore.scenarioList.setDefaultScenario(getScenario);
        else setErrorLogin(true);
      }
      return 'OK';
    }
    rootStore.acs01List.setLocalStatus(0);
    setErrorLogin(true);
    return new Error();
  };

  const handleChangeLostTicket = (event: any, newValue: any) => {
    if (newValue !== null) {
      rootStore.settings.setLostTicket(newValue.id);
    }
  };

  const handleChangeSerialPort = (event: any, newValue: any) => {
    if (newValue !== null && newValue !== 'No ports detected') {
      setSelectedSerialPort(newValue.path);
      ipcRenderer.send('setSerialPath', newValue.path);
      rootStore.settings.setSerialPortPath(newValue.path);
    }
  };

  const handleRestart = (event: any) => {
    ipcRenderer.send('restart', 'tst');
  };

  const [emvDLStatus, setEmvDLStatus] = useState<string | null>(null);
const [emvBusy, setEmvBusy] = useState(false);

const handleEmvParamDownload = async () => {
  setEmvBusy(true);
  setEmvDLStatus('Starting…');
  try {
    const { ipEMV, merchantId, operatorId, tranDeviceId } = rootStore.settings;
    if (!ipEMV || !merchantId || !operatorId || !tranDeviceId) {
      setEmvDLStatus('Missing EMV settings (IP/Merchant/Operator/TranDevice).');
      return;
    }

    const resp = await ipcRenderer.invoke('datacap-emvParamDownload', {
      merchantId,
      operatorId,
      tranDeviceId,
      ipEmv: ipEMV,
    });

    if (resp === 'ERROR') {
      setEmvDLStatus('Download failed (see logs).');
      logEmv(rootStore, 'EMVParamDownload failed', ['IPC ERROR']);
      return;
    }

    const r = resp?.RStream ?? {};
    const status = r?.CmdStatus ?? 'Unknown';
    const code = r?.DSIXReturnCode ?? '—';
    const msg  = r?.TextResponse ?? '';
    setEmvDLStatus(`Param download: ${status} (${code})`);

    logEmv(rootStore, 
      status === 'Success' ? 'EMVParamDownload success' : 'EMVParamDownload error',
      [
        `CmdStatus: ${status}`,
        `DSIXReturnCode: ${code}`,
        `TextResponse: ${msg}`,
        `TranCode: ${r?.TranCode ?? 'EMVParamDownload'}`,
        `SequenceNo: ${r?.SequenceNo ?? ''}`,
      ]
    );
  } catch (e) {
    console.error('EMVParamDownload click error:', e);
    setEmvDLStatus('Unexpected error (see console).');
    logEmv(rootStore, 'EMVParamDownload exception', [String(e)]);
  } finally {
    setEmvBusy(false);
  }
};


const [batchStatus, setBatchStatus] = useState<string | null>(null);
const [batchBusy, setBatchBusy] = useState(false);

const handleBatchSummaryAndClose = async () => {
  setBatchBusy(true);
  setBatchStatus('Fetching Batch Summary…');

  try {
    const { ipEMV, merchantId, operatorId, tranDeviceId, terminalId } = rootStore.settings;
    if (!ipEMV || !merchantId || !operatorId || !tranDeviceId) {
      setBatchStatus('Missing settings (IP/Merchant/Operator/TranDevice).');
      return;
    }

    // one IPC that does summary -> close
    const resp = await ipcRenderer.invoke('datacap-batchSummaryAndClose', {
      merchantId, operatorId, tranDeviceId, ipEmv: ipEMV, terminalId,
    });

    if (!resp || resp === 'ERROR') {
      setBatchStatus('Batch close failed (transport).');
      rootStore.logs.addLog(new Log({
        type: 'Batch',
        subType: 'Manual',
        name: 'Batch close transport error',
        reason: 'IPC returned ERROR',
        user: 'Operator',
      }));
      return;
    }

    // log summary stage
    const sum = resp?.summary ?? {};
    const sumR = resp?.summaryResp?.RStream ?? {};
    rootStore.logs.addLog(new Log({
      type: 'BatchSummary',
      subType: 'Manual',
      name: resp.stage === 'summary' && resp.error ? 'Batch summary failed' : 'Batch summary fetched',
      reason: [
        `CmdStatus: ${sumR?.CmdStatus ?? ''}`,
        `DSIXReturnCode: ${sumR?.DSIXReturnCode ?? ''}`,
        `TextResponse: ${sumR?.TextResponse ?? ''}`,
        `TerminalID: ${sum.TerminalID ?? sumR.TerminalID ?? ''}`,
        `BatchNo: ${sum.BatchNo ?? sumR.BatchNo ?? ''}`,
        `BatchItemCount: ${sum.BatchItemCount ?? sumR.BatchItemCount ?? ''}`,
        `NetBatchTotal: ${sum.NetBatchTotal ?? sumR.NetBatchTotal ?? ''}`,
      ].join(' | '),
      user: 'Operator',
    }));

    if (resp.stage === 'summary' && resp.error) {
      setBatchStatus(`BatchSummary failed: ${resp.DSIXReturnCode ?? '—'} ${resp.TextResponse ?? ''}`);
      return;
    }

    const closeR = resp?.closeResp?.RStream ?? {};
    const ok = resp.ok === true;
    const batchNo = resp?.BatchNo ?? sum.BatchNo ?? closeR.BatchNo ?? '';

    rootStore.logs.addLog(new Log({
      type: 'BatchClose',
      subType: 'Manual',
      name: ok ? 'Batch closed successfully' : 'Batch close failed',
      reason: [
        `BatchNo: ${batchNo}`,
        `NetBatchTotal: ${sum.NetBatchTotal ?? closeR.NetBatchTotal ?? ''}`,
        `BatchItemCount: ${sum.BatchItemCount ?? closeR.BatchItemCount ?? ''}`,
        `CmdStatus: ${closeR.CmdStatus ?? ''}`,
        `Code: ${resp?.DSIXReturnCode ?? closeR.DSIXReturnCode ?? ''}`,
        `Msg: ${resp?.TextResponse ?? closeR.TextResponse ?? ''}`,
      ].join(' | '),
      user: 'Operator',
    }));

    // UI status
      const code = resp.DSIXReturnCode ?? '—';
      const msg  = resp.TextResponse ?? '';
      setBatchStatus(
        ok
          ? `Batch closed OK${batchNo ? ` (Batch ${batchNo})` : ''}`
          : `Batch close failed: ${code} ${msg}`
      );

      // Catch block
      } catch (e) {
        console.error('BatchSummaryAndClose error:', e);
        setBatchStatus('Unexpected error (see console).');

    rootStore.logs.addLog(new Log({
      type: 'Batch',
      subType: 'Manual',
      name: 'Batch close error',
      reason: String(e),
      user: 'Operator',
    }));
  } finally {
    setBatchBusy(false);
  }
};

  return (
    <>
      {rootStore.acs01List.defaultAcs01 &&
      rootStore.acs01List.defaultAcs01?.localName !== '' ? (
        <Grid container justifyContent="center" alignItems="center" spacing={0}>
          <Grid item xs={12} md={12} lg={12} xl={12}>
            <Paper
              elevation={3}
              className={classes.paperTop}
              style={{ background: `${rootStore.settings.backgroundColor}` }}
            >
              <Paper className={classes.paperInput}>
  <Grid item xs={12}>
    <Typography className={classes.content} variant="h6" component="span">
      Use scanner connected to display
    </Typography>
    <Switch
      checked={rootStore.terminal.scannerConnectedToDisplay}
      onChange={async () => {
        rootStore.terminal.setScannerConnectedToDisplay(
          !rootStore.terminal.scannerConnectedToDisplay
        );
      }}
      inputProps={{ 'aria-label': 'controlled' }}
    />
  </Grid>

  {rootStore.terminal.scannerConnectedToDisplay && (
    <>
      <br />
      {rootStore.settings.serialPortList.length === 0 ? (
        <Typography className={classes.content} variant="body1">
          No serial port detected.
        </Typography>
      ) : (
        <>
          <Autocomplete
            id="serialPort"
            value={rootStore.settings.getSerialByPath(
              rootStore.settings.serialPortPath
            )}
            options={rootStore.settings.serialPortList}
            getOptionLabel={(option) => option.path}
            onChange={handleChangeSerialPort}
            disableClearable
            selectOnFocus
            clearOnBlur
            renderInput={(params) => (
              <TextField
                {...params}
                label="Serial port scanner"
                variant="outlined"
              />
            )}
          />
          <br />
        </>
      )}

      {selectedSerialPort !==
        rootStore.settings.getSerialByPath(
          rootStore.settings.serialPortPath
        ) ? (
        <>
          <Typography className={classes.content} variant="body1">
            Please reboot application in order for the changes to apply.
          </Typography>
          <Button variant="contained" color="primary" onClick={handleRestart}>
            Restart
          </Button>
        </>
      ) : null}
    </>
  )}
</Paper>
             
              <FormControl fullWidth variant="outlined">
                <TextField
                  variant="outlined"
                  label= "lost ticket price"
                  value={rootStore.terminal.lostTicketPrice}
                  onChange={(ev) => {
                    rootStore.terminal.setLostTicketPrice(
                      ev.target.value || '0.00'
                    );
                  }}
                  InputProps={{
                    className: classes.inputNumbers,
                  }}
                  InputLabelProps={{
                    className: classes.inputLabel,
                  }}
                />
              </FormControl>
              <br />
              <br />
 
              <Paper className={classes.paperInput}>
                <Grid item xs={12}>
                  <Typography
                    className={classes.content}
                    variant="h6"
                    component="span"
                  >
                    Manual pay mode
                  </Typography>
                  <Switch
                    checked={rootStore.ui.manualPayOption}
                    onChange={() => {
                      rootStore.ui.setManualPayOption(
                        !rootStore.ui.manualPayOption
                      );
                    }}
                    inputProps={{ 'aria-label': 'controlled' }}
                  />
                </Grid>
              </Paper>
              {!rootStore.ui.manualPayOption && rootStore.settings.applicationMode === 5 ? (
                      <Paper className={classes.paperInputNested}>
                        
                        <TextField
                          id="filled-name"
                    label="Ip-EMV"
                    fullWidth
                    value={rootStore.settings.ipEMV}
                    onChange={(e) =>
                      rootStore.settings.setIpEMV(e.target.value)
                    }
                    variant="outlined"
                  />
                  <br />
                  <br />
                  <Grid item xs={12}>
                    <Typography
                      className={classes.content}
                      variant="h6"
                      component="span"
                    >
                      Use datacap EMV
                    </Typography>
                    <Switch
                      checked={rootStore.settings.emvDatacap}
                      onChange={async () => {
                        rootStore.settings.setEmvDatacap(
                          !rootStore.settings.emvDatacap
                        );
                      }}
                      inputProps={{ 'aria-label': 'controlled' }}
                    />
                  </Grid>
                  <br />
                  <br />
                  {rootStore.settings.emvDatacap ? (
                <>
                  <TextField
                    id="Merchant"
                    label="Merchant ID"
                    fullWidth
                    value={rootStore.settings.merchantId}
                    onChange={(e) => rootStore.settings.setMerchantId(e.target.value)}
                    variant="outlined"
                  />
                  <br /><br />

                  <TextField
                    id="Operator"
                    label="Operator ID"
                    fullWidth
                    value={rootStore.settings.operatorId}
                    onChange={(e) => rootStore.settings.setOperatorId(e.target.value)}
                    variant="outlined"
                  />
                  <br /><br />

                  <TextField
                    id="TranDevice"
                    label="TranDevice ID"
                    fullWidth
                    value={rootStore.settings.tranDeviceId}
                    onChange={(e) => rootStore.settings.setTranDeviceId(e.target.value)}
                    variant="outlined"
                  />
                  <br /><br />

                  <TextField
                    id="Tax percentage"
                    label="Tax percentage"
                    fullWidth
                    value={rootStore.ui.btw}
                    onChange={(e) => rootStore.ui.setBtw(parseInt(e.target.value, 10) || 0)}
                    variant="outlined"
                  />
                  <br /><br />
                 

                  <Grid container spacing={2}>
                    <Grid item>
                      <Button
                        variant="contained"
                        color="primary"
                        disabled={emvBusy}
                        onClick={handleEmvParamDownload}
                      >
                        {emvBusy ? 'Downloading…' : 'Download EMV Params'}
                      </Button>
                    </Grid>
                  </Grid>

                  {emvDLStatus ? (
                    <>
                      <br />
                      <Typography variant="body2">{emvDLStatus}</Typography>
                      <br /><br />
                    </>
                  ) : null}
                    <br /><br />                     
                    <Grid container spacing={2}>
                      <Grid item>
                        <Button
                          variant="contained"
                          color="secondary"
                          disabled={batchBusy}
                          onClick={handleBatchSummaryAndClose}
                        >
                          {batchBusy ? 'Processing…' : 'Batch Summary + Close'}
                        </Button>
                      </Grid>
                    </Grid>

                    {batchStatus && (
                      <>
                        <br />
                        <Typography variant="body2">{batchStatus}</Typography>
                      </>
                    )}
                    <br /><br />
                </>
              ) : null}
                  {rootStore.ticketList.all.length !== 0 ? (
                    <>
                      <Autocomplete
                        id="lostTicket"
                        value={rootStore.ticketList.getTicketById(
                          rootStore.settings.lostTicketId
                        )}
                        options={rootStore.ticketList.all}
                        getOptionLabel={(option) => option.title}
                        onChange={handleChangeLostTicket}
                        disableClearable
                        selectOnFocus
                        clearOnBlur
                        renderInput={(params) => (
                          <TextField
                            {...params}
                            label="Lost ticket"
                            variant="outlined"
                          />
                        )}
                      />
                      <br />
                      <br />
                    </>
                  ) : null}
                  
                  <br />
                  <br />
                  <FormControl fullWidth variant="outlined">
                    <TextField
                      variant="outlined"
                      label="Proof of payment itemText"
                      value={rootStore.ui.itemText}
                      onChange={(ev) => {
                        rootStore.ui.setItemText(ev.target.value || "" );
                      }}
                      InputLabelProps={{
                        className: classes.inputLabel,
                      }}
                    />
                  </FormControl>
                  <br />
                  <br />
                  <FormControl fullWidth variant="outlined">
                    <TextField
                      variant="outlined"
                      label="Proof of payment method"
                      value={rootStore.ui.method}
                      onChange={(ev) => {
                        rootStore.ui.setMethod(ev.target.value || "");
                      }}
                      InputLabelProps={{
                        className: classes.inputLabel,
                      }}
                    />
                  </FormControl>
                  <br />
                  <br />
                  <FormControl fullWidth variant="outlined">
                    <TextField
                      variant="outlined"
                      label="Proof of payment goodby"
                      value={rootStore.ui.goodBy}
                      onChange={(ev) => {
                        rootStore.ui.setGoodBy(ev.target.value || "" );
                      }}
                      InputLabelProps={{
                        className: classes.inputLabel,
                      }}
                    />
                  </FormControl>
                  <br />
                  <br />
                </Paper>
              ) : null}
              
            </Paper>
          </Grid>
        </Grid>
      ) : null}
    </>
  );
});

export default ExitUnitPayAdvanced;
