feat[BE]: membetulkan perhitungan hpp di module penjualan harian

This commit is contained in:
aguhh18
2025-12-18 09:58:31 +07:00
parent a7069a2e50
commit 1b23861656
11 changed files with 592 additions and 299 deletions
@@ -25,6 +25,7 @@ type PurchaseRepository interface {
NextPrNumber(ctx context.Context, tx *gorm.DB) (string, error)
NextPoNumber(ctx context.Context, tx *gorm.DB) (string, error)
BackfillProjectFlockKandang(ctx context.Context, purchaseID uint) error
GetItemsByProjectFlockID(ctx context.Context, projectFlockID uint) ([]entity.PurchaseItem, error)
}
type PurchaseRepositoryImpl struct {
@@ -289,6 +290,17 @@ func (r *PurchaseRepositoryImpl) numberExists(ctx context.Context, db *gorm.DB,
return count > 0, nil
}
func (r *PurchaseRepositoryImpl) GetItemsByProjectFlockID(ctx context.Context, projectFlockID uint) ([]entity.PurchaseItem, error) {
var items []entity.PurchaseItem
err := r.DB().WithContext(ctx).
Preload("Product").
Preload("Product.Flags").
Joins("JOIN project_flock_kandangs ON project_flock_kandangs.id = purchase_items.project_flock_kandang_id").
Where("project_flock_kandangs.project_flock_id = ?", projectFlockID).
Find(&items).Error
return items, err
}
func parseNumericSuffix(value, prefix string) (int, bool) {
if !strings.HasPrefix(value, prefix) {
return 0, false