Nama ERP DocsNama ERP Docs
Home
Namasoft.com
Data Model
GitHub
Home
Namasoft.com
Data Model
GitHub
  • Home

    • Search
    • Getting Started
    • Platform Features

      • Screen Modifier
      • List Views
      • Approvals
      • الصلاحيات والأمان
      • Entity Flows
      • Reports
      • Business Intelligence
      • Notifications
      • .
    • Modules

      • الفواتير والضرائب والخصومات
      • Supply Chain
      • Manufacturing
      • Human Resources
      • Point of Sale
      • Real Estate
      • Mobile Applications
      • e-commerce Integration
      • .
    • External Integrations
    • System Administration

      • Troubleshooting
      • Reprocessing Transactions

        • Reprocessing Quantity, Cost, and Stock Ages
        • Accounting Utilities - Ledger and Debt Ages Reprocessing
        • Queries to Check for (and Fix) Cost And Qty Problems
        • Inventory Related Utility Queries
        • Manufacturing Utilities
        • Fixed Assets Module Utilities
        • Real Estate Utilities
        • Database Related Operations
        • Suggest Indexes for Large Detail Tables
        • General Purpose Utility Queries
        • Replication Utilities
        • .
      • .
    • Developer Reference
    • AI Generated Entity Flows Documentation

      • Core
      • Accounting Module
      • AI Module
      • Contracting Module
      • CRM Module
      • EGTax Reader Module
      • Freight Management System Module
      • Hospital Management System Module
      • HR Module
      • e-commerce Integration Module
      • Manufacturing Module
      • POS Module
      • Real Estate Module
      • Service Center Module
      • Supply Chain Module
      • .
    • Release Notes

      • 2016
      • 2017
      • 2018
      • 2019
      • 2020
      • 2021
      • 2022
      • 2023
      • 2024
      • 2025
      • 2026
      • .
    • Video Tutorials

      • Supply Chain Videos
      • Report Wizard Videos
      • Human Resources Videos
      • .

Manufacturing Utilities

Production Delivery Cost Problem (Cost Callback)

Details
with delivery as (
select sum(cin.netCost) receiptCost,po.id from ProductionOrder po inner join ProductDelivery pod on pod.productionOrder_id = po.id inner join StockReceipt sr on sr.fromDoc_id = pod.id
inner join CostInTransLine cin on cin.originId = sr.id 
group by po.id
),
issue as (
select sum(cout.netCost) materialCost,po.id from ProductionOrder po inner join RawMaterialIssue pod on pod.productionOrder_id = po.id inner join StockIssue sr on sr.fromDoc_id = pod.id
inner join CostOutTransLine cout on cout.originId = sr.id
group by po.id
),
ret as (
select sum(cin.netCost) retCost,po.id from ProductionOrder po inner join RawMaterialReturn pod on pod.productionOrder_id = po.id inner join StockReceipt sr on sr.fromDoc_id = pod.id
inner join CostInTransLine cin on cin.originId = sr.id 
group by po.id
),
resources as(
select sum(l.total) resourceCost,po.id from ProductionOrder po inner join ResourceVoucher v on v.productionOrder_id = po.id left join ResourceVoucherLine l on l.resourceVoucher_id = v.id
group by po.id
)
select cv.entityType, cv.id,po.valueDate, receiptCost,materialCost+resourceCost-coalesce(retCost,0),receiptCost-(materialCost+resourceCost-coalesce(retCost,0)),issue.materialCost,ret.retCost,resources.resourceCost from ProductionOrder po left join
delivery on delivery.id = po.id left join issue on issue.id = po.id left join ret on ret.id = po.id 
left join resources on resources.id = po.id
left join OrderCloseVoucher cv on cv.productionOrder_id = po.id
where abs(receiptCost-(materialCost+resourceCost-coalesce(retCost,0)))>1.5 and cv.id is not null

Zombie ProductionMovementSysEntry

Details
delete e from ProductionMovementSysEntry e left join EntitySystemEntry ese on ese.targetId = e.ownerid
where ese.id is null

Edit On github
Last Updated:: 6/4/26, 9:58 PM
Prev
Inventory Related Utility Queries
Next
Fixed Assets Module Utilities