112 $connection = Main\Application::getConnection();
113 $type = $connection->getType();
114 if ($type ==
"mysql")
116 $sqlDelete =
"TRUNCATE TABLE ".self::getTableName();
117 $connection->query($sqlDelete);
119 $sqlInsertInSelect =
"
120 INSERT INTO ".self::getTableName().
" (USER_ID, LID, CURRENCY, LAST_ORDER_DATE, COUNT_FULL_PAID_ORDER, COUNT_PART_PAID_ORDER, SUM_PAID)
121 SELECT UN.USER_ID, UN.LID, UN.CURRENCY, MAX(UN.DATE_INSERT), SUM(CASE WHEN UN.PAYED = 'Y' THEN 1 ELSE 0 END), SUM(CASE WHEN NOT UN.SUM_PAID = 0 THEN 1 ELSE 0 END), SUM(UN.SUM_PAID)
123 (SELECT USER_ID, LID, CURRENCY, DATE_INSERT, PAYED, SUM_PAID FROM b_sale_order)
125 (SELECT USER_ID, LID, CURRENCY, DATE_INSERT, PAYED, SUM_PAID FROM b_sale_order_archive)
127 GROUP BY UN.USER_ID, UN.CURRENCY, UN.LID
128 ORDER BY UN.USER_ID";
129 $connection->query($sqlInsertInSelect);