7199-devToTest_2316 #2287
|
@ -8,59 +8,22 @@ BEGIN
|
||||||
UPDATE accountReconciliation ar
|
UPDATE accountReconciliation ar
|
||||||
JOIN (
|
JOIN (
|
||||||
SELECT id,
|
SELECT id,
|
||||||
calculatedId,
|
calculatedCode,
|
||||||
CONCAT(
|
CONCAT(
|
||||||
calculatedId,
|
calculatedCode,
|
||||||
'(',
|
'(',
|
||||||
ROW_NUMBER() OVER (PARTITION BY calculatedId ORDER BY id),
|
ROW_NUMBER() OVER (PARTITION BY calculatedCode ORDER BY id),
|
||||||
')'
|
')'
|
||||||
) newId
|
) newId
|
||||||
FROM accountReconciliation
|
FROM accountReconciliation ar
|
||||||
WHERE calculatedId IN (
|
WHERE calculatedCode IN (
|
||||||
SELECT calculatedId
|
SELECT calculatedCode
|
||||||
FROM accountReconciliation
|
FROM accountReconciliation
|
||||||
GROUP BY calculatedId
|
GROUP BY calculatedCode
|
||||||
HAVING COUNT(*) > 1
|
HAVING COUNT(*) > 1
|
||||||
)
|
)
|
||||||
ORDER BY calculatedId, id
|
ORDER BY calculatedCode, id
|
||||||
) sub2 ON ar.id = sub2.id
|
) sub2 ON ar.id = sub2.id
|
||||||
SET ar.calculatedId = sub2.newId;
|
SET ar.calculatedCode = sub2.newId;
|
||||||
|
|
||||||
INSERT INTO till(
|
|
||||||
dated,
|
|
||||||
isAccountable,
|
|
||||||
serie,
|
|
||||||
concept,
|
|
||||||
`in`,
|
|
||||||
`out`,
|
|
||||||
bankFk,
|
|
||||||
companyFk,
|
|
||||||
warehouseFk,
|
|
||||||
supplierAccountFk,
|
|
||||||
calculatedCode,
|
|
||||||
InForeignValue,
|
|
||||||
OutForeignValue,
|
|
||||||
workerFk
|
|
||||||
)
|
|
||||||
SELECT ar.operationDate dated,
|
|
||||||
TRUE isAccountable,
|
|
||||||
'MB' serie,
|
|
||||||
ar.concept concept,
|
|
||||||
@totalIn := IF(ar.debitCredit = arc.debitCredit2 AND a.currencyFk = arc.currencyFk, ar.amount, NULL) `in`,
|
|
||||||
@totalOut := IF(ar.debitCredit = arc.debitCredit AND a.currencyFk = arc.currencyFk, ar.amount, NULL) `out`,
|
|
||||||
a.id bankFk,
|
|
||||||
sa.supplierFk companyFk,
|
|
||||||
arc.warehouseFk warehouseFk,
|
|
||||||
ar.supplierAccountFk supplierAccountFk,
|
|
||||||
ar.calculatedId calculatedCode,
|
|
||||||
@totalIn InForeignValue,
|
|
||||||
@totalOut OutForeignValue,
|
|
||||||
account.myUser_getId() user
|
|
||||||
FROM accountReconciliation ar
|
|
||||||
JOIN supplierAccount sa ON sa.id = ar.supplierAccountFk
|
|
||||||
JOIN accounting a ON a.id = sa.accountingFk
|
|
||||||
LEFT JOIN till t ON t.calculatedCode = ar.calculatedId
|
|
||||||
JOIN accountReconciliationConfig arc
|
|
||||||
WHERE t.id IS NULL;
|
|
||||||
END$$
|
END$$
|
||||||
DELIMITER ;
|
DELIMITER ;
|
Loading…
Reference in New Issue