Compare commits
No commits in common. "8a0fd7699bd02b6f47a5a237de3ca782c2028076" and "94fcbe9b398f4cef4224a6d6856684f29d0f8b41" have entirely different histories.
8a0fd7699b
...
94fcbe9b39
|
|
@ -1,5 +0,0 @@
|
||||||
{
|
|
||||||
"recommendations": [
|
|
||||||
"cweijan.dbclient-jdbc"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -2,17 +2,17 @@ import { TypeOrmModuleOptions } from '@nestjs/typeorm';
|
||||||
import { ConnectionOptions } from 'typeorm';
|
import { ConnectionOptions } from 'typeorm';
|
||||||
|
|
||||||
export const typeOrmConfig: TypeOrmModuleOptions = {
|
export const typeOrmConfig: TypeOrmModuleOptions = {
|
||||||
type: 'oracle',
|
type: "oracle",
|
||||||
// host: "192.168.100.40",
|
// host: "192.168.100.40",
|
||||||
// username: "LIVIA",
|
// username: "LIVIA",
|
||||||
// password: "LIVIA",
|
// password: "LIVIA",
|
||||||
host: '10.1.1.241',
|
host: "10.1.1.241",
|
||||||
username: 'SEVEN',
|
username: "SEVEN",
|
||||||
password: 'USR54SEV',
|
password: "USR54SEV",
|
||||||
// username: "API",
|
// username: "API",
|
||||||
// password: "E05H5KIEQV3YKDJR",
|
// password: "E05H5KIEQV3YKDJR",
|
||||||
port: 1521,
|
port: 1521,
|
||||||
serviceName: 'WINT',
|
sid: "WINT",
|
||||||
synchronize: false,
|
synchronize: false,
|
||||||
logging: false,
|
logging: false,
|
||||||
entities: [__dirname + '/../**/*.entity.{js,ts}'],
|
entities: [__dirname + '/../**/*.entity.{js,ts}'],
|
||||||
|
|
@ -20,13 +20,14 @@ export const typeOrmConfig: TypeOrmModuleOptions = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const connectionOptions: ConnectionOptions = {
|
export const connectionOptions: ConnectionOptions = {
|
||||||
type: 'oracle',
|
type: "oracle",
|
||||||
host: '10.1.1.241',
|
host: "10.1.1.241",
|
||||||
username: 'SEVEN',
|
username: "SEVEN",
|
||||||
password: 'USR54SEV',
|
password: "USR54SEV",
|
||||||
port: 1521,
|
port: 1521,
|
||||||
serviceName: 'WINT',
|
sid: "WINT",
|
||||||
synchronize: false,
|
synchronize: false,
|
||||||
logging: false,
|
logging: false,
|
||||||
entities: [__dirname + '/../**/*.entity.{js,ts}'],
|
entities: [__dirname + '/../**/*.entity.{js,ts}'],
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,4 @@ export class Shopping {
|
||||||
@Column({ name: 'CODTABELAFRETE' })
|
@Column({ name: 'CODTABELAFRETE' })
|
||||||
codtabelafrete: number;
|
codtabelafrete: number;
|
||||||
|
|
||||||
@Column({ name: 'CODPRACA' })
|
|
||||||
codpraca: number;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,24 +0,0 @@
|
||||||
export class CartUpdate {
|
|
||||||
constructor(
|
|
||||||
public id: string,
|
|
||||||
public idCustomer: number,
|
|
||||||
public idAddress: number,
|
|
||||||
public saleStore: string,
|
|
||||||
public userId: number,
|
|
||||||
public idSeller: number,
|
|
||||||
public idProfessional: number,
|
|
||||||
public idPaymentPlan: number,
|
|
||||||
public idBilling: string,
|
|
||||||
public shippingValue: number,
|
|
||||||
public scheduleDelivery: boolean,
|
|
||||||
public shippingDate: Date,
|
|
||||||
public shippingPriority: string,
|
|
||||||
public idStorePlace: number,
|
|
||||||
public notation1: string,
|
|
||||||
public notation2: string,
|
|
||||||
public deliveryNote1: string,
|
|
||||||
public deliveryNote2: string,
|
|
||||||
public deliveryNote3: string,
|
|
||||||
public carrierId: number,
|
|
||||||
) { }
|
|
||||||
}
|
|
||||||
|
|
@ -1,22 +1,14 @@
|
||||||
import {
|
import { Body, Controller, Get, HttpException, HttpStatus, Param, Post, Query } from '@nestjs/common';
|
||||||
Body,
|
import { CustomerService } from './customer.service';
|
||||||
Controller,
|
import { ResultModel } from '../../domain/models/result.model';
|
||||||
Get,
|
|
||||||
HttpException,
|
|
||||||
HttpStatus,
|
|
||||||
Param,
|
|
||||||
Post,
|
|
||||||
Query,
|
|
||||||
} from '@nestjs/common';
|
|
||||||
import { ApiTags } from '@nestjs/swagger';
|
|
||||||
import { error } from 'console';
|
import { error } from 'console';
|
||||||
import { Customer } from 'src/domain/models/customer.model';
|
import { Customer } from 'src/domain/models/customer.model';
|
||||||
import { ResultModel } from '../../domain/models/result.model';
|
import { ApiTags } from '@nestjs/swagger';
|
||||||
import { CustomerService } from './customer.service';
|
|
||||||
|
|
||||||
@ApiTags('Customer')
|
@ApiTags('Customer')
|
||||||
@Controller('api/v1/customer')
|
@Controller('api/v1/customer')
|
||||||
export class CustomerController {
|
export class CustomerController {
|
||||||
|
|
||||||
constructor(private readonly customerService: CustomerService){}
|
constructor(private readonly customerService: CustomerService){}
|
||||||
|
|
||||||
@Get(':name')
|
@Get(':name')
|
||||||
|
|
@ -25,15 +17,8 @@ export class CustomerController {
|
||||||
const customers = await this.customerService.findCustomerByName(name);
|
const customers = await this.customerService.findCustomerByName(name);
|
||||||
return new ResultModel(true, null, customers, null);
|
return new ResultModel(true, null, customers, null);
|
||||||
} catch(err){
|
} catch(err){
|
||||||
throw new HttpException(
|
throw new HttpException(new ResultModel(false, 'Não foi possível consultar o cadastro de clientes.', {}, error),
|
||||||
new ResultModel(
|
HttpStatus.INTERNAL_SERVER_ERROR);
|
||||||
false,
|
|
||||||
'Não foi possível consultar o cadastro de clientes.',
|
|
||||||
{},
|
|
||||||
error,
|
|
||||||
),
|
|
||||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -43,10 +28,8 @@ export class CustomerController {
|
||||||
const categories = await this.customerService.getCategory();
|
const categories = await this.customerService.getCategory();
|
||||||
return categories;
|
return categories;
|
||||||
} catch(err){
|
} catch(err){
|
||||||
throw new HttpException(
|
throw new HttpException(new ResultModel(false, err.message, {}, error),
|
||||||
new ResultModel(false, err.message, {}, error),
|
HttpStatus.INTERNAL_SERVER_ERROR);
|
||||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -56,29 +39,23 @@ export class CustomerController {
|
||||||
const subCategories = await this.customerService.getSubCategory();
|
const subCategories = await this.customerService.getSubCategory();
|
||||||
return subCategories;
|
return subCategories;
|
||||||
} catch(err){
|
} catch(err){
|
||||||
throw new HttpException(
|
throw new HttpException(new ResultModel(false, err.message, {}, error),
|
||||||
new ResultModel(false, err.message, {}, error),
|
HttpStatus.INTERNAL_SERVER_ERROR);
|
||||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
async getCustomer(@Query() query){
|
async getCustomer(@Query() query){
|
||||||
try{
|
try{
|
||||||
const field = query['field'];
|
const field = query['field'];
|
||||||
const textSearch = query['textsearch'];
|
const textSearch = query['textsearch'];
|
||||||
const customers = await this.customerService.findCustomerByQuery(
|
const customers = await this.customerService.findCustomerByQuery(field, textSearch);
|
||||||
field,
|
|
||||||
textSearch,
|
|
||||||
);
|
|
||||||
return new ResultModel(true, null, customers, null);
|
return new ResultModel(true, null, customers, null);
|
||||||
} catch(err){
|
} catch(err){
|
||||||
// 'Não foi possível consultar o cadastro de clientes.'
|
// 'Não foi possível consultar o cadastro de clientes.'
|
||||||
throw new HttpException(
|
throw new HttpException(new ResultModel(false, err.message, {}, error),
|
||||||
new ResultModel(false, err.message, {}, error),
|
HttpStatus.INTERNAL_SERVER_ERROR);
|
||||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -88,36 +65,21 @@ export class CustomerController {
|
||||||
const customers = await this.customerService.findCustomerById(id);
|
const customers = await this.customerService.findCustomerById(id);
|
||||||
return new ResultModel(true, null, customers, null);
|
return new ResultModel(true, null, customers, null);
|
||||||
} catch(err){
|
} catch(err){
|
||||||
throw new HttpException(
|
throw new HttpException(new ResultModel(false, 'Não foi possível consultar o cadastro de clientes.', {}, error),
|
||||||
new ResultModel(
|
HttpStatus.INTERNAL_SERVER_ERROR);
|
||||||
false,
|
|
||||||
'Não foi possível consultar o cadastro de clientes.',
|
|
||||||
{},
|
|
||||||
error,
|
|
||||||
),
|
|
||||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get('cpf/:cpf')
|
@Get('cpf/:cpf')
|
||||||
async getCustomerByCpf(@Param('cpf') cpf: string){
|
async getCustomerByCpf(@Param('cpf') cpf: string){
|
||||||
try{
|
try{
|
||||||
console.log('pesquisando por cpf');
|
console.log("pesquisando por cpf");
|
||||||
const customer = await this.customerService.findCustomerByCpf(cpf);
|
const customer = await this.customerService.findCustomerByCpf(cpf);
|
||||||
if (!customer)
|
if (!customer) return new ResultModel(false, 'Cliente não cadastrado', null, null);
|
||||||
return new ResultModel(false, 'Cliente não cadastrado', null, null);
|
|
||||||
return new ResultModel(true, null, customer, null);
|
return new ResultModel(true, null, customer, null);
|
||||||
} catch(err){
|
} catch(err){
|
||||||
throw new HttpException(
|
throw new HttpException(new ResultModel(false, 'Não foi possível consultar o cadastro de clientes.', {}, error),
|
||||||
new ResultModel(
|
HttpStatus.INTERNAL_SERVER_ERROR);
|
||||||
false,
|
|
||||||
'Não foi possível consultar o cadastro de clientes.',
|
|
||||||
{},
|
|
||||||
error,
|
|
||||||
),
|
|
||||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@Get('create/proxnumcli')
|
@Get('create/proxnumcli')
|
||||||
|
|
@ -131,6 +93,7 @@ export class CustomerController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Post('create')
|
@Post('create')
|
||||||
async createCustomer(@Body() customer: Customer){
|
async createCustomer(@Body() customer: Customer){
|
||||||
try{
|
try{
|
||||||
|
|
@ -139,10 +102,8 @@ export class CustomerController {
|
||||||
return new ResultModel(true, null, result, null);
|
return new ResultModel(true, null, result, null);
|
||||||
//return new ResultModel(true, null, id, null);
|
//return new ResultModel(true, null, id, null);
|
||||||
} catch(err){
|
} catch(err){
|
||||||
throw new HttpException(
|
throw new HttpException(new ResultModel(false, 'Erro ao cadastrar cliente.', {}, err),
|
||||||
new ResultModel(false, 'Erro ao cadastrar cliente.', {}, err),
|
HttpStatus.INTERNAL_SERVER_ERROR);
|
||||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,26 +1,28 @@
|
||||||
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
|
import { HttpStatus } from '@nestjs/common';
|
||||||
import { Connection } from 'typeorm';
|
import { Injectable, HttpException } from '@nestjs/common';
|
||||||
import { connectionOptions } from '../../configs/typeorm.config';
|
import { connectionOptions } from '../../configs/typeorm.config';
|
||||||
import { Customer } from '../../domain/models/customer.model';
|
import { Customer } from '../../domain/models/customer.model';
|
||||||
|
import { Connection } from 'typeorm';
|
||||||
//import { DataSource } from 'typeorm';
|
//import { DataSource } from 'typeorm';
|
||||||
|
import { EntityManager } from 'typeorm';
|
||||||
|
import { Pcclient } from '../../domain/entity/tables/pcclient.entity';
|
||||||
import { Estcategoriacliente } from '../../domain/entity/tables/estcategoriacliente.entity';
|
import { Estcategoriacliente } from '../../domain/entity/tables/estcategoriacliente.entity';
|
||||||
import { Estsubcategoriacliente } from '../../domain/entity/tables/estsubcategoriacliente.entity';
|
import { Estsubcategoriacliente } from '../../domain/entity/tables/estsubcategoriacliente.entity';
|
||||||
import { Pcclient } from '../../domain/entity/tables/pcclient.entity';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class CustomerService {
|
export class CustomerService {
|
||||||
|
|
||||||
async findCustomerByName(name: string) {
|
async findCustomerByName(name: string) {
|
||||||
let auxName = '';
|
let auxName = '';
|
||||||
for (let i = 0; i < name.length; i++) {
|
for (let i = 0; i < name.length; i++) {
|
||||||
auxName += name[i].replace('@', '%');
|
auxName += name[i].replace("@", "%");
|
||||||
}
|
}
|
||||||
const connection = new Connection(connectionOptions);
|
const connection = new Connection(connectionOptions);
|
||||||
await connection.connect();
|
await connection.connect();
|
||||||
const queryRunner = connection.createQueryRunner();
|
const queryRunner = connection.createQueryRunner();
|
||||||
await queryRunner.connect();
|
await queryRunner.connect();
|
||||||
try {
|
try {
|
||||||
const sql =
|
const sql = ' SELECT pcclient.cliente as "name" ' +
|
||||||
' SELECT pcclient.cliente as "name" ' +
|
|
||||||
' ,pcclient.codcli as "customerId" ' +
|
' ,pcclient.codcli as "customerId" ' +
|
||||||
' ,pcclient.emailnfe as "email" ' +
|
' ,pcclient.emailnfe as "email" ' +
|
||||||
' ,pcclient.cgcent as "cpfCnpj" ' +
|
' ,pcclient.cgcent as "cpfCnpj" ' +
|
||||||
|
|
@ -50,22 +52,17 @@ export class CustomerService {
|
||||||
' ,pcclient.tipoendereco as "addressType" ' +
|
' ,pcclient.tipoendereco as "addressType" ' +
|
||||||
' FROM pcclient, pccidade ' +
|
' FROM pcclient, pccidade ' +
|
||||||
' WHERE pcclient.codcidade = pccidade.codcidade (+)';
|
' WHERE pcclient.codcidade = pccidade.codcidade (+)';
|
||||||
let where =
|
let where = ` AND ( pcclient.cliente like '%'||'${auxName.replace('@', '%')}'||'%' OR ` +
|
||||||
` AND ( pcclient.cliente like '%'||'${auxName.replace(
|
|
||||||
'@',
|
|
||||||
'%',
|
|
||||||
)}'||'%' OR ` +
|
|
||||||
` REGEXP_REPLACE(pcclient.cgcent, '[^0-9]', '') = REGEXP_REPLACE('${name}', '[^0-9]') OR ` +
|
` REGEXP_REPLACE(pcclient.cgcent, '[^0-9]', '') = REGEXP_REPLACE('${name}', '[^0-9]') OR ` +
|
||||||
` pcclient.codcli = REGEXP_REPLACE('${name}', '[^0-9]') )`;
|
` pcclient.codcli = REGEXP_REPLACE('${name}', '[^0-9]') )`;
|
||||||
where += ` AND pcclient.codcli NOT IN (2) AND pcclient.DTEXCLUSAO IS NULL `;
|
where += ` AND pcclient.codcli NOT IN (2) AND pcclient.DTEXCLUSAO IS NULL `;
|
||||||
const orderBy = ` ORDER BY pcclient.cliente `;
|
const orderBy = ` ORDER BY pcclient.cliente `;
|
||||||
const pagination = ` OFFSET 0 ROWS FETCH NEXT 100 ROWS ONLY`;
|
const pagination = ` OFFSET 0 ROWS FETCH NEXT 100 ROWS ONLY`;
|
||||||
const customers = (await queryRunner.manager.query(
|
const customers = await queryRunner.manager
|
||||||
sql + where + orderBy + pagination,
|
.query(sql + where + orderBy + pagination) as Customer[];
|
||||||
)) as Customer[];
|
let customerList: Customer[] = [];
|
||||||
const customerList: Customer[] = [];
|
|
||||||
for (let i = 0; i < customers.length; i++) {
|
for (let i = 0; i < customers.length; i++) {
|
||||||
const customer = customers[i];
|
let customer = customers[i];
|
||||||
const place = await queryRunner.query(`SELECT PCPRACA.CODPRACA as "placeId"
|
const place = await queryRunner.query(`SELECT PCPRACA.CODPRACA as "placeId"
|
||||||
,PCPRACA.PRACA as "name"
|
,PCPRACA.PRACA as "name"
|
||||||
FROM PCPRACA
|
FROM PCPRACA
|
||||||
|
|
@ -90,8 +87,7 @@ export class CustomerService {
|
||||||
const queryRunner = connection.createQueryRunner();
|
const queryRunner = connection.createQueryRunner();
|
||||||
await queryRunner.connect();
|
await queryRunner.connect();
|
||||||
try {
|
try {
|
||||||
const sql =
|
const sql = ' SELECT pcclient.cliente as "name" ' +
|
||||||
' SELECT pcclient.cliente as "name" ' +
|
|
||||||
' ,pcclient.codcli as "customerId" ' +
|
' ,pcclient.codcli as "customerId" ' +
|
||||||
' ,pcclient.emailnfe as "email" ' +
|
' ,pcclient.emailnfe as "email" ' +
|
||||||
' ,pcclient.cgcent as "cpfCnpj" ' +
|
' ,pcclient.cgcent as "cpfCnpj" ' +
|
||||||
|
|
@ -119,12 +115,11 @@ export class CustomerService {
|
||||||
' ,pcclient.codmunicipio as "ibgeCode" ' +
|
' ,pcclient.codmunicipio as "ibgeCode" ' +
|
||||||
' ,pcclient.codcidade as "cityId" ' +
|
' ,pcclient.codcidade as "cityId" ' +
|
||||||
' ,pcclient.tipoendereco as "addressType" ' +
|
' ,pcclient.tipoendereco as "addressType" ' +
|
||||||
' ,DECODE(pcclient.dtexclusao, NULL, 1, 0) as "deletedCustomer" ' +
|
|
||||||
' FROM pcclient, pccidade ' +
|
' FROM pcclient, pccidade ' +
|
||||||
' WHERE pcclient.codcidade = pccidade.codcidade (+)';
|
' WHERE pcclient.codcidade = pccidade.codcidade (+)';
|
||||||
const where = ` AND REGEXP_REPLACE(pcclient.cgcent, '[^0-9]', '') =REGEXP_REPLACE('${cpf}', '[^0-9]', '')`;
|
const where = ` AND REGEXP_REPLACE(pcclient.cgcent, '[^0-9]', '') =REGEXP_REPLACE('${cpf}', '[^0-9]', '')`;
|
||||||
const customer = await queryRunner.query(sql + where);
|
const customer = await queryRunner.query(sql + where);
|
||||||
return customer as Customer[];
|
return customer[0];
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
throw error;
|
throw error;
|
||||||
|
|
@ -140,8 +135,8 @@ export class CustomerService {
|
||||||
const queryRunner = connection.createQueryRunner();
|
const queryRunner = connection.createQueryRunner();
|
||||||
await queryRunner.connect();
|
await queryRunner.connect();
|
||||||
try {
|
try {
|
||||||
const sql =
|
|
||||||
' SELECT pcclient.cliente as "name" ' +
|
const sql = ' SELECT pcclient.cliente as "name" ' +
|
||||||
' ,pcclient.codcli as "customerId" ' +
|
' ,pcclient.codcli as "customerId" ' +
|
||||||
' ,pcclient.emailnfe as "email" ' +
|
' ,pcclient.emailnfe as "email" ' +
|
||||||
' ,pcclient.cgcent as "cpfCnpj" ' +
|
' ,pcclient.cgcent as "cpfCnpj" ' +
|
||||||
|
|
@ -189,37 +184,25 @@ export class CustomerService {
|
||||||
}
|
}
|
||||||
|
|
||||||
async findCustomerByQuery(field: string, textSearch: string) {
|
async findCustomerByQuery(field: string, textSearch: string) {
|
||||||
let where = '';
|
let where = "";
|
||||||
switch (field) {
|
switch (field) {
|
||||||
case 'name':
|
case "name":
|
||||||
where += '"pcclient".cliente like \'' + textSearch + "%'";
|
where += "\"pcclient\".cliente like '" + textSearch + "%'";
|
||||||
break;
|
break;
|
||||||
case 'document':
|
case "document":
|
||||||
where +=
|
where += "REGEXP_REPLACE(\"pcclient\".cgcent, '[^0-9]', '') = REGEXP_REPLACE('" + textSearch + "', '[^0-9]', '')";
|
||||||
"REGEXP_REPLACE(\"pcclient\".cgcent, '[^0-9]', '') = REGEXP_REPLACE('" +
|
|
||||||
textSearch +
|
|
||||||
"', '[^0-9]', '')";
|
|
||||||
break;
|
break;
|
||||||
case 'phone':
|
case "phone":
|
||||||
where +=
|
where += "REGEXP_REPLACE(\"pcclient\".telent, '[^0-9]', '') = REGEXP_REPLACE('" + textSearch + "', '[^0-9]', '')";
|
||||||
"REGEXP_REPLACE(\"pcclient\".telent, '[^0-9]', '') = REGEXP_REPLACE('" +
|
|
||||||
textSearch +
|
|
||||||
"', '[^0-9]', '')";
|
|
||||||
break;
|
break;
|
||||||
case 'cellphone':
|
case "cellphone":
|
||||||
where +=
|
where += "REGEXP_REPLACE(\"pcclient\".telcelent, '[^0-9]', '') = REGEXP_REPLACE('" + textSearch + "', '[^0-9]', '')";
|
||||||
"REGEXP_REPLACE(\"pcclient\".telcelent, '[^0-9]', '') = REGEXP_REPLACE('" +
|
|
||||||
textSearch +
|
|
||||||
"', '[^0-9]', '')";
|
|
||||||
break;
|
break;
|
||||||
case 'customerId':
|
case "customerId":
|
||||||
where += '"pcclient".codcli = ' + textSearch;
|
where += "\"pcclient\".codcli = " + textSearch;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new HttpException(
|
throw new HttpException('Não foi informado um campo válido para pesquisa.', HttpStatus.BAD_REQUEST);
|
||||||
'Não foi informado um campo válido para pesquisa.',
|
|
||||||
HttpStatus.BAD_REQUEST,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const connection = new Connection(connectionOptions);
|
const connection = new Connection(connectionOptions);
|
||||||
|
|
@ -230,33 +213,31 @@ export class CustomerService {
|
||||||
const customers = await queryRunner.manager
|
const customers = await queryRunner.manager
|
||||||
.getRepository(Pcclient)
|
.getRepository(Pcclient)
|
||||||
.createQueryBuilder('pcclient')
|
.createQueryBuilder('pcclient')
|
||||||
.select('"pcclient".codcli as "customerId"')
|
.select("\"pcclient\".codcli as \"customerId\"")
|
||||||
.addSelect('"pcclient".cliente as "name"')
|
.addSelect("\"pcclient\".cliente as \"name\"")
|
||||||
.addSelect('"pcclient".emailnfe as "email"')
|
.addSelect("\"pcclient\".emailnfe as \"email\"")
|
||||||
.addSelect('"pcclient".cgcent as "cpfCnpj"')
|
.addSelect("\"pcclient\".cgcent as \"cpfCnpj\"")
|
||||||
.addSelect('"pcclient".sexo as "gender"')
|
.addSelect("\"pcclient\".sexo as \"gender\"")
|
||||||
.addSelect('"pcclient".enderent as "address"')
|
.addSelect("\"pcclient\".enderent as \"address\"")
|
||||||
.addSelect('"pcclient".numeroent as "addressNumber"')
|
.addSelect("\"pcclient\".numeroent as \"addressNumber\"")
|
||||||
.addSelect('"pcclient".bairroent as "neighborhood"')
|
.addSelect("\"pcclient\".bairroent as \"neighborhood\"")
|
||||||
.addSelect('"pcclient".complementoent as "complement"')
|
.addSelect("\"pcclient\".complementoent as \"complement\"")
|
||||||
.addSelect('"pcclient".municent as "city"')
|
.addSelect("\"pcclient\".municent as \"city\"")
|
||||||
.addSelect('"pcclient".estent as "state"')
|
.addSelect("\"pcclient\".estent as \"state\"")
|
||||||
.addSelect('"pcclient".cepent as "zipCode"')
|
.addSelect("\"pcclient\".cepent as \"zipCode\"")
|
||||||
.addSelect('"pcclient".telent as "phone"')
|
.addSelect("\"pcclient\".telent as \"phone\"")
|
||||||
.addSelect('"pcclient".telcelent as "cellPhone"')
|
.addSelect("\"pcclient\".telcelent as \"cellPhone\"")
|
||||||
.addSelect('"pcclient".codcategoria as "categoryId"')
|
.addSelect("\"pcclient\".codcategoria as \"categoryId\"")
|
||||||
.addSelect('"pcclient".codsubcategoria as "subCategoryId"')
|
.addSelect("\"pcclient\".codsubcategoria as \"subCategoryId\"")
|
||||||
.addSelect('"pcclient".codpraca as "placeId"')
|
.addSelect("\"pcclient\".codpraca as \"placeId\"")
|
||||||
.addSelect('"pcclient".ieent as "numberState"')
|
.addSelect("\"pcclient\".ieent as \"numberState\"")
|
||||||
.addSelect('"pcclient".latitude as "latitude"')
|
.addSelect("\"pcclient\".latitude as \"latitude\"")
|
||||||
.addSelect('"pcclient".longitude as "longitude"')
|
.addSelect("\"pcclient\".longitude as \"longitude\"")
|
||||||
.addSelect('"pcclient".codmunicipio as "ibgeCode"')
|
.addSelect("\"pcclient\".codmunicipio as \"ibgeCode\"")
|
||||||
.addSelect('"pcclient".codcidade as "cityId"')
|
.addSelect("\"pcclient\".codcidade as \"cityId\"")
|
||||||
.addSelect('"pcclient".esc_tipoeclieente as "addressType"')
|
.addSelect("\"pcclient\".esc_tipoeclieente as \"addressType\"")
|
||||||
.where(where)
|
.where(where)
|
||||||
.andWhere(
|
.andWhere("\"pcclient\".CODCLI NOT IN (2) AND \"pcclient\".DTEXCLUSAO IS NULL")
|
||||||
'"pcclient".CODCLI NOT IN (2) AND "pcclient".DTEXCLUSAO IS NULL',
|
|
||||||
)
|
|
||||||
.getRawMany();
|
.getRawMany();
|
||||||
return customers;
|
return customers;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
@ -270,11 +251,10 @@ export class CustomerService {
|
||||||
|
|
||||||
async createCustomer(customer: Customer) {
|
async createCustomer(customer: Customer) {
|
||||||
try {
|
try {
|
||||||
console.log('Dados consumer: ' + JSON.stringify(customer));
|
console.log("Dados consumer: " + JSON.stringify(customer));
|
||||||
const newCustomer = await this.InitializeCustomer();
|
const newCustomer = await this.InitializeCustomer();
|
||||||
newCustomer.tipofj = customer.company == 'true' ? 'J' : 'F';
|
newCustomer.tipofj = (customer.company == 'true' ? "J" : "F");
|
||||||
newCustomer.ieent =
|
newCustomer.ieent = (customer.company == 'true' ? customer.numberState : "ISENTO");
|
||||||
customer.company == 'true' ? customer.numberState : 'ISENTO';
|
|
||||||
newCustomer.inscestadual = newCustomer.ieent;
|
newCustomer.inscestadual = newCustomer.ieent;
|
||||||
newCustomer.cgcent = customer.cpfCnpj;
|
newCustomer.cgcent = customer.cpfCnpj;
|
||||||
newCustomer.sexo = customer.gender;
|
newCustomer.sexo = customer.gender;
|
||||||
|
|
@ -287,18 +267,13 @@ export class CustomerService {
|
||||||
newCustomer.telcelent = customer.cellPhone;
|
newCustomer.telcelent = customer.cellPhone;
|
||||||
newCustomer.celularwhatsapp = customer.cellPhone;
|
newCustomer.celularwhatsapp = customer.cellPhone;
|
||||||
newCustomer.codusur1 = customer.sellerId;
|
newCustomer.codusur1 = customer.sellerId;
|
||||||
newCustomer.codatv1 =
|
newCustomer.codatv1 = ( customer.ramo != null && customer.ramo.id > 0 ) ? customer.ramo.id : newCustomer.codatv1;
|
||||||
customer.ramo != null && customer.ramo.id > 0
|
|
||||||
? customer.ramo.id
|
|
||||||
: newCustomer.codatv1;
|
|
||||||
//Endereço de entrega
|
//Endereço de entrega
|
||||||
newCustomer.cepent = customer.zipCode;
|
newCustomer.cepent = customer.zipCode;
|
||||||
newCustomer.enderent = customer.address.toUpperCase();
|
newCustomer.enderent = customer.address.toUpperCase();
|
||||||
newCustomer.numeroent = customer.addressNumber;
|
newCustomer.numeroent = customer.addressNumber;
|
||||||
if ( customer.complement !== null && customer.complement.length > 80 ) {
|
if ( customer.complement !== null && customer.complement.length > 80 ) {
|
||||||
newCustomer.complementoent = customer.complement
|
newCustomer.complementoent = customer.complement.substring(0, 80 ).toUpperCase();
|
||||||
.substring(0, 80)
|
|
||||||
.toUpperCase();
|
|
||||||
} else {
|
} else {
|
||||||
if ( customer.complement != null ) {
|
if ( customer.complement != null ) {
|
||||||
newCustomer.complementoent = customer.complement.toUpperCase();
|
newCustomer.complementoent = customer.complement.toUpperCase();
|
||||||
|
|
@ -312,9 +287,7 @@ export class CustomerService {
|
||||||
newCustomer.endercom = customer.address.toUpperCase();
|
newCustomer.endercom = customer.address.toUpperCase();
|
||||||
newCustomer.numerocom = customer.addressNumber.toUpperCase();
|
newCustomer.numerocom = customer.addressNumber.toUpperCase();
|
||||||
if ( customer.complement !== null && customer.complement.length > 80 ) {
|
if ( customer.complement !== null && customer.complement.length > 80 ) {
|
||||||
newCustomer.complementocom = customer.complement
|
newCustomer.complementocom = customer.complement.substring(0, 80 ).toUpperCase();
|
||||||
.substring(0, 80)
|
|
||||||
.toUpperCase();
|
|
||||||
} else {
|
} else {
|
||||||
if ( customer.complement != null ) {
|
if ( customer.complement != null ) {
|
||||||
newCustomer.complementocom = customer.complement.toUpperCase();
|
newCustomer.complementocom = customer.complement.toUpperCase();
|
||||||
|
|
@ -328,9 +301,7 @@ export class CustomerService {
|
||||||
newCustomer.endercob = customer.address.toUpperCase();
|
newCustomer.endercob = customer.address.toUpperCase();
|
||||||
newCustomer.numerocob = customer.addressNumber;
|
newCustomer.numerocob = customer.addressNumber;
|
||||||
if ( customer.complement !== null && customer.complement.length > 80 ) {
|
if ( customer.complement !== null && customer.complement.length > 80 ) {
|
||||||
newCustomer.complementocob = customer.complement
|
newCustomer.complementocob = customer.complement.substring(0, 80 ).toUpperCase();
|
||||||
.substring(0, 80)
|
|
||||||
.toUpperCase();
|
|
||||||
} else {
|
} else {
|
||||||
if ( customer.complement ) {
|
if ( customer.complement ) {
|
||||||
newCustomer.complementocob = customer.complement.toUpperCase();
|
newCustomer.complementocob = customer.complement.toUpperCase();
|
||||||
|
|
@ -339,15 +310,10 @@ export class CustomerService {
|
||||||
newCustomer.bairrocob = customer.neighborhood.toUpperCase();
|
newCustomer.bairrocob = customer.neighborhood.toUpperCase();
|
||||||
newCustomer.municcob = customer.city.toUpperCase();
|
newCustomer.municcob = customer.city.toUpperCase();
|
||||||
newCustomer.estcob = customer.state.toUpperCase();
|
newCustomer.estcob = customer.state.toUpperCase();
|
||||||
newCustomer.codcategoria =
|
newCustomer.codcategoria = (customer.category != null) ? customer.category.id : null;
|
||||||
customer.category != null ? customer.category.id : null;
|
newCustomer.codsubcategoria = (customer.subCategory != null) ? customer.subCategory.id : null;
|
||||||
newCustomer.codsubcategoria =
|
|
||||||
customer.subCategory != null ? customer.subCategory.id : null;
|
|
||||||
newCustomer.codpraca = customer.place.id;
|
newCustomer.codpraca = customer.place.id;
|
||||||
newCustomer.codcidade =
|
newCustomer.codcidade = customer.ibgeCode != null ? await this.findCity(customer.ibgeCode) : null;
|
||||||
customer.ibgeCode != null
|
|
||||||
? await this.findCity(customer.ibgeCode)
|
|
||||||
: null;
|
|
||||||
newCustomer.codmunicipio = Number.parseInt(customer.ibgeCode);
|
newCustomer.codmunicipio = Number.parseInt(customer.ibgeCode);
|
||||||
newCustomer.codcidadecom = newCustomer.codcidade;
|
newCustomer.codcidadecom = newCustomer.codcidade;
|
||||||
newCustomer.dtnasc = customer.birthdate;
|
newCustomer.dtnasc = customer.birthdate;
|
||||||
|
|
@ -367,66 +333,37 @@ export class CustomerService {
|
||||||
await this.updateCustomer(newCustomer);
|
await this.updateCustomer(newCustomer);
|
||||||
return {
|
return {
|
||||||
customerId: oldCustomer.customerId,
|
customerId: oldCustomer.customerId,
|
||||||
company: customer.company,
|
company: customer.company, name: customer.name, sexo: customer.gender,
|
||||||
name: customer.name,
|
cpfCnpj: customer.cpfCnpj, numberState: customer.numberState,
|
||||||
sexo: customer.gender,
|
email: customer.email, zipCode: customer.zipCode, address: customer.address,
|
||||||
cpfCnpj: customer.cpfCnpj,
|
addressNumber: customer.addressNumber, complement: customer.complement,
|
||||||
numberState: customer.numberState,
|
|
||||||
email: customer.email,
|
|
||||||
zipCode: customer.zipCode,
|
|
||||||
address: customer.address,
|
|
||||||
addressNumber: customer.addressNumber,
|
|
||||||
complement: customer.complement,
|
|
||||||
neighborhood: customer.neighborhood,
|
neighborhood: customer.neighborhood,
|
||||||
city: customer.city,
|
city: customer.city, state: customer.state,
|
||||||
state: customer.state,
|
allowMessage: customer.allowMessage, cellPhone: customer.cellPhone,
|
||||||
allowMessage: customer.allowMessage,
|
category: customer.category, subCategory: customer.subCategory,
|
||||||
cellPhone: customer.cellPhone,
|
place: customer.place, ramo: customer.ramo, meiocomunicacao: customer.communicate,
|
||||||
category: customer.category,
|
latitude: customer.latitude, longitude: customer.longitude, ibgeCode: customer.ibgeCode,
|
||||||
subCategory: customer.subCategory,
|
|
||||||
place: customer.place,
|
|
||||||
ramo: customer.ramo,
|
|
||||||
meiocomunicacao: customer.communicate,
|
|
||||||
latitude: customer.latitude,
|
|
||||||
longitude: customer.longitude,
|
|
||||||
ibgeCode: customer.ibgeCode,
|
|
||||||
addressType: customer.addressType,
|
addressType: customer.addressType,
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
const idCustomer = await this.generateIdCustomer();
|
const idCustomer = await this.generateIdCustomer();
|
||||||
if (idCustomer == -1)
|
if (idCustomer == -1)
|
||||||
return new HttpException(
|
return new HttpException("Erro ao gerar númeração de cliente.", HttpStatus.INTERNAL_SERVER_ERROR);
|
||||||
'Erro ao gerar númeração de cliente.',
|
|
||||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
|
||||||
);
|
|
||||||
newCustomer.codcli = idCustomer;
|
newCustomer.codcli = idCustomer;
|
||||||
await this.insertCustomer(newCustomer);
|
await this.insertCustomer(newCustomer);
|
||||||
return {
|
return {
|
||||||
customerId: idCustomer,
|
customerId: idCustomer,
|
||||||
company: customer.company,
|
company: customer.company, name: customer.name,
|
||||||
name: customer.name,
|
cpfCnpj: customer.cpfCnpj, gender: customer.gender, numberState: customer.numberState,
|
||||||
cpfCnpj: customer.cpfCnpj,
|
email: customer.email, zipCode: customer.zipCode, address: customer.address,
|
||||||
gender: customer.gender,
|
addressNumber: customer.addressNumber, complement: customer.complement,
|
||||||
numberState: customer.numberState,
|
|
||||||
email: customer.email,
|
|
||||||
zipCode: customer.zipCode,
|
|
||||||
address: customer.address,
|
|
||||||
addressNumber: customer.addressNumber,
|
|
||||||
complement: customer.complement,
|
|
||||||
neighborhood: customer.neighborhood,
|
neighborhood: customer.neighborhood,
|
||||||
city: customer.city,
|
city: customer.city, state: customer.state,
|
||||||
state: customer.state,
|
allowMessage: customer.allowMessage, cellPhone: customer.cellPhone,
|
||||||
allowMessage: customer.allowMessage,
|
category: customer.category, subCategory: customer.subCategory,
|
||||||
cellPhone: customer.cellPhone,
|
place: customer.place, meiocomunicacao: customer.communicate,
|
||||||
category: customer.category,
|
ramo: customer.ramo, latitude: customer.latitude, longitude: customer.longitude,
|
||||||
subCategory: customer.subCategory,
|
ibgeCode: customer.ibgeCode, addressType: customer.addressType,
|
||||||
place: customer.place,
|
|
||||||
meiocomunicacao: customer.communicate,
|
|
||||||
ramo: customer.ramo,
|
|
||||||
latitude: customer.latitude,
|
|
||||||
longitude: customer.longitude,
|
|
||||||
ibgeCode: customer.ibgeCode,
|
|
||||||
addressType: customer.addressType,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
@ -441,7 +378,7 @@ export class CustomerService {
|
||||||
await queryRunner.connect();
|
await queryRunner.connect();
|
||||||
await queryRunner.startTransaction();
|
await queryRunner.startTransaction();
|
||||||
try {
|
try {
|
||||||
console.log('MEIO DE COMUNICACAO: ' + client.meiocomunicacao);
|
console.log("MEIO DE COMUNICACAO: " + client.meiocomunicacao);
|
||||||
await queryRunner.manager
|
await queryRunner.manager
|
||||||
.createQueryBuilder()
|
.createQueryBuilder()
|
||||||
.update(Pcclient)
|
.update(Pcclient)
|
||||||
|
|
@ -487,7 +424,7 @@ export class CustomerService {
|
||||||
dtultalter: client.dtultalter,
|
dtultalter: client.dtultalter,
|
||||||
latitude: client.latitude,
|
latitude: client.latitude,
|
||||||
longitude: client.longitude,
|
longitude: client.longitude,
|
||||||
tipoendereco: client.tipoendereco,
|
tipoendereco: client.tipoendereco
|
||||||
})
|
})
|
||||||
.where({ codcli: client.codcli })
|
.where({ codcli: client.codcli })
|
||||||
.execute();
|
.execute();
|
||||||
|
|
@ -503,6 +440,7 @@ export class CustomerService {
|
||||||
await queryRunner.release();
|
await queryRunner.release();
|
||||||
await connection.close();
|
await connection.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async findCity(ibgeCode: string) {
|
async findCity(ibgeCode: string) {
|
||||||
|
|
@ -514,10 +452,7 @@ export class CustomerService {
|
||||||
const queryRunner = connection.createQueryRunner();
|
const queryRunner = connection.createQueryRunner();
|
||||||
await queryRunner.connect();
|
await queryRunner.connect();
|
||||||
try {
|
try {
|
||||||
const city = await queryRunner.query(
|
const city = await queryRunner.query('SELECT PCCIDADE.CODCIDADE as "codigoCidade" FROM PCCIDADE WHERE PCCIDADE.codibge = :1', [ibgeCode]);
|
||||||
'SELECT PCCIDADE.CODCIDADE as "codigoCidade" FROM PCCIDADE WHERE PCCIDADE.codibge = :1',
|
|
||||||
[ibgeCode],
|
|
||||||
);
|
|
||||||
let cityId = 0;
|
let cityId = 0;
|
||||||
if (city.length > 0) {
|
if (city.length > 0) {
|
||||||
cityId = city[0].codigoCidade;
|
cityId = city[0].codigoCidade;
|
||||||
|
|
@ -536,67 +471,68 @@ export class CustomerService {
|
||||||
cliente.codusur1 = 1;
|
cliente.codusur1 = 1;
|
||||||
cliente.codplpag = 10;
|
cliente.codplpag = 10;
|
||||||
cliente.codpraca = 119;
|
cliente.codpraca = 119;
|
||||||
cliente.codcob = 'D';
|
cliente.codcob = "D";
|
||||||
cliente.dtcadastro = new Date();
|
cliente.dtcadastro = new Date();
|
||||||
cliente.codcontab = '1';
|
cliente.codcontab = "1";
|
||||||
cliente.aceitavendafracao = 'N';
|
cliente.aceitavendafracao = "N";
|
||||||
//cliente.Meiocomunicacao = "N";
|
//cliente.Meiocomunicacao = "N";
|
||||||
cliente.bloqueio = 'N';
|
cliente.bloqueio = "N";
|
||||||
cliente.bloqueiosefaz = 'N';
|
cliente.bloqueiosefaz = "N";
|
||||||
cliente.bloqueiosefazped = 'N';
|
cliente.bloqueiosefazped = "N";
|
||||||
cliente.bloqvendapf = 'N';
|
cliente.bloqvendapf = "N";
|
||||||
cliente.condvenda1 = 'S';
|
cliente.condvenda1 = "S";
|
||||||
cliente.condvenda5 = 'S';
|
cliente.condvenda5 = "S";
|
||||||
cliente.condvenda7 = 'S';
|
cliente.condvenda7 = "S";
|
||||||
cliente.condvenda8 = 'S';
|
cliente.condvenda8 = "S";
|
||||||
cliente.contribuinte = 'N';
|
cliente.contribuinte = "N";
|
||||||
cliente.validarmultiplovenda = 'N';
|
cliente.validarmultiplovenda = "N";
|
||||||
cliente.codfunccad = 1;
|
cliente.codfunccad = 1;
|
||||||
cliente.codfunccadastro = 1;
|
cliente.codfunccadastro = 1;
|
||||||
cliente.horacadastro = new Date();
|
cliente.horacadastro = new Date();
|
||||||
cliente.dtcadastro = new Date();
|
cliente.dtcadastro = new Date();
|
||||||
cliente.dtultvisita = new Date();
|
cliente.dtultvisita = new Date();
|
||||||
cliente.codatv1 = 7;
|
cliente.codatv1 = 7;
|
||||||
cliente.aceitatrocanegativa = 'N';
|
cliente.aceitatrocanegativa = "N";
|
||||||
cliente.consumidorfinal = 'S';
|
cliente.consumidorfinal = "S";
|
||||||
cliente.aplicadescnf = 'S';
|
cliente.aplicadescnf = "S";
|
||||||
cliente.simplesnacional = 'N';
|
cliente.simplesnacional = "N";
|
||||||
cliente.sexo = 'M';
|
cliente.sexo = "M";
|
||||||
cliente.isencaosuframa = 'T';
|
cliente.isencaosuframa = "T";
|
||||||
cliente.clicrm = 'N';
|
cliente.clicrm = "N";
|
||||||
cliente.tv10usacustoproduto = 'N';
|
cliente.tv10usacustoproduto = "N";
|
||||||
cliente.inscestadual = 'ISENTO';
|
cliente.inscestadual = "ISENTO";
|
||||||
cliente.codpais = 1058; //Brasil
|
cliente.codpais = 1058; //Brasil
|
||||||
cliente.observacao = 'Importado do E-Commerce';
|
cliente.observacao = "Importado do E-Commerce";
|
||||||
cliente.aceitachterceiros = 'S';
|
cliente.aceitachterceiros = "S";
|
||||||
cliente.agregarvalorstdescfin = 'N';
|
cliente.agregarvalorstdescfin = "N";
|
||||||
cliente.anvisa = 'N';
|
cliente.anvisa = "N";
|
||||||
cliente.aplicredbaseicmstransp = 'N';
|
cliente.aplicredbaseicmstransp = "N";
|
||||||
cliente.atendedomingo = 'N';
|
cliente.atendedomingo = "N";
|
||||||
cliente.atendequarta = 'N';
|
cliente.atendequarta = "N";
|
||||||
cliente.atendequinta = 'N';
|
cliente.atendequinta = "N";
|
||||||
cliente.atendesabado = 'N';
|
cliente.atendesabado = "N";
|
||||||
cliente.atendesegunda = 'N';
|
cliente.atendesegunda = "N";
|
||||||
cliente.atendesexta = 'N';
|
cliente.atendesexta = "N";
|
||||||
cliente.atendeterca = 'N';
|
cliente.atendeterca = "N";
|
||||||
cliente.atualizasaldoccdescfin = 'N';
|
cliente.atualizasaldoccdescfin = "N";
|
||||||
cliente.bloqremcob = 'N';
|
cliente.bloqremcob = "N";
|
||||||
cliente.clientedan = 'N';
|
cliente.clientedan = "N";
|
||||||
cliente.clientefontest = 'N';
|
cliente.clientefontest = "N";
|
||||||
cliente.clientemonitorado = 'N';
|
cliente.clientemonitorado = "N";
|
||||||
cliente.clientprotesto = 'S';
|
cliente.clientprotesto = "S";
|
||||||
cliente.fretedespacho = '0';
|
cliente.fretedespacho = "0";
|
||||||
cliente.aceitavendafracao = 'S';
|
cliente.aceitavendafracao = "S";
|
||||||
cliente.validarmultiplovenda = 'S';
|
cliente.validarmultiplovenda = "S";
|
||||||
|
|
||||||
return cliente;
|
return cliente;
|
||||||
}
|
}
|
||||||
|
|
||||||
async generateIdCustomer() {
|
async generateIdCustomer() {
|
||||||
console.log('Gerando idcustomer');
|
console.log("Gerando idcustomer");
|
||||||
const connection = new Connection(connectionOptions);
|
const connection = new Connection(connectionOptions);
|
||||||
const queryRunner = connection.createQueryRunner();
|
const queryRunner = connection.createQueryRunner();
|
||||||
try {
|
try {
|
||||||
|
|
||||||
await connection.connect();
|
await connection.connect();
|
||||||
|
|
||||||
await queryRunner.connect();
|
await queryRunner.connect();
|
||||||
|
|
@ -604,6 +540,7 @@ export class CustomerService {
|
||||||
// lets now open a new transaction:
|
// lets now open a new transaction:
|
||||||
await queryRunner.startTransaction();
|
await queryRunner.startTransaction();
|
||||||
|
|
||||||
|
|
||||||
let sql = `SELECT PROXNUMCLI as "proxnumcli" FROM PCCONSUM WHERE 1 = 1 FOR UPDATE`;
|
let sql = `SELECT PROXNUMCLI as "proxnumcli" FROM PCCONSUM WHERE 1 = 1 FOR UPDATE`;
|
||||||
let param = await queryRunner.query(sql);
|
let param = await queryRunner.query(sql);
|
||||||
|
|
||||||
|
|
@ -626,6 +563,7 @@ export class CustomerService {
|
||||||
// commit transaction now:
|
// commit transaction now:
|
||||||
await queryRunner.commitTransaction();
|
await queryRunner.commitTransaction();
|
||||||
return idCustomer;
|
return idCustomer;
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// since we have errors let's rollback changes we made
|
// since we have errors let's rollback changes we made
|
||||||
if ( queryRunner.isTransactionActive) {
|
if ( queryRunner.isTransactionActive) {
|
||||||
|
|
@ -633,6 +571,7 @@ export class CustomerService {
|
||||||
}
|
}
|
||||||
console.log(err);
|
console.log(err);
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
if ( queryRunner.isTransactionActive) {
|
if ( queryRunner.isTransactionActive) {
|
||||||
await queryRunner.rollbackTransaction();
|
await queryRunner.rollbackTransaction();
|
||||||
|
|
@ -673,15 +612,16 @@ export class CustomerService {
|
||||||
}
|
}
|
||||||
|
|
||||||
async getCategory() {
|
async getCategory() {
|
||||||
const connectionDb = new Connection(connectionOptions);
|
const connectionDb = new Connection(connectionOptions)
|
||||||
await connectionDb.connect();
|
await connectionDb.connect();
|
||||||
const queryRunner = connectionDb.createQueryRunner();
|
const queryRunner = connectionDb.createQueryRunner();
|
||||||
await queryRunner.connect();
|
await queryRunner.connect();
|
||||||
try {
|
try {
|
||||||
return await queryRunner.manager
|
return await queryRunner.manager
|
||||||
.getRepository(Estcategoriacliente)
|
.getRepository(Estcategoriacliente)
|
||||||
.createQueryBuilder('estcategoriacliente')
|
.createQueryBuilder("estcategoriacliente")
|
||||||
.getMany();
|
.getMany();
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
throw err;
|
throw err;
|
||||||
|
|
@ -692,15 +632,16 @@ export class CustomerService {
|
||||||
}
|
}
|
||||||
|
|
||||||
async getSubCategory() {
|
async getSubCategory() {
|
||||||
const connectionDb = new Connection(connectionOptions);
|
const connectionDb = new Connection(connectionOptions)
|
||||||
await connectionDb.connect();
|
await connectionDb.connect();
|
||||||
const queryRunner = connectionDb.createQueryRunner();
|
const queryRunner = connectionDb.createQueryRunner();
|
||||||
await queryRunner.connect();
|
await queryRunner.connect();
|
||||||
try {
|
try {
|
||||||
return await queryRunner.manager
|
return await queryRunner.manager
|
||||||
.getRepository(Estsubcategoriacliente)
|
.getRepository(Estsubcategoriacliente)
|
||||||
.createQueryBuilder('estsubcategoriacliente')
|
.createQueryBuilder("estsubcategoriacliente")
|
||||||
.getMany();
|
.getMany();
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
throw err;
|
throw err;
|
||||||
|
|
@ -709,4 +650,5 @@ export class CustomerService {
|
||||||
await connectionDb.close();
|
await connectionDb.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,24 @@
|
||||||
/* eslint-disable @typescript-eslint/camelcase */
|
/* eslint-disable @typescript-eslint/camelcase */
|
||||||
import { HttpException, HttpStatus, Inject, Injectable } from '@nestjs/common';
|
import { HttpException, HttpStatus, Injectable,Inject } from '@nestjs/common';
|
||||||
import { ListsService } from 'src/backoffice/lists/lists.service';
|
|
||||||
import { connectionOptions } from 'src/configs/typeorm.config';
|
|
||||||
import { ShoppingItens } from 'src/domain/entity/tables/estprevendai.entity';
|
import { ShoppingItens } from 'src/domain/entity/tables/estprevendai.entity';
|
||||||
import { Sale } from 'src/domain/entity/tables/estvenda.entity';
|
import { Sale } from 'src/domain/entity/tables/estvenda.entity';
|
||||||
import { Pcpedctemp } from 'src/domain/entity/tables/pcpedctemp.entity';
|
import { Pcpedctemp } from 'src/domain/entity/tables/pcpedctemp.entity';
|
||||||
import { Pcpeditemp } from 'src/domain/entity/tables/pcpeditemp.entity';
|
|
||||||
import { Cart } from 'src/domain/models/cart.model';
|
|
||||||
import { Connection, QueryRunner } from 'typeorm';
|
import { Connection, QueryRunner } from 'typeorm';
|
||||||
import { Pcclient } from '../../domain/entity/tables/pcclient.entity';
|
import { Pcclient } from '../../domain/entity/tables/pcclient.entity';
|
||||||
|
import { Pcpeditemp } from 'src/domain/entity/tables/pcpeditemp.entity';
|
||||||
|
import { Cart } from 'src/domain/models/cart.model';
|
||||||
import { Pcpedc } from '../../domain/entity/tables/pcpedc.entity';
|
import { Pcpedc } from '../../domain/entity/tables/pcpedc.entity';
|
||||||
import { AddressCustomerService } from '../address-customer/address-customer.service';
|
import { connectionOptions } from 'src/configs/typeorm.config';
|
||||||
|
import { ListsService } from 'src/backoffice/lists/lists.service';
|
||||||
import { CustomerService } from '../customer/customer.service';
|
import { CustomerService } from '../customer/customer.service';
|
||||||
|
import { AddressCustomerService } from '../address-customer/address-customer.service';
|
||||||
import { ShoppingService } from '../shopping/shopping.service';
|
import { ShoppingService } from '../shopping/shopping.service';
|
||||||
import Redis = require('ioredis');
|
import Redis = require('ioredis');
|
||||||
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class OrderService {
|
export class OrderService {
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@Inject('REDIS_CLIENT') private readonly redisClient: Redis.Redis,
|
@Inject('REDIS_CLIENT') private readonly redisClient: Redis.Redis,
|
||||||
private readonly listsService: ListsService,
|
private readonly listsService: ListsService,
|
||||||
|
|
@ -28,10 +30,7 @@ export class OrderService {
|
||||||
async create(cart: Cart) {
|
async create(cart: Cart) {
|
||||||
const shopping = await this.findShopping(cart.id);
|
const shopping = await this.findShopping(cart.id);
|
||||||
if (shopping == null)
|
if (shopping == null)
|
||||||
throw new HttpException(
|
throw new HttpException("Carrinho de compras não localizado.", HttpStatus.NOT_FOUND);
|
||||||
'Carrinho de compras não localizado.',
|
|
||||||
HttpStatus.NOT_FOUND,
|
|
||||||
);
|
|
||||||
const order = await this.createOrder(cart);
|
const order = await this.createOrder(cart);
|
||||||
return order;
|
return order;
|
||||||
}
|
}
|
||||||
|
|
@ -43,27 +42,17 @@ export class OrderService {
|
||||||
await queryRunner.connect();
|
await queryRunner.connect();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const orderCancel = await queryRunner.query(
|
const orderCancel = await queryRunner.query('SELECT PCPEDC.NUMPED FROM PCPEDC WHERE NUMPED = :NUMPED', [orderId]);
|
||||||
'SELECT PCPEDC.NUMPED FROM PCPEDC WHERE NUMPED = :NUMPED',
|
|
||||||
[orderId],
|
|
||||||
);
|
|
||||||
|
|
||||||
if (orderCancel !== null && orderCancel.length > 0) {
|
if (orderCancel !== null && orderCancel.length > 0) {
|
||||||
await queryRunner.startTransaction();
|
await queryRunner.startTransaction();
|
||||||
await queryRunner.query(
|
await queryRunner.query("UPDATE PCPEDC SET VENDAASSISTIDA = 'N', RESERVAESTOQUETV7 = 'N' WHERE NUMPEDENTFUT = :1", [orderId]);
|
||||||
"UPDATE PCPEDC SET VENDAASSISTIDA = 'N', RESERVAESTOQUETV7 = 'N' WHERE NUMPEDENTFUT = :1",
|
|
||||||
[orderId],
|
|
||||||
);
|
|
||||||
await queryRunner.commitTransaction();
|
await queryRunner.commitTransaction();
|
||||||
const ordersDelivery = await queryRunner.query(
|
const ordersDelivery = await queryRunner
|
||||||
'SELECT PCPEDC.NUMPED FROM PCPEDC WHERE NUMPEDENTFUT = :1',
|
.query("SELECT PCPEDC.NUMPED FROM PCPEDC WHERE NUMPEDENTFUT = :1", [orderId]);
|
||||||
[orderId],
|
|
||||||
);
|
|
||||||
for (const orderDelivery of ordersDelivery) {
|
for (const orderDelivery of ordersDelivery) {
|
||||||
await queryRunner.query(
|
await queryRunner
|
||||||
'BEGIN ESK_VENDA.CANCELAR_PEDIDO(:1, :2); END;',
|
.query("BEGIN ESK_VENDA.CANCELAR_PEDIDO(:1, :2); END;", [orderDelivery.numped, userId]);
|
||||||
[orderDelivery.numped, userId],
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (erro) {
|
} catch (erro) {
|
||||||
|
|
@ -81,6 +70,7 @@ export class OrderService {
|
||||||
}
|
}
|
||||||
|
|
||||||
async createOrder(cart: Cart) {
|
async createOrder(cart: Cart) {
|
||||||
|
|
||||||
const prevenda = await this.shoppingService.getShopping(cart.id);
|
const prevenda = await this.shoppingService.getShopping(cart.id);
|
||||||
let idPreOrder = 0;
|
let idPreOrder = 0;
|
||||||
cart.idSeller = prevenda.codusur;
|
cart.idSeller = prevenda.codusur;
|
||||||
|
|
@ -96,28 +86,20 @@ export class OrderService {
|
||||||
await queryRunner.connect();
|
await queryRunner.connect();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
if (prevenda.numped > 0) {
|
if (prevenda.numped > 0) {
|
||||||
// await this.deleteOrdersDelivery(prevenda.numped, cart.userId);
|
// await this.deleteOrdersDelivery(prevenda.numped, cart.userId);
|
||||||
const orders = await queryRunner.query(
|
const orders = await queryRunner.query('SELECT PCPEDC.NUMPED FROM PCPEDC WHERE NUMPED = :NUMPED', [prevenda.numped]);
|
||||||
'SELECT PCPEDC.NUMPED FROM PCPEDC WHERE NUMPED = :NUMPED',
|
|
||||||
[prevenda.numped],
|
|
||||||
);
|
|
||||||
if (orders !== null && orders.length > 0) {
|
if (orders !== null && orders.length > 0) {
|
||||||
await queryRunner.query(
|
await queryRunner
|
||||||
'BEGIN ESK_VENDA.CANCELAR_PEDIDO(:1, :2); END;',
|
.query("BEGIN ESK_VENDA.CANCELAR_PEDIDO(:1, :2); END;", [prevenda.numped, cart.userId]);
|
||||||
[prevenda.numped, cart.userId],
|
const orderCancel = await queryRunner
|
||||||
);
|
.query('SELECT PCPEDC.NUMPED FROM PCPEDC WHERE NUMPED = :1', [prevenda.numped]);
|
||||||
const orderCancel = await queryRunner.query(
|
|
||||||
'SELECT PCPEDC.NUMPED FROM PCPEDC WHERE NUMPED = :1',
|
|
||||||
[prevenda.numped],
|
|
||||||
);
|
|
||||||
if (orderCancel.length > 0) {
|
if (orderCancel.length > 0) {
|
||||||
throw new HttpException(
|
throw new HttpException('Não foi possível alterar o pedido de venda, verifique se o pedido já não encontra-se FATURADO ou em SEPARAÇÃO.', HttpStatus.BAD_REQUEST);
|
||||||
'Não foi possível alterar o pedido de venda, verifique se o pedido já não encontra-se FATURADO ou em SEPARAÇÃO.',
|
|
||||||
HttpStatus.BAD_REQUEST,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// if ( prevenda.codcli === null || prevenda.codcli === 1){
|
// if ( prevenda.codcli === null || prevenda.codcli === 1){
|
||||||
|
|
@ -126,30 +108,20 @@ export class OrderService {
|
||||||
|
|
||||||
const preOrder = await this.createPreOrder(cart, idPreOrder);
|
const preOrder = await this.createPreOrder(cart, idPreOrder);
|
||||||
|
|
||||||
await queryRunner.query(
|
await queryRunner
|
||||||
'BEGIN IMPORTARVENDAS.IMPORTARPEDIDOWEB(:preOrder, :idSeller); END;',
|
.query("BEGIN IMPORTARVENDAS.IMPORTARPEDIDOWEB(:preOrder, :idSeller); END;", [preOrder.numpedrca, preOrder.codusur]);
|
||||||
[preOrder.numpedrca, preOrder.codusur],
|
|
||||||
);
|
|
||||||
|
|
||||||
const order = await queryRunner.manager
|
const order = await queryRunner.manager
|
||||||
.getRepository(Pcpedc)
|
.getRepository(Pcpedc)
|
||||||
.createQueryBuilder('pcpedc')
|
.createQueryBuilder('pcpedc')
|
||||||
.where(
|
.where("\"pcpedc\".numpedrca = :idPreOrder AND \"pcpedc\".CONDVENDA IN (1,7)", { idPreOrder: preOrder.numpedrca })
|
||||||
'"pcpedc".numpedrca = :idPreOrder AND "pcpedc".CONDVENDA IN (1,7)',
|
|
||||||
{ idPreOrder: preOrder.numpedrca },
|
|
||||||
)
|
|
||||||
.getOne();
|
.getOne();
|
||||||
|
|
||||||
if (!order) {
|
if (!order) {
|
||||||
const logPreOrder = await queryRunner.query(
|
const logPreOrder = await queryRunner.query('SELECT PCPEDCTEMP.NUMPEDRCA, PCPEDCTEMP.observacao_pc as \"resultado\" FROM PCPEDCTEMP WHERE PCPEDCTEMP.NUMPEDRCA = :idPreOrder',
|
||||||
'SELECT PCPEDCTEMP.NUMPEDRCA, PCPEDCTEMP.observacao_pc as "resultado" FROM PCPEDCTEMP WHERE PCPEDCTEMP.NUMPEDRCA = :idPreOrder',
|
[preOrder.numpedrca]);
|
||||||
[preOrder.numpedrca],
|
|
||||||
);
|
|
||||||
console.log(JSON.stringify(logPreOrder));
|
console.log(JSON.stringify(logPreOrder));
|
||||||
throw new HttpException(
|
throw new HttpException('Erro ao gerar pedido de venda - ' + logPreOrder[0].resultado, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||||
'Erro ao gerar pedido de venda - ' + logPreOrder[0].resultado,
|
|
||||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (queryRunner.isTransactionActive) {
|
if (queryRunner.isTransactionActive) {
|
||||||
|
|
@ -159,13 +131,11 @@ export class OrderService {
|
||||||
await queryRunner.startTransaction();
|
await queryRunner.startTransaction();
|
||||||
try {
|
try {
|
||||||
// Atualizar numero do pedido na tabela de pre venda para
|
// Atualizar numero do pedido na tabela de pre venda para
|
||||||
let sql =
|
let sql = ` UPDATE ESTPREVENDAC SET NUMPED = ${order.numped} ` +
|
||||||
` UPDATE ESTPREVENDAC SET NUMPED = ${order.numped} ` +
|
|
||||||
` WHERE ESTPREVENDAC.ID = '${cart.id}' `;
|
` WHERE ESTPREVENDAC.ID = '${cart.id}' `;
|
||||||
await queryRunner.query(sql);
|
await queryRunner.query(sql);
|
||||||
|
|
||||||
sql =
|
sql = `UPDATE PCORCAVENDAC SET ORCAMENTOUTILIZADO = 'S' ` +
|
||||||
`UPDATE PCORCAVENDAC SET ORCAMENTOUTILIZADO = 'S' ` +
|
|
||||||
` ,NUMPED = ${order.numped} ` +
|
` ,NUMPED = ${order.numped} ` +
|
||||||
` WHERE PCORCAVENDAC.NUMORCA = ( SELECT ESTPREVENDAC.NUMORCA FROM ESTPREVENDAC WHERE ID = '${cart.id}' ) `;
|
` WHERE PCORCAVENDAC.NUMORCA = ( SELECT ESTPREVENDAC.NUMORCA FROM ESTPREVENDAC WHERE ID = '${cart.id}' ) `;
|
||||||
await queryRunner.query(sql);
|
await queryRunner.query(sql);
|
||||||
|
|
@ -173,8 +143,8 @@ export class OrderService {
|
||||||
// await queryRunner
|
// await queryRunner
|
||||||
// .query("BEGIN ESK_VENDA.RESERVA_PIGMENTO_TINTOMETRICO(:1); END;", [cart.id]);
|
// .query("BEGIN ESK_VENDA.RESERVA_PIGMENTO_TINTOMETRICO(:1); END;", [cart.id]);
|
||||||
|
|
||||||
sql =
|
|
||||||
`UPDATE PCPEDC SET ` +
|
sql = `UPDATE PCPEDC SET ` +
|
||||||
` POSICAO = 'L' ` +
|
` POSICAO = 'L' ` +
|
||||||
` , MOTIVOPOSICAO = NULL ` +
|
` , MOTIVOPOSICAO = NULL ` +
|
||||||
` , CODMOTIVO = NULL ` +
|
` , CODMOTIVO = NULL ` +
|
||||||
|
|
@ -195,9 +165,9 @@ export class OrderService {
|
||||||
` OR EXISTS(SELECT PCCOB.CODCOB FROM PCCOB ` +
|
` OR EXISTS(SELECT PCCOB.CODCOB FROM PCCOB ` +
|
||||||
` WHERE PCCOB.CODCOB = PCPEDC.CODCOB ` +
|
` WHERE PCCOB.CODCOB = PCPEDC.CODCOB ` +
|
||||||
` AND NVL(PCCOB.CARTAO,'N') = 'S') ) `;
|
` AND NVL(PCCOB.CARTAO,'N') = 'S') ) `;
|
||||||
await queryRunner.manager.query(sql, [order.numped]);
|
await queryRunner.manager
|
||||||
sql =
|
.query(sql, [order.numped]);
|
||||||
`UPDATE PCPEDI SET POSICAO = 'L' WHERE NUMPED = :1 ` +
|
sql = `UPDATE PCPEDI SET POSICAO = 'L' WHERE NUMPED = :1 ` +
|
||||||
` AND EXISTS( SELECT PCPEDC.NUMPED FROM PCPEDC ` +
|
` AND EXISTS( SELECT PCPEDC.NUMPED FROM PCPEDC ` +
|
||||||
` WHERE PCPEDC.NUMPED = PCPEDI.NUMPED ` +
|
` WHERE PCPEDC.NUMPED = PCPEDI.NUMPED ` +
|
||||||
` AND NOT EXISTS(SELECT PCBLOQUEIO.CODMOTBLOQUEIO FROM PCBLOQUEIO WHERE PCBLOQUEIO.CODCOB = PCPEDC.CODCOB) ` +
|
` AND NOT EXISTS(SELECT PCBLOQUEIO.CODMOTBLOQUEIO FROM PCBLOQUEIO WHERE PCBLOQUEIO.CODCOB = PCPEDC.CODCOB) ` +
|
||||||
|
|
@ -205,12 +175,13 @@ export class OrderService {
|
||||||
` OR EXISTS(SELECT PCCOB.CODCOB FROM PCCOB ` +
|
` OR EXISTS(SELECT PCCOB.CODCOB FROM PCCOB ` +
|
||||||
` WHERE PCCOB.CODCOB = PCPEDC.CODCOB ` +
|
` WHERE PCCOB.CODCOB = PCPEDC.CODCOB ` +
|
||||||
` AND NVL(PCCOB.CARTAO,'N') = 'S') ) )`;
|
` AND NVL(PCCOB.CARTAO,'N') = 'S') ) )`;
|
||||||
await queryRunner.manager.query(sql, [order.numped]);
|
await queryRunner.manager
|
||||||
|
.query(sql, [order.numped]);
|
||||||
|
|
||||||
await this.updateStatusItem(queryRunner, order.numped);
|
await this.updateStatusItem(queryRunner, order.numped);
|
||||||
|
|
||||||
sql =
|
|
||||||
` UPDATE PCPEDC SET ` +
|
sql = ` UPDATE PCPEDC SET ` +
|
||||||
` POSICAO = 'L' ` +
|
` POSICAO = 'L' ` +
|
||||||
` , MOTIVOPOSICAO = NULL ` +
|
` , MOTIVOPOSICAO = NULL ` +
|
||||||
` , CODMOTIVO = NULL ` +
|
` , CODMOTIVO = NULL ` +
|
||||||
|
|
@ -234,8 +205,7 @@ export class OrderService {
|
||||||
` AND TV7.POSICAO = 'L' )`;
|
` AND TV7.POSICAO = 'L' )`;
|
||||||
|
|
||||||
await queryRunner.manager.query(sql, [order.numped]);
|
await queryRunner.manager.query(sql, [order.numped]);
|
||||||
sql =
|
sql = ` UPDATE PCPEDC SET ` +
|
||||||
` UPDATE PCPEDC SET ` +
|
|
||||||
` POSICAO = ( SELECT PCPEDI.POSICAO FROM PCPEDI WHERE PCPEDI.NUMPED = PCPEDC.NUMPED AND ROWNUM = 1 ) ` +
|
` POSICAO = ( SELECT PCPEDI.POSICAO FROM PCPEDI WHERE PCPEDI.NUMPED = PCPEDC.NUMPED AND ROWNUM = 1 ) ` +
|
||||||
` , MOTIVOPOSICAO = NULL ` +
|
` , MOTIVOPOSICAO = NULL ` +
|
||||||
` , CODMOTIVO = NULL ` +
|
` , CODMOTIVO = NULL ` +
|
||||||
|
|
@ -260,8 +230,7 @@ export class OrderService {
|
||||||
await queryRunner.manager.query(sql, [order.numped]);
|
await queryRunner.manager.query(sql, [order.numped]);
|
||||||
|
|
||||||
// atualizar campos padrão para rotina 4116
|
// atualizar campos padrão para rotina 4116
|
||||||
sql =
|
sql = ` UPDATE PCPEDC SET ` +
|
||||||
` UPDATE PCPEDC SET ` +
|
|
||||||
` DTENTREGA = TRUNC(DTENTREGA) ` +
|
` DTENTREGA = TRUNC(DTENTREGA) ` +
|
||||||
` , DATA = TRUNC(DATA) ` +
|
` , DATA = TRUNC(DATA) ` +
|
||||||
` , DTPREVENTREGA = TRUNC(DTENTREGA) ` +
|
` , DTPREVENTREGA = TRUNC(DTENTREGA) ` +
|
||||||
|
|
@ -288,8 +257,7 @@ export class OrderService {
|
||||||
`WHERE ( PCPEDC.NUMPED = :1 OR PCPEDC.NUMPEDENTFUT = :2 ) `;
|
`WHERE ( PCPEDC.NUMPED = :1 OR PCPEDC.NUMPEDENTFUT = :2 ) `;
|
||||||
await queryRunner.manager.query(sql, [order.numped, order.numped]);
|
await queryRunner.manager.query(sql, [order.numped, order.numped]);
|
||||||
|
|
||||||
sql =
|
sql = ` UPDATE PCPEDC SET ` +
|
||||||
` UPDATE PCPEDC SET ` +
|
|
||||||
` CODCOB = ( SELECT TV7.CODCOB FROM PCPEDC TV7 WHERE TV7.NUMPED = PCPEDC.NUMPEDENTFUT ) ` +
|
` CODCOB = ( SELECT TV7.CODCOB FROM PCPEDC TV7 WHERE TV7.NUMPED = PCPEDC.NUMPEDENTFUT ) ` +
|
||||||
` , CODPLPAG = ( SELECT TV7.CODPLPAG FROM PCPEDC TV7 WHERE TV7.NUMPED = PCPEDC.NUMPEDENTFUT ) ` +
|
` , CODPLPAG = ( SELECT TV7.CODPLPAG FROM PCPEDC TV7 WHERE TV7.NUMPED = PCPEDC.NUMPEDENTFUT ) ` +
|
||||||
` , RESERVAESTOQUETV7 = 'N' ` +
|
` , RESERVAESTOQUETV7 = 'N' ` +
|
||||||
|
|
@ -297,8 +265,7 @@ export class OrderService {
|
||||||
`WHERE (PCPEDC.NUMPEDENTFUT = :1 ) `;
|
`WHERE (PCPEDC.NUMPEDENTFUT = :1 ) `;
|
||||||
await queryRunner.manager.query(sql, [order.numped]);
|
await queryRunner.manager.query(sql, [order.numped]);
|
||||||
|
|
||||||
sql =
|
sql = ` UPDATE PCPEDI SET CODSUPERVISOR = ( SELECT PCPEDC.CODSUPERVISOR FROM PCPEDC WHERE PCPEDC.NUMPED = PCPEDI.NUMPED ) ` +
|
||||||
` UPDATE PCPEDI SET CODSUPERVISOR = ( SELECT PCPEDC.CODSUPERVISOR FROM PCPEDC WHERE PCPEDC.NUMPED = PCPEDI.NUMPED ) ` +
|
|
||||||
` ,DTENTREGA = ( SELECT PCPEDC.DTENTREGA FROM PCPEDC WHERE PCPEDI.NUMPED = PCPEDC.NUMPED ) ` +
|
` ,DTENTREGA = ( SELECT PCPEDC.DTENTREGA FROM PCPEDC WHERE PCPEDI.NUMPED = PCPEDC.NUMPED ) ` +
|
||||||
` ,COMPLEMENTO = NVL(( SELECT PCPEDITEMP.COMPLEMENTO FROM PCPEDITEMP, PCPEDCTEMP ` +
|
` ,COMPLEMENTO = NVL(( SELECT PCPEDITEMP.COMPLEMENTO FROM PCPEDITEMP, PCPEDCTEMP ` +
|
||||||
` WHERE PCPEDITEMP.NUMPEDRCA = PCPEDCTEMP.NUMPEDRCA ` +
|
` WHERE PCPEDITEMP.NUMPEDRCA = PCPEDCTEMP.NUMPEDRCA ` +
|
||||||
|
|
@ -316,11 +283,10 @@ export class OrderService {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
let status = '';
|
let status = '';
|
||||||
const statusOrder = await queryRunner.query(
|
const statusOrder = await queryRunner
|
||||||
'SELECT PCPEDC.POSICAO as "status" FROM PCPEDC WHERE NUMPED = :1',
|
.query('SELECT PCPEDC.POSICAO as "status" FROM PCPEDC WHERE NUMPED = :1', [order.numped]);
|
||||||
[order.numped],
|
|
||||||
);
|
|
||||||
switch (statusOrder[0].status) {
|
switch (statusOrder[0].status) {
|
||||||
case 'L': {
|
case 'L': {
|
||||||
status = 'LIBERADO';
|
status = 'LIBERADO';
|
||||||
|
|
@ -342,6 +308,7 @@ export class OrderService {
|
||||||
status = 'CANCELADO';
|
status = 'CANCELADO';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Sempre ira retornar status = LIBERADO*/
|
/* Sempre ira retornar status = LIBERADO*/
|
||||||
|
|
@ -349,7 +316,7 @@ export class OrderService {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
idOrder: order.numped,
|
idOrder: order.numped,
|
||||||
status: status,
|
status: status
|
||||||
};
|
};
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
|
|
@ -364,8 +331,7 @@ export class OrderService {
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateStatusItem(queryRunner: QueryRunner, orderId: number) {
|
async updateStatusItem(queryRunner: QueryRunner, orderId: number) {
|
||||||
const sql =
|
const sql = ` SELECT PCPEDI.ROWID as "rid", PCPEDI.NUMPED as "numped", PCPEDI.CODPROD as "codprod", PCPEDI.CODFILIALRETIRA as "codfilialretira", ` +
|
||||||
` SELECT PCPEDI.ROWID as "rid", PCPEDI.NUMPED as "numped", PCPEDI.CODPROD as "codprod", PCPEDI.CODFILIALRETIRA as "codfilialretira", ` +
|
|
||||||
` PCPEDI.QT as "qt", PCPEDI.POSICAO as "posicao", ` +
|
` PCPEDI.QT as "qt", PCPEDI.POSICAO as "posicao", ` +
|
||||||
` ( NVL(PCEST.QTESTGER,0) - NVL(PCEST.QTRESERV,0) - NVL(PCEST.QTBLOQUEADA,0) - NVL(PCEST.QTPENDENTE,0) + PCPEDI.QT ) as "qtestoque_disponivel" ` +
|
` ( NVL(PCEST.QTESTGER,0) - NVL(PCEST.QTRESERV,0) - NVL(PCEST.QTBLOQUEADA,0) - NVL(PCEST.QTPENDENTE,0) + PCPEDI.QT ) as "qtestoque_disponivel" ` +
|
||||||
` FROM PCPEDI, PCPEDC, PCEST, PCPEDC TV7 ` +
|
` FROM PCPEDI, PCPEDC, PCEST, PCPEDC TV7 ` +
|
||||||
|
|
@ -386,23 +352,19 @@ export class OrderService {
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateStockItem(queryRunner: QueryRunner, item: any) {
|
async updateStockItem(queryRunner: QueryRunner, item: any) {
|
||||||
let sql = '';
|
let sql = "";
|
||||||
if (item.posicao === 'B') {
|
if (item.posicao === "B") {
|
||||||
if (item.qt > item.qtestoque_disponivel) {
|
if (item.qt > item.qtestoque_disponivel) {
|
||||||
sql = `UPDATE PCPEDI SET POSICAO = 'P' ` + ` WHERE PCPEDI.ROWID = :1`;
|
sql = `UPDATE PCPEDI SET POSICAO = 'P' ` +
|
||||||
|
` WHERE PCPEDI.ROWID = :1`;
|
||||||
await queryRunner.manager.query(sql, [item.rid]);
|
await queryRunner.manager.query(sql, [item.rid]);
|
||||||
} else {
|
} else {
|
||||||
sql =
|
sql = `UPDATE PCEST SET QTPENDENTE = GREATEST((QTPENDENTE - :1), 0) ` +
|
||||||
`UPDATE PCEST SET QTPENDENTE = GREATEST((QTPENDENTE - :1), 0) ` +
|
|
||||||
` ,QTRESERV = QTRESERV + :2 ` +
|
` ,QTRESERV = QTRESERV + :2 ` +
|
||||||
` WHERE PCEST.CODFILIAL = :3 AND PCEST.CODPROD = :4`;
|
` WHERE PCEST.CODFILIAL = :3 AND PCEST.CODPROD = :4`;
|
||||||
await queryRunner.manager.query(sql, [
|
await queryRunner.manager.query(sql, [item.qt, item.qt, item.codfilialretira, item.codprod]);
|
||||||
item.qt,
|
sql = `UPDATE PCPEDI SET POSICAO = 'L' ` +
|
||||||
item.qt,
|
` WHERE PCPEDI.ROWID = :1`;
|
||||||
item.codfilialretira,
|
|
||||||
item.codprod,
|
|
||||||
]);
|
|
||||||
sql = `UPDATE PCPEDI SET POSICAO = 'L' ` + ` WHERE PCPEDI.ROWID = :1`;
|
|
||||||
await queryRunner.manager.query(sql, [item.rid]);
|
await queryRunner.manager.query(sql, [item.rid]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -427,9 +389,9 @@ export class OrderService {
|
||||||
codmotivo: null,
|
codmotivo: null,
|
||||||
motivoposicao: null,
|
motivoposicao: null,
|
||||||
vlbonific: 0,
|
vlbonific: 0,
|
||||||
vendaassistida: 'S',
|
vendaassistida: 'S'
|
||||||
})
|
})
|
||||||
.where('numped = :numped', { numped: orderDelivery.numped })
|
.where("numped = :numped", { numped: orderDelivery.numped })
|
||||||
.execute();
|
.execute();
|
||||||
await queryRunner.commitTransaction();
|
await queryRunner.commitTransaction();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
@ -452,14 +414,14 @@ export class OrderService {
|
||||||
.createQueryBuilder()
|
.createQueryBuilder()
|
||||||
.delete()
|
.delete()
|
||||||
.from(Pcpeditemp)
|
.from(Pcpeditemp)
|
||||||
.where('"PCPEDITEMP".NUMPEDRCA = :numpedrca', { numpedrca: idPreOrder })
|
.where("\"PCPEDITEMP\".NUMPEDRCA = :numpedrca", { numpedrca: idPreOrder })
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
await queryRunner.manager
|
await queryRunner.manager
|
||||||
.createQueryBuilder()
|
.createQueryBuilder()
|
||||||
.delete()
|
.delete()
|
||||||
.from(Pcpedctemp)
|
.from(Pcpedctemp)
|
||||||
.where('"PCPEDCTEMP".NUMPEDRCA = :numpedrca', { numpedrca: idPreOrder })
|
.where("\"PCPEDCTEMP\".NUMPEDRCA = :numpedrca", { numpedrca: idPreOrder })
|
||||||
.execute();
|
.execute();
|
||||||
await queryRunner.commitTransaction();
|
await queryRunner.commitTransaction();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
@ -471,11 +433,8 @@ export class OrderService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async createPreOrder(
|
async createPreOrder(cart: Cart, idPreOrder: number, idPreOrderTV7: number = null) {
|
||||||
cart: Cart,
|
|
||||||
idPreOrder: number,
|
|
||||||
idPreOrderTV7: number = null,
|
|
||||||
) {
|
|
||||||
const connection = new Connection(connectionOptions);
|
const connection = new Connection(connectionOptions);
|
||||||
await connection.connect();
|
await connection.connect();
|
||||||
const queryRunner = connection.createQueryRunner();
|
const queryRunner = connection.createQueryRunner();
|
||||||
|
|
@ -487,52 +446,36 @@ export class OrderService {
|
||||||
const customer = await this.getCustomer(cart.idCustomer);
|
const customer = await this.getCustomer(cart.idCustomer);
|
||||||
let idSellerPreorder = cart.idSeller;
|
let idSellerPreorder = cart.idSeller;
|
||||||
//Verifica se existe orçamento para a prevenda (CART)
|
//Verifica se existe orçamento para a prevenda (CART)
|
||||||
const cartPreOrder = await queryRunner.query(
|
const cartPreOrder = await queryRunner.query('SELECT ESTPREVENDAC.NUMORCA, PCORCAVENDAC.CODUSUR as "idSeller" ' +
|
||||||
'SELECT ESTPREVENDAC.NUMORCA, PCORCAVENDAC.CODUSUR as "idSeller" ' +
|
|
||||||
' FROM ESTPREVENDAC, PCORCAVENDAC ' +
|
' FROM ESTPREVENDAC, PCORCAVENDAC ' +
|
||||||
` WHERE ESTPREVENDAC.ID = '${cart.id}' ` +
|
` WHERE ESTPREVENDAC.ID = '${cart.id}' ` +
|
||||||
' AND ESTPREVENDAC.NUMORCA = PCORCAVENDAC.NUMORCA ',
|
' AND ESTPREVENDAC.NUMORCA = PCORCAVENDAC.NUMORCA ');
|
||||||
);
|
|
||||||
|
|
||||||
if (cartPreOrder != null && cartPreOrder.length > 0) {
|
if (cartPreOrder != null && cartPreOrder.length > 0) {
|
||||||
idSellerPreorder = cartPreOrder[0].idSeller;
|
idSellerPreorder = cartPreOrder[0].idSeller;
|
||||||
}
|
}
|
||||||
|
|
||||||
const supervisor = await queryRunner.manager.query(
|
const supervisor = await queryRunner.manager.query('SELECT PCUSUARI.CODSUPERVISOR FROM PCUSUARI WHERE CODUSUR = :1', [idSellerPreorder]);
|
||||||
'SELECT PCUSUARI.CODSUPERVISOR FROM PCUSUARI WHERE CODUSUR = :1',
|
|
||||||
[idSellerPreorder],
|
|
||||||
);
|
|
||||||
console.log(supervisor);
|
console.log(supervisor);
|
||||||
|
|
||||||
//Create pre-customers
|
//Create pre-customers
|
||||||
if (cart.idCustomer === 1 && cart.preCustomerDocument !== null) {
|
if (cart.idCustomer === 1 && cart.preCustomerDocument !== null) {
|
||||||
const preCustomer = await queryRunner.query(
|
const preCustomer = await queryRunner.query(`SELECT ESTVENDAPRECLIENTE.CPF FROM ESTVENDAPRECLIENTE ` +
|
||||||
`SELECT ESTVENDAPRECLIENTE.CPF FROM ESTVENDAPRECLIENTE ` +
|
` WHERE IDCART = :1 AND CPF = :2`, [cart.id, cart.preCustomerDocument]);
|
||||||
` WHERE IDCART = :1 AND CPF = :2`,
|
|
||||||
[cart.id, cart.preCustomerDocument],
|
|
||||||
);
|
|
||||||
if (preCustomer === null || preCustomer.length === 0) {
|
if (preCustomer === null || preCustomer.length === 0) {
|
||||||
const sqlInsert =
|
const sqlInsert = ` INSERT INTO ESTVENDAPRECLIENTE ( CPF, IDCART, NOME, TELEFONE, DTCADASTRO, CODUSUR, NUMPEDRCA ) ` +
|
||||||
` INSERT INTO ESTVENDAPRECLIENTE ( CPF, IDCART, NOME, TELEFONE, DTCADASTRO, CODUSUR, NUMPEDRCA ) ` +
|
|
||||||
` VALUES ( REGEXP_REPLACE(:CPF, '[^0-9]', '') , :IDCART, :NOME, :TELEFONE, SYSDATE, :CODUSUR, :NUMPEDRCA ) `;
|
` VALUES ( REGEXP_REPLACE(:CPF, '[^0-9]', '') , :IDCART, :NOME, :TELEFONE, SYSDATE, :CODUSUR, :NUMPEDRCA ) `;
|
||||||
await queryRunner.query(sqlInsert, [
|
await queryRunner.query(sqlInsert, [cart.preCustomerDocument,
|
||||||
cart.preCustomerDocument,
|
cart.id, cart.preCustomerName, cart.preCustomerPhone, cart.idSeller, idPreOrder]);
|
||||||
cart.id,
|
|
||||||
cart.preCustomerName,
|
|
||||||
cart.preCustomerPhone,
|
|
||||||
cart.idSeller,
|
|
||||||
idPreOrder,
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (cart.preCustomerDocument !== null) {
|
if (cart.preCustomerDocument !== null) {
|
||||||
await queryRunner.query(
|
await queryRunner.query(`DELETE FROM ESTVENDAPRECLIENTE WHERE IDCART = :1 AND REGEXP_REPLACE(:CPF, '[^0-9]', '')`,
|
||||||
`DELETE FROM ESTVENDAPRECLIENTE WHERE IDCART = :1 AND REGEXP_REPLACE(:CPF, '[^0-9]', '')`,
|
[cart.id, cart.preCustomerDocument]);
|
||||||
[cart.id, cart.preCustomerDocument],
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//#region create PCPEDCTEMP
|
//#region create PCPEDCTEMP
|
||||||
console.log('Cart: ' + cart);
|
console.log('Cart: ' + cart);
|
||||||
const dateNow = new Date();
|
const dateNow = new Date();
|
||||||
|
|
@ -558,18 +501,18 @@ export class OrderService {
|
||||||
preOrder.hora = preOrder.data.getHours();
|
preOrder.hora = preOrder.data.getHours();
|
||||||
preOrder.minuto = preOrder.data.getMinutes();
|
preOrder.minuto = preOrder.data.getMinutes();
|
||||||
preOrder.dtentrega = dateDelivery;
|
preOrder.dtentrega = dateDelivery;
|
||||||
(preOrder.codfilial = cart.saleStore),
|
preOrder.codfilial = cart.saleStore,
|
||||||
(preOrder.codfilialnf = preOrder.codfilial);
|
preOrder.codfilialnf = preOrder.codfilial;
|
||||||
preOrder.codusur = idSellerPreorder; // cart.idSeller;
|
preOrder.codusur = idSellerPreorder; // cart.idSeller;
|
||||||
if (supervisor != null) {
|
if (supervisor != null) {
|
||||||
preOrder.codsupervisor = supervisor.codsupervisor;
|
preOrder.codsupervisor = supervisor.codsupervisor;
|
||||||
}
|
}
|
||||||
preOrder.codemitente = cart.userId;
|
preOrder.codemitente = cart.userId;
|
||||||
preOrder.codusur3 = cart.idProfessional;
|
preOrder.codusur3 = cart.idProfessional;
|
||||||
preOrder.tipointegracao = 'W';
|
preOrder.tipointegracao = "W";
|
||||||
preOrder.validarnivelvenda = 'N';
|
preOrder.validarnivelvenda = "N";
|
||||||
preOrder.dtentrega = cart.shippingDate;
|
preOrder.dtentrega = cart.shippingDate;
|
||||||
preOrder.esc_tipoentrega = cart.scheduleDelivery === true ? 'P' : 'N';
|
preOrder.esc_tipoentrega = (cart.scheduleDelivery === true) ? 'P' : 'N';
|
||||||
// preOrder.vlfrete = cart.shippingValue; --Já esta sendo incluido item para o valor de frete
|
// preOrder.vlfrete = cart.shippingValue; --Já esta sendo incluido item para o valor de frete
|
||||||
preOrder.vldescontocupom = 0;
|
preOrder.vldescontocupom = 0;
|
||||||
preOrder.vldescontofinanceiro = 0;
|
preOrder.vldescontofinanceiro = 0;
|
||||||
|
|
@ -577,15 +520,15 @@ export class OrderService {
|
||||||
preOrder.vlfretenf = 0;
|
preOrder.vlfretenf = 0;
|
||||||
preOrder.vloutrasdesp = 0;
|
preOrder.vloutrasdesp = 0;
|
||||||
preOrder.vltroco = 0;
|
preOrder.vltroco = 0;
|
||||||
preOrder.origemped = 'W';
|
preOrder.origemped = "W";
|
||||||
preOrder.integradora = 10;
|
preOrder.integradora = 10;
|
||||||
preOrder.importado = 'N';
|
preOrder.importado = "N";
|
||||||
preOrder.codautorizacaotef = 0;
|
preOrder.codautorizacaotef = 0;
|
||||||
preOrder.esc_ajustarfinanceiro = 'N';
|
preOrder.esc_ajustarfinanceiro = "N";
|
||||||
preOrder.esc_obternsu = 'N';
|
preOrder.esc_obternsu = "N";
|
||||||
preOrder.esc_vloutrasdespweb = 0;
|
preOrder.esc_vloutrasdespweb = 0;
|
||||||
preOrder.pedidopagoecommerce = 'S';
|
preOrder.pedidopagoecommerce = "S";
|
||||||
preOrder.numpedmktplace = '';
|
preOrder.numpedmktplace = "";
|
||||||
preOrder.numitens = cart.itens.length;
|
preOrder.numitens = cart.itens.length;
|
||||||
preOrder.obs1 = cart.notation1;
|
preOrder.obs1 = cart.notation1;
|
||||||
preOrder.obs2 = cart.notation2;
|
preOrder.obs2 = cart.notation2;
|
||||||
|
|
@ -595,10 +538,7 @@ export class OrderService {
|
||||||
|
|
||||||
//Dados do cliente
|
//Dados do cliente
|
||||||
preOrder.codcli = cart.idCustomer;
|
preOrder.codcli = cart.idCustomer;
|
||||||
preOrder.codpraca =
|
preOrder.codpraca = (cart.shippingPriority == "M" && cart.idStorePlace != null ) ? cart.idStorePlace : customer.codpraca;
|
||||||
cart.shippingPriority == 'M' && cart.idStorePlace != null
|
|
||||||
? cart.idStorePlace
|
|
||||||
: customer.codpraca;
|
|
||||||
preOrder.fretedespacho = customer.fretedespacho;
|
preOrder.fretedespacho = customer.fretedespacho;
|
||||||
preOrder.codfornecfrete = cart.carrierId;
|
preOrder.codfornecfrete = cart.carrierId;
|
||||||
|
|
||||||
|
|
@ -612,8 +552,8 @@ export class OrderService {
|
||||||
|
|
||||||
let numeroSeq = 1;
|
let numeroSeq = 1;
|
||||||
for (const item of cart.itens) {
|
for (const item of cart.itens) {
|
||||||
const kit = await queryRunner.query(
|
|
||||||
'SELECT PCFORMPROD.CODPRODMP as "idProduct", ' +
|
const kit = await queryRunner.query('SELECT PCFORMPROD.CODPRODMP as "idProduct", ' +
|
||||||
' PCFORMPROD.QTPRODMP as "qtComponent", ' +
|
' PCFORMPROD.QTPRODMP as "qtComponent", ' +
|
||||||
' PCPRODUT.CODAUXILIAR as "ean" ,' +
|
' PCPRODUT.CODAUXILIAR as "ean" ,' +
|
||||||
` case when ESTLISTAPRODUTOS.PRECOPROMOCIONAL > 0 AND '${cart.idBilling}' <> 'CHM' THEN ` +
|
` case when ESTLISTAPRODUTOS.PRECOPROMOCIONAL > 0 AND '${cart.idBilling}' <> 'CHM' THEN ` +
|
||||||
|
|
@ -624,19 +564,17 @@ export class OrderService {
|
||||||
' AND PCFORMPROD.CODPRODMP = PCPRODUT.CODPROD ' +
|
' AND PCFORMPROD.CODPRODMP = PCPRODUT.CODPROD ' +
|
||||||
' AND PCPRODUT.CODPROD = ESTLISTAPRODUTOS.CODPROD ' +
|
' AND PCPRODUT.CODPROD = ESTLISTAPRODUTOS.CODPROD ' +
|
||||||
' AND ESTLISTAPRODUTOS.CODFILIAL = :2',
|
' AND ESTLISTAPRODUTOS.CODFILIAL = :2',
|
||||||
[item.idProduct, preOrder.codfilial],
|
[item.idProduct, preOrder.codfilial]);
|
||||||
);
|
|
||||||
if (kit.length > 0) {
|
if (kit.length > 0) {
|
||||||
for (const componente of kit) {
|
for (const componente of kit) {
|
||||||
|
|
||||||
const listPrice = componente.listPrice;
|
const listPrice = componente.listPrice;
|
||||||
|
|
||||||
const salePrice = (
|
const salePrice = (componente.listPrice *
|
||||||
componente.listPrice *
|
(item.salePrice / item.listPrice)).toFixed(2);
|
||||||
(item.salePrice / item.listPrice)
|
|
||||||
).toFixed(2);
|
|
||||||
|
|
||||||
const itemOrder = new Pcpeditemp();
|
const itemOrder = new Pcpeditemp();
|
||||||
itemOrder.tipointegracao = 'W';
|
itemOrder.tipointegracao = "W";
|
||||||
itemOrder.integradora = 10;
|
itemOrder.integradora = 10;
|
||||||
itemOrder.numpedrca = idPreOrder;
|
itemOrder.numpedrca = idPreOrder;
|
||||||
itemOrder.numpedweb = idPreOrder;
|
itemOrder.numpedweb = idPreOrder;
|
||||||
|
|
@ -646,15 +584,14 @@ export class OrderService {
|
||||||
itemOrder.codprod = componente.idProduct;
|
itemOrder.codprod = componente.idProduct;
|
||||||
itemOrder.codauxiliar = componente.ean;
|
itemOrder.codauxiliar = componente.ean;
|
||||||
itemOrder.codfilialretira = item.idStock;
|
itemOrder.codfilialretira = item.idStock;
|
||||||
itemOrder.tipoentrega =
|
itemOrder.tipoentrega = (item.deliveryMethod == 'RA') ? "RP" : item.deliveryMethod;
|
||||||
item.deliveryMethod == 'RA' ? 'RP' : item.deliveryMethod;
|
itemOrder.rp_imediata = (item.deliveryMethod == 'RA') ? "S" : "N";
|
||||||
itemOrder.rp_imediata = item.deliveryMethod == 'RA' ? 'S' : 'N';
|
|
||||||
if ( item.deliveryMethod == 'RA') {
|
if ( item.deliveryMethod == 'RA') {
|
||||||
preOrder.dtentrega = new Date();
|
preOrder.dtentrega = new Date();
|
||||||
}
|
}
|
||||||
itemOrder.ptabela = Number.parseFloat(listPrice);
|
itemOrder.ptabela = Number.parseFloat(listPrice);
|
||||||
itemOrder.pvenda = Number.parseFloat(salePrice);
|
itemOrder.pvenda = Number.parseFloat(salePrice);
|
||||||
itemOrder.qt = item.quantity * componente.qtComponent;
|
itemOrder.qt = (item.quantity * componente.qtComponent);
|
||||||
itemOrder.data = new Date();
|
itemOrder.data = new Date();
|
||||||
itemOrder.complemento = item.descriptionAux;
|
itemOrder.complemento = item.descriptionAux;
|
||||||
itemOrder.localizacao = item.environment;
|
itemOrder.localizacao = item.environment;
|
||||||
|
|
@ -667,10 +604,10 @@ export class OrderService {
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
numeroSeq = numeroSeq + 1;
|
numeroSeq = numeroSeq + 1;
|
||||||
}
|
};
|
||||||
} else {
|
} else {
|
||||||
const itemOrder = new Pcpeditemp();
|
const itemOrder = new Pcpeditemp();
|
||||||
itemOrder.tipointegracao = 'W';
|
itemOrder.tipointegracao = "W";
|
||||||
itemOrder.integradora = 10;
|
itemOrder.integradora = 10;
|
||||||
itemOrder.numpedrca = idPreOrder;
|
itemOrder.numpedrca = idPreOrder;
|
||||||
itemOrder.numpedweb = idPreOrder;
|
itemOrder.numpedweb = idPreOrder;
|
||||||
|
|
@ -680,9 +617,8 @@ export class OrderService {
|
||||||
itemOrder.codprod = item.idProduct;
|
itemOrder.codprod = item.idProduct;
|
||||||
itemOrder.codauxiliar = item.ean;
|
itemOrder.codauxiliar = item.ean;
|
||||||
itemOrder.codfilialretira = item.idStock;
|
itemOrder.codfilialretira = item.idStock;
|
||||||
itemOrder.tipoentrega =
|
itemOrder.tipoentrega = (item.deliveryMethod == 'RA') ? "RP" : item.deliveryMethod;
|
||||||
item.deliveryMethod == 'RA' ? 'RP' : item.deliveryMethod;
|
itemOrder.rp_imediata = (item.deliveryMethod == 'RA') ? "S" : "N";
|
||||||
itemOrder.rp_imediata = item.deliveryMethod == 'RA' ? 'S' : 'N';
|
|
||||||
if ( item.deliveryMethod == 'RA') {
|
if ( item.deliveryMethod == 'RA') {
|
||||||
preOrder.dtentrega = new Date();
|
preOrder.dtentrega = new Date();
|
||||||
}
|
}
|
||||||
|
|
@ -701,6 +637,7 @@ export class OrderService {
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
numeroSeq = numeroSeq + 1;
|
numeroSeq = numeroSeq + 1;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -708,7 +645,7 @@ export class OrderService {
|
||||||
|
|
||||||
if (cart.shippingValue > 0) {
|
if (cart.shippingValue > 0) {
|
||||||
const itemOrder = new Pcpeditemp();
|
const itemOrder = new Pcpeditemp();
|
||||||
itemOrder.tipointegracao = 'W';
|
itemOrder.tipointegracao = "W";
|
||||||
itemOrder.integradora = 10;
|
itemOrder.integradora = 10;
|
||||||
itemOrder.numpedrca = idPreOrder;
|
itemOrder.numpedrca = idPreOrder;
|
||||||
itemOrder.numpedweb = idPreOrder;
|
itemOrder.numpedweb = idPreOrder;
|
||||||
|
|
@ -724,6 +661,7 @@ export class OrderService {
|
||||||
itemOrder.qt = 1;
|
itemOrder.qt = 1;
|
||||||
itemOrder.data = new Date();
|
itemOrder.data = new Date();
|
||||||
|
|
||||||
|
|
||||||
await queryRunner.manager
|
await queryRunner.manager
|
||||||
.createQueryBuilder()
|
.createQueryBuilder()
|
||||||
.insert()
|
.insert()
|
||||||
|
|
@ -744,6 +682,7 @@ export class OrderService {
|
||||||
|
|
||||||
await queryRunner.commitTransaction();
|
await queryRunner.commitTransaction();
|
||||||
return preOrder;
|
return preOrder;
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
await queryRunner.rollbackTransaction();
|
await queryRunner.rollbackTransaction();
|
||||||
throw err;
|
throw err;
|
||||||
|
|
@ -751,6 +690,8 @@ export class OrderService {
|
||||||
await queryRunner.release();
|
await queryRunner.release();
|
||||||
await connection.close();
|
await connection.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async findSale(id: string) {
|
async findSale(id: string) {
|
||||||
|
|
@ -762,7 +703,7 @@ export class OrderService {
|
||||||
const sale = await queryRunner.manager
|
const sale = await queryRunner.manager
|
||||||
.getRepository(Sale)
|
.getRepository(Sale)
|
||||||
.createQueryBuilder('estvenda')
|
.createQueryBuilder('estvenda')
|
||||||
.where('"estvenda".id = :id', { id: id })
|
.where("\"estvenda\".id = :id", { id: id })
|
||||||
.getOne();
|
.getOne();
|
||||||
return sale;
|
return sale;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
@ -783,7 +724,7 @@ export class OrderService {
|
||||||
const shopping = await queryRunner.manager
|
const shopping = await queryRunner.manager
|
||||||
.getRepository(ShoppingItens)
|
.getRepository(ShoppingItens)
|
||||||
.createQueryBuilder('estshopping')
|
.createQueryBuilder('estshopping')
|
||||||
.where('"estshopping".id = :id', { id: idshopping })
|
.where("\"estshopping\".id = :id", { id: idshopping })
|
||||||
.getMany();
|
.getMany();
|
||||||
return shopping;
|
return shopping;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
@ -801,8 +742,7 @@ export class OrderService {
|
||||||
const queryRunner = connection.createQueryRunner();
|
const queryRunner = connection.createQueryRunner();
|
||||||
await queryRunner.connect();
|
await queryRunner.connect();
|
||||||
console.log('Consultando usuario ' + idSeller);
|
console.log('Consultando usuario ' + idSeller);
|
||||||
let sql =
|
let sql = 'SELECT NVL(PROXNUMPEDWEB,0) as "proxnumpedweb" FROM PCUSUARI ' +
|
||||||
'SELECT NVL(PROXNUMPEDWEB,0) as "proxnumpedweb" FROM PCUSUARI ' +
|
|
||||||
' WHERE PCUSUARI.CODUSUR = :1 FOR UPDATE';
|
' WHERE PCUSUARI.CODUSUR = :1 FOR UPDATE';
|
||||||
const seller = await queryRunner.query(sql, [idSeller]);
|
const seller = await queryRunner.query(sql, [idSeller]);
|
||||||
|
|
||||||
|
|
@ -812,21 +752,27 @@ export class OrderService {
|
||||||
await queryRunner.startTransaction();
|
await queryRunner.startTransaction();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
sql =
|
|
||||||
'UPDATE PCUSUARI SET PROXNUMPEDWEB = NVL(PROXNUMPEDWEB,0) + 1 ' +
|
sql = 'UPDATE PCUSUARI SET PROXNUMPEDWEB = NVL(PROXNUMPEDWEB,0) + 1 ' +
|
||||||
' WHERE PCUSUARI.CODUSUR = :1';
|
' WHERE PCUSUARI.CODUSUR = :1';
|
||||||
await queryRunner.query(sql, [idSeller]);
|
await queryRunner.query(sql, [idSeller]);
|
||||||
|
|
||||||
|
|
||||||
await queryRunner.commitTransaction();
|
await queryRunner.commitTransaction();
|
||||||
return idOrder;
|
return idOrder;
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
||||||
await queryRunner.rollbackTransaction();
|
await queryRunner.rollbackTransaction();
|
||||||
console.log(err);
|
console.log(err);
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
|
|
||||||
await queryRunner.release();
|
await queryRunner.release();
|
||||||
await connection.close();
|
await connection.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async getCustomer(idCustomer: number) {
|
async getCustomer(idCustomer: number) {
|
||||||
|
|
@ -838,7 +784,7 @@ export class OrderService {
|
||||||
const customer = await queryRunner.manager
|
const customer = await queryRunner.manager
|
||||||
.getRepository(Pcclient)
|
.getRepository(Pcclient)
|
||||||
.createQueryBuilder('pcclient')
|
.createQueryBuilder('pcclient')
|
||||||
.where('"pcclient".codcli = :idCustomer', { idCustomer })
|
.where("\"pcclient\".codcli = :idCustomer", { idCustomer })
|
||||||
.getOne();
|
.getOne();
|
||||||
return customer;
|
return customer;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
@ -850,15 +796,8 @@ export class OrderService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async getOrders(
|
async getOrders(store: string, initialDate: Date, finalDate: Date,
|
||||||
store: string,
|
document: string, name: string, sellerId: number, idOrder: string) {
|
||||||
initialDate: Date,
|
|
||||||
finalDate: Date,
|
|
||||||
document: string,
|
|
||||||
name: string,
|
|
||||||
sellerId: number,
|
|
||||||
idOrder: string,
|
|
||||||
) {
|
|
||||||
const connection = new Connection(connectionOptions);
|
const connection = new Connection(connectionOptions);
|
||||||
await connection.connect();
|
await connection.connect();
|
||||||
const queryRunner = connection.createQueryRunner();
|
const queryRunner = connection.createQueryRunner();
|
||||||
|
|
@ -867,8 +806,8 @@ export class OrderService {
|
||||||
let sql = '';
|
let sql = '';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
sql =
|
|
||||||
` SELECT TO_CHAR(PCPEDC.DATA, \'DD/MM/YYYY\') as "createDate" ` +
|
sql = ` SELECT TO_CHAR(PCPEDC.DATA, \'DD/MM/YYYY\') as "createDate" ` +
|
||||||
` ,PCPEDC.NUMPED as "orderId" ` +
|
` ,PCPEDC.NUMPED as "orderId" ` +
|
||||||
` ,PCPEDC.CODFILIAL as "store" ` +
|
` ,PCPEDC.CODFILIAL as "store" ` +
|
||||||
` ,CASE WHEN PCPEDC.POSICAO = 'B' THEN 'BLOQUEADO' ` +
|
` ,CASE WHEN PCPEDC.POSICAO = 'B' THEN 'BLOQUEADO' ` +
|
||||||
|
|
@ -894,10 +833,7 @@ export class OrderService {
|
||||||
sqlWhere += ` AND REGEXP_REPLACE(PCCLIENT.CGCENT, '[^0-9]', '') = REGEXP_REPLACE('${document}', '[^0-9]', '')`;
|
sqlWhere += ` AND REGEXP_REPLACE(PCCLIENT.CGCENT, '[^0-9]', '') = REGEXP_REPLACE('${document}', '[^0-9]', '')`;
|
||||||
}
|
}
|
||||||
if (name != null && name != '') {
|
if (name != null && name != '') {
|
||||||
sqlWhere += ` AND PCCLIENT.CLIENTE LIKE '${name.replace(
|
sqlWhere += ` AND PCCLIENT.CLIENTE LIKE '${name.replace('@', '%')}'||'%'`;
|
||||||
'@',
|
|
||||||
'%',
|
|
||||||
)}'||'%'`;
|
|
||||||
}
|
}
|
||||||
if (sellerId > 0) {
|
if (sellerId > 0) {
|
||||||
sqlWhere += ` AND PCPEDC.CODUSUR = ${sellerId} `;
|
sqlWhere += ` AND PCPEDC.CODUSUR = ${sellerId} `;
|
||||||
|
|
@ -909,14 +845,14 @@ export class OrderService {
|
||||||
//tratamento de data//
|
//tratamento de data//
|
||||||
const startDate = new Date(initialDate);
|
const startDate = new Date(initialDate);
|
||||||
let day = startDate.getDate();
|
let day = startDate.getDate();
|
||||||
let month = ('00' + (startDate.getMonth() + 1)).slice(-2);
|
let month = ("00" + (startDate.getMonth() + 1)).slice(-2);
|
||||||
let year = startDate.getFullYear();
|
let year = startDate.getFullYear();
|
||||||
const startFormat = day + '/' + month + '/' + year;
|
const startFormat = day + "/" + month + "/" + year;
|
||||||
const endDate = new Date(finalDate);
|
const endDate = new Date(finalDate);
|
||||||
day = endDate.getDate();
|
day = endDate.getDate();
|
||||||
month = ('00' + (endDate.getMonth() + 1)).slice(-2);
|
month = ("00" + (endDate.getMonth() + 1)).slice(-2);
|
||||||
year = endDate.getFullYear();
|
year = endDate.getFullYear();
|
||||||
const endFormat = day + '/' + month + '/' + year;
|
const endFormat = day + "/" + month + "/" + year;
|
||||||
|
|
||||||
sqlWhere += ` AND PCPEDC.DATA BETWEEN TO_DATE('${startFormat}', 'DD/MM/YYYY') AND TO_DATE('${endFormat}', 'DD/MM/YYYY') `;
|
sqlWhere += ` AND PCPEDC.DATA BETWEEN TO_DATE('${startFormat}', 'DD/MM/YYYY') AND TO_DATE('${endFormat}', 'DD/MM/YYYY') `;
|
||||||
|
|
||||||
|
|
@ -929,8 +865,10 @@ export class OrderService {
|
||||||
await queryRunner.release();
|
await queryRunner.release();
|
||||||
await connection.close();
|
await connection.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async getItensOrder(idOrder: number) {
|
async getItensOrder(idOrder: number) {
|
||||||
const connection = new Connection(connectionOptions);
|
const connection = new Connection(connectionOptions);
|
||||||
await connection.connect();
|
await connection.connect();
|
||||||
|
|
@ -939,8 +877,8 @@ export class OrderService {
|
||||||
let sql = '';
|
let sql = '';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
sql =
|
|
||||||
` SELECT PCPEDI.CODPROD as "productId", PCPRODUT.DESCRICAO as "description", ` +
|
sql = ` SELECT PCPEDI.CODPROD as "productId", PCPRODUT.DESCRICAO as "description", ` +
|
||||||
` PCPRODUT.EMBALAGEM as "package", ` +
|
` PCPRODUT.EMBALAGEM as "package", ` +
|
||||||
` ( SELECT PCPEDITEMP.COMPLEMENTO FROM PCPEDITEMP ` +
|
` ( SELECT PCPEDITEMP.COMPLEMENTO FROM PCPEDITEMP ` +
|
||||||
` WHERE PCPEDC.NUMPEDRCA = PCPEDITEMP.NUMPEDRCA ` +
|
` WHERE PCPEDC.NUMPEDRCA = PCPEDITEMP.NUMPEDRCA ` +
|
||||||
|
|
@ -967,6 +905,7 @@ export class OrderService {
|
||||||
await queryRunner.release();
|
await queryRunner.release();
|
||||||
await connection.close();
|
await connection.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async getCartId(orderId: number) {
|
async getCartId(orderId: number) {
|
||||||
|
|
@ -975,8 +914,7 @@ export class OrderService {
|
||||||
const queryRunner = connection.createQueryRunner();
|
const queryRunner = connection.createQueryRunner();
|
||||||
await queryRunner.connect();
|
await queryRunner.connect();
|
||||||
try {
|
try {
|
||||||
const order = await queryRunner.query(
|
const order = await queryRunner.query('SELECT PCPEDC.DATA as "createDate" ' +
|
||||||
'SELECT PCPEDC.DATA as "createDate" ' +
|
|
||||||
' ,PCPEDC.NUMPED as "orderId" ' +
|
' ,PCPEDC.NUMPED as "orderId" ' +
|
||||||
' ,PCPEDC.CODFILIAL as "invoiceStore" ' +
|
' ,PCPEDC.CODFILIAL as "invoiceStore" ' +
|
||||||
' ,PCPEDC.CODCLI as "customerId" ' +
|
' ,PCPEDC.CODCLI as "customerId" ' +
|
||||||
|
|
@ -986,6 +924,7 @@ export class OrderService {
|
||||||
' ,PCPEDC.CODUSUR3 as "partnerId" ' +
|
' ,PCPEDC.CODUSUR3 as "partnerId" ' +
|
||||||
' ,ESTPREVENDAC.ID as "cartId" ' +
|
' ,ESTPREVENDAC.ID as "cartId" ' +
|
||||||
' ,PCPEDC.POSICAO as "status" ' +
|
' ,PCPEDC.POSICAO as "status" ' +
|
||||||
|
|
||||||
' ,PCPEDC.OBS as "notification" ' +
|
' ,PCPEDC.OBS as "notification" ' +
|
||||||
' ,PCPEDC.OBS1 as "notification1" ' +
|
' ,PCPEDC.OBS1 as "notification1" ' +
|
||||||
' ,PCPEDC.OBS2 as "notification2" ' +
|
' ,PCPEDC.OBS2 as "notification2" ' +
|
||||||
|
|
@ -997,64 +936,35 @@ export class OrderService {
|
||||||
` ,NVL(PCPEDC.TIPOPRIORIDADEENTREGA, 'B') as "priorityDelivery" ` +
|
` ,NVL(PCPEDC.TIPOPRIORIDADEENTREGA, 'B') as "priorityDelivery" ` +
|
||||||
' FROM PCPEDC, ESTPREVENDAC ' +
|
' FROM PCPEDC, ESTPREVENDAC ' +
|
||||||
' WHERE PCPEDC.NUMPED = ESTPREVENDAC.NUMPED ' +
|
' WHERE PCPEDC.NUMPED = ESTPREVENDAC.NUMPED ' +
|
||||||
' AND PCPEDC.NUMPED = :1',
|
' AND PCPEDC.NUMPED = :1', [orderId]);
|
||||||
[orderId],
|
|
||||||
);
|
|
||||||
|
|
||||||
if (order.length == 0) {
|
if (order.length == 0) {
|
||||||
throw new HttpException(
|
throw new HttpException(`Pedido não foi localizado`, HttpStatus.NOT_FOUND);
|
||||||
`Pedido não foi localizado`,
|
|
||||||
HttpStatus.NOT_FOUND,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (order.status == 'F') {
|
if (order.status == 'F') {
|
||||||
throw new HttpException(
|
throw new HttpException(`Pedido já FATURADO, alteração não permitida.`, HttpStatus.NOT_FOUND);
|
||||||
`Pedido já FATURADO, alteração não permitida.`,
|
|
||||||
HttpStatus.NOT_FOUND,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const invoiceStores = await this.listsService.GetStoreAll();
|
const invoiceStores = await this.listsService.GetStoreAll();
|
||||||
const invoiceStore = await invoiceStores.find(
|
const invoiceStore = await invoiceStores.find(data => data.id === order[0].invoiceStore);
|
||||||
data => data.id === order[0].invoiceStore,
|
const customer = await this.customerService.findCustomerById(order[0].customerId);
|
||||||
);
|
|
||||||
const customer = await this.customerService.findCustomerById(
|
|
||||||
order[0].customerId,
|
|
||||||
);
|
|
||||||
const billinds = await this.listsService.GetBilling(order[0].customerId);
|
const billinds = await this.listsService.GetBilling(order[0].customerId);
|
||||||
const partners = await this.listsService.GetPartners();
|
const partners = await this.listsService.GetPartners();
|
||||||
const address = await this.addressCustomerService.getAddress(
|
const address = await this.addressCustomerService.getAddress(order[0].customerId, order[0].addressId);
|
||||||
order[0].customerId,
|
|
||||||
order[0].addressId,
|
|
||||||
);
|
|
||||||
const billing = billinds.find(data => data.codcob === order[0].billindId);
|
const billing = billinds.find(data => data.codcob === order[0].billindId);
|
||||||
const paymentPlans = await this.listsService.GetPaymentPlan(
|
const paymentPlans = await this.listsService.GetPaymentPlan(billing.codcob);
|
||||||
billing.codcob,
|
const paymentPlan = paymentPlans.find(data => data.codplpag === order[0].paymentPlanId);
|
||||||
);
|
|
||||||
const paymentPlan = paymentPlans.find(
|
|
||||||
data => data.codplpag === order[0].paymentPlanId,
|
|
||||||
);
|
|
||||||
const partner = partners.find(data => data.id === order[0].partnerId);
|
const partner = partners.find(data => data.id === order[0].partnerId);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
cartId: order[0].cartId,
|
cartId: order[0].cartId, invoiceStore: invoiceStore, customer: customer, partner: partner,
|
||||||
invoiceStore: invoiceStore,
|
paymentPlan: paymentPlan, billing: billing, address: address,
|
||||||
customer: customer,
|
notification: order[0].notification, notification1: order[0].notification1, notification2: order[0].notification2,
|
||||||
partner: partner,
|
notificationDelivery1: order[0].notificationDelivery1, notificationDelivery2: order[0].notificationDelivery2, notificationDelivery3: order[0].notificationDelivery3,
|
||||||
paymentPlan: paymentPlan,
|
deliveryDate: order[0].deliveryDate, squeduleDelivery: order[0].esc_tipoEntrega == 'P' ? true : false, priorityDelivery: order[0].priorityDelivery
|
||||||
billing: billing,
|
}
|
||||||
address: address,
|
|
||||||
notification: order[0].notification,
|
|
||||||
notification1: order[0].notification1,
|
|
||||||
notification2: order[0].notification2,
|
|
||||||
notificationDelivery1: order[0].notificationDelivery1,
|
|
||||||
notificationDelivery2: order[0].notificationDelivery2,
|
|
||||||
notificationDelivery3: order[0].notificationDelivery3,
|
|
||||||
deliveryDate: order[0].deliveryDate,
|
|
||||||
squeduleDelivery: order[0].esc_tipoEntrega == 'P' ? true : false,
|
|
||||||
priorityDelivery: order[0].priorityDelivery,
|
|
||||||
};
|
|
||||||
} finally {
|
} finally {
|
||||||
await queryRunner.release();
|
await queryRunner.release();
|
||||||
await connection.close();
|
await connection.close();
|
||||||
|
|
@ -1062,31 +972,25 @@ export class OrderService {
|
||||||
}
|
}
|
||||||
|
|
||||||
async createPreCustomer(cart: Cart) {
|
async createPreCustomer(cart: Cart) {
|
||||||
|
|
||||||
const connection = new Connection(connectionOptions);
|
const connection = new Connection(connectionOptions);
|
||||||
await connection.connect();
|
await connection.connect();
|
||||||
const queryRunner = connection.createQueryRunner();
|
const queryRunner = connection.createQueryRunner();
|
||||||
await queryRunner.connect();
|
await queryRunner.connect();
|
||||||
await queryRunner.startTransaction();
|
await queryRunner.startTransaction();
|
||||||
try {
|
try {
|
||||||
const preCustomer = await queryRunner.query(
|
const preCustomer = await queryRunner.query(`SELECT ESTVENDAPRECLIENTE.CPF FROM ESTVENDAPRECLIENTE ` +
|
||||||
`SELECT ESTVENDAPRECLIENTE.CPF FROM ESTVENDAPRECLIENTE ` +
|
` WHERE IDCART = :1 AND CPF = :2`, [cart.id, cart.preCustomerDocument]);
|
||||||
` WHERE IDCART = :1 AND CPF = :2`,
|
|
||||||
[cart.id, cart.preCustomerDocument],
|
|
||||||
);
|
|
||||||
if (preCustomer.length === 0) {
|
if (preCustomer.length === 0) {
|
||||||
const sqlInsert =
|
const sqlInsert = ` INSERT INTO ESTVENDAPRECLIENTE ( CPF, IDCART, NOME, TELEFONE, DTCADASTRO, CODUSUR ) ` +
|
||||||
` INSERT INTO ESTVENDAPRECLIENTE ( CPF, IDCART, NOME, TELEFONE, DTCADASTRO, CODUSUR ) ` +
|
|
||||||
` VALUES ( REGEXP_REPLACE(:CPF, '[^0-9]', '') , :IDCART, :NOME, :TELEFONE, SYSDATE, :CODUSUR ) `;
|
` VALUES ( REGEXP_REPLACE(:CPF, '[^0-9]', '') , :IDCART, :NOME, :TELEFONE, SYSDATE, :CODUSUR ) `;
|
||||||
await queryRunner.query(sqlInsert, [
|
await queryRunner.query(sqlInsert, [cart.preCustomerDocument,
|
||||||
cart.preCustomerDocument,
|
cart.id, cart.preCustomerName, cart.preCustomerPhone, cart.idSeller]);
|
||||||
cart.id,
|
|
||||||
cart.preCustomerName,
|
|
||||||
cart.preCustomerPhone,
|
|
||||||
cart.idSeller,
|
|
||||||
]);
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
}
|
}
|
||||||
await queryRunner.commitTransaction();
|
await queryRunner.commitTransaction();
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
await queryRunner.rollbackTransaction();
|
await queryRunner.rollbackTransaction();
|
||||||
console.log(err);
|
console.log(err);
|
||||||
|
|
@ -1097,8 +1001,7 @@ export class OrderService {
|
||||||
}
|
}
|
||||||
|
|
||||||
async productsWithoutTax(idCart: string, idCustomer: number) {
|
async productsWithoutTax(idCart: string, idCustomer: number) {
|
||||||
const sql =
|
const sql = ' SELECT ESTPREVENDAI.CODPROD as "productId", PCPRODUT.DESCRICAO as "description", ' +
|
||||||
' SELECT ESTPREVENDAI.CODPROD as "productId", PCPRODUT.DESCRICAO as "description", ' +
|
|
||||||
' PCPRODUT.EMBALAGEM as "package", PCCLIENT.ESTENT as "uf" ' +
|
' PCPRODUT.EMBALAGEM as "package", PCCLIENT.ESTENT as "uf" ' +
|
||||||
' FROM ESTPREVENDAI, ESTPREVENDAC, PCCLIENT, PCPRODUT ' +
|
' FROM ESTPREVENDAI, ESTPREVENDAC, PCCLIENT, PCPRODUT ' +
|
||||||
' WHERE ESTPREVENDAI.IDCART = ESTPREVENDAC.ID ' +
|
' WHERE ESTPREVENDAI.IDCART = ESTPREVENDAC.ID ' +
|
||||||
|
|
@ -1125,8 +1028,8 @@ export class OrderService {
|
||||||
}
|
}
|
||||||
|
|
||||||
async OrderRetiraPosterior() {
|
async OrderRetiraPosterior() {
|
||||||
const sql =
|
|
||||||
' SELECT ' +
|
const sql = ' SELECT ' +
|
||||||
' p.DATA as "data" ' +
|
' p.DATA as "data" ' +
|
||||||
' ,p.numped as "orderId" ' +
|
' ,p.numped as "orderId" ' +
|
||||||
` ,TO_CHAR(p.datapedido, 'DD/MM/YYYY HH24:MI') as "orderDate" ` +
|
` ,TO_CHAR(p.datapedido, 'DD/MM/YYYY HH24:MI') as "orderDate" ` +
|
||||||
|
|
@ -1140,7 +1043,6 @@ export class OrderService {
|
||||||
' ,round( trunc(sysdate-p.DATAPEDIDO) * 24 + (sysdate-p.DATAPEDIDO - trunc(sysdate-p.DATAPEDIDO)) * 24) as "timeHour" ' +
|
' ,round( trunc(sysdate-p.DATAPEDIDO) * 24 + (sysdate-p.DATAPEDIDO - trunc(sysdate-p.DATAPEDIDO)) * 24) as "timeHour" ' +
|
||||||
' ,round(( ( trunc(sysdate-p.DATAPEDIDO) * 24 + (sysdate-p.DATAPEDIDO - trunc(sysdate-p.DATAPEDIDO)) * 24) - ' +
|
' ,round(( ( trunc(sysdate-p.DATAPEDIDO) * 24 + (sysdate-p.DATAPEDIDO - trunc(sysdate-p.DATAPEDIDO)) * 24) - ' +
|
||||||
' TRUNC(( trunc(sysdate-p.DATAPEDIDO) * 24 + (sysdate-p.DATAPEDIDO - trunc(sysdate-p.DATAPEDIDO)) * 24)) ) * 60,0) as "timeMinute" ' +
|
' TRUNC(( trunc(sysdate-p.DATAPEDIDO) * 24 + (sysdate-p.DATAPEDIDO - trunc(sysdate-p.DATAPEDIDO)) * 24)) ) * 60,0) as "timeMinute" ' +
|
||||||
' ,p.codfilial as "storeId" ' +
|
|
||||||
' FROM esvpedidoretiraposterior p ' +
|
' FROM esvpedidoretiraposterior p ' +
|
||||||
' ORDER BY p.datapedido ';
|
' ORDER BY p.datapedido ';
|
||||||
|
|
||||||
|
|
@ -1155,19 +1057,15 @@ export class OrderService {
|
||||||
await queryRunner.release();
|
await queryRunner.release();
|
||||||
await connection.close();
|
await connection.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async getProductsOrder(
|
async getProductsOrder(store: string, initialDate: Date, finalDate: Date,
|
||||||
store: string,
|
document: string, name: string, sellerId: number, idOrder: string,
|
||||||
initialDate: Date,
|
typeFilterProduct: string, productText: string
|
||||||
finalDate: Date,
|
|
||||||
document: string,
|
|
||||||
name: string,
|
|
||||||
sellerId: number,
|
|
||||||
idOrder: string,
|
|
||||||
typeFilterProduct: string,
|
|
||||||
productText: string,
|
|
||||||
) {
|
) {
|
||||||
|
|
||||||
const sql = `SELECT PCPEDC.DATA as "date"
|
const sql = `SELECT PCPEDC.DATA as "date"
|
||||||
,PCPEDC.NUMPED as "orderId"
|
,PCPEDC.NUMPED as "orderId"
|
||||||
,PCPEDC.NUMNOTA as "invoice"
|
,PCPEDC.NUMNOTA as "invoice"
|
||||||
|
|
@ -1211,10 +1109,7 @@ export class OrderService {
|
||||||
sqlWhere += ` AND REGEXP_REPLACE(PCCLIENT.CGCENT, '[^0-9]', '') = REGEXP_REPLACE('${document}', '[^0-9]', '')`;
|
sqlWhere += ` AND REGEXP_REPLACE(PCCLIENT.CGCENT, '[^0-9]', '') = REGEXP_REPLACE('${document}', '[^0-9]', '')`;
|
||||||
}
|
}
|
||||||
if (name != null && name != '') {
|
if (name != null && name != '') {
|
||||||
sqlWhere += ` AND PCCLIENT.CLIENTE LIKE '${name.replace(
|
sqlWhere += ` AND PCCLIENT.CLIENTE LIKE '${name.replace('@', '%')}'||'%'`;
|
||||||
'@',
|
|
||||||
'%',
|
|
||||||
)}'||'%'`;
|
|
||||||
}
|
}
|
||||||
if (sellerId > 0) {
|
if (sellerId > 0) {
|
||||||
sqlWhere += ` AND PCPEDC.CODUSUR = ${sellerId} `;
|
sqlWhere += ` AND PCPEDC.CODUSUR = ${sellerId} `;
|
||||||
|
|
@ -1237,25 +1132,25 @@ export class OrderService {
|
||||||
case 'PARTNER':
|
case 'PARTNER':
|
||||||
sqlWhere += ` AND PCPRODUT.CODFAB like '${productText}%'`;
|
sqlWhere += ` AND PCPRODUT.CODFAB like '${productText}%'`;
|
||||||
break;
|
break;
|
||||||
default:
|
default: break;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//tratamento de data//
|
//tratamento de data//
|
||||||
const startDate = new Date(initialDate);
|
const startDate = new Date(initialDate);
|
||||||
let day = startDate.getDate();
|
let day = startDate.getDate();
|
||||||
let month = ('00' + (startDate.getMonth() + 1)).slice(-2);
|
let month = ("00" + (startDate.getMonth() + 1)).slice(-2);
|
||||||
let year = startDate.getFullYear();
|
let year = startDate.getFullYear();
|
||||||
const startFormat = day + '/' + month + '/' + year;
|
const startFormat = day + "/" + month + "/" + year;
|
||||||
const endDate = new Date(finalDate);
|
const endDate = new Date(finalDate);
|
||||||
day = endDate.getDate();
|
day = endDate.getDate();
|
||||||
month = ('00' + (endDate.getMonth() + 1)).slice(-2);
|
month = ("00" + (endDate.getMonth() + 1)).slice(-2);
|
||||||
year = endDate.getFullYear();
|
year = endDate.getFullYear();
|
||||||
const endFormat = day + '/' + month + '/' + year;
|
const endFormat = day + "/" + month + "/" + year;
|
||||||
|
|
||||||
sqlWhere += ` AND PCPEDI.DATA BETWEEN TO_DATE('${startFormat}', 'DD/MM/YYYY') AND TO_DATE('${endFormat}', 'DD/MM/YYYY') `;
|
sqlWhere += ` AND PCPEDI.DATA BETWEEN TO_DATE('${startFormat}', 'DD/MM/YYYY') AND TO_DATE('${endFormat}', 'DD/MM/YYYY') `;
|
||||||
|
|
||||||
|
|
||||||
const connection = new Connection(connectionOptions);
|
const connection = new Connection(connectionOptions);
|
||||||
await connection.connect();
|
await connection.connect();
|
||||||
const queryRunner = connection.createQueryRunner();
|
const queryRunner = connection.createQueryRunner();
|
||||||
|
|
@ -1268,4 +1163,5 @@ export class OrderService {
|
||||||
await connection.close();
|
await connection.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,19 @@
|
||||||
import { HttpException, HttpStatus, Inject, Injectable } from '@nestjs/common';
|
import { Injectable, HttpException, HttpStatus, Inject, CACHE_MANAGER } from '@nestjs/common';
|
||||||
import { Connection } from 'typeorm';
|
|
||||||
import { connectionOptions } from '../../configs/typeorm.config';
|
|
||||||
import { Estavisoestoque } from '../../domain/entity/tables/estavisoestoque.entity';
|
|
||||||
import { Estruptura } from '../../domain/entity/tables/estruptura.entity';
|
|
||||||
import { Pcclient } from '../../domain/entity/tables/pcclient.entity';
|
import { Pcclient } from '../../domain/entity/tables/pcclient.entity';
|
||||||
import { Esvanalisevendarca } from '../../domain/entity/views/esvanalisevendarca.entity';
|
|
||||||
import { Esvdepartamento } from '../../domain/entity/views/esvdepartamento.entity';
|
|
||||||
import { Esvparcelamentovenda } from '../../domain/entity/views/esvparcelamentovenda.entity';
|
|
||||||
import { SalesProduct } from '../../domain/entity/views/esvprodutosvenda.entity';
|
import { SalesProduct } from '../../domain/entity/views/esvprodutosvenda.entity';
|
||||||
import { Esvsecao } from '../../domain/entity/views/esvsecao.entity';
|
import { Connection, getConnection } from 'typeorm';
|
||||||
import { Esvsituacaopedido } from '../../domain/entity/views/esvsituacaopedido.entity';
|
import { Esvsituacaopedido } from '../../domain/entity/views/esvsituacaopedido.entity';
|
||||||
|
import { Stock } from '../../domain/entity/views/esvestoquevenda.entity';
|
||||||
import { FilterProduct } from '../../domain/models/filter-product.model';
|
import { FilterProduct } from '../../domain/models/filter-product.model';
|
||||||
import { Notify } from '../../domain/models/notify.model';
|
import { Notify } from '../../domain/models/notify.model';
|
||||||
|
import { Estavisoestoque } from '../../domain/entity/tables/estavisoestoque.entity';
|
||||||
|
import { Esvparcelamentovenda } from '../../domain/entity/views/esvparcelamentovenda.entity';
|
||||||
import { Rupture } from '../../domain/models/rupture.model';
|
import { Rupture } from '../../domain/models/rupture.model';
|
||||||
|
import { Estruptura } from '../../domain/entity/tables/estruptura.entity';
|
||||||
|
import { Esvsecao } from '../../domain/entity/views/esvsecao.entity';
|
||||||
|
import { Esvdepartamento } from '../../domain/entity/views/esvdepartamento.entity';
|
||||||
|
import { Esvanalisevendarca } from '../../domain/entity/views/esvanalisevendarca.entity';
|
||||||
|
import { connectionOptions } from '../../configs/typeorm.config';
|
||||||
import { CustomerService } from '../customer/customer.service';
|
import { CustomerService } from '../customer/customer.service';
|
||||||
import Redis = require('ioredis');
|
import Redis = require('ioredis');
|
||||||
|
|
||||||
|
|
@ -953,12 +954,9 @@ export class SalesService {
|
||||||
WHERE PCFILIALRETIRA.CODFILIALVENDA = '${storeId}'
|
WHERE PCFILIALRETIRA.CODFILIALVENDA = '${storeId}'
|
||||||
AND PCFILIALRETIRA.CODFILIALRETIRA = ESVESTOQUEVENDA.CODFILIAL ) > 0 THEN 1
|
AND PCFILIALRETIRA.CODFILIALRETIRA = ESVESTOQUEVENDA.CODFILIAL ) > 0 THEN 1
|
||||||
ELSE 0 END ) as "allowDelivery"
|
ELSE 0 END ) as "allowDelivery"
|
||||||
, NVL(PCEST.QTEXPOSICAO,0) as "exhibition"
|
FROM ESVESTOQUEVENDA, PCFILIAL
|
||||||
FROM ESVESTOQUEVENDA, PCFILIAL, PCEST
|
|
||||||
WHERE ESVESTOQUEVENDA.CODPROD = ${id}
|
WHERE ESVESTOQUEVENDA.CODPROD = ${id}
|
||||||
AND ESVESTOQUEVENDA.CODFILIAL = PCFILIAL.CODIGO
|
AND ESVESTOQUEVENDA.CODFILIAL = PCFILIAL.CODIGO
|
||||||
AND ESVESTOQUEVENDA.CODFILIAL = PCEST.CODFILIAL
|
|
||||||
AND ESVESTOQUEVENDA.CODPROD = PCEST.CODPROD
|
|
||||||
ORDER BY TO_NUMBER(ESVESTOQUEVENDA.CODFILIAL) `;
|
ORDER BY TO_NUMBER(ESVESTOQUEVENDA.CODFILIAL) `;
|
||||||
|
|
||||||
const stock = await queryRunner.query(sql);
|
const stock = await queryRunner.query(sql);
|
||||||
|
|
@ -1470,7 +1468,6 @@ export class SalesService {
|
||||||
.query(sql, [cityId, cartId]);
|
.query(sql, [cityId, cartId]);
|
||||||
return deliveryTaxTable;
|
return deliveryTaxTable;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(err);
|
|
||||||
throw err;
|
throw err;
|
||||||
} finally {
|
} finally {
|
||||||
await queryRunner.release();
|
await queryRunner.release();
|
||||||
|
|
@ -1505,20 +1502,7 @@ export class SalesService {
|
||||||
}
|
}
|
||||||
|
|
||||||
async calculateDeliveryTaxOrder(dataDeliveryTax: any) {
|
async calculateDeliveryTaxOrder(dataDeliveryTax: any) {
|
||||||
console.log("json dataDeliveryTax", dataDeliveryTax);
|
let cityId = await this.customerService.findCity(dataDeliveryTax.ibgeCode);
|
||||||
/*const dataDeliveryTax = {
|
|
||||||
cartId: cartId,
|
|
||||||
cityId: cityId,
|
|
||||||
ibgeCode: ibgeCode,
|
|
||||||
priorityDelivery: priorityDelivery,
|
|
||||||
};*/
|
|
||||||
|
|
||||||
let cityId = 0;
|
|
||||||
if (dataDeliveryTax.ibgeCode) {
|
|
||||||
cityId = await this.customerService.findCity(dataDeliveryTax.ibgeCode);
|
|
||||||
} else {
|
|
||||||
cityId = dataDeliveryTax.cityId;
|
|
||||||
}
|
|
||||||
await this.updatePriorityDelivery(dataDeliveryTax.cartId, dataDeliveryTax.priorityDelivery);
|
await this.updatePriorityDelivery(dataDeliveryTax.cartId, dataDeliveryTax.priorityDelivery);
|
||||||
|
|
||||||
if (cityId == 0) {
|
if (cityId == 0) {
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,6 @@ import { OrderDiscount } from 'src/domain/models/order-discount.model';
|
||||||
import { OrderTaxDelivery } from 'src/domain/models/order-taxdelivery.model';
|
import { OrderTaxDelivery } from 'src/domain/models/order-taxdelivery.model';
|
||||||
import { LogOrder } from 'src/domain/models/log-order.model';
|
import { LogOrder } from 'src/domain/models/log-order.model';
|
||||||
import { ApiTags } from '@nestjs/swagger';
|
import { ApiTags } from '@nestjs/swagger';
|
||||||
import { Cart } from 'src/domain/models/cart.model';
|
|
||||||
import { CartUpdate } from 'src/domain/models/cart-update.model';
|
|
||||||
|
|
||||||
@ApiTags('Shopping')
|
@ApiTags('Shopping')
|
||||||
@Controller('api/v1/shopping')
|
@Controller('api/v1/shopping')
|
||||||
|
|
@ -84,19 +82,6 @@ export class ShoppingController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Put('cart')
|
|
||||||
async updateCart(@Body() cart: CartUpdate) {
|
|
||||||
try {
|
|
||||||
if (cart.id == null) {
|
|
||||||
throw new HttpException('Cart sem Id informado, faça a inclusão do item no carrinho.', HttpStatus.BAD_REQUEST);
|
|
||||||
}
|
|
||||||
const updateCart = await this.shoppingService.updateShopping(cart);
|
|
||||||
return updateCart;
|
|
||||||
} catch (error) {
|
|
||||||
throw new HttpException(error.message, HttpStatus.BAD_REQUEST);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Post('log')
|
@Post('log')
|
||||||
async logOrderShopping(@Body() logOrder: LogOrder){
|
async logOrderShopping(@Body() logOrder: LogOrder){
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,6 @@ import { Shopping } from 'src/domain/entity/tables/estprevendac.entity';
|
||||||
import { OrderTaxDelivery } from 'src/domain/models/order-taxdelivery.model';
|
import { OrderTaxDelivery } from 'src/domain/models/order-taxdelivery.model';
|
||||||
import { connectionOptions } from 'src/configs/typeorm.config';
|
import { connectionOptions } from 'src/configs/typeorm.config';
|
||||||
import { LogOrder } from 'src/domain/models/log-order.model';
|
import { LogOrder } from 'src/domain/models/log-order.model';
|
||||||
import { Cart } from 'src/domain/models/cart.model';
|
|
||||||
import { CartUpdate } from 'src/domain/models/cart-update.model';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ShoppingService {
|
export class ShoppingService {
|
||||||
|
|
@ -301,58 +299,6 @@ export class ShoppingService {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateShopping(cart: CartUpdate) {
|
|
||||||
const connectionDb = new Connection(connectionOptions);
|
|
||||||
await connectionDb.connect();
|
|
||||||
const queryRunner = connectionDb.createQueryRunner();
|
|
||||||
await queryRunner.connect();
|
|
||||||
await queryRunner.startTransaction();
|
|
||||||
|
|
||||||
try {
|
|
||||||
const sqlUpdate = `UPDATE ESTPREVENDAC SET
|
|
||||||
CODFILIAL = :1,
|
|
||||||
CODUSUR = :2,
|
|
||||||
CODCLI = :3,
|
|
||||||
CODENDENTCLI = :4,
|
|
||||||
VLPEDIDO = :5,
|
|
||||||
VLDESCONTO = :6,
|
|
||||||
VLTAXAENTREGA = :7,
|
|
||||||
TIPOPRIORIDADEENTREGA = :8
|
|
||||||
WHERE ID = :9
|
|
||||||
`;
|
|
||||||
|
|
||||||
const total = await queryRunner.query('SELECT SUM(ESTPREVENDAI.PTABELA * ESTPREVENDAI.QT) as "vltabela" ' +
|
|
||||||
' ,SUM(ESTPREVENDAI.PVENDA * ESTPREVENDAI.QT) as "vlatend" ' +
|
|
||||||
' ,SUM(ESTPREVENDAI.VLDESCONTO * ESTPREVENDAI.QT) as "vldesconto" ' +
|
|
||||||
' ,SUM(PCPRODUT.PESOBRUTO * ESTPREVENDAI.QT) as "totpeso" ' +
|
|
||||||
' FROM ESTPREVENDAI, PCPRODUT ' +
|
|
||||||
' WHERE ESTPREVENDAI.CODPROD = PCPRODUT.CODPROD ' +
|
|
||||||
' AND ESTPREVENDAI.IDCART = :1', [cart.id]);
|
|
||||||
|
|
||||||
await queryRunner.query(sqlUpdate, [
|
|
||||||
cart.saleStore,
|
|
||||||
cart.userId,
|
|
||||||
cart.idCustomer,
|
|
||||||
cart.idAddress,
|
|
||||||
total[0].vlatend,
|
|
||||||
total[0].vldesconto,
|
|
||||||
cart.shippingValue,
|
|
||||||
cart.shippingPriority,
|
|
||||||
cart.id
|
|
||||||
]);
|
|
||||||
|
|
||||||
await queryRunner.commitTransaction();
|
|
||||||
|
|
||||||
return cart;
|
|
||||||
} catch (error) {
|
|
||||||
await queryRunner.rollbackTransaction();
|
|
||||||
throw error;
|
|
||||||
} finally {
|
|
||||||
await queryRunner.release();
|
|
||||||
await connectionDb.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async updateTotalShopping(idCart: string) {
|
async updateTotalShopping(idCart: string) {
|
||||||
const connection = new Connection(connectionOptions);
|
const connection = new Connection(connectionOptions);
|
||||||
await connection.connect();
|
await connection.connect();
|
||||||
|
|
|
||||||
|
|
@ -13,9 +13,7 @@
|
||||||
"paths": {
|
"paths": {
|
||||||
"src/*": ["./src/*"]
|
"src/*": ["./src/*"]
|
||||||
},
|
},
|
||||||
"incremental": true,
|
"incremental": true
|
||||||
"skipLibCheck": true,
|
|
||||||
"strict": false
|
|
||||||
},
|
},
|
||||||
"exclude": ["node_modules", "dist"]
|
"exclude": ["node_modules", "dist"]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue