Novo calculo de taxa de entrega para MOSQUEIRO
This commit is contained in:
parent
94fcbe9b39
commit
c062b65a35
|
|
@ -36,7 +36,7 @@ export class Shopping {
|
||||||
@Column({ name: 'VLDESCONTO' })
|
@Column({ name: 'VLDESCONTO' })
|
||||||
vldesconto: number;
|
vldesconto: number;
|
||||||
|
|
||||||
@Column({name: 'VLCUSTOFIN'})
|
@Column({ name: 'VLCUSTOFIN' })
|
||||||
vlcustofin: number;
|
vlcustofin: number;
|
||||||
|
|
||||||
@Column({ name: 'CODFUNCAUTOR' })
|
@Column({ name: 'CODFUNCAUTOR' })
|
||||||
|
|
@ -60,4 +60,7 @@ export class Shopping {
|
||||||
@Column({ name: 'CODTABELAFRETE' })
|
@Column({ name: 'CODTABELAFRETE' })
|
||||||
codtabelafrete: number;
|
codtabelafrete: number;
|
||||||
|
|
||||||
|
@Column({ name: 'CODPRACA' })
|
||||||
|
codpraca: number;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
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,
|
||||||
|
) { }
|
||||||
|
}
|
||||||
|
|
@ -23,7 +23,7 @@ export class SalesService {
|
||||||
constructor(
|
constructor(
|
||||||
@Inject('REDIS_CLIENT') private readonly redisClient: Redis.Redis,
|
@Inject('REDIS_CLIENT') private readonly redisClient: Redis.Redis,
|
||||||
private readonly customerService: CustomerService
|
private readonly customerService: CustomerService
|
||||||
) {}
|
) { }
|
||||||
|
|
||||||
|
|
||||||
async GetProducts2(store: string, pageSize: number, pageNumber: number, filter: FilterProduct = null,) {
|
async GetProducts2(store: string, pageSize: number, pageNumber: number, filter: FilterProduct = null,) {
|
||||||
|
|
@ -1468,6 +1468,7 @@ 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();
|
||||||
|
|
@ -1502,7 +1503,20 @@ export class SalesService {
|
||||||
}
|
}
|
||||||
|
|
||||||
async calculateDeliveryTaxOrder(dataDeliveryTax: any) {
|
async calculateDeliveryTaxOrder(dataDeliveryTax: any) {
|
||||||
let cityId = await this.customerService.findCity(dataDeliveryTax.ibgeCode);
|
console.log("json dataDeliveryTax", dataDeliveryTax);
|
||||||
|
/*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,15 +6,17 @@ 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')
|
||||||
export class ShoppingController {
|
export class ShoppingController {
|
||||||
|
|
||||||
constructor(private shoppingService: ShoppingService){}
|
constructor(private shoppingService: ShoppingService) { }
|
||||||
|
|
||||||
@Get('cart/:id')
|
@Get('cart/:id')
|
||||||
async getCart(@Param('id') id: string){
|
async getCart(@Param('id') id: string) {
|
||||||
try {
|
try {
|
||||||
const cart = await this.shoppingService.GetItensCart(id);
|
const cart = await this.shoppingService.GetItensCart(id);
|
||||||
if (cart == null || cart.length == 0)
|
if (cart == null || cart.length == 0)
|
||||||
|
|
@ -27,10 +29,10 @@ export class ShoppingController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get(':id')
|
@Get(':id')
|
||||||
async getPreVenda(@Param('id') id: string ){
|
async getPreVenda(@Param('id') id: string) {
|
||||||
try {
|
try {
|
||||||
const cart = await this.shoppingService.getShopping(id);
|
const cart = await this.shoppingService.getShopping(id);
|
||||||
if (cart == null )
|
if (cart == null)
|
||||||
throw new HttpException("Carrinho de compras não encontrado", HttpStatus.NOT_FOUND);
|
throw new HttpException("Carrinho de compras não encontrado", HttpStatus.NOT_FOUND);
|
||||||
return cart;
|
return cart;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
@ -41,13 +43,13 @@ export class ShoppingController {
|
||||||
|
|
||||||
@Get('cart/:idcart/item/:idProduct/tipoentrega/:deliveryType')
|
@Get('cart/:idcart/item/:idProduct/tipoentrega/:deliveryType')
|
||||||
async getItemCart(@Req() request, @Param('idCart') idCart: string,
|
async getItemCart(@Req() request, @Param('idCart') idCart: string,
|
||||||
@Param('idProduct') idProduct: string, @Param('deliveryType') deliveryType: string){
|
@Param('idProduct') idProduct: string, @Param('deliveryType') deliveryType: string) {
|
||||||
let store = '99';
|
let store = '99';
|
||||||
try {
|
try {
|
||||||
if (request.headers['x-store'])
|
if (request.headers['x-store'])
|
||||||
store = request.headers['x-store'];
|
store = request.headers['x-store'];
|
||||||
const cart = await this.shoppingService.getItemCart(idCart, idProduct, store, deliveryType);
|
const cart = await this.shoppingService.getItemCart(idCart, idProduct, store, deliveryType);
|
||||||
if (cart == null )
|
if (cart == null)
|
||||||
throw new HttpException("Item não foi encontrado no carrinho de compras.", HttpStatus.NOT_FOUND);
|
throw new HttpException("Item não foi encontrado no carrinho de compras.", HttpStatus.NOT_FOUND);
|
||||||
return cart;
|
return cart;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
@ -57,8 +59,8 @@ export class ShoppingController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get('cart/lot/:productId/:customerId')
|
@Get('cart/lot/:productId/:customerId')
|
||||||
async getLotProduct( @Req() request, @Param('productId') productId: number,
|
async getLotProduct(@Req() request, @Param('productId') productId: number,
|
||||||
@Param('customerId') customerId: number ) {
|
@Param('customerId') customerId: number) {
|
||||||
let store = '99';
|
let store = '99';
|
||||||
try {
|
try {
|
||||||
if (request.headers['x-store'])
|
if (request.headers['x-store'])
|
||||||
|
|
@ -73,7 +75,7 @@ export class ShoppingController {
|
||||||
|
|
||||||
|
|
||||||
@Post('item')
|
@Post('item')
|
||||||
async createItemShopping(@Body() item: ShoppingItem){
|
async createItemShopping(@Body() item: ShoppingItem) {
|
||||||
console.log('createItemShopping')
|
console.log('createItemShopping')
|
||||||
try {
|
try {
|
||||||
return await this.shoppingService.createItemCart(item);
|
return await this.shoppingService.createItemCart(item);
|
||||||
|
|
@ -82,8 +84,21 @@ 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 {
|
||||||
console.log('logOrderShopping')
|
console.log('logOrderShopping')
|
||||||
return await this.shoppingService.createLogShopping(logOrder);
|
return await this.shoppingService.createLogShopping(logOrder);
|
||||||
|
|
@ -93,10 +108,10 @@ export class ShoppingController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Put('item')
|
@Put('item')
|
||||||
async updateQuantityItem(@Body() item: ShoppingItem){
|
async updateQuantityItem(@Body() item: ShoppingItem) {
|
||||||
console.log(item);
|
console.log(item);
|
||||||
try {
|
try {
|
||||||
if (item.id == null){
|
if (item.id == null) {
|
||||||
throw new HttpException('Item sem Id informado, faça a inclusão do item no carrinho.', HttpStatus.BAD_REQUEST);
|
throw new HttpException('Item sem Id informado, faça a inclusão do item no carrinho.', HttpStatus.BAD_REQUEST);
|
||||||
}
|
}
|
||||||
const itemCreate = await this.shoppingService.updateItem(item);
|
const itemCreate = await this.shoppingService.updateItem(item);
|
||||||
|
|
@ -107,10 +122,10 @@ export class ShoppingController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Put('item/discount')
|
@Put('item/discount')
|
||||||
async updatePriceItem(@Body() item: ShoppingItem){
|
async updatePriceItem(@Body() item: ShoppingItem) {
|
||||||
console.log(item);
|
console.log(item);
|
||||||
try {
|
try {
|
||||||
if (item.id == null){
|
if (item.id == null) {
|
||||||
throw new HttpException('Item sem Id informado, faça a inclusão do item no carrinho.', HttpStatus.BAD_REQUEST);
|
throw new HttpException('Item sem Id informado, faça a inclusão do item no carrinho.', HttpStatus.BAD_REQUEST);
|
||||||
}
|
}
|
||||||
const itemCreate = await this.shoppingService.updatePrice(item);
|
const itemCreate = await this.shoppingService.updatePrice(item);
|
||||||
|
|
@ -142,7 +157,7 @@ export class ShoppingController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Delete('item/delete/:id')
|
@Delete('item/delete/:id')
|
||||||
async deleteItem(@Param('id') id: string){
|
async deleteItem(@Param('id') id: string) {
|
||||||
try {
|
try {
|
||||||
await this.shoppingService.deleteItem(id);
|
await this.shoppingService.deleteItem(id);
|
||||||
return new ResultModel(true, 'Item excluído com sucesso!', id, null,);
|
return new ResultModel(true, 'Item excluído com sucesso!', id, null,);
|
||||||
|
|
@ -165,4 +180,4 @@ export class ShoppingController {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,8 @@ 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 {
|
||||||
|
|
@ -167,7 +169,7 @@ export class ShoppingService {
|
||||||
AND E.CODFILIAL = '${itemShopping.stockStore}'`);
|
AND E.CODFILIAL = '${itemShopping.stockStore}'`);
|
||||||
|
|
||||||
let quantityStock = 0;
|
let quantityStock = 0;
|
||||||
if ( dataStockItem.length > 0 ) {
|
if (dataStockItem.length > 0) {
|
||||||
quantityStock = dataStockItem[0].quantityStock;
|
quantityStock = dataStockItem[0].quantityStock;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -299,6 +301,58 @@ 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();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue