/* ============================================================================ *\
|| ########################################################################## ||
|| # Auction Software Marketplace Release: 0.6 Build 0.7 # ||
|| # ---------------------------------------------------------------------- # ||
|| # License # 35YAHCNR9344X6O666C123AB # ||
|| # ---------------------------------------------------------------------- # ||
|| # Copyright ©2014–2021 Develop Scripts LLC. All Rights Reserved # ||
|| # This file may not be redistributed in whole or significant part. # ||
|| # ------------- AUCTION SOFTWARE IS NOT FREE SOFTWARE ------------------ # ||
|| # http://www.auctionsoftwaremarketplace.com|support@auctionsoftware.com # ||
|| # ---------------------------------------------------------------------- # ||
|| ########################################################################## ||
\* ============================================================================ */
const dateFormat = require('dateformat')
const md5 = require('md5')
const _ = require('underscore')
const moment = require('moment')
const mysqclass = require('./mysqli').default
const commonProduct = require('../../common/products').default
/**
* @class class to handle invoice functions
*/
class adminShippingModule {
/**
* fetch shipping all new
* @param {object} req req object
* @param {string} type report type
* @param {number} count count for the pagination
* @returns {object} sql response
*/
static async fetchShippingAllNew(req, count) {
const mysql = {}
const { action } = req.body
const baseTableUsed = global.configColumns.buynow
const customTableUsed = { enabled: 0 }
let row = ''
let where = ''
let limitf = ''
let order = ''
where += 'and b.paid = 1'
const dateNow = dateFormat(new Date(), 'yyyy-mm-dd HH:MM:ss')
if (typeof req.body.limit === 'undefined') {
req.body.limit = global.configurations.variables.search_limit || 25
}
if (typeof req.body.page === 'undefined') {
req.body.page = 1
}
order = `order by b.common_invoice desc `
if (req.body.orderby || req.body.order) {
const sortReturn = commonProduct.sortOrderData(req, where)
if (sortReturn.order) {
order = sortReturn.order
}
if (sortReturn.where) {
where += sortReturn.where
}
}
if (req.body.similars) {
where += commonProduct.similarData(req)
}
if (req.body.filters) {
where += commonProduct.filterData(req)
}
const generatedData = commonProduct.generateJoinWithColum(baseTableUsed, customTableUsed, [
'id',
])
mysql.customTableJoin = generatedData.customTableJoin
mysql.columns = generatedData.rowstoFetch
row = count === 1 ? 'shipping_all_item_cnt' : 'shipping_all_item'
const limitrg = req.body.limit
let uidc = 0
if (req.user) {
uidc = typeof req.user.id === 'undefined' ? 0 : req.user.id
}
const escapeData = []
if (count === 1) {
let pagen = (req.body.page - 1) * limitrg
if (parseInt(pagen, 10) < 0) {
pagen = 0
}
limitf = ` limit ${pagen},${limitrg}`
}
mysql.userid = uidc
mysql.order = order
mysql.where = where
mysql.limitf = limitf
mysql.dateNow = dateNow
mysql.groupby = 'group by b.common_invoice'
mysql.customTableJoin = generatedData.customTableJoin
mysql.columns = generatedData.rowstoFetch
mysql.mainTable = generatedData.mainTableJoin
const additionalTable = global.configColumns.projects
const customAdditionalTable = global.configColumns.custom_projects
const additionalGeneratedData = commonProduct.additionalTableJoin(
additionalTable,
customAdditionalTable,
baseTableUsed,
'inner join',
'id',
'project_id',
)
mysql.customTableJoin = `${mysql.customTableJoin} ${additionalGeneratedData.customTableJoin}`
mysql.columns = mysql.columns.concat(additionalGeneratedData.rowstoFetch)
const strQuery = await mysqclass.mysqli(mysql, row)
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
/**
*get shipping details
* @param {Object} req request object
* @param {number} count if count = 1 fetch count else fetch shiping details
* @returns {object} sql response
*/
static async getShippingDetails(req, count) {
const mysql = {}
const { action } = req.body
const baseTableUsed = global.configColumns.buynow
const customTableUsed = { enabled: 0 }
let row = ''
let where = ''
let limitf = ''
let order = ''
where += 'and b.paid = 1'
const dateNow = dateFormat(new Date(), 'yyyy-mm-dd HH:MM:ss')
if (typeof req.body.limit === 'undefined') {
req.body.limit = global.configurations.variables.search_limit || 25
}
if (typeof req.body.page === 'undefined') {
req.body.page = 1
}
order = `order by b.common_invoice desc `
if (req.body.orderby || req.body.order) {
const sortReturn = commonProduct.sortOrderData(req, where)
if (sortReturn.order) {
order = sortReturn.order
}
if (sortReturn.where) {
where += sortReturn.where
}
}
if (req.body.similars) {
where += commonProduct.similarData(req)
}
if (req.body.filters) {
where += commonProduct.filterData(req)
}
const generatedData = commonProduct.generateJoinWithColum(baseTableUsed, customTableUsed, [
'id',
])
mysql.customTableJoin = generatedData.customTableJoin
mysql.columns = generatedData.rowstoFetch
row = count === 1 ? 'shipping_all_item_cnt' : 'shipping_all_item'
const limitrg = req.body.limit
let uidc = 0
if (req.user) {
uidc = typeof req.user.id === 'undefined' ? 0 : req.user.id
}
const escapeData = []
if (count === 1) {
let pagen = (req.body.page - 1) * limitrg
if (parseInt(pagen, 10) < 0) {
pagen = 0
}
limitf = ` limit ${pagen},${limitrg}`
}
mysql.userid = uidc
mysql.order = order
mysql.where = where
mysql.limitf = limitf
mysql.dateNow = dateNow
mysql.groupby = 'group by b.common_invoice'
mysql.customTableJoin = generatedData.customTableJoin
mysql.columns = generatedData.rowstoFetch
mysql.mainTable = generatedData.mainTableJoin
const additionalTable = global.configColumns.projects
const customAdditionalTable = global.configColumns.custom_projects
const additionalGeneratedData = commonProduct.additionalTableJoin(
additionalTable,
customAdditionalTable,
baseTableUsed,
'inner join',
'id',
'project_id',
)
mysql.customTableJoin = `${mysql.customTableJoin} ${additionalGeneratedData.customTableJoin}`
mysql.columns = mysql.columns.concat(additionalGeneratedData.rowstoFetch)
const strQuery = await mysqclass.mysqli(mysql, row)
const dataReturn = await global.mysql.query(strQuery, escapeData)
return dataReturn
}
}
module.exports.default = adminShippingModule