stock request table created

This commit is contained in:
2026-07-04 17:49:54 +05:30
parent f220c24c17
commit abe2cb997b
24 changed files with 648 additions and 61 deletions

View File

@@ -21,6 +21,7 @@ type OrderService interface {
GetCustomerOrdersv3(customerID, tenantID, moduleID, fromDate, toDate, orderStatus, keyword string, pageSize, offset int) ([]models.CustomerOrder, error)
GetTenantLocationOrders(input models.DeliveryQuery) ([]models.OrderInfo, error)
GetRevenueSummary(tid, lid int, fdate, tdate string) (*models.TenantRevenueSummary, error)
GetSalesSummary(tid, lid int, fdate, tdate string) (*models.SalesSummaryResponse, error)
}
type orderService struct {
@@ -91,3 +92,7 @@ func (s *orderService) GetRevenueSummary(tid, lid int, fdate, tdate string) (*mo
return s.repo.GetRevenueSummary(tid, lid, fdate, tdate)
}
func (s *orderService) GetSalesSummary(tid, lid int, fdate, tdate string) (*models.SalesSummaryResponse, error) {
return s.repo.GetSalesSummary(tid, lid, fdate, tdate)
}

View File

@@ -12,6 +12,7 @@ type PartnerService interface {
GetLocationConfig(uid, cid int) ([]models.Locationconfigs, error)
GetRiderLogs(pid, aid int, fdate, tdate string) ([]models.RiderlogDetails, error)
GetRiderInfo(userid int) (models.RiderInfo, error)
GetFleetSummary(aid, tid int, fdate, tdate string) (models.FleetSummary, error)
}
type partnerService struct {
@@ -53,3 +54,7 @@ func (s *partnerService) GetRiderLogs(pid, aid int, fdate, tdate string) ([]mode
func (s *partnerService) GetRiderInfo(userid int) (models.RiderInfo, error) {
return s.repo.GetRiderInfo(userid)
}
func (s *partnerService) GetFleetSummary(aid, tid int, fdate, tdate string) (models.FleetSummary, error) {
return s.repo.GetFleetSummary(aid, tid, fdate, tdate)
}

View File

@@ -0,0 +1,58 @@
package services
import (
"nearle/models"
"nearle/repositories"
"time"
)
type StockRequestService interface {
CreateStockRequest(req *models.StockRequest) error
GetStockRequests(tenantID int, locationID int, status string, pageNo int, pageSize int) ([]models.StockRequest, error)
UpdateStockRequest(requestID int, status string) error
}
type stockRequestService struct {
repo repositories.StockRequestRepository
productService ProductService
}
func NewStockRequestService(repo repositories.StockRequestRepository, productService ProductService) StockRequestService {
return &stockRequestService{repo: repo, productService: productService}
}
func (s *stockRequestService) CreateStockRequest(req *models.StockRequest) error {
return s.repo.CreateStockRequest(req)
}
func (s *stockRequestService) GetStockRequests(tenantID int, locationID int, status string, pageNo int, pageSize int) ([]models.StockRequest, error) {
return s.repo.GetStockRequests(tenantID, locationID, status, pageNo, pageSize)
}
func (s *stockRequestService) UpdateStockRequest(requestID int, status string) error {
// If the request is being marked as Received, we need to update the actual store inventory
if status == "Received" {
req, err := s.repo.GetStockRequestByID(requestID)
if err != nil {
return err
}
if req.Status != "Received" { // prevent double receiving
stk := models.Productstock{
Tenantid: req.Tenantid,
Locationid: req.Locationid,
Productid: req.Productid,
Quantity: req.Qty,
Stocktype: "Credit",
Stockdate: time.Now(),
}
err = s.productService.CreateProductStock([]models.Productstock{stk})
if err != nil {
return err
}
}
}
return s.repo.UpdateStockRequest(requestID, status)
}

View File

@@ -17,6 +17,7 @@ type TenantService interface {
GetTenantPricing(tid, aid int) (models.Tenantpricing, error)
UpdateLocation(input models.Tenantlocations) error
CreateLocation(data models.Tenantlocations) error
DeleteLocation(locationid int, tenantid int) error
GetStaffs(tid int) ([]models.StaffInfo, error)
CreateStaff(user models.User) error
UpdateStaff(user models.User) error
@@ -89,6 +90,10 @@ func (s *tenantService) CreateLocation(data models.Tenantlocations) error {
return s.repo.CreateLocation(data)
}
func (s *tenantService) DeleteLocation(locationid int, tenantid int) error {
return s.repo.DeleteLocation(locationid, tenantid)
}
func (s *tenantService) GetStaffs(tid int) ([]models.StaffInfo, error) {
return s.repo.GetStaffs(tid)
}

View File

@@ -143,6 +143,19 @@ func (s *userService) AppLogin(user models.User) (models.TenantUserInfo, fiber.M
// ✅ Fetch tenant user info
info := s.repo.GetTenantUserById(uid)
// ✅ Check if assigned store is inactive
if info.Locationid > 0 {
storeStatus := s.repo.GetLocationStatus(info.Locationid)
if storeStatus == "InActive" {
resp := fiber.Map{
"status": false,
"code": 403,
"message": "Assigned store is inactive. Contact admin.",
}
return models.TenantUserInfo{}, resp, errors.New("inactive store")
}
}
// ✅ Return success response
resp := fiber.Map{
"status": true,
@@ -247,8 +260,6 @@ func (s *userService) TenantWebLogin(user models.User) (models.TenantUserInfo, m
}
}
user.Userid = uid
// Step 4: Update FCM if provided
if user.Userfcmtoken != "" {
_ = s.repo.UpdateUserFcmToken(uid, user.Userfcmtoken)
@@ -257,6 +268,18 @@ func (s *userService) TenantWebLogin(user models.User) (models.TenantUserInfo, m
// Step 5: Get full tenant info
info := s.repo.GetTenantUserById(uid)
// Step 6: Check if assigned store is inactive
if info.Locationid > 0 {
storeStatus := s.repo.GetLocationStatus(info.Locationid)
if storeStatus == "InActive" {
return models.TenantUserInfo{}, map[string]interface{}{
"status": false,
"code": 403,
"message": "Assigned store is inactive. Contact admin.",
}
}
}
return info, map[string]interface{}{
"status": true,
"code": 200,