Не совсем понял, на сервере нет полностью кассы или нескольких ее смен.
Если "отсутствующую" кассу зарегистрировать на сервере и она сольет на него чеки (не напутав ничего в уже существующих), то лучше так. Когда-то тут была подобная тема, но сам не делал.
По скрипту.
Готового не видел, немного поправил исходный.
Много чего еще можно доделать - безнал, скидки в cashdisc либо пересчет цены позиции в cashsail. Но по минимуму выдает верные цифры.
На v49 должно работать.
Код:
SET @shop_index=56; -- Индекс магазина
SET @date_from='2016-07-22'; -- от
SET @date_to='2016-07-22'; -- до
-- cashsail
SELECT
@shop_index AS Shopindex,
h1.pos AS CashNumber,
s3.number as Znumber,
h1.local_number CheckNumber,
i2.position AS ID,
DATE_FORMAT(h1.date, "%d/%m/%Y") AS Date,
DATE_FORMAT(h1.date, "%H%i") AS Time,
i2.item CardArticul,
"NOSIZE" AS CardSize,
REPLACE(FORMAT(i2.quantity, 3), ',', '') AS Quantity,
REPLACE(FORMAT(i2.price,2), ',', '') AS PriceRub,
0 AS PriceCur,
REPLACE(FORMAT(i2.total+i2.discount,2), ',', '') AS TotalRub,
0 AS TotalCur,
0 AS Department,
l1.user_id AS Casher,
i2.stock_id AS UsingIndex,
IF(h1.type IN(1,4,9,10),0,1) AS "Replace",
IF(h1.type IN(1,4,9,10),0,1) AS Operation,
0 AS CredCardIndex,
0 AS DiscCli,
0 AS Linked
FROM
`trm_out_receipt_header` h1
RIGHT JOIN `trm_out_receipt_footer` f1 ON h1.id = f1.id AND h1.cash_id = f1.cash_id
RIGHT JOIN `trm_out_receipt_item` i2 ON h1.id = i2.receipt_header AND h1.cash_id = i2.cash_id
RIGHT JOIN `trm_out_shift_open` s3 ON h1.shift_open = s3.id AND h1.cash_id = s3.cash_id
LEFT JOIN `trm_out_login` l1 ON s3.login = l1.id AND h1.cash_id = l1.cash_id
WHERE
(s3.date between @date_from AND CONCAT(@date_to, ' 23:59:59'))
AND f1.result=0
AND i2.type=0
ORDER BY
`h1`.`pos`,
`s3`.`number`,
`h1`.`local_number`,
`i2`.`position`;
Код:
SET @shop_index=56; -- Индекс магазина
SET @date_from='2016-07-22'; -- от
SET @date_to='2016-07-22'; -- до
-- currests
SELECT
@shop_index AS Shopindex,
h1.pos AS CashNumber,
s3.number as Znumber,
DATE_FORMAT(s3.date, "%d/%m/%Y") AS Date,
REPLACE(FORMAT(SUM(IF(h1.type IN(1,4,9,10), 0, i2.total+i2.discount)),2), ',', '') AS Sale,
REPLACE(FORMAT(SUM(IF(h1.type IN(1,4,9,10), i2.total+i2.discount, 0)),2), ',', '') AS "Return",
0 AS Storno,
0 AS StornRet,
REPLACE(FORMAT(SUM(IF(h1.type IN(1,4,9,10), -(i2.total+i2.discount), i2.total+i2.discount)),2), ',', '') AS Result,
0 AS WasOutput
FROM
`trm_out_receipt_header` h1
RIGHT JOIN `trm_out_receipt_footer` f1 ON h1.id = f1.id AND h1.cash_id = f1.cash_id
RIGHT JOIN `trm_out_receipt_item` i2 ON h1.id = i2.receipt_header AND h1.cash_id = i2.cash_id
RIGHT JOIN `trm_out_shift_open` s3 ON h1.shift_open = s3.id AND h1.cash_id = s3.cash_id
WHERE
(s3.date between @date_from AND CONCAT(@date_to, ' 23:59:59'))
AND f1.result=0
AND i2.type=0
GROUP BY
`h1`.`pos`,
`s3`.`number`;