feat: Add new sales and shopping cart management module.
All checks were successful
Build (develop) / Promote (main) / build-and-push-deploy (push) Successful in 1m45s
All checks were successful
Build (develop) / Promote (main) / build-and-push-deploy (push) Successful in 1m45s
This commit is contained in:
@@ -1613,7 +1613,7 @@ export class SalesService {
|
|||||||
// const sql = `SELECT ESF_CALCULAR_PRAZO_ENTREGA(TO_DATE('${saleDate}', 'DD-MM-YYYY')) AS "days" FROM DUAL`;
|
// const sql = `SELECT ESF_CALCULAR_PRAZO_ENTREGA(TO_DATE('${saleDate}', 'DD-MM-YYYY')) AS "days" FROM DUAL`;
|
||||||
const timeDays = await queryRunner.query(sql);
|
const timeDays = await queryRunner.query(sql);
|
||||||
|
|
||||||
const sqlRetiraPosterior = `SELECT ( PROXIMO_DIA_UTIL(TO_DATE('${saleDate}', 'DD-MM-YYYY'), '4') - TRUNC(SYSDATE) ) AS "days" FROM DUAL`;
|
const sqlRetiraPosterior = `SELECT ( PROXIMO_DIA_UTIL(TO_DATE('${saleDate}', 'DD-MM-YYYY'), '1') - TRUNC(SYSDATE) ) AS "days" FROM DUAL`;
|
||||||
const timeDaysRetiraPosterior = await queryRunner.query(sqlRetiraPosterior);
|
const timeDaysRetiraPosterior = await queryRunner.query(sqlRetiraPosterior);
|
||||||
|
|
||||||
return { deliveryDays: timeDays[0].days, retiraPosteriorDays: timeDaysRetiraPosterior[0].days };
|
return { deliveryDays: timeDays[0].days, retiraPosteriorDays: timeDaysRetiraPosterior[0].days };
|
||||||
|
|||||||
@@ -6,15 +6,16 @@ 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';
|
||||||
|
|
||||||
@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 +28,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) {
|
||||||
@@ -39,15 +40,24 @@ export class ShoppingController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Put('cart')
|
||||||
|
async updateCart(@Body() cart: Cart) {
|
||||||
|
try {
|
||||||
|
return await this.shoppingService.updateShopping(cart);
|
||||||
|
} catch (error) {
|
||||||
|
throw new HttpException(error.message, HttpStatus.BAD_REQUEST);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@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 +67,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 +83,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);
|
||||||
@@ -83,7 +93,7 @@ export class ShoppingController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@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 +103,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 +117,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 +152,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 +175,4 @@ export class ShoppingController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ 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';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ShoppingService {
|
export class ShoppingService {
|
||||||
@@ -167,7 +168,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -605,6 +606,39 @@ export class ShoppingService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async updateShopping(shopping: any) {
|
||||||
|
const connection = new Connection(connectionOptions);
|
||||||
|
await connection.connect();
|
||||||
|
const queryRunner = connection.createQueryRunner();
|
||||||
|
await queryRunner.connect();
|
||||||
|
try {
|
||||||
|
console.log(JSON.stringify(shopping));
|
||||||
|
const sql = `UPDATE ESTPREVENDAC
|
||||||
|
SET ESTPREVENDAC.CODCLI = :codcli
|
||||||
|
,ESTPREVENDAC.codendentcli = :codendentcli
|
||||||
|
,ESTPREVENDAC.codplpag = :codplpag
|
||||||
|
,ESTPREVENDAC.codcob = :codcob
|
||||||
|
,ESTPREVENDAC.codfilial = :codfilial
|
||||||
|
WHERE ID = :id `;
|
||||||
|
|
||||||
|
await queryRunner.query(sql, [
|
||||||
|
shopping.codcli,
|
||||||
|
shopping.codendentcli,
|
||||||
|
shopping.codplpag,
|
||||||
|
shopping.codcob,
|
||||||
|
shopping.saleStore,
|
||||||
|
shopping.id
|
||||||
|
]);
|
||||||
|
|
||||||
|
return shopping;
|
||||||
|
} catch (error) {
|
||||||
|
throw error;
|
||||||
|
} finally {
|
||||||
|
await queryRunner.release();
|
||||||
|
await connection.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async updatePriceShopping(idCart: string, idPaymentPlan: number) {
|
async updatePriceShopping(idCart: string, idPaymentPlan: number) {
|
||||||
const connection = new Connection(connectionOptions);
|
const connection = new Connection(connectionOptions);
|
||||||
await connection.connect();
|
await connection.connect();
|
||||||
|
|||||||
Reference in New Issue
Block a user