toutpratique/modules/ordertaxprofitreport/lib/module-tools_class.php
ToutPratique 1d1a2def5f push prod
2016-05-17 15:54:37 +02:00

644 lines
29 KiB
PHP

<?php
/**
* module-tools_class.php file defines all tools method in module - transverse
*/
class BT_OtprModuleTools
{
/**
* setColTitle() method set title of each column used in report
*/
public static function setColTitle()
{
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['ord_date_add']['title'] = OrderTaxProfitReport::$oModule->l('Order\'s adding date', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['ord_date_upd']['title'] = OrderTaxProfitReport::$oModule->l('Order\'s updating date', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['ord_delivery_date']['title'] = OrderTaxProfitReport::$oModule->l('Order delivery date', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['ord_invoice_date']['title'] = OrderTaxProfitReport::$oModule->l('Order invoice date', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['shop_name']['title'] = OrderTaxProfitReport::$oModule->l('Shop Name', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['id_order']['title'] = OrderTaxProfitReport::$oModule->l('Order ID', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['invoice_number']['title'] = OrderTaxProfitReport::$oModule->l('Invoice number', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['delivery_number']['title'] = OrderTaxProfitReport::$oModule->l('Delivery number', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['ord_carrier']['title'] = OrderTaxProfitReport::$oModule->l('Carrier', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['ord_payment_method']['title'] = OrderTaxProfitReport::$oModule->l('Payment method', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['order_state']['title'] = OrderTaxProfitReport::$oModule->l('Order state', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['total_paid']['title'] = OrderTaxProfitReport::$oModule->l('Total paid', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['total_paid_real']['title'] = OrderTaxProfitReport::$oModule->l('Total real paid', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['total_products_no_tax']['title'] = OrderTaxProfitReport::$oModule->l('Total products no tax', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['ecotax_no_tax']['title'] = OrderTaxProfitReport::$oModule->l('Including Ecotax Tax Excl.', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['ecotax_tax_amount']['title'] = OrderTaxProfitReport::$oModule->l('Including Ecotax Tax amount', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['total_shipping']['title'] = OrderTaxProfitReport::$oModule->l('Total shipping without tax', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['total_shipping_tax']['title'] = OrderTaxProfitReport::$oModule->l('Shipping tax amount', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['total_tax']['title'] = OrderTaxProfitReport::$oModule->l('Total tax', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['total_discounts_no_tax']['title'] = OrderTaxProfitReport::$oModule->l('Total discounts Tax Excl.', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['discounts_tax_amount']['title'] = OrderTaxProfitReport::$oModule->l('Discounts Tax amount', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['total_wrapping_no_tax']['title'] = OrderTaxProfitReport::$oModule->l('Total wrapping Tax Excl.', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['wrapping_tax_amount']['title'] = OrderTaxProfitReport::$oModule->l('Wrapping Tax amount', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['total_prod_tax']['title'] = OrderTaxProfitReport::$oModule->l('Products Tax', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['total_cost']['title'] = OrderTaxProfitReport::$oModule->l('Total cost', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['price']['title'] = OrderTaxProfitReport::$oModule->l('Price', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['gross_profit']['title'] = OrderTaxProfitReport::$oModule->l('Gross Profit Before Discounts.', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['net_profit']['title'] = OrderTaxProfitReport::$oModule->l('Net Profit Tax Excl.', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['gross_margin']['title'] = OrderTaxProfitReport::$oModule->l('Gross Margin Before Discounts.', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['net_margin']['title'] = OrderTaxProfitReport::$oModule->l('Net Margin Tax Excl.', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['id_product']['title'] = OrderTaxProfitReport::$oModule->l('Product ID', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['id_image']['title'] = OrderTaxProfitReport::$oModule->l('Image', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['product_name']['title'] = OrderTaxProfitReport::$oModule->l('Product Name', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['product_ref']['title'] = OrderTaxProfitReport::$oModule->l('Product reference', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['product_supplier_ref']['title'] = OrderTaxProfitReport::$oModule->l('Supplier reference', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['product_ean']['title'] = OrderTaxProfitReport::$oModule->l('EAN reference', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['product_upc']['title'] = OrderTaxProfitReport::$oModule->l('UPC reference', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['product_name']['defaulttext'] = OrderTaxProfitReport::$oModule->l('Product was deleted, info not available', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['prod_total_quantity']['title'] = OrderTaxProfitReport::$oModule->l('Total quantity', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['prod_unit_price']['title'] = OrderTaxProfitReport::$oModule->l('Avg. Unit Price', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['prod_tax_rate']['title'] = OrderTaxProfitReport::$oModule->l('Tax rate', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['prod_total_no_tax']['title'] = OrderTaxProfitReport::$oModule->l('Total product no tax', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['prod_total_tax']['title'] = OrderTaxProfitReport::$oModule->l('Net Tax (product - reduction)', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['prod_total_costs']['title'] = OrderTaxProfitReport::$oModule->l('Total cost', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['prod_gross_profit']['title'] = OrderTaxProfitReport::$oModule->l('Gross Profit', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['prod_gross_margin']['title'] = OrderTaxProfitReport::$oModule->l('Gross Margin', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['prod_net_profit']['title'] = OrderTaxProfitReport::$oModule->l('Net Profit', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['prod_net_margin']['title'] = OrderTaxProfitReport::$oModule->l('Net Margin', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['percent_total_sales']['title'] = OrderTaxProfitReport::$oModule->l('% of total sales', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['percent_total_gross_profits']['title'] = OrderTaxProfitReport::$oModule->l('% of total gross profits', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['percent_total_net_profits']['title'] = OrderTaxProfitReport::$oModule->l('% of total net profits', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['total_sales_cumulative']['title'] = OrderTaxProfitReport::$oModule->l('Cumulative % of total sales', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['total_gross_profits_cumulative']['title'] = OrderTaxProfitReport::$oModule->l('Cumulative % of total gross profits', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['total_net_profits_cumulative']['title'] = OrderTaxProfitReport::$oModule->l('Cumulative % of total net profits', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['manufacturer_name']['title'] = OrderTaxProfitReport::$oModule->l('Manufacturer name', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['manufacturer_name']['defaulttext'] = OrderTaxProfitReport::$oModule->l('Manufacturer was deleted, info not available', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['id_manufacturer']['title'] = OrderTaxProfitReport::$oModule->l('Manufacturer ID', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['cat_name']['title'] = OrderTaxProfitReport::$oModule->l('Category name', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['cat_name']['defaulttext'] = OrderTaxProfitReport::$oModule->l('Category was deleted, info not available', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['id_category']['title'] = OrderTaxProfitReport::$oModule->l('Category ID', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['supplier_name']['title'] = OrderTaxProfitReport::$oModule->l('Supplier name', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['supplier_name']['defaulttext'] = OrderTaxProfitReport::$oModule->l('Supplier was deleted, info not available', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['id_supplier']['title'] = OrderTaxProfitReport::$oModule->l('Supplier ID', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['email']['title'] = OrderTaxProfitReport::$oModule->l('Email', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['birthday']['title'] = OrderTaxProfitReport::$oModule->l('Birthday', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['lastname']['title'] = OrderTaxProfitReport::$oModule->l('Last name', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['firstname']['title'] = OrderTaxProfitReport::$oModule->l('First name', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['cust_date_add']['title'] = OrderTaxProfitReport::$oModule->l('Customer adding date', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['cust_date_upd']['title'] = OrderTaxProfitReport::$oModule->l('Customer updating date', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['addr_company']['title'] = OrderTaxProfitReport::$oModule->l('Company', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['addr_lastname']['title'] = OrderTaxProfitReport::$oModule->l('Last name', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['addr_firstname']['title'] = OrderTaxProfitReport::$oModule->l('First name', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['addr_address1']['title'] = OrderTaxProfitReport::$oModule->l('Address 1', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['addr_address2']['title'] = OrderTaxProfitReport::$oModule->l('Address 2', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['addr_postcode']['title'] = OrderTaxProfitReport::$oModule->l('Postcode', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['addr_city']['title'] = OrderTaxProfitReport::$oModule->l('City', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['addr_phone']['title'] = OrderTaxProfitReport::$oModule->l('Phone', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['addr_country']['title'] = OrderTaxProfitReport::$oModule->l('Country', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['first_order']['title'] = OrderTaxProfitReport::$oModule->l('First order', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['id_customer']['title'] = OrderTaxProfitReport::$oModule->l('Customer ID', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['last_order']['title'] = OrderTaxProfitReport::$oModule->l('Last order', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['nb_orders']['title'] = OrderTaxProfitReport::$oModule->l('# of orders', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['order_nb_products']['title'] = OrderTaxProfitReport::$oModule->l('# of products ordered', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['average_cart']['title'] = OrderTaxProfitReport::$oModule->l('Average cart (all included)', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['products_ordered']['title'] = OrderTaxProfitReport::$oModule->l('Products ordered', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['id_slip']['title'] = OrderTaxProfitReport::$oModule->l('Credit Slip ID', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['slip_date']['title'] = OrderTaxProfitReport::$oModule->l('Credit Slip date', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['slip_product_no_tax']['title'] = OrderTaxProfitReport::$oModule->l('Total products no tax', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['slip_product_total_tax']['title'] = OrderTaxProfitReport::$oModule->l('Products Tax', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['slip_total_shipping_no_tax']['title'] = OrderTaxProfitReport::$oModule->l('Total shipping without tax', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['slip_total_shipping_tax']['title'] = OrderTaxProfitReport::$oModule->l('Shipping tax amount', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['slip_total_no_tax']['title'] = OrderTaxProfitReport::$oModule->l('Total no tax', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['slip_total_tax']['title'] = OrderTaxProfitReport::$oModule->l('Total tax', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['slip_total_incl']['title'] = OrderTaxProfitReport::$oModule->l('Total tax Incl.', 'module-tools_class');
// add tooltips for columns
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['gross_profit']['tooltip'] = OrderTaxProfitReport::$oModule->l('Total products no tax - Total cost', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['net_profit']['tooltip'] = OrderTaxProfitReport::$oModule->l('Total products no tax - Total cost - Total discounts Tax Excl.', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['gross_margin']['tooltip'] = OrderTaxProfitReport::$oModule->l('Gross Profit Tax Excl / Total products no tax x 100', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_COLS']['net_margin']['tooltip'] = OrderTaxProfitReport::$oModule->l('(Net Profit Tax Excl + Total wrapping Tax Excl.) / (Total products no tax - Total discounts Tax Excl. + Total wrapping Tax Excl.) x 10', 'module-tools_class');
// ddd($GLOBALS[_OTPR_MODULE_NAME . '_COLS']);
}
/**
* setColsSuffix() method set suffix of cols
*/
public static function setColsSuffix()
{
// get currency
$sCurrency = self::getCurrency(true);
foreach ($GLOBALS[_OTPR_MODULE_NAME . '_COLS'] as $sTitle => &$aCol) {
if ($aCol['type'] == 'n' && empty($aCol['suffix'])) {
$aCol['suffix'] = $sCurrency;
}
}
}
/**
* setDateFormatTitle() method set title of date label
*/
public static function setDateFormatTitle()
{
$GLOBALS[_OTPR_MODULE_NAME . '_DATE_FORMAT']['en']['label'] = OrderTaxProfitReport::$oModule->l('English', 'module-tools_class') . ' - mm/dd/yyyy';
$GLOBALS[_OTPR_MODULE_NAME . '_DATE_FORMAT']['fr']['label'] = OrderTaxProfitReport::$oModule->l('French', 'module-tools_class'). ' - dd/mm/yyyy';
}
/**
* setDateTypeTitle() method set title of date type
*/
public static function setDateTypeTitle()
{
$GLOBALS[_OTPR_MODULE_NAME . '_DATE_TYPE']['order'] = OrderTaxProfitReport::$oModule->l('Order', 'module-tools_class') ;
$GLOBALS[_OTPR_MODULE_NAME . '_DATE_TYPE']['delivery'] = OrderTaxProfitReport::$oModule->l('Delivery', 'module-tools_class') ;
$GLOBALS[_OTPR_MODULE_NAME . '_DATE_TYPE']['invoice'] = OrderTaxProfitReport::$oModule->l('Invoice', 'module-tools_class');
}
/**
* setTranslatedJsMsg() method returns good translated js errors
*/
public static function setTranslatedJsMsg()
{
$GLOBALS[_OTPR_MODULE_NAME . '_JS_MSG']['orderStartNumber'] = OrderTaxProfitReport::$oModule->l('Order start number isn\'t an integer', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_JS_MSG']['orderEndNumber'] = OrderTaxProfitReport::$oModule->l('Order end number isn\'t an integer', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_JS_MSG']['invoiceStartNumber'] = OrderTaxProfitReport::$oModule->l('Invoice start number isn\'t an integer', 'module-tools_class');
$GLOBALS[_OTPR_MODULE_NAME . '_JS_MSG']['invoiceEndNumber'] = OrderTaxProfitReport::$oModule->l('Invoice end number isn\'t an integer', 'module-tools_class');
}
/**
* setReportTemplate() method set already defined report templates
*
* @return bool
*/
public static function setReportTemplate()
{
foreach ($GLOBALS[_OTPR_MODULE_NAME . '_SEARCH_TEMPLATE'] as $sId => $aTemplate) {
if (!BT_OtprModuleDao::addTemplate($sId, array('cols' => $aTemplate['cols'], 'group' => $aTemplate['group']), $aTemplate['lang'])) {
return false;
}
}
return true;
}
/**
* getConfiguration() method get all constant module in ps_configuration
*/
public static function getConfiguration()
{
// get configuration options
OrderTaxProfitReport::$aConfiguration = Configuration::getMultiple(array_keys($GLOBALS[_OTPR_MODULE_NAME . '_CONFIGURATION']));
}
/**
* updateConfiguration() method update new keys in new module version
*/
public static function updateConfiguration()
{
// check to update new module version
foreach ($GLOBALS[_OTPR_MODULE_NAME . '_CONFIGURATION'] as $sKey => $mVal) {
// use case - not exists
if (!Configuration::get($sKey)) {
// update key/ value
Configuration::updateValue($sKey, $mVal);
}
}
}
/**
* getTranslatedTplTitle() method set good template title
*/
public static function getTranslatedTplTitle(&$aTemplates)
{
// get languages
$aLanguages = Language::getLanguages(true);
foreach ($aTemplates as &$aTemplate) {
// use case - translated title exists
if (array_key_exists(OrderTaxProfitReport::$sCurrentLang, $aTemplate['lang']) ) {
$aTemplate['title'] = $aTemplate['lang'][OrderTaxProfitReport::$sCurrentLang];
}
else {
$aTemplate['title'] = $aTemplate['lang']['en'];
}
}
// destruct
unset($aLanguages);
}
/**
* recursiveCategoryTree() method process categories to generate tree of them
*
* @param array $aCategories
* @param array $aIndexedCat
* @param array $aCurrentCat
* @param int $iCurrentIndex
* @param int $iDefaultId
* @return array
*/
public static function recursiveCategoryTree(array $aCategories, array $aIndexedCat, $aCurrentCat, $iCurrentIndex = 1, $iDefaultId = null)
{
// set variables
static $_aTmpCat;
static $_aFormatCat;
if ($iCurrentIndex == 1) {
$_aTmpCat = null;
$_aFormatCat = null;
}
if (!isset($_aTmpCat[$aCurrentCat['infos']['id_parent']])) {
$_aTmpCat[$aCurrentCat['infos']['id_parent']] = 0;
}
$_aTmpCat[$aCurrentCat['infos']['id_parent']] += 1;
// calculate new level
$aCurrentCat['infos']['iNewLevel'] = $aCurrentCat['infos']['level_depth'] + (version_compare(_PS_VERSION_, '1.5.0', '>')? 0 : 1);
// calculate type of gif to display - displays tree in good
$aCurrentCat['infos']['sGifType'] = (count($aCategories[$aCurrentCat['infos']['id_parent']]) == $_aTmpCat[$aCurrentCat['infos']['id_parent']] ? 'f' : 'b');
// calculate if checked
if (in_array($iCurrentIndex, $aIndexedCat)) {
$aCurrentCat['infos']['bCurrent'] = true;
}
else {
$aCurrentCat['infos']['bCurrent'] = false;
}
// define class name with default cat id
$aCurrentCat['infos']['mDefaultCat'] = ($iDefaultId === null)? 'default' : $iCurrentIndex;
$_aFormatCat[] = $aCurrentCat['infos'];
if (isset($aCategories[$iCurrentIndex])) {
foreach ($aCategories[$iCurrentIndex] as $iCatId => $aCat) {
if ($iCatId != 'infos') {
self::recursiveCategoryTree($aCategories, $aIndexedCat, $aCategories[$iCurrentIndex][$iCatId], $iCatId);
}
}
}
return $_aFormatCat;
}
/**
* getSortFields() method get all sortable fields in sql query
*
* @return array
*/
public static function getSortFields()
{
// set
$aSortFields = array();
foreach ($GLOBALS[_OTPR_MODULE_NAME . '_SEARCH_TEMPLATE'] as $sTemplate => $aParams) {
foreach ($aParams['cols'] as $sCol) {
if (array_key_exists($sCol, $GLOBALS[_OTPR_MODULE_NAME . '_COLS'])
&&
$GLOBALS[_OTPR_MODULE_NAME . '_COLS'][$sCol]['sort']
&&
!empty($GLOBALS[_OTPR_MODULE_NAME . '_COLS'][$sCol]['title'])
) {
$aSortFields[$sTemplate][$sCol] = $GLOBALS[_OTPR_MODULE_NAME . '_COLS'][$sCol]['title'];
}
}
}
// return
return $aSortFields;
}
/**
* getIsoLang() method set good iso lang
*
* @return string
*/
public static function getIsoLang()
{
// get iso lang
$sIsoLang = Language::getIsoById(OrderTaxProfitReport::$iCurrentLang);
if (false === $sIsoLang) {
$sIsoLang = 'en';
}
return $sIsoLang;
}
/**
* getCurrency() method returns current currency sign or id
*
* @param bool $bStringCurrency
* @return mixed : string or int
*/
public static function getCurrency($bStringCurrency)
{
// get currency id
$mCurrencyId = Configuration::get('PS_CURRENCY_DEFAULT');
if ($bStringCurrency) {
$mCurrencyId = Currency::getCurrency($mCurrencyId);
$mCurrencyId = $mCurrencyId['sign'];
}
return $mCurrencyId;
}
/**
* getTimeStamp() method returns timestamp
*
* @param string $sDate
* @param string $sType
* @param string $bDayEnd
* @return mixed : bool or int
*/
public static function getTimeStamp($sDate, $sType = 'en', $bDayEnd = false)
{
// set variable
$iTimeStamp = false;
// get date
$aTmpDate = explode(' ', str_replace(array('-', '/'), ' ', $sDate));
if (count($aTmpDate) > 1) {
if ($sType == 'en') {
$iTimeStamp = ($bDayEnd) ? mktime(23, 59, 59, $aTmpDate[0], $aTmpDate[1], $aTmpDate[2]) : mktime(0, 0, 0, $aTmpDate[0], $aTmpDate[1], $aTmpDate[2]);
}
else {
$iTimeStamp = ($bDayEnd) ? mktime(23, 59, 59, $aTmpDate[1], $aTmpDate[0], $aTmpDate[2]) : mktime(0, 0, 0, $aTmpDate[1], $aTmpDate[0], $aTmpDate[2]);
}
}
// destruct
unset($aTmpDate);
return $iTimeStamp;
}
/**
* getColAttributes() method returns list of table fields
*
* @param array $aCols
* @param string $sType
* @param bool $bUTF8
* @return array
*/
public static function getColAttributes(array $aCols, $sType, $bUTF8 = true)
{
// set variable
$aFields = array();
foreach ($aCols as $sColName) {
// use case - if we can use it or display it
$bUsable = $sType == 'db' ? $GLOBALS[_OTPR_MODULE_NAME . '_COLS'][$sColName]['use'] : $GLOBALS[_OTPR_MODULE_NAME . '_COLS'][$sColName]['display'];
if (array_key_exists($sColName, $GLOBALS[_OTPR_MODULE_NAME . '_COLS'])
&& !empty($GLOBALS[_OTPR_MODULE_NAME . '_COLS'][$sColName][$sType])
&& $bUsable
) {
$aFields[$sColName] = ($bUTF8)? $GLOBALS[_OTPR_MODULE_NAME . '_COLS'][$sColName][$sType] : utf8_decode($GLOBALS[_OTPR_MODULE_NAME . '_COLS'][$sColName][$sType]);
}
}
unset($bUsable);
return $aFields;
}
/**
* setOrderDetailDistribution() method calculate discount and wrapping distribution from orders for orders detail
*
* @param float $fTotal
* @param float $fTotalProducts
* @param float $fProductPrice
* @param float $fTax
* @param int $iQuantity
* @return array
*/
public static function setOrderDetailDistribution($fTotal, $fTotalProducts, $fProductPrice, $fTax = 0, $iQuantity = 1)
{
// get coefficient
if (floatval($fTotalProducts) != 0) {
$fCoeff = floatval(($fProductPrice * $iQuantity) / $fTotalProducts);
}
else {
$fCoeff = floatval(1);
}
// set distribution
$fTaxIncl = floatval($fCoeff * $fTotal);
// set amount WT
$fTaxExcl = (intval($fTax) != 0)? floatval($fTaxIncl / (1 + ($fTax / 100))) : $fTaxIncl;
// set discount / wrapping without tax
$fTaxAmount = floatval($fTaxIncl - $fTaxExcl);
return (
array('taxIncl' => $fTaxIncl, 'taxExcl' => $fTaxExcl, 'taxAmount' => $fTaxAmount)
);
}
/**
* populateDiscountOrdersDetail() method populate discount / wrapping orders detail
*
* @param int $iOrderId
* @param int $iOrderDetailId
* @param float $fTotal
* @param float $fTotalProducts
* @param float $fProductPrice
* @param float $fTax
* @param int $iQuantity
* @return array
*/
public static function populateDiscountOrdersDetail($iOrderId, $iOrderDetailId, $fTotal, $fTotalProducts, $fProductPrice, $fTax = 0, $iQuantity = 1)
{
$bReturn = true;
// use case - if discount is not empty
if (intval($fTotal) != 0) {
$aResult = self::setOrderDetailDistribution($fTotal, $fTotalProducts, $fProductPrice, $fTax, $iQuantity);
}
else {
$aResult = array('taxIncl' => 0.00, 'taxExcl' => 0.00, 'taxAmount' => 0.00);
}
// populate our table order_wrapping
$bInsert = BT_OtprModuleDao::populateDiscountOrdersDetail($iOrderId, $iOrderDetailId, $aResult['taxExcl'], $aResult['taxIncl'], $aResult['taxAmount']);
if (!$bInsert) {
$bReturn = false;
}
return $bReturn;
}
/**
* populateWrappingOrdersDetail() method populate discount / wrapping orders detail
*
* @param int $iOrderId
* @param float $fTotal
* @param float $fWrappingTaxExcl
* @param float $fWrappingTaxIncl
* @return array
*/
public static function populateWrappingOrdersDetail($iOrderId, $fTotal, $fWrappingTaxExcl = null, $fWrappingTaxIncl = null)
{
$bReturn = true;
// use case - under Prestashop 1.5
if ($fWrappingTaxIncl == null && $fWrappingTaxExcl === null) {
// instantiate
$oTax = new Tax(Configuration::get('PS_GIFT_WRAPPING_TAX'));
$fWrappingTaxIncl = $fTotal;
$fWrappingTaxExcl = $fTotal / (1 + ((float)($oTax->rate) / 100));
unset($oTax);
}
// calculate tax amount
$fTaxAmount = $fWrappingTaxIncl - $fWrappingTaxExcl;
// populate our table order_wrapping
$bInsert = BT_OtprModuleDao::populateWrappingOrdersDetail($iOrderId, $fWrappingTaxExcl, $fWrappingTaxIncl, $fTaxAmount);
if (!$bInsert) {
$bReturn = false;
}
return $bReturn;
}
/**
* checkGroupMultiShop() method check if multi-shop is activated and if the group or global context is used
*
* @return bool
*/
public static function checkGroupMultiShop()
{
return (
version_compare(_PS_VERSION_, '1.5', '>')
&&
Configuration::get('PS_MULTISHOP_FEATURE_ACTIVE')
&&
(
strpos(OrderTaxProfitReport::$oCookie->shopContext, 'g-') !== FALSE
||
empty(OrderTaxProfitReport::$oCookie->shopContext))
);
}
/**
* round() method round on numeric
*
* @param float $fVal
* @param int $iPrecision
* @return float
*/
public static function round($fVal, $iPrecision = 2)
{
if (method_exists('Tools', 'ps_round')) {
$fVal = Tools::ps_round($fVal, $iPrecision);
}
else {
$fVal = round($fVal, $iPrecision);
}
return $fVal;
}
/**
* detectHttpUri() method detects and returns available URI - resolve Prestashop compatibility
*
* @param string $sURI
* @return string
*/
public static function detectHttpUri($sURI)
{
// use case - only with relative URI
if (!strstr($sURI, 'http')) {
$sURI = 'http' . (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off'? 's' : '') . '://' . $_SERVER['HTTP_HOST'] . $sURI;
}
return $sURI;
}
/**
* truncateUri() method truncate current request_uri in order to delete params : sAction and sType
*
* @return string
*/
public static function truncateUri()
{
return (
strstr($_SERVER['REQUEST_URI'], '&sAction')? substr($_SERVER['REQUEST_URI'], 0 , strpos($_SERVER['REQUEST_URI'], '&sAction' )) : $_SERVER['REQUEST_URI']
);
}
/**
* jsonEncode() method detects available method and apply json encode
*
* @param array $aData
* @return string
*/
public static function jsonEncode($aData)
{
if (function_exists('json_encode')) {
$aData = json_encode($aData);
}
elseif (method_exists('Tools', 'jsonEncode')) {
$aData = Tools::jsonEncode($aData);
}
else {
if (is_null($aData)) {
return 'null';
}
if ($aData === false) {
return 'false';
}
if ($aData === true) {
return 'true';
}
if (is_scalar($aData)) {
$aData = addslashes($aData);
$aData = str_replace("\n", '\n', $aData);
$aData = str_replace("\r", '\r', $aData);
$aData = preg_replace('{(</)(script)}i', "$1'+'$2", $aData);
return "'$aData'";
}
$isList = true;
for ($i=0, reset($aData); $i<count($aData); $i++, next($aData)) {
if (key($aData) !== $i) {
$isList = false;
break;
}
}
$result = array();
if ($isList) {
foreach ($aData as $v) {
$result[] = self::json_encode($v);
}
$aData = '[ ' . join(', ', $result) . ' ]';
}
else {
foreach ($aData as $k => $v) {
$result[] = self::json_encode($k) . ': ' . self::json_encode($v);
}
$aData = '{ ' . join(', ', $result) . ' }';
}
}
return $aData;
}
/**
* jsonDecode() method detects available method and apply json decode
*
* @param array $aData
* @return mixed
*/
public static function jsonDecode($aData)
{
if (function_exists('json_decode')) {
$aData = json_decode($aData);
}
elseif (method_exists('Tools', 'jsonDecode')) {
$aData = Tools::jsonDecode($aData);
}
return $aData;
}
}