commit
8ddc4147f6
@ -0,0 +1 @@ |
|||||||
|
node_modules |
@ -0,0 +1,94 @@ |
|||||||
|
var config = require('../config/dbconfig') |
||||||
|
const sql = require('mssql') |
||||||
|
|
||||||
|
async function getRptControlDocumentosClientes() { |
||||||
|
try { |
||||||
|
let pool = await sql.connect(config) |
||||||
|
let reporte = await pool |
||||||
|
.request() |
||||||
|
.query("SELECT * FROM ReportesDocsSir WHERE Estatus='Activo'") |
||||||
|
return reporte.recordset |
||||||
|
} catch (error) { |
||||||
|
console.log(error) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
async function getNoPartesAmazon(id) { |
||||||
|
try { |
||||||
|
let pool = await sql.connect(config) |
||||||
|
const result = await pool |
||||||
|
.request() |
||||||
|
.input('id', id) |
||||||
|
.execute(`[Clientes.Amazon.Invoice.NoPartes2Excel.Get]`) |
||||||
|
//const NoPartesSIR = result.recordset;
|
||||||
|
console.log(result.recordset) |
||||||
|
return result.recordset |
||||||
|
} catch (error) { |
||||||
|
console.log(error) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
async function getExceptionsFile4Amazon(id) { |
||||||
|
try { |
||||||
|
let pool = await sql.connect(config) |
||||||
|
const result = await pool |
||||||
|
.request() |
||||||
|
.input('id', id) |
||||||
|
.execute(`[Clientes.Amazon.Invoice.ExceptionsFile.Get]`) |
||||||
|
console.log(result.recordset) |
||||||
|
return result.recordset |
||||||
|
} catch (error) { |
||||||
|
console.log(error) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
async function getAmazonInvoiceDetail(id) { |
||||||
|
try { |
||||||
|
let pool = await sql.connect(config) |
||||||
|
const result = await pool |
||||||
|
.request() |
||||||
|
.input('id', id)
|
||||||
|
.query(`SELECT ItemId,ItemDescription, ItemQuantityUnitOfMeasure, CountryOfOrigin,Quantity,WeightValue, ActualUnitCostMonetaryAmount, TotalUnitValueMonetaryAmount FROM [Clientes.Amazon.Invoice.Detail] WHERE IdHeader = @id`) |
||||||
|
console.log(result.recordset) |
||||||
|
return result.recordset |
||||||
|
} catch (error) { |
||||||
|
console.log(error) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
async function getAmazonInvoiceShipmentInfo(id) { |
||||||
|
try { |
||||||
|
let pool = await sql.connect(config) |
||||||
|
const result = await pool |
||||||
|
.request() |
||||||
|
.input('id', id) |
||||||
|
.query(`SELECT * FROM [Clientes.Amazon.Invoice.ShipFromAddress] WHERE IdHeader = @id and (AddressType = 'SELLER' or AddressType = 'BILLER')`) |
||||||
|
console.log(result.recordset) |
||||||
|
return result.recordset |
||||||
|
} catch (error) { |
||||||
|
console.log(error) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
async function getAmazonInvoiceHeader(id) { |
||||||
|
try { |
||||||
|
let pool = await sql.connect(config) |
||||||
|
const result = await pool |
||||||
|
.request() |
||||||
|
.input('id', id) |
||||||
|
.query(`SELECT * FROM [Clientes.Amazon.Invoice.Header] WHERE id = @id`) |
||||||
|
console.log(result.recordset) |
||||||
|
return result.recordset |
||||||
|
} catch (error) { |
||||||
|
console.log(error) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
module.exports = { |
||||||
|
getRptControlDocumentosClientes: getRptControlDocumentosClientes, |
||||||
|
getNoPartesAmazon: getNoPartesAmazon, |
||||||
|
getExceptionsFile4Amazon: getExceptionsFile4Amazon, |
||||||
|
getAmazonInvoiceDetail: getAmazonInvoiceDetail, |
||||||
|
getAmazonInvoiceShipmentInfo: getAmazonInvoiceShipmentInfo, |
||||||
|
getAmazonInvoiceHeader: getAmazonInvoiceHeader |
||||||
|
} |
@ -0,0 +1,88 @@ |
|||||||
|
const express = require('express'); |
||||||
|
var html_to_pdf = require('html-pdf-node'); |
||||||
|
const report = require("puppeteer-report"); |
||||||
|
//import puppeteer from "puppeteer";
|
||||||
|
const puppeteer = require('puppeteer') |
||||||
|
var Reportes = require('./Repository/Reportes'); |
||||||
|
const app = express() |
||||||
|
let options = { format: 'A4' }; |
||||||
|
const port = 9091 |
||||||
|
|
||||||
|
app.set('view engine', 'ejs') |
||||||
|
const user = { |
||||||
|
firstName: 'Tim', |
||||||
|
lastName: 'Cook', |
||||||
|
} |
||||||
|
|
||||||
|
app.get('/', (req, res) => { |
||||||
|
Reportes.getAmazonInvoicePDF(req.query.id).then((InvoiceDetail) => { |
||||||
|
//res.status(200).send(data);
|
||||||
|
res.render('pages/AmazonInvoice', { |
||||||
|
user: user, |
||||||
|
InvoiceDetail: InvoiceDetail |
||||||
|
}) |
||||||
|
}) |
||||||
|
}) |
||||||
|
|
||||||
|
app.get('/Invoice', async (req, res) => { |
||||||
|
const InvoiceDetail = await Reportes.getAmazonInvoiceDetail(req.query.id).then((InvoiceDetail) => { |
||||||
|
return InvoiceDetail |
||||||
|
}) |
||||||
|
const InvoiceShipmentInfo = await Reportes.getAmazonInvoiceShipmentInfo(req.query.id).then((InvoiceShipmentInfo) => { |
||||||
|
return InvoiceShipmentInfo |
||||||
|
}) |
||||||
|
const InvoiceHeader = await Reportes.getAmazonInvoiceHeader(req.query.id).then((InvoiceHeader) => { |
||||||
|
return InvoiceHeader |
||||||
|
}) |
||||||
|
const ObjBillerInfo = InvoiceShipmentInfo.filter(shipment => shipment.AddressType === 'BILLER'); |
||||||
|
const BillerL1 = ObjBillerInfo[0].Name |
||||||
|
const BillerL2 = ObjBillerInfo[0].AddressLine1 + ", " + ObjBillerInfo[0].City + ", " + ObjBillerInfo[0].StateProvince + ", " + ObjBillerInfo[0].CountryName |
||||||
|
const BillerL3 = ObjBillerInfo[0].Zip |
||||||
|
const ObjSellerInfo = InvoiceShipmentInfo.filter(shipment => shipment.AddressType === 'SELLER'); |
||||||
|
const SellerL1 = ObjSellerInfo[0].Name |
||||||
|
const SellerL2 = ObjSellerInfo[0].AddressLine1 + ", " + ObjBillerInfo[0].City + ", " + ObjBillerInfo[0].StateProvince + ", " + ObjBillerInfo[0].CountryName |
||||||
|
const SellerL3 = ObjSellerInfo[0].Zip |
||||||
|
res.render('pages/Amazon/Invoice', { |
||||||
|
user: user, |
||||||
|
InvoiceDetail: InvoiceDetail, |
||||||
|
InvoiceHeader: InvoiceHeader[0], |
||||||
|
AmazonShipmentReferenceId: InvoiceDetail[0].AmazonShipmentReferenceId, |
||||||
|
BillerL1: BillerL1, |
||||||
|
BillerL2: BillerL2, |
||||||
|
BillerL3: BillerL3, |
||||||
|
SellerL1: SellerL1, |
||||||
|
SellerL2: SellerL2, |
||||||
|
SellerL3: SellerL3 |
||||||
|
}) |
||||||
|
}) |
||||||
|
|
||||||
|
async function printPDF() { |
||||||
|
const browser = await puppeteer.launch({ headless: true }); |
||||||
|
const page = await browser.newPage(); |
||||||
|
await page.goto('http://localhost:9091/Invoice?id=2', { waitUntil: 'networkidle0' }); |
||||||
|
const pdf = await page.pdf({ |
||||||
|
format: 'A4', displayHeaderFooter: true, |
||||||
|
headerTemplate: ``, |
||||||
|
footerTemplate: ` |
||||||
|
<div style="border-top: solid 1px #bbb; width: 100%; font-size: 9px; |
||||||
|
padding: 5px 5px 0; color: #bbb; position: relative;"> |
||||||
|
<div style="position: absolute; right: 5px; top: 5px;"><span class="pageNumber"></span> DE <span class="totalPages"></span></div> |
||||||
|
</div> |
||||||
|
`,
|
||||||
|
margin: { bottom: '70px' }, |
||||||
|
}); |
||||||
|
await browser.close(); |
||||||
|
return pdf |
||||||
|
} |
||||||
|
|
||||||
|
app.get('/getAmazonInvoicePDF', async (req, res) => { |
||||||
|
let file = [{ url: "http://localhost:9091/Invoice?id=2", name: 'AmazonInvoice.pdf' }]; |
||||||
|
printPDF().then(pdf => { |
||||||
|
res.set({ 'Content-Type': 'application/pdf', 'Content-Length': pdf.length }) |
||||||
|
res.send(pdf) |
||||||
|
}) |
||||||
|
}) |
||||||
|
|
||||||
|
app.listen(port, () => { |
||||||
|
console.log(`App listening at port ${port}`) |
||||||
|
}) |
@ -0,0 +1,13 @@ |
|||||||
|
const config = { |
||||||
|
user: 'sa', // sql user
|
||||||
|
password: 'toor1234', //sql user password
|
||||||
|
server: 'localhost', // if it does not work try- localhost
|
||||||
|
database: 'GEMCO', |
||||||
|
options: { |
||||||
|
// trustedConnection: true,
|
||||||
|
trustServerCertificate: true, |
||||||
|
}, |
||||||
|
port: 1433 |
||||||
|
} |
||||||
|
|
||||||
|
module.exports = config; |
@ -0,0 +1,11 @@ |
|||||||
|
{ |
||||||
|
"dependencies": { |
||||||
|
"ejs": "^3.1.8", |
||||||
|
"express": "^4.18.2", |
||||||
|
"html-pdf-node": "^1.0.8", |
||||||
|
"mssql": "^9.0.1", |
||||||
|
"puppeteer": "^19.5.2", |
||||||
|
"puppeteer-core": "^19.5.2", |
||||||
|
"puppeteer-report": "^3.1.0" |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,34 @@ |
|||||||
|
<%- include('../../partials/Amazon/InvoiceHeader')%> |
||||||
|
<%- include('../../partials/Amazon/ItemsTableHeader')%> |
||||||
|
<% var ren=1; InvoiceDetail.forEach((item)=> { %> |
||||||
|
<tr> |
||||||
|
<td> |
||||||
|
<%= ren++ %> |
||||||
|
</td> |
||||||
|
<td> |
||||||
|
<%= item.ItemId %> |
||||||
|
</td> |
||||||
|
<td> |
||||||
|
<%= item.ItemDescription %> |
||||||
|
</td> |
||||||
|
<td> |
||||||
|
<%= item.ItemQuantityUnitOfMeasure %> |
||||||
|
</td> |
||||||
|
<td> |
||||||
|
<%= item.CountryOfOrigin %> |
||||||
|
</td> |
||||||
|
<td> |
||||||
|
<%= item.Quantity %> |
||||||
|
</td> |
||||||
|
<td> |
||||||
|
<%= item.WeightValue %> |
||||||
|
</td> |
||||||
|
<td> |
||||||
|
<%= item.ActualUnitCostMonetaryAmount %> |
||||||
|
</th> |
||||||
|
<td> |
||||||
|
<%= item.TotalUnitValueMonetaryAmount %> |
||||||
|
</td> |
||||||
|
</tr> |
||||||
|
<% }) %> |
||||||
|
<%- include('../../partials/Amazon/InvoiceFooter')%> |
@ -0,0 +1,30 @@ |
|||||||
|
<!-- <tfoot> |
||||||
|
<tr> |
||||||
|
<td></td> |
||||||
|
<td></td> |
||||||
|
<td></td> |
||||||
|
<td></td> |
||||||
|
<td class="bolder"=>TOTAL QTY</td> |
||||||
|
<td class="bolder" style="font-size:17px;"><%= InvoiceDetail.length %></td> |
||||||
|
<th colspan="2" style="text-align: right;">TOTAL USD $</th> |
||||||
|
<td class="bolder" style="font-size:17px;"><%= InvoiceHeader.TotalInvoiceValueMonetaryAmount %></td> |
||||||
|
</tr> |
||||||
|
</tfoot> --> |
||||||
|
</table> |
||||||
|
<table width="100%"> |
||||||
|
<tr> |
||||||
|
<td width="60%"> </td> |
||||||
|
<td width="40%"> |
||||||
|
<table width="100%" style="text-align:right"> |
||||||
|
<tr class="bolder"> |
||||||
|
<td>Total Qty:</td> |
||||||
|
<td style="font-size:18px"><%= InvoiceDetail.length %></td> |
||||||
|
<td>TOTAL USD$:</td> |
||||||
|
<td style="font-size:18px"><%= InvoiceHeader.TotalInvoiceValueMonetaryAmount %></td> |
||||||
|
</tr> |
||||||
|
</table> |
||||||
|
</td> |
||||||
|
</tr> |
||||||
|
</table> |
||||||
|
|
||||||
|
</html> |
@ -0,0 +1,179 @@ |
|||||||
|
<!DOCTYPE html> |
||||||
|
<html lang="en"> |
||||||
|
|
||||||
|
<head> |
||||||
|
<meta charset="UTF-8"> |
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge"> |
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"> |
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" |
||||||
|
integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous"> |
||||||
|
<style> |
||||||
|
.bolder { |
||||||
|
font-weight: bold; |
||||||
|
} |
||||||
|
|
||||||
|
.frame { |
||||||
|
border-color: 3px black; |
||||||
|
} |
||||||
|
</style> |
||||||
|
</head> |
||||||
|
<table border='0' cellpadding='0' cellspacing='0' width='100%'> |
||||||
|
<tr> |
||||||
|
<td width='70%'> |
||||||
|
<table width='100%' style='font-size: 12px;' cellpadding='0' cellspacing='0'> |
||||||
|
<tr> |
||||||
|
<td> |
||||||
|
<!-- <table border=1 width='100%'> |
||||||
|
<tr> |
||||||
|
<td class="bolder">Seller</td> |
||||||
|
</tr> |
||||||
|
<tr> |
||||||
|
<td> |
||||||
|
<%= SellerL1 %> <br> |
||||||
|
<%= SellerL2 %> <br> |
||||||
|
<%= SellerL3 %> |
||||||
|
</td> |
||||||
|
</tr> |
||||||
|
</table> --> |
||||||
|
<center> |
||||||
|
<div class="card" style="width: 90%; padding-left: 20px; text-align: left;"> |
||||||
|
<div class="card-body"> |
||||||
|
<span style="font-size:15px; font-weight:bold;">SELLER</span> <br> |
||||||
|
<%= SellerL1 %> <br> |
||||||
|
<%= SellerL2 %> <br> |
||||||
|
<%= SellerL3 %> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
</center> |
||||||
|
</td> |
||||||
|
</tr> |
||||||
|
<tr> |
||||||
|
<td> |
||||||
|
<!-- <div class="m-1 btn btn-light |
||||||
|
border border-danger border-5" style="width: 100%;"> |
||||||
|
<table width='100%'> |
||||||
|
<tr> |
||||||
|
<td class="bolder">Bill to:</td> |
||||||
|
</tr> |
||||||
|
<tr> |
||||||
|
<td> |
||||||
|
<%= BillerL1 %> <br> |
||||||
|
<%= BillerL2 %> <br> |
||||||
|
<%= BillerL3 %> |
||||||
|
</td> |
||||||
|
</tr> |
||||||
|
</table> |
||||||
|
</div> --> |
||||||
|
<center> |
||||||
|
<div class="card" style="width: 90%; padding-left: 20px; text-align: left;"> |
||||||
|
<div class="card-body"> |
||||||
|
<span style="font-size:15px; font-weight:bold;">BILLER</span> <br> |
||||||
|
<%= BillerL1 %> <br> |
||||||
|
<%= BillerL2 %> <br> |
||||||
|
<%= BillerL3 %> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
</center> |
||||||
|
</td> |
||||||
|
</tr> |
||||||
|
</table> |
||||||
|
</td> |
||||||
|
<td width='50%'> |
||||||
|
<table cellpadding='0' cellspacing='0' width='100%' style="padding-top:50px"> |
||||||
|
<tr> |
||||||
|
<td> |
||||||
|
<table cellpadding='0' cellspacing='0' width='100%'> |
||||||
|
<tr> |
||||||
|
<td> |
||||||
|
<!-- <table width='100%'> |
||||||
|
<tr> |
||||||
|
<td class="bolder">Date:</td> |
||||||
|
</tr> |
||||||
|
<tr> |
||||||
|
<td> |
||||||
|
<%= InvoiceHeader.CommercialInvoiceDate %> |
||||||
|
</td> |
||||||
|
</tr> |
||||||
|
</table> --> |
||||||
|
<center> |
||||||
|
<div class="card" style="width: 100%; padding-left: 20px; text-align: left; ; font-size:12px;"> |
||||||
|
<div class="card-body"> |
||||||
|
<span style="font-size:15px; font-weight:bold;">Date:</span> <br> |
||||||
|
<%= InvoiceHeader.CommercialInvoiceDate %> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
</center> |
||||||
|
</td> |
||||||
|
<td> |
||||||
|
<!-- <table width='100%'> |
||||||
|
<tr> |
||||||
|
<td class="bolder">Invoice No:</td> |
||||||
|
</tr> |
||||||
|
<tr> |
||||||
|
<td> |
||||||
|
<%= InvoiceHeader.InvoiceNumber %> |
||||||
|
</td> |
||||||
|
</tr> |
||||||
|
</table> --> |
||||||
|
<center> |
||||||
|
<div class="card" style="width: 90%; padding-left: 20px; text-align: left; font-size:12px;"> |
||||||
|
<div class="card-body"> |
||||||
|
<span style="font-size:15px; font-weight:bold;">Invoice No:</span> <br> |
||||||
|
<%= InvoiceHeader.InvoiceNumber %> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
</center> |
||||||
|
</td> |
||||||
|
</tr> |
||||||
|
</table> |
||||||
|
</td> |
||||||
|
</tr=> |
||||||
|
<tr> |
||||||
|
<td> |
||||||
|
<!-- <table border=1 width='100%'> |
||||||
|
<tr> |
||||||
|
<td class="bolder">Amazon Shipment Reference Id:</td> |
||||||
|
</tr> |
||||||
|
<tr> |
||||||
|
<td colspan='2' style='text-align: center;'> |
||||||
|
<%= AmazonShipmentReferenceId %><br> |
||||||
|
</td> |
||||||
|
</th> |
||||||
|
</tr> |
||||||
|
</table> --> |
||||||
|
<center> |
||||||
|
<div class="card" style="width: 95%; padding-left: 20px; text-align: left; font-size:12px;"> |
||||||
|
<div class="card-body"> |
||||||
|
<span style="font-size:15px; font-weight:bold;">Amazon Shipment Reference Id:</span> <br> |
||||||
|
<%= AmazonShipmentReferenceId %> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
</center> |
||||||
|
</td> |
||||||
|
</tr> |
||||||
|
<tr> |
||||||
|
<td> |
||||||
|
<!-- <table border=1 width='100%'> |
||||||
|
<tr> |
||||||
|
<td class="bolder">Incoterms:</td> |
||||||
|
</tr> |
||||||
|
<tr> |
||||||
|
<td style='text-align: center; '> |
||||||
|
<%= InvoiceHeader.Incoterms %> |
||||||
|
</td> |
||||||
|
</tr> |
||||||
|
</table> --> |
||||||
|
<center> |
||||||
|
<div class="card" style="width: 95%; padding-left: 20px; text-align: left; font-size:12px;"> |
||||||
|
<div class="card-body"> |
||||||
|
<span style="font-size:15px; font-weight:bold;">Incoterms:</span> <br> |
||||||
|
<%= InvoiceHeader.Incoterms %> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
</center> |
||||||
|
</td> |
||||||
|
</tr> |
||||||
|
</table> |
||||||
|
</td> |
||||||
|
</tr> |
||||||
|
</table> |
@ -0,0 +1,37 @@ |
|||||||
|
<%- include('../Amazon/partials/header')%> |
||||||
|
<%- include('../Amazon/partials/tableHeader')%> |
||||||
|
<tbody> |
||||||
|
<% var ren=1; |
||||||
|
InvoiceDetail.forEach((item)=> { %> |
||||||
|
<tr> |
||||||
|
<td> |
||||||
|
<%= ren++ %> |
||||||
|
</td> |
||||||
|
<td> |
||||||
|
<%= item.ItemId %> |
||||||
|
</td> |
||||||
|
<td> |
||||||
|
<%= item.ItemDescription %> |
||||||
|
</td> |
||||||
|
<td> |
||||||
|
<%= item.ItemQuantityUnitOfMeasure %> |
||||||
|
</td> |
||||||
|
<td> |
||||||
|
<%= item.CountryOfOrigin %> |
||||||
|
</td> |
||||||
|
<td> |
||||||
|
<%= item.Quantity %> |
||||||
|
</td> |
||||||
|
<td> |
||||||
|
<%= item.WeightValue %> |
||||||
|
</td> |
||||||
|
<td> |
||||||
|
<%= item.ActualUnitCostMonetaryAmount %> |
||||||
|
</td> |
||||||
|
<td> |
||||||
|
<%= item.TotalUnitValueMonetaryAmount %> |
||||||
|
</td> |
||||||
|
</tr> |
||||||
|
<% }) %> |
||||||
|
</tbody> |
||||||
|
<%- include('../Amazon/partials/footer')%> |
@ -0,0 +1,14 @@ |
|||||||
|
<table width='100%' class='table table-striped table-sm' style="font-size:12px"> |
||||||
|
<thead> |
||||||
|
<tr> |
||||||
|
<th>Ord</th> |
||||||
|
<th>ASIN#</th> |
||||||
|
<th>Description of Goods</th> |
||||||
|
<th>Unit Meas.</th> |
||||||
|
<th>Country of Origin</th> |
||||||
|
<th>Qty Shipped</th> |
||||||
|
<th>Unit Net Weight Kg</th> |
||||||
|
<th>Unit Cost USD</th> |
||||||
|
<th>Total Value USD</th> |
||||||
|
</tr> |
||||||
|
</thead> |
Loading…
Reference in new issue