/** * @param string $dateBegin datestamp (YYYYMMDD) for the date when the first customer should be created. * @param bool $switchDateOnNewCustomer 'true' - create customers day by day, 'false' - create all customers * in one day. */ protected function _createDownlineCustomers($dateBegin = self::DATE_PERIOD_BEGIN, $switchDateOnNewCustomer = true) { $dtToday = $dateBegin; foreach ($this->DEFAULT_DWNL_TREE as $customerRef => $parentRef) { $customerMageId = $this->_mapCustomerMageIdByIndex[$customerRef]; /* get magento customer data */ $request = new CustomerAddRequest(); $request->setCustomerId($customerMageId); $request->setParentId($this->_mapCustomerMageIdByIndex[$parentRef]); $request->setReference($this->_mapCustomerMageIdByIndex[$customerRef]); $request->setCountryCode(self::DEFAULT_DOWNLINE_COUNTRY_CODE); $request->setDate($this->_toolPeriod->getTimestampFrom($dtToday)); /* Create customer per day or all customers in the same day. */ if ($switchDateOnNewCustomer) { $dtToday = $this->_toolPeriod->getPeriodNext($dtToday); } $response = $this->_callDownlineCustomer->add($request); if ($response->isSucceed()) { $path = $response->getData(Customer::ATTR_PATH); $depth = $response->getData(Customer::ATTR_DEPTH); $this->_logger->debug("New customer #{$customerMageId} is added to path '{$path}' on depth {$depth} at '{$dtToday}'."); } else { $this->_logger->error("Cannot add new customer #{$customerMageId} to downline tree."); } } }
public function calc(Request\Calc $request) { $result = new Response\Calc(); $assetTypeId = $request->getAssetTypeId(); $dateTo = $request->getDateTo(); /* get the last balance date */ $reqLastDate = new Request\GetLastDate(); $reqLastDate->setData(Request\GetLastDate::ASSET_TYPE_ID, $assetTypeId); $respLastDate = $this->getLastDate($reqLastDate); $lastDate = $respLastDate->getLastDate(); $balances = $this->_repoMod->getBalancesOnDate($assetTypeId, $lastDate); /* get transactions for period */ $dtFrom = $this->_toolPeriod->getTimestampFrom($lastDate, IPeriod::TYPE_DAY); $dtTo = $this->_toolPeriod->getTimestampTo($dateTo, IPeriod::TYPE_DAY); $trans = $this->_repoMod->getTransactionsForPeriod($assetTypeId, $dtFrom, $dtTo); $updates = $this->_subCalcSimple->calcBalances($balances, $trans); $this->_repoMod->updateBalances($updates); $result->markSucceed(); return $result; }
/** * SELECT * SUM(pps.total) * FROM `prxgt_pv_sale` AS `pps` * WHERE (pps.date_paid >= '2016-01-01 08:00:00') * AND (pps.date_paid <= '2017-01-01 07:59:59') * * @param string $dsFrom * @param string $dsTo */ function getSalesOrdersPvForPeriod($dsFrom, $dsTo) { $tsFrom = $this->_toolPeriod->getTimestampFrom($dsFrom); $tsTo = $this->_toolPeriod->getTimestampTo($dsTo); /* aliases and tables */ $asSummary = 'summary'; $asPv = 'pps'; $tblPv = $this->_resource->getTableName(PvSale::ENTITY_NAME); // SELECT FROM prxgt_pv_sale pps $query = $this->_conn->select(); $query->from([$asPv => $tblPv], [$asSummary => 'SUM(' . PvSale::ATTR_TOTAL . ')']); // where $whereFrom = $asPv . '.' . PvSale::ATTR_DATE_PAID . '>=' . $this->_conn->quote($tsFrom); $whereTo = $asPv . '.' . PvSale::ATTR_DATE_PAID . '<=' . $this->_conn->quote($tsTo); $query->where("{$whereFrom} AND {$whereTo}"); // $sql = (string)$query; $result = $this->_conn->fetchOne($query); return $result; }
/** * SELECT * pps.sale_id, * pps.date_paid, * sfo.base_grand_total, * ce.entity_id * FROM prxgt_pv_sale pps * LEFT JOIN sales_flat_order sfo * ON pps.sale_id = sfo.entity_id * LEFT JOIN customer_entity ce * ON sfo.customer_id = ce.entity_id * WHERE pps.date_paid >= '2016-01-01 00:00:00' * AND pps.date_paid <= '2016-01-31 23:59:59' * * @param $dsBegin - '20160101' * @param $dsEnd - '20160131' * * @return array [ $custId => [$orderId=>[$amount], ... ], ... ] */ public function getSaleOrdersForRebate($dsBegin, $dsEnd) { $result = []; /* aliases and tables */ $asPvSale = 'pps'; $asMageSale = 'sfo'; $asMageCust = 'ce'; $tblPvSale = $this->_resource->getTableName(PvSale::ENTITY_NAME); $tblMageSale = $this->_resource->getTableName(Cfg::ENTITY_MAGE_SALES_ORDER); $tblMageCust = $this->_resource->getTableName(Cfg::ENTITY_MAGE_CUSTOMER); // FROM prxgt_pv_sale pps $query = $this->_conn->select(); $cols = [PvSale::ATTR_SALE_ID, PvSale::ATTR_DATE_PAID]; $query->from([$asPvSale => $tblPvSale], $cols); // LEFT JOIN sales_flat_order sfo ON pps.sale_id = sfo.entity_id $on = "{$asPvSale}." . PvSale::ATTR_SALE_ID . "={$asMageSale}." . Cfg::E_COMMON_A_ENTITY_ID; $cols = [Cfg::E_SALE_ORDER_A_BASE_GRAND_TOTAL]; $query->joinLeft([$asMageSale => $tblMageSale], $on, $cols); // LEFT JOIN customer_entity ce ON sfo.customer_id = ce.entity_id $on = "{$asMageSale}." . Cfg::E_SALE_ORDER_A_CUSTOMER_ID . "={$asMageCust}." . Cfg::E_CUSTOMER_A_ENTITY_ID; $cols = [Cfg::E_CUSTOMER_A_ENTITY_ID]; $query->joinLeft([$asMageCust => $tblMageCust], $on, $cols); // where $from = $this->_toolPeriod->getTimestampFrom($dsBegin); $to = $this->_toolPeriod->getTimestampTo($dsEnd); $whereFrom = PvSale::ATTR_DATE_PAID . '>=' . $this->_conn->quote($from); $whereTo = PvSale::ATTR_DATE_PAID . '<=' . $this->_conn->quote($to); $wherePv = PvSale::ATTR_TOTAL . ">0"; $query->where("{$whereFrom} AND {$whereTo} AND {$wherePv}"); // $sql = (string)$query; $data = $this->_conn->fetchAll($query); foreach ($data as $item) { $custId = $item[Cfg::E_CUSTOMER_A_ENTITY_ID]; $saleId = $item[PvSale::ATTR_SALE_ID]; $amount = $item[Cfg::E_SALE_ORDER_A_BASE_GRAND_TOTAL]; $result[$custId][$saleId] = $amount; } return $result; }
/** * SELECT * `pps`.`sale_id`, * `sfo`.`customer_id` * FROM `prxgt_pv_sale` AS `pps` * LEFT JOIN `sales_flat_order` AS `sfo` * ON pps.sale_id = sfo.entity_id * WHERE (pps.date_paid >= '2016-01-01 08:00:00' * AND pps.date_paid <= '2017-01-01 07:59:59') * * @param string $dsFrom * @param string $dsTo * * @return array */ function getSalesOrdersForPeriod($dsFrom, $dsTo) { $tsFrom = $this->_toolPeriod->getTimestampFrom($dsFrom); $tsTo = $this->_toolPeriod->getTimestampTo($dsTo); /* aliases and tables */ $asPv = 'pps'; $asOrder = 'sfo'; $tblPv = $this->_resource->getTableName(PvSale::ENTITY_NAME); $tblOrder = $this->_resource->getTableName(Cfg::ENTITY_MAGE_SALES_ORDER); // SELECT FROM prxgt_pv_sale pps $query = $this->_conn->select(); $query->from([$asPv => $tblPv], [PvSale::ATTR_SALE_ID, PvSale::ATTR_TOTAL]); // LEFT JOIN sales_flat_order sfo ON pps.sale_id = sfo.entity_id $on = "{$asPv}." . PvSale::ATTR_SALE_ID . "={$asOrder}." . Cfg::E_SALE_ORDER_A_ENTITY_ID; $cols = [Cfg::E_SALE_ORDER_A_CUSTOMER_ID]; $query->joinLeft([$asOrder => $tblOrder], $on, $cols); // where $whereFrom = $asPv . '.' . PvSale::ATTR_DATE_PAID . '>=' . $this->_conn->quote($tsFrom); $whereTo = $asPv . '.' . PvSale::ATTR_DATE_PAID . '<=' . $this->_conn->quote($tsTo); $query->where("{$whereFrom} AND {$whereTo}"); // $sql = (string)$query; $result = $this->_conn->fetchAll($query); return $result; }