CMXX - Improved whereclause
This commit is contained in:
@@ -190,6 +190,7 @@ function menu($selected,$selected_child){
|
||||
}
|
||||
return $menu;
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
// Template Header
|
||||
//------------------------------------------
|
||||
@@ -642,6 +643,89 @@ function ioAPIv2($api_call, $data, $token){
|
||||
return $resp;
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
// DEFINE WHERECLAUSE BASED ON ACCOUNTHIERARCHY ALL
|
||||
//------------------------------------------
|
||||
|
||||
function getWhereclause($table_name,$permission,$partner){
|
||||
|
||||
//api_name converter to table
|
||||
$table =[
|
||||
"equipment" => "e.accounthierarchy",
|
||||
"profile" => "partnerhierarchy"
|
||||
];
|
||||
|
||||
$table = ($table_name != '') ? $table[$table_name] : 'accounthierarchy';
|
||||
|
||||
//SoldTo is empty
|
||||
if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} else {$soldto_search = '-%';}
|
||||
|
||||
//default whereclause
|
||||
$whereclause = '';
|
||||
|
||||
switch ($permission) {
|
||||
case '4':
|
||||
$whereclause = '';
|
||||
break;
|
||||
case '3':
|
||||
$whereclause = '';
|
||||
break;
|
||||
case '2':
|
||||
$condition = '__salesid___'.$partner->salesid.'___soldto___'.substr($partner->soldto, 0, strpos($partner->soldto, "-")).$soldto_search;
|
||||
$whereclause = 'WHERE '.$table.' like :condition ';
|
||||
break;
|
||||
default:
|
||||
$condition = '__salesid___'.$partner->salesid.'___soldto___'.substr($partner->soldto, 0, strpos($partner->soldto, "-")).$soldto_search.'___shipto___'.substr($partner->shipto, 0, strpos($partner->shipto, "-")).'%___location___'.substr($partner->location, 0, strpos($partner->location, "-")).'%';
|
||||
$whereclause = 'WHERE '.$table.' like :condition ';
|
||||
break;
|
||||
}
|
||||
|
||||
return array($whereclause,$condition);
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
// DEFINE WHERECLAUSE BASED ON ACCOUNTHIERARCHY SALES AND SOLD
|
||||
//------------------------------------------
|
||||
function getWhereclauselvl2($table_name,$permission,$partner){
|
||||
|
||||
//api_name converter to table
|
||||
$table =[
|
||||
"pricelist" => "pls.accounthierarchy",
|
||||
"communications" => "salesID",
|
||||
"partners" => "salesID",
|
||||
"discounts" => "d.accounthierarchy",
|
||||
"invoice" => "inv.accounthierarchy",
|
||||
"attributes" => "pat.accounthierarchy",
|
||||
"config" => "pc.accounthierarchy",
|
||||
"software" => "p.accounthierarchy",
|
||||
"transactions" => "tx.accounthierarchy",
|
||||
"categories" => "c.accounthierarchy"
|
||||
];
|
||||
|
||||
$table = ($table_name != '') ? $table[$table_name] : 'accounthierarchy';
|
||||
|
||||
//SoldTo is empty
|
||||
if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} else {$soldto_search = '-%';}
|
||||
|
||||
//default whereclause
|
||||
$whereclause = '';
|
||||
|
||||
switch ($permission) {
|
||||
case '4':
|
||||
$whereclause = '';
|
||||
break;
|
||||
case '3':
|
||||
$whereclause = '';
|
||||
break;
|
||||
default:
|
||||
$condition = '__salesid___'.$partner->salesid.'___soldto___'.substr($partner->soldto, 0, strpos($partner->soldto, "-")).$soldto_search;
|
||||
$whereclause = 'WHERE '.$table.' like "'.$condition.'"';
|
||||
break;
|
||||
}
|
||||
|
||||
return array($whereclause,$condition);
|
||||
}
|
||||
|
||||
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
//get user profile||$profile=settings, $permision = userright()
|
||||
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
@@ -3439,14 +3523,26 @@ function transformOrderData(array $orderData): array {
|
||||
$firstRow = $orderData[0];
|
||||
|
||||
$result = [
|
||||
'header' => [
|
||||
"id" => $firstRow['id'],
|
||||
"txn_id" => $firstRow['txn_id'],
|
||||
"payment_status" => $firstRow['payment_status'],
|
||||
"payment_method" => $firstRow['payment_method'],
|
||||
"shipping_method" => $firstRow['shipping_method'],
|
||||
"discount_code" => $firstRow['discount_code'],
|
||||
"created" => $firstRow['created'],
|
||||
"updated " => $firstRow['updated']
|
||||
],
|
||||
'customer' => [
|
||||
'account_id' => $firstRow['account_id'],
|
||||
'email' => $firstRow['payer_email'],
|
||||
'name' => $firstRow['first_name'] . ' ' . $firstRow['last_name'],
|
||||
'street' => $firstRow['address_street'],
|
||||
'zip' => $firstRow['address_zip'],
|
||||
'state' => $firstRow['address_state'],
|
||||
'city' => $firstRow['address_city'],
|
||||
'country' => $firstRow['address_country']
|
||||
|
||||
'country' => $firstRow['address_country'],
|
||||
'phone' => $firstRow['address_phone']
|
||||
],
|
||||
'products' => [],
|
||||
'invoice' => [
|
||||
@@ -3477,6 +3573,7 @@ function transformOrderData(array $orderData): array {
|
||||
// Add product information
|
||||
$result['products'][] = [
|
||||
'item_id' => $row['item_id'],
|
||||
'productcode' => $row['productcode'],
|
||||
'product_name' => $row['productname'],
|
||||
'options' => $itemOptions,
|
||||
'quantity' => $row['item_quantity'],
|
||||
@@ -3493,4 +3590,67 @@ function transformOrderData(array $orderData): array {
|
||||
$result['pricing']['payment_amount'] = number_format(floatval($result['pricing']['payment_amount']), 2, '.', '');
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
//=============================================
|
||||
// Use giftcart
|
||||
//=============================================
|
||||
|
||||
function useGiftCart($pdo, $discount_code, $accounthierarchy){
|
||||
|
||||
// Get the current date
|
||||
$end_date = date("Y-m-d H:i:s");
|
||||
|
||||
//Check if Giftcard already exists
|
||||
$stmt = $pdo->prepare('SELECT * from discounts WHERE discount_code = ? AND accounthierarchy = ?');
|
||||
$stmt->execute([$discount_code,$accounthierarchy]);
|
||||
$discount_exist = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
if (!empty($discount_exist) || $discount_exist != '') {
|
||||
//Update Giftcard end data
|
||||
$stmt = $pdo->prepare('UPDATE discounts SET end_date = ? WHERE discount_code = ? AND accounthierarchy = ?');
|
||||
$stmt->execute([$end_date,$discount_code, $accounthierarchy]);
|
||||
}
|
||||
}
|
||||
|
||||
function createGiftCart($pdo, $orderID, $giftcard_categoryID,$accounthierarchy){
|
||||
|
||||
//Check if Giftcard is ordered
|
||||
$stmt = $pdo->prepare('SELECT t.payer_email as email, ti.id as id, t.txn_id as txn, ti.item_price as item_price, ti.item_quantity as item_quantity FROM transactions t INNER JOIN transactions_items ti ON t.txn_id = ti.txn_id INNER JOIN products_categories p ON ti.item_id = p.product_id WHERE p.category_id = ? AND ti.txn_id = ? AND accounthierarchy = ?');
|
||||
$stmt->execute([$giftcard_categoryID,$orderID,$accounthierarchy]);
|
||||
$giftcards = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
if ($giftcards) {
|
||||
foreach ($giftcards as $giftcard) {
|
||||
|
||||
//For each quantity
|
||||
$x = 0;
|
||||
|
||||
while ($x < $giftcard['item_quantity']){
|
||||
|
||||
//Generate discount code = TXN/ID/X
|
||||
$discount_code = $giftcard['txn'].'#'.$giftcard['id'].'#'.$x;
|
||||
$value = $giftcard['item_price'];
|
||||
|
||||
// Get the current date
|
||||
$start_date = date("Y-m-d H:i:s");
|
||||
$end_date = date("Y-m-d H:i:s", strtotime("+5 years"));;
|
||||
|
||||
//Check if Giftcard already exists
|
||||
$stmt = $pdo->prepare('SELECT * from discounts WHERE discount_code = ? AND accounthierarchy = ?');
|
||||
$stmt->execute([$discount_code,$accounthierarchy]);
|
||||
$discount_exist = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
if (empty($discount_exist) || $discount_exist == '') {
|
||||
//Insert Giftcard
|
||||
$discount_type = 0; //Fixed
|
||||
//SQL Insert
|
||||
$stmt = $pdo->prepare('INSERT INTO discounts (discount_code,discount_type,discount_value,start_date,end_date,accounthierarchy) VALUES (?,?,?,?,?,?)');
|
||||
$stmt->execute([$discount_code, $discount_type, $value, $start_date, $end_date,$accounthierarchy]);
|
||||
}
|
||||
$x++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user