mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-24 15:25:43 +00:00
adjust repo hpp v2
This commit is contained in:
@@ -266,6 +266,26 @@ func (r *HppV2RepositoryImpl) GetRecordingStockRoutingAdjustmentCostByProjectFlo
|
||||
utils.FlagVitamin,
|
||||
utils.FlagKimia,
|
||||
}
|
||||
transferExistsCondition := `
|
||||
EXISTS (
|
||||
SELECT 1
|
||||
FROM laying_transfer_targets AS ltt
|
||||
JOIN laying_transfers AS lt ON lt.id = ltt.laying_transfer_id
|
||||
WHERE ltt.deleted_at IS NULL
|
||||
AND lt.deleted_at IS NULL
|
||||
AND lt.executed_at IS NOT NULL
|
||||
AND ltt.target_project_flock_kandang_id = r.project_flock_kandangs_id
|
||||
AND COALESCE(DATE(lt.effective_move_date), DATE(lt.economic_cutoff_date), DATE(lt.transfer_date)) <= DATE(?)
|
||||
AND (
|
||||
SELECT a.action
|
||||
FROM approvals a
|
||||
WHERE a.approvable_type = ?
|
||||
AND a.approvable_id = lt.id
|
||||
ORDER BY a.id DESC
|
||||
LIMIT 1
|
||||
) = ?
|
||||
)
|
||||
`
|
||||
|
||||
var total float64
|
||||
err := r.db.WithContext(ctx).
|
||||
@@ -284,7 +304,19 @@ func (r *HppV2RepositoryImpl) GetRecordingStockRoutingAdjustmentCostByProjectFlo
|
||||
Joins("JOIN purchase_items AS pi ON pi.id = sa.stockable_id").
|
||||
Where("pfk_rec.project_flock_id = ?", projectFlockID).
|
||||
Where("DATE(r.record_datetime) <= DATE(?)", periodDate).
|
||||
Where("(rs.project_flock_kandang_id IS NULL OR rs.project_flock_kandang_id <> r.project_flock_kandangs_id)").
|
||||
Where(
|
||||
fmt.Sprintf(
|
||||
"((%s) AND rs.project_flock_kandang_id IS NOT NULL AND rs.project_flock_kandang_id <> r.project_flock_kandangs_id) OR (NOT (%s) AND rs.project_flock_kandang_id IS NULL)",
|
||||
transferExistsCondition,
|
||||
transferExistsCondition,
|
||||
),
|
||||
periodDate,
|
||||
string(utils.ApprovalWorkflowTransferToLaying),
|
||||
entity.ApprovalActionApproved,
|
||||
periodDate,
|
||||
string(utils.ApprovalWorkflowTransferToLaying),
|
||||
entity.ApprovalActionApproved,
|
||||
).
|
||||
Where("EXISTS (SELECT 1 FROM flags f WHERE f.flagable_id = pw.product_id AND f.flagable_type = ? AND f.name IN ?)", entity.FlagableTypeProduct, flags).
|
||||
Scan(&total).Error
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user