Done upto reconcile
Pending: stock movement trial balance unposted
This commit is contained in:
parent
85d05392b8
commit
2b2430c5b2
brewman
main.py
routers/reports
overlord/src/app
cash-flow
daybook
net-transactions
purchase-entries
purchases
@ -18,7 +18,20 @@ from .routers import (
|
|||||||
login,
|
login,
|
||||||
)
|
)
|
||||||
from .routers.auth import client, user, role
|
from .routers.auth import client, user, role
|
||||||
from .routers.reports import ledger, balance_sheet, profit_loss, closing_stock
|
from .routers.reports import (
|
||||||
|
ledger,
|
||||||
|
balance_sheet,
|
||||||
|
profit_loss,
|
||||||
|
closing_stock,
|
||||||
|
cash_flow,
|
||||||
|
daybook,
|
||||||
|
net_transactions,
|
||||||
|
product_ledger,
|
||||||
|
purchase_entries,
|
||||||
|
purchases,
|
||||||
|
raw_material_cost,
|
||||||
|
reconcile,
|
||||||
|
)
|
||||||
from .db.base_class import Base
|
from .db.base_class import Base
|
||||||
from .config import Settings as settings
|
from .config import Settings as settings
|
||||||
from .db.session import engine
|
from .db.session import engine
|
||||||
@ -60,10 +73,19 @@ app.include_router(recipe.router, prefix="/api/recipes", tags=["products"])
|
|||||||
app.include_router(client.router, prefix="/api/clients", tags=["clients"])
|
app.include_router(client.router, prefix="/api/clients", tags=["clients"])
|
||||||
app.include_router(role.router, prefix="/api/roles", tags=["users"])
|
app.include_router(role.router, prefix="/api/roles", tags=["users"])
|
||||||
app.include_router(user.router, prefix="/api/users", tags=["users"])
|
app.include_router(user.router, prefix="/api/users", tags=["users"])
|
||||||
|
|
||||||
app.include_router(ledger.router, prefix="/api/ledger", tags=["reports"])
|
app.include_router(ledger.router, prefix="/api/ledger", tags=["reports"])
|
||||||
app.include_router(balance_sheet.router, prefix="/api/balance-sheet", tags=["reports"])
|
app.include_router(balance_sheet.router, prefix="/api/balance-sheet", tags=["reports"])
|
||||||
app.include_router(profit_loss.router, prefix="/api/profit-loss", tags=["reports"])
|
app.include_router(profit_loss.router, prefix="/api/profit-loss", tags=["reports"])
|
||||||
app.include_router(closing_stock.router, prefix="/api/closing-stock", tags=["reports"])
|
app.include_router(closing_stock.router, prefix="/api/closing-stock", tags=["reports"])
|
||||||
|
app.include_router(cash_flow.router, prefix="/api/cash-flow", tags=["reports"])
|
||||||
|
app.include_router(daybook.router, prefix="/api/daybook", tags=["reports"])
|
||||||
|
app.include_router(net_transactions.router, prefix="/api/net-transactions", tags=["reports"])
|
||||||
|
app.include_router(product_ledger.router, prefix="/api/product-ledger", tags=["reports"])
|
||||||
|
app.include_router(purchase_entries.router, prefix="/api/purchase-entries", tags=["reports"])
|
||||||
|
app.include_router(purchases.router, prefix="/api/purchases", tags=["reports"])
|
||||||
|
app.include_router(raw_material_cost.router, prefix="/api/raw-material-cost", tags=["reports"])
|
||||||
|
app.include_router(reconcile.router, prefix="/api/reconcile", tags=["reports"])
|
||||||
|
|
||||||
|
|
||||||
def init():
|
def init():
|
||||||
|
@ -1,8 +1,13 @@
|
|||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
|
from fastapi import APIRouter, Depends, Security, Request
|
||||||
|
from sqlalchemy.orm import Session
|
||||||
from sqlalchemy.orm.util import aliased
|
from sqlalchemy.orm.util import aliased
|
||||||
from sqlalchemy.sql.expression import func, desc
|
from sqlalchemy.sql.expression import func, desc
|
||||||
|
|
||||||
|
from ...schemas.auth import UserToken
|
||||||
|
from ...core.security import get_current_active_user as get_user
|
||||||
|
from ...db.session import SessionLocal
|
||||||
from brewman.models.master import AccountBase, AccountType
|
from brewman.models.master import AccountBase, AccountType
|
||||||
from brewman.models.voucher import Voucher, Journal, VoucherType
|
from brewman.models.voucher import Voucher, Journal, VoucherType
|
||||||
from brewman.routers.services.session import (
|
from brewman.routers.services.session import (
|
||||||
@ -11,57 +16,75 @@ from brewman.routers.services.session import (
|
|||||||
session_period_finish,
|
session_period_finish,
|
||||||
)
|
)
|
||||||
|
|
||||||
from fastapi import APIRouter
|
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
|
|
||||||
@router.get("/api/cash-flow") # "Cash Flow"
|
# Dependency
|
||||||
def report_blank(request):
|
def get_db() -> Session:
|
||||||
|
try:
|
||||||
|
db = SessionLocal()
|
||||||
|
yield db
|
||||||
|
finally:
|
||||||
|
db.close()
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("")
|
||||||
|
def report_blank(
|
||||||
|
request: Request,
|
||||||
|
user: UserToken = Security(get_user, scopes=["cash-flow"]),
|
||||||
|
):
|
||||||
return {
|
return {
|
||||||
"startDate": session_period_start(request),
|
"startDate": session_period_start(request.session),
|
||||||
"finishDate": session_period_finish(request),
|
"finishDate": session_period_finish(request.session),
|
||||||
"body": [],
|
"body": [],
|
||||||
"footer": {},
|
"footer": {},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@router.get("/api/cash-flow", request_param=["s", "f"], permission="Cash Flow")
|
@router.get("/data")
|
||||||
def report_data(request):
|
def report_data(
|
||||||
start_date = request.GET["s"]
|
request: Request,
|
||||||
finish_date = request.GET["f"]
|
s: str = None,
|
||||||
body, footer = build_report(start_date, finish_date, request)
|
f: str = None,
|
||||||
session_period_set(start_date, finish_date, request)
|
db: Session = Depends(get_db),
|
||||||
|
user: UserToken = Security(get_user, scopes=["cash-flow"]),
|
||||||
|
):
|
||||||
|
body, footer = build_report(s, f, db)
|
||||||
|
session_period_set(s, f, request.session)
|
||||||
return {
|
return {
|
||||||
"startDate": start_date,
|
"startDate": s,
|
||||||
"finishDate": finish_date,
|
"finishDate": f,
|
||||||
"body": body,
|
"body": body,
|
||||||
"footer": footer,
|
"footer": footer,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@router.get("/api/cash-flow/{id}", request_param=["s", "f"], permission="Cash Flow")
|
@router.get("/{id_}")
|
||||||
def get_cash_flow_id(request):
|
def report_id(
|
||||||
id_ = request.matchdict["id"]
|
id_: int,
|
||||||
start_date = request.GET["s"]
|
request: Request,
|
||||||
finish_date = request.GET["f"]
|
s: str = None,
|
||||||
details, footer = build_report_id(int(id_), start_date, finish_date, request)
|
f: str = None,
|
||||||
session_period_set(start_date, finish_date, request)
|
db: Session = Depends(get_db),
|
||||||
|
user: UserToken = Security(get_user, scopes=["cash-flow"]),
|
||||||
|
):
|
||||||
|
details, footer = build_report_id(id_, s, f, db)
|
||||||
|
session_period_set(s, f, request.session)
|
||||||
return {
|
return {
|
||||||
"startDate": start_date,
|
"startDate": s,
|
||||||
"finishDate": finish_date,
|
"finishDate": f,
|
||||||
"body": {"details": details},
|
"body": {"details": details},
|
||||||
"footer": footer,
|
"footer": footer,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def build_report(start_date, finish_date, request):
|
def build_report(start_date, finish_date, db):
|
||||||
sub_voucher = aliased(Voucher)
|
sub_voucher = aliased(Voucher)
|
||||||
sub_journal = aliased(Journal)
|
sub_journal = aliased(Journal)
|
||||||
sub_account = aliased(AccountBase)
|
sub_account = aliased(AccountBase)
|
||||||
|
|
||||||
sub_query = (
|
sub_query = (
|
||||||
request.dbsession.query(sub_voucher.id)
|
db.query(sub_voucher.id)
|
||||||
.join(sub_journal, sub_voucher.journals)
|
.join(sub_journal, sub_voucher.journals)
|
||||||
.join(sub_account, sub_journal.account)
|
.join(sub_account, sub_journal.account)
|
||||||
.filter(sub_account.type == AccountType.by_name("Cash").id)
|
.filter(sub_account.type == AccountType.by_name("Cash").id)
|
||||||
@ -71,7 +94,7 @@ def build_report(start_date, finish_date, request):
|
|||||||
)
|
)
|
||||||
|
|
||||||
query = (
|
query = (
|
||||||
request.dbsession.query(AccountBase.type, func.sum(Journal.signed_amount))
|
db.query(AccountBase.type, func.sum(Journal.signed_amount))
|
||||||
.join(Journal, Voucher.journals)
|
.join(Journal, Voucher.journals)
|
||||||
.join(AccountBase, Journal.account)
|
.join(AccountBase, Journal.account)
|
||||||
.filter(Voucher.id.in_(sub_query))
|
.filter(Voucher.id.in_(sub_query))
|
||||||
@ -89,17 +112,13 @@ def build_report(start_date, finish_date, request):
|
|||||||
cf[lt.cash_flow_classification.lower()].append(
|
cf[lt.cash_flow_classification.lower()].append(
|
||||||
{
|
{
|
||||||
"name": lt.name,
|
"name": lt.name,
|
||||||
"url": request.route_url(
|
"url": "", # request.route_url("cash_flow_id", id=str(lt.id), _query={"startDate": start_date, "finishDate": finish_date},),
|
||||||
"cash_flow_id",
|
|
||||||
id=str(lt.id),
|
|
||||||
_query={"startDate": start_date, "finishDate": finish_date},
|
|
||||||
),
|
|
||||||
"amount": amount * -1,
|
"amount": amount * -1,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
opening = (
|
opening = (
|
||||||
request.dbsession.query(func.sum(Journal.amount * Journal.debit))
|
db.query(func.sum(Journal.amount * Journal.debit))
|
||||||
.join(Journal.voucher)
|
.join(Journal.voucher)
|
||||||
.join(Journal.account)
|
.join(Journal.account)
|
||||||
.filter(Voucher.date < start_date)
|
.filter(Voucher.date < start_date)
|
||||||
@ -109,7 +128,7 @@ def build_report(start_date, finish_date, request):
|
|||||||
)
|
)
|
||||||
|
|
||||||
closing = (
|
closing = (
|
||||||
request.dbsession.query(func.sum(Journal.amount * Journal.debit))
|
db.query(func.sum(Journal.amount * Journal.debit))
|
||||||
.join(Journal.voucher)
|
.join(Journal.voucher)
|
||||||
.join(Journal.account)
|
.join(Journal.account)
|
||||||
.filter(Voucher.date <= finish_date)
|
.filter(Voucher.date <= finish_date)
|
||||||
@ -134,14 +153,14 @@ def build_report(start_date, finish_date, request):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def build_report_id(account_type, start_date, finish_date, request):
|
def build_report_id(account_type, start_date, finish_date, db):
|
||||||
details = []
|
details = []
|
||||||
sub_voucher = aliased(Voucher)
|
sub_voucher = aliased(Voucher)
|
||||||
sub_journal = aliased(Journal)
|
sub_journal = aliased(Journal)
|
||||||
sub_account = aliased(AccountBase)
|
sub_account = aliased(AccountBase)
|
||||||
|
|
||||||
sub_query = (
|
sub_query = (
|
||||||
request.dbsession.query(sub_voucher.id)
|
db.query(sub_voucher.id)
|
||||||
.join(sub_journal, sub_voucher.journals)
|
.join(sub_journal, sub_voucher.journals)
|
||||||
.join(sub_account, sub_journal.account)
|
.join(sub_account, sub_journal.account)
|
||||||
.filter(sub_account.type == AccountType.by_name("Cash").id)
|
.filter(sub_account.type == AccountType.by_name("Cash").id)
|
||||||
@ -151,7 +170,7 @@ def build_report_id(account_type, start_date, finish_date, request):
|
|||||||
)
|
)
|
||||||
|
|
||||||
query = (
|
query = (
|
||||||
request.dbsession.query(AccountBase, func.sum(Journal.signed_amount))
|
db.query(AccountBase, func.sum(Journal.signed_amount))
|
||||||
.join(Journal, Voucher.journals)
|
.join(Journal, Voucher.journals)
|
||||||
.join(AccountBase, Journal.account)
|
.join(AccountBase, Journal.account)
|
||||||
.filter(Voucher.id.in_(sub_query))
|
.filter(Voucher.id.in_(sub_query))
|
||||||
@ -167,11 +186,7 @@ def build_report_id(account_type, start_date, finish_date, request):
|
|||||||
details.append(
|
details.append(
|
||||||
{
|
{
|
||||||
"name": account.name,
|
"name": account.name,
|
||||||
"url": request.route_url(
|
"url": "", # request.route_url("ledger_id", id=account.id, _query={"startDate": start_date, "finishDate": finish_date},),
|
||||||
"ledger_id",
|
|
||||||
id=account.id,
|
|
||||||
_query={"startDate": start_date, "finishDate": finish_date},
|
|
||||||
),
|
|
||||||
"amount": amount * -1,
|
"amount": amount * -1,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -1,43 +1,60 @@
|
|||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
from sqlalchemy.orm import joinedload_all
|
from fastapi import APIRouter, Depends, Security, Request
|
||||||
|
from sqlalchemy.orm import joinedload_all, Session
|
||||||
|
|
||||||
|
from ...schemas.auth import UserToken
|
||||||
|
from ...core.security import get_current_active_user as get_user
|
||||||
|
from ...db.session import SessionLocal
|
||||||
from brewman.models.voucher import Voucher, Journal, VoucherType
|
from brewman.models.voucher import Voucher, Journal, VoucherType
|
||||||
from brewman.routers.services.session import (
|
from brewman.routers.services.session import (
|
||||||
session_period_set,
|
session_period_set,
|
||||||
session_period_start,
|
session_period_start,
|
||||||
session_period_finish,
|
session_period_finish,
|
||||||
)
|
)
|
||||||
from brewman.routers.services.voucher import get_edit_url
|
|
||||||
|
|
||||||
from fastapi import APIRouter
|
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
|
|
||||||
@router.get("/api/daybook") # "Daybook"
|
# Dependency
|
||||||
def report_blank(request):
|
def get_db() -> Session:
|
||||||
|
try:
|
||||||
|
db = SessionLocal()
|
||||||
|
yield db
|
||||||
|
finally:
|
||||||
|
db.close()
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("")
|
||||||
|
def report_blank(
|
||||||
|
request: Request,
|
||||||
|
user: UserToken = Security(get_user, scopes=["daybook"]),
|
||||||
|
):
|
||||||
return {
|
return {
|
||||||
"startDate": session_period_start(request),
|
"startDate": session_period_start(request.session),
|
||||||
"finishDate": session_period_finish(request),
|
"finishDate": session_period_finish(request.session),
|
||||||
"body": [],
|
"body": [],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@router.get("/api/daybook", request_param=["s", "f"], permission="Daybook")
|
@router.get("/{start}/{finish}")
|
||||||
def report_data(request):
|
def report_data(
|
||||||
start_date = request.GET["s"]
|
start: str,
|
||||||
finish_date = request.GET["f"]
|
finish: str,
|
||||||
body = build_report(start_date, finish_date, request)
|
request: Request,
|
||||||
session_period_set(start_date, finish_date, request)
|
db: Session = Depends(get_db),
|
||||||
return {"startDate": start_date, "finishDate": finish_date, "body": body}
|
user: UserToken = Security(get_user, scopes=["daybook"]),
|
||||||
|
):
|
||||||
|
body = build_report(start, finish, db)
|
||||||
|
session_period_set(start, finish, request.session)
|
||||||
|
return {"startDate": start, "finishDate": finish, "body": body}
|
||||||
|
|
||||||
|
|
||||||
def build_report(start_date, finish_date, request):
|
def build_report(start_date, finish_date, db):
|
||||||
body = []
|
body = []
|
||||||
|
|
||||||
query = (
|
query = (
|
||||||
request.dbsession.query(Voucher)
|
db.query(Voucher)
|
||||||
.options(joinedload_all(Voucher.journals, Journal.account, innerjoin=True))
|
.options(joinedload_all(Voucher.journals, Journal.account, innerjoin=True))
|
||||||
.filter(Voucher.date >= datetime.datetime.strptime(start_date, "%d-%b-%Y"))
|
.filter(Voucher.date >= datetime.datetime.strptime(start_date, "%d-%b-%Y"))
|
||||||
.filter(Voucher.date <= datetime.datetime.strptime(finish_date, "%d-%b-%Y"))
|
.filter(Voucher.date <= datetime.datetime.strptime(finish_date, "%d-%b-%Y"))
|
||||||
@ -66,7 +83,7 @@ def build_report(start_date, finish_date, request):
|
|||||||
{
|
{
|
||||||
"id": voucher.id,
|
"id": voucher.id,
|
||||||
"date": voucher.date.strftime("%d-%b-%Y"),
|
"date": voucher.date.strftime("%d-%b-%Y"),
|
||||||
"url": get_edit_url(voucher, request),
|
"url": "", # get_edit_url(voucher, request),
|
||||||
"type": VoucherType.by_id(voucher.type).name,
|
"type": VoucherType.by_id(voucher.type).name,
|
||||||
"narration": voucher.narration,
|
"narration": voucher.narration,
|
||||||
"posted": voucher.posted,
|
"posted": voucher.posted,
|
||||||
|
@ -51,7 +51,6 @@ def show_data(
|
|||||||
user: UserToken = Security(get_user, scopes=["ledger"]),
|
user: UserToken = Security(get_user, scopes=["ledger"]),
|
||||||
):
|
):
|
||||||
account = db.query(AccountBase).filter(AccountBase.id == id_).first()
|
account = db.query(AccountBase).filter(AccountBase.id == id_).first()
|
||||||
|
|
||||||
start_date = s if s is not None else session_period_start(request.session)
|
start_date = s if s is not None else session_period_start(request.session)
|
||||||
finish_date = f if f is not None else session_period_finish(request.session)
|
finish_date = f if f is not None else session_period_finish(request.session)
|
||||||
body = build_report(account.id, start_date, finish_date, db)
|
body = build_report(account.id, start_date, finish_date, db)
|
||||||
|
@ -1,8 +1,13 @@
|
|||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
|
from fastapi import APIRouter, Depends, Security, Request
|
||||||
|
from sqlalchemy.orm import Session
|
||||||
from sqlalchemy.sql.expression import func, desc
|
from sqlalchemy.sql.expression import func, desc
|
||||||
|
|
||||||
|
from ...schemas.auth import UserToken
|
||||||
|
from ...core.security import get_current_active_user as get_user
|
||||||
|
from ...db.session import SessionLocal
|
||||||
from brewman.models.master import AccountBase
|
from brewman.models.master import AccountBase
|
||||||
|
|
||||||
from brewman.models.voucher import Voucher, Journal, VoucherType
|
from brewman.models.voucher import Voucher, Journal, VoucherType
|
||||||
from brewman.routers.services.session import (
|
from brewman.routers.services.session import (
|
||||||
session_period_set,
|
session_period_set,
|
||||||
@ -10,33 +15,47 @@ from brewman.routers.services.session import (
|
|||||||
session_period_finish,
|
session_period_finish,
|
||||||
)
|
)
|
||||||
|
|
||||||
from fastapi import APIRouter
|
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
|
|
||||||
@router.get("/api/net-transactions") # "Net Transactions"
|
# Dependency
|
||||||
def show_blank(request):
|
def get_db() -> Session:
|
||||||
|
try:
|
||||||
|
db = SessionLocal()
|
||||||
|
yield db
|
||||||
|
finally:
|
||||||
|
db.close()
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("")
|
||||||
|
def show_blank(
|
||||||
|
request: Request,
|
||||||
|
user: UserToken = Security(get_user, scopes=["net-transactions"]),
|
||||||
|
):
|
||||||
return {
|
return {
|
||||||
"startDate": session_period_start(request),
|
"startDate": session_period_start(request.session),
|
||||||
"finishDate": session_period_finish(request),
|
"finishDate": session_period_finish(request.session),
|
||||||
"body": [],
|
"body": [],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@router.get("/api/net-transactions", request_param=["s", "f"], permission="Net Transactions")
|
@router.get("/{start}/{finish}")
|
||||||
def show_data(request):
|
def show_data(
|
||||||
start_date = request.GET["s"]
|
start: str,
|
||||||
finish_date = request.GET["f"]
|
finish: str,
|
||||||
session_period_set(start_date, finish_date, request)
|
request: Request,
|
||||||
|
db: Session = Depends(get_db),
|
||||||
|
user: UserToken = Security(get_user, scopes=["net-transactions"]),
|
||||||
|
):
|
||||||
|
session_period_set(start, finish, request.session)
|
||||||
return {
|
return {
|
||||||
"startDate": start_date,
|
"startDate": start,
|
||||||
"finishDate": finish_date,
|
"finishDate": finish,
|
||||||
"body": build_report(start_date, finish_date, request.dbsession),
|
"body": build_report(start, finish, db),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def build_report(start_date, finish_date, dbsession):
|
def build_report(start_date, finish_date, db):
|
||||||
if not isinstance(start_date, datetime.datetime):
|
if not isinstance(start_date, datetime.datetime):
|
||||||
start_date = datetime.datetime.strptime(start_date, "%d-%b-%Y")
|
start_date = datetime.datetime.strptime(start_date, "%d-%b-%Y")
|
||||||
if not isinstance(finish_date, datetime.datetime):
|
if not isinstance(finish_date, datetime.datetime):
|
||||||
@ -44,7 +63,7 @@ def build_report(start_date, finish_date, dbsession):
|
|||||||
|
|
||||||
amount_sum = func.sum(Journal.amount * Journal.debit).label("amount")
|
amount_sum = func.sum(Journal.amount * Journal.debit).label("amount")
|
||||||
query = (
|
query = (
|
||||||
dbsession.query(AccountBase, amount_sum)
|
db.query(AccountBase, amount_sum)
|
||||||
.join(Journal.voucher)
|
.join(Journal.voucher)
|
||||||
.join(Journal.account)
|
.join(Journal.account)
|
||||||
.filter(Voucher.date >= start_date)
|
.filter(Voucher.date >= start_date)
|
||||||
|
@ -1,43 +1,60 @@
|
|||||||
import datetime
|
import datetime
|
||||||
|
import uuid
|
||||||
|
|
||||||
from sqlalchemy.orm import joinedload
|
from fastapi import APIRouter, Depends, Security, Request
|
||||||
|
from sqlalchemy.orm import joinedload, Session
|
||||||
from sqlalchemy.sql.expression import func
|
from sqlalchemy.sql.expression import func
|
||||||
|
|
||||||
|
from ...schemas.auth import UserToken
|
||||||
|
from ...core.security import get_current_active_user as get_user
|
||||||
|
from ...db.session import SessionLocal
|
||||||
from brewman.models.master import Product, CostCentre
|
from brewman.models.master import Product, CostCentre
|
||||||
from brewman.models.validation_exception import ValidationError
|
|
||||||
from brewman.models.voucher import Voucher, Journal, VoucherType, Inventory
|
from brewman.models.voucher import Voucher, Journal, VoucherType, Inventory
|
||||||
from brewman.routers import to_uuid
|
|
||||||
from brewman.routers.services.session import (
|
from brewman.routers.services.session import (
|
||||||
session_period_set,
|
session_period_set,
|
||||||
session_period_start,
|
session_period_start,
|
||||||
session_period_finish,
|
session_period_finish,
|
||||||
)
|
)
|
||||||
from brewman.routers.services.voucher import get_edit_url
|
|
||||||
from fastapi import APIRouter
|
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
|
|
||||||
@router.get("/api/product-ledger") # "Product Ledger"
|
# Dependency
|
||||||
def show_blank(request):
|
def get_db() -> Session:
|
||||||
|
try:
|
||||||
|
db = SessionLocal()
|
||||||
|
yield db
|
||||||
|
finally:
|
||||||
|
db.close()
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("")
|
||||||
|
def show_blank(
|
||||||
|
request: Request,
|
||||||
|
user: UserToken = Security(get_user, scopes=["product-ledger"]),
|
||||||
|
):
|
||||||
return {
|
return {
|
||||||
"startDate": session_period_start(request),
|
"startDate": session_period_start(request.session),
|
||||||
"finishDate": session_period_finish(request),
|
"finishDate": session_period_finish(request.session),
|
||||||
"product": None,
|
"product": None,
|
||||||
"body": [],
|
"body": [],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@router.get("/api/product-ledger/{id}") # "Product Ledger"
|
@router.get("/{id}")
|
||||||
def show_data(request):
|
def show_data(
|
||||||
id_ = to_uuid(request.matchdict["id"])
|
id_: uuid.UUID,
|
||||||
if id_ is None:
|
request: Request,
|
||||||
raise ValidationError("Invalid Product")
|
s: str = None,
|
||||||
product = request.dbsession.query(Product).filter(Product.id == id_).first()
|
f: str = None,
|
||||||
start_date = request.GET.get("s", session_period_start(request))
|
db: Session = Depends(get_db),
|
||||||
finish_date = request.GET.get("f", session_period_finish(request))
|
user: UserToken = Security(get_user, scopes=["product-ledger"]),
|
||||||
body = build_report(product.id, start_date, finish_date, request)
|
):
|
||||||
session_period_set(start_date, finish_date, request)
|
product = db.query(Product).filter(Product.id == id_).first()
|
||||||
|
start_date = s if s is not None else session_period_start(request.session)
|
||||||
|
finish_date = f if f is not None else session_period_finish(request.session)
|
||||||
|
body = build_report(product.id, start_date, finish_date, db)
|
||||||
|
session_period_set(start_date, finish_date, request.session)
|
||||||
return {
|
return {
|
||||||
"startDate": start_date,
|
"startDate": start_date,
|
||||||
"finishDate": finish_date,
|
"finishDate": finish_date,
|
||||||
@ -46,15 +63,15 @@ def show_data(request):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def build_report(product_id, start_date, finish_date, request):
|
def build_report(product_id, start_date, finish_date, db):
|
||||||
body = []
|
body = []
|
||||||
running_total_q, running_total_a, opening = opening_balance(
|
running_total_q, running_total_a, opening = opening_balance(
|
||||||
product_id, start_date, request.dbsession
|
product_id, start_date, db
|
||||||
)
|
)
|
||||||
body.append(opening)
|
body.append(opening)
|
||||||
|
|
||||||
query = (
|
query = (
|
||||||
request.dbsession.query(Voucher, Inventory, Journal)
|
db.query(Voucher, Inventory, Journal)
|
||||||
.options(
|
.options(
|
||||||
joinedload(Journal.account, innerjoin=True),
|
joinedload(Journal.account, innerjoin=True),
|
||||||
joinedload(Journal.cost_centre, innerjoin=True),
|
joinedload(Journal.cost_centre, innerjoin=True),
|
||||||
@ -90,7 +107,7 @@ def build_report(product_id, start_date, finish_date, request):
|
|||||||
"id": row.Voucher.id,
|
"id": row.Voucher.id,
|
||||||
"date": row.Voucher.date.strftime("%d-%b-%Y"),
|
"date": row.Voucher.date.strftime("%d-%b-%Y"),
|
||||||
"name": name,
|
"name": name,
|
||||||
"url": get_edit_url(row.Voucher, request),
|
"url": "", # get_edit_url(row.Voucher, request),
|
||||||
"type": VoucherType.by_id(row.Voucher.type).name,
|
"type": VoucherType.by_id(row.Voucher.type).name,
|
||||||
"narration": row.Voucher.narration,
|
"narration": row.Voucher.narration,
|
||||||
"posted": row.Voucher.posted
|
"posted": row.Voucher.posted
|
||||||
@ -107,9 +124,9 @@ def build_report(product_id, start_date, finish_date, request):
|
|||||||
return body
|
return body
|
||||||
|
|
||||||
|
|
||||||
def opening_balance(product_id, start_date, dbsession):
|
def opening_balance(product_id, start_date, db):
|
||||||
quantity, amount = (
|
quantity, amount = (
|
||||||
dbsession.query(
|
db.query(
|
||||||
func.sum(Inventory.quantity * Journal.debit),
|
func.sum(Inventory.quantity * Journal.debit),
|
||||||
func.sum(Inventory.amount * Journal.debit),
|
func.sum(Inventory.amount * Journal.debit),
|
||||||
)
|
)
|
||||||
|
@ -7,7 +7,6 @@ from sqlalchemy.sql.expression import func, desc
|
|||||||
from ...schemas.auth import UserToken
|
from ...schemas.auth import UserToken
|
||||||
from ...core.security import get_current_active_user as get_user
|
from ...core.security import get_current_active_user as get_user
|
||||||
from ...db.session import SessionLocal
|
from ...db.session import SessionLocal
|
||||||
|
|
||||||
from brewman.models.master import AccountType, AccountBase
|
from brewman.models.master import AccountType, AccountBase
|
||||||
from brewman.models.voucher import Voucher, Journal, VoucherType
|
from brewman.models.voucher import Voucher, Journal, VoucherType
|
||||||
from brewman.routers.reports.closing_stock import get_opening_stock, get_closing_stock
|
from brewman.routers.reports.closing_stock import get_opening_stock, get_closing_stock
|
||||||
|
@ -1,42 +1,61 @@
|
|||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
|
from fastapi import APIRouter, Depends, Security, Request
|
||||||
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
|
from ...schemas.auth import UserToken
|
||||||
|
from ...core.security import get_current_active_user as get_user
|
||||||
|
from ...db.session import SessionLocal
|
||||||
from brewman.models.voucher import Voucher, VoucherType
|
from brewman.models.voucher import Voucher, VoucherType
|
||||||
from brewman.routers.services.session import (
|
from brewman.routers.services.session import (
|
||||||
session_period_set,
|
session_period_set,
|
||||||
session_period_start,
|
session_period_start,
|
||||||
session_period_finish,
|
session_period_finish,
|
||||||
)
|
)
|
||||||
from brewman.routers.services.voucher import get_edit_url
|
|
||||||
|
|
||||||
from fastapi import APIRouter
|
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
|
|
||||||
@router.get("/api/purchase-entries") # "Purchase Entries"
|
# Dependency
|
||||||
def report_blank(request):
|
def get_db() -> Session:
|
||||||
|
try:
|
||||||
|
db = SessionLocal()
|
||||||
|
yield db
|
||||||
|
finally:
|
||||||
|
db.close()
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("")
|
||||||
|
def report_blank(
|
||||||
|
request: Request,
|
||||||
|
user: UserToken = Security(get_user, scopes=["purchase-entries"]),
|
||||||
|
):
|
||||||
return {
|
return {
|
||||||
"startDate": session_period_start(request),
|
"startDate": session_period_start(request.session),
|
||||||
"finishDate": session_period_finish(request),
|
"finishDate": session_period_finish(request.session),
|
||||||
"body": [],
|
"body": [],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@router.get("/api/purchase-entries", request_param=["s", "f"], permission="Purchase Entries")
|
@router.get("/{start}/{finish}")
|
||||||
def report_data(request):
|
def report_data(
|
||||||
start_date = request.GET["s"]
|
start: str,
|
||||||
finish_date = request.GET["f"]
|
finish: str,
|
||||||
body = build_report(start_date, finish_date, request)
|
request: Request,
|
||||||
session_period_set(start_date, finish_date, request)
|
db: Session = Depends(get_db),
|
||||||
return {"startDate": start_date, "finishDate": finish_date, "body": body}
|
user: UserToken = Security(get_user, scopes=["net-transactions"]),
|
||||||
|
):
|
||||||
|
body = build_report(start, finish, db)
|
||||||
|
session_period_set(start, finish, request.session)
|
||||||
|
return {"startDate": start, "finishDate": finish, "body": body}
|
||||||
|
|
||||||
|
|
||||||
def build_report(start_date, finish_date, request):
|
def build_report(start_date, finish_date, db):
|
||||||
start_date = datetime.datetime.strptime(start_date, "%d-%b-%Y")
|
start_date = datetime.datetime.strptime(start_date, "%d-%b-%Y")
|
||||||
finish_date = datetime.datetime.strptime(finish_date, "%d-%b-%Y")
|
finish_date = datetime.datetime.strptime(finish_date, "%d-%b-%Y")
|
||||||
body = []
|
body = []
|
||||||
query = (
|
query = (
|
||||||
request.dbsession.query(Voucher)
|
db.query(Voucher)
|
||||||
.filter(Voucher.date >= start_date)
|
.filter(Voucher.date >= start_date)
|
||||||
.filter(Voucher.date <= finish_date)
|
.filter(Voucher.date <= finish_date)
|
||||||
.filter(Voucher.type == VoucherType.by_name("Purchase").id)
|
.filter(Voucher.type == VoucherType.by_name("Purchase").id)
|
||||||
@ -51,7 +70,7 @@ def build_report(start_date, finish_date, request):
|
|||||||
row = {
|
row = {
|
||||||
"date": voucher.date.strftime("%d-%b-%Y"),
|
"date": voucher.date.strftime("%d-%b-%Y"),
|
||||||
"supplier": journal.account.name,
|
"supplier": journal.account.name,
|
||||||
"url": get_edit_url(voucher, request),
|
"url": "", # get_edit_url(voucher, request),
|
||||||
"products": [],
|
"products": [],
|
||||||
"product": item.product.full_name,
|
"product": item.product.full_name,
|
||||||
"quantity": item.quantity,
|
"quantity": item.quantity,
|
||||||
|
@ -1,7 +1,13 @@
|
|||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
|
from fastapi import APIRouter, Depends, Security, Request
|
||||||
|
from sqlalchemy.orm import Session
|
||||||
from sqlalchemy.sql.expression import func, desc
|
from sqlalchemy.sql.expression import func, desc
|
||||||
|
|
||||||
|
from ...schemas.auth import UserToken
|
||||||
|
from ...core.security import get_current_active_user as get_user
|
||||||
|
from ...db.session import SessionLocal
|
||||||
|
|
||||||
from brewman.models.master import CostCentre, Product
|
from brewman.models.master import CostCentre, Product
|
||||||
from brewman.models.voucher import Voucher, Journal, Inventory, VoucherType
|
from brewman.models.voucher import Voucher, Journal, Inventory, VoucherType
|
||||||
from brewman.routers.services.session import (
|
from brewman.routers.services.session import (
|
||||||
@ -10,43 +16,57 @@ from brewman.routers.services.session import (
|
|||||||
session_period_finish,
|
session_period_finish,
|
||||||
)
|
)
|
||||||
|
|
||||||
from fastapi import APIRouter
|
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
|
|
||||||
@router.get("/api/purchases") # "Purchases"
|
# Dependency
|
||||||
def report_blank(request):
|
def get_db() -> Session:
|
||||||
|
try:
|
||||||
|
db = SessionLocal()
|
||||||
|
yield db
|
||||||
|
finally:
|
||||||
|
db.close()
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/api/purchases")
|
||||||
|
def report_blank(
|
||||||
|
request: Request,
|
||||||
|
user: UserToken = Security(get_user, scopes=["purchases"]),
|
||||||
|
):
|
||||||
return {
|
return {
|
||||||
"startDate": session_period_start(request),
|
"startDate": session_period_start(request.session),
|
||||||
"finishDate": session_period_finish(request),
|
"finishDate": session_period_finish(request.session),
|
||||||
"body": [],
|
"body": [],
|
||||||
"footer": {},
|
"footer": {},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@router.get("/api/purchases", request_param=["s", "f"], permission="Purchases")
|
@router.get("/{start}/{finish}")
|
||||||
def report_data(request):
|
def report_data(
|
||||||
start_date = request.GET["s"]
|
start: str,
|
||||||
finish_date = request.GET["f"]
|
finish: str,
|
||||||
body, footer = build_report(start_date, finish_date, request)
|
request: Request,
|
||||||
session_period_set(start_date, finish_date, request)
|
db: Session = Depends(get_db),
|
||||||
|
user: UserToken = Security(get_user, scopes=["purchases"]),
|
||||||
|
):
|
||||||
|
body, footer = build_report(start, finish, db)
|
||||||
|
session_period_set(start, finish, request.session)
|
||||||
return {
|
return {
|
||||||
"startDate": start_date,
|
"startDate": start,
|
||||||
"finishDate": finish_date,
|
"finishDate": finish,
|
||||||
"body": body,
|
"body": body,
|
||||||
"footer": footer,
|
"footer": footer,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def build_report(start_date, finish_date, request):
|
def build_report(start_date, finish_date, db):
|
||||||
body = []
|
body = []
|
||||||
quantity_sum = func.sum(Journal.debit * Inventory.quantity).label("quantity")
|
quantity_sum = func.sum(Journal.debit * Inventory.quantity).label("quantity")
|
||||||
amount_sum = func.sum(
|
amount_sum = func.sum(
|
||||||
Journal.debit * Inventory.quantity * Inventory.rate * (1 + Inventory.tax)
|
Journal.debit * Inventory.quantity * Inventory.rate * (1 + Inventory.tax)
|
||||||
).label("amount")
|
).label("amount")
|
||||||
query = (
|
query = (
|
||||||
request.dbsession.query(Product, quantity_sum, amount_sum)
|
db.query(Product, quantity_sum, amount_sum)
|
||||||
.join(Product.inventories)
|
.join(Product.inventories)
|
||||||
.join(Inventory.voucher)
|
.join(Inventory.voucher)
|
||||||
.join(Voucher.journals)
|
.join(Voucher.journals)
|
||||||
@ -68,11 +88,7 @@ def build_report(start_date, finish_date, request):
|
|||||||
"quantity": quantity,
|
"quantity": quantity,
|
||||||
"rate": rate,
|
"rate": rate,
|
||||||
"amount": amount,
|
"amount": amount,
|
||||||
"url": request.route_url(
|
"url": "", # request.route_url("product_ledger_id", id=product.id, _query={"startDate": start_date, "finishDate": finish_date},),
|
||||||
"product_ledger_id",
|
|
||||||
id=product.id,
|
|
||||||
_query={"startDate": start_date, "finishDate": finish_date},
|
|
||||||
),
|
|
||||||
}
|
}
|
||||||
body.append(row)
|
body.append(row)
|
||||||
return body, {"name": "Total", "amount": total_amount}
|
return body, {"name": "Total", "amount": total_amount}
|
||||||
|
@ -1,8 +1,13 @@
|
|||||||
import datetime
|
import datetime
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
|
from fastapi import APIRouter, Depends, Security, Request
|
||||||
|
from sqlalchemy.orm import Session
|
||||||
from sqlalchemy.sql.expression import func, case
|
from sqlalchemy.sql.expression import func, case
|
||||||
|
|
||||||
|
from ...schemas.auth import UserToken
|
||||||
|
from ...core.security import get_current_active_user as get_user
|
||||||
|
from ...db.session import SessionLocal
|
||||||
from brewman.models.master import AccountBase, CostCentre, Product, ProductGroup
|
from brewman.models.master import AccountBase, CostCentre, Product, ProductGroup
|
||||||
from brewman.models.voucher import Voucher, Journal, Inventory
|
from brewman.models.voucher import Voucher, Journal, Inventory
|
||||||
from brewman.routers.services.session import (
|
from brewman.routers.services.session import (
|
||||||
@ -11,51 +16,69 @@ from brewman.routers.services.session import (
|
|||||||
session_period_finish,
|
session_period_finish,
|
||||||
)
|
)
|
||||||
|
|
||||||
from fastapi import APIRouter
|
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
|
|
||||||
@router.get("/api/raw-material-cost") # "Raw Material Cost"
|
# Dependency
|
||||||
def report_blank(request):
|
def get_db() -> Session:
|
||||||
|
try:
|
||||||
|
db = SessionLocal()
|
||||||
|
yield db
|
||||||
|
finally:
|
||||||
|
db.close()
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("")
|
||||||
|
def report_blank(
|
||||||
|
request: Request,
|
||||||
|
user: UserToken = Security(get_user, scopes=["raw-material-cost"]),
|
||||||
|
):
|
||||||
return {
|
return {
|
||||||
"startDate": session_period_start(request),
|
"startDate": session_period_start(request.session),
|
||||||
"finishDate": session_period_finish(request),
|
"finishDate": session_period_finish(request.session),
|
||||||
"body": [],
|
"body": [],
|
||||||
"footer": {},
|
"footer": {},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@router.get("/api/raw-material-cost", request_param=["s", "f"], permission="Raw Material Cost")
|
@router.get("/data")
|
||||||
def report_data(request):
|
def report_data(
|
||||||
start_date = request.GET["s"]
|
request: Request,
|
||||||
finish_date = request.GET["f"]
|
s: str = None,
|
||||||
body, footer = build_report(start_date, finish_date, request)
|
f: str = None,
|
||||||
session_period_set(start_date, finish_date, request)
|
db: Session = Depends(get_db),
|
||||||
|
user: UserToken = Security(get_user, scopes=["raw-material-cost"]),
|
||||||
|
):
|
||||||
|
body, footer = build_report(s, f, db)
|
||||||
|
session_period_set(s, f, request.session)
|
||||||
return {
|
return {
|
||||||
"startDate": start_date,
|
"startDate": s,
|
||||||
"finishDate": finish_date,
|
"finishDate": f,
|
||||||
"body": body,
|
"body": body,
|
||||||
"footer": footer,
|
"footer": footer,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@router.get("/api/raw-material-cost/{id}", request_param=["s", "f"], permission="Raw Material Cost")
|
@router.get("/{id_}")
|
||||||
def report_id(request):
|
def report_id(
|
||||||
id_ = request.matchdict["id"]
|
id_: uuid.UUID,
|
||||||
start_date = request.GET["s"]
|
request: Request,
|
||||||
finish_date = request.GET["f"]
|
s: str = None,
|
||||||
body = build_report_id(uuid.UUID(id_), start_date, finish_date, request)
|
f: str = None,
|
||||||
session_period_set(start_date, finish_date, request)
|
db: Session = Depends(get_db),
|
||||||
|
user: UserToken = Security(get_user, scopes=["raw-material-cost"]),
|
||||||
|
):
|
||||||
|
body = build_report_id(id_, s, f, db)
|
||||||
|
session_period_set(s, f, request.session)
|
||||||
return {
|
return {
|
||||||
"id": id_,
|
"id": id_,
|
||||||
"startDate": start_date,
|
"startDate": s,
|
||||||
"finishDate": finish_date,
|
"finishDate": f,
|
||||||
"body": body,
|
"body": body,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def build_report(start_date, finish_date, request):
|
def build_report(start_date, finish_date, db):
|
||||||
body = []
|
body = []
|
||||||
sum_issue = func.sum(
|
sum_issue = func.sum(
|
||||||
case([(AccountBase.type == 2, Journal.signed_amount)], else_=0)
|
case([(AccountBase.type == 2, Journal.signed_amount)], else_=0)
|
||||||
@ -65,7 +88,7 @@ def build_report(start_date, finish_date, request):
|
|||||||
).label("sale")
|
).label("sale")
|
||||||
|
|
||||||
query = (
|
query = (
|
||||||
request.dbsession.query(CostCentre, sum_issue, sum_sale)
|
db.query(CostCentre, sum_issue, sum_sale)
|
||||||
.join(CostCentre.journals)
|
.join(CostCentre.journals)
|
||||||
.join(Journal.voucher)
|
.join(Journal.voucher)
|
||||||
.join(Journal.account)
|
.join(Journal.account)
|
||||||
@ -90,11 +113,7 @@ def build_report(start_date, finish_date, request):
|
|||||||
"issue": issue,
|
"issue": issue,
|
||||||
"sale": sale,
|
"sale": sale,
|
||||||
"rmc": rmc,
|
"rmc": rmc,
|
||||||
"url": request.route_url(
|
"url": "", # request.route_url("raw_material_cost_id",id=str(cost_centre.id),_query={"startDate": start_date, "finishDate": finish_date},),
|
||||||
"raw_material_cost_id",
|
|
||||||
id=str(cost_centre.id),
|
|
||||||
_query={"startDate": start_date, "finishDate": finish_date},
|
|
||||||
),
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -102,13 +121,13 @@ def build_report(start_date, finish_date, request):
|
|||||||
return body, {"name": "Total", "issue": issues, "sale": sales, "rmc": rmc}
|
return body, {"name": "Total", "issue": issues, "sale": sales, "rmc": rmc}
|
||||||
|
|
||||||
|
|
||||||
def build_report_id(cost_centre_id, start_date, finish_date, request):
|
def build_report_id(cost_centre_id, start_date, finish_date, db):
|
||||||
sum_quantity = func.sum(Inventory.quantity * Journal.debit).label("quantity")
|
sum_quantity = func.sum(Inventory.quantity * Journal.debit).label("quantity")
|
||||||
sum_net = func.sum(Inventory.rate * Inventory.quantity * Journal.debit).label("net")
|
sum_net = func.sum(Inventory.rate * Inventory.quantity * Journal.debit).label("net")
|
||||||
sum_gross = func.sum(Inventory.amount * Journal.debit).label("gross")
|
sum_gross = func.sum(Inventory.amount * Journal.debit).label("gross")
|
||||||
|
|
||||||
query = (
|
query = (
|
||||||
request.dbsession.query(Product, sum_quantity, sum_net, sum_gross)
|
db.query(Product, sum_quantity, sum_net, sum_gross)
|
||||||
.join(Product.inventories)
|
.join(Product.inventories)
|
||||||
.join(Inventory.voucher)
|
.join(Inventory.voucher)
|
||||||
.join(Voucher.journals)
|
.join(Voucher.journals)
|
||||||
|
@ -1,8 +1,14 @@
|
|||||||
import datetime
|
import datetime
|
||||||
import uuid
|
import uuid
|
||||||
from sqlalchemy.orm import joinedload_all
|
|
||||||
|
|
||||||
|
from fastapi import APIRouter, Depends, Security, Request
|
||||||
|
from sqlalchemy.orm import joinedload_all, Session
|
||||||
from sqlalchemy.sql.expression import func, or_, and_
|
from sqlalchemy.sql.expression import func, or_, and_
|
||||||
|
|
||||||
|
from ...schemas.auth import UserToken
|
||||||
|
from ...core.security import get_current_active_user as get_user
|
||||||
|
from ...db.session import SessionLocal
|
||||||
from brewman.models.master import AccountBase
|
from brewman.models.master import AccountBase
|
||||||
from brewman.models.voucher import Voucher, Journal, VoucherType
|
from brewman.models.voucher import Voucher, Journal, VoucherType
|
||||||
from brewman.routers.services.session import (
|
from brewman.routers.services.session import (
|
||||||
@ -10,34 +16,46 @@ from brewman.routers.services.session import (
|
|||||||
session_period_start,
|
session_period_start,
|
||||||
session_period_finish,
|
session_period_finish,
|
||||||
)
|
)
|
||||||
from brewman.routers.services.voucher import get_edit_url
|
|
||||||
|
|
||||||
from fastapi import APIRouter
|
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
|
|
||||||
@router.get("/api/reconcile") # "Reconcile"
|
# Dependency
|
||||||
def show_blank(request):
|
def get_db() -> Session:
|
||||||
|
try:
|
||||||
|
db = SessionLocal()
|
||||||
|
yield db
|
||||||
|
finally:
|
||||||
|
db.close()
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("")
|
||||||
|
def show_blank(
|
||||||
|
request: Request,
|
||||||
|
user: UserToken = Security(get_user, scopes=["reconcile"]),
|
||||||
|
):
|
||||||
return {
|
return {
|
||||||
"startDate": session_period_start(request),
|
"startDate": session_period_start(request.session),
|
||||||
"finishDate": session_period_finish(request),
|
"finishDate": session_period_finish(request.session),
|
||||||
"account": None,
|
"account": None,
|
||||||
"body": [],
|
"body": [],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@router.get("/api/reconcile/{id}") # "Reconcile"
|
@router.get("/{id_}")
|
||||||
def show_data(request):
|
def show_data(
|
||||||
account = (
|
id_: uuid.UUID,
|
||||||
request.dbsession.query(AccountBase)
|
request: Request,
|
||||||
.filter(AccountBase.id == uuid.UUID(request.matchdict["id"]))
|
s: str = None,
|
||||||
.first()
|
f: str = None,
|
||||||
)
|
db: Session = Depends(get_db),
|
||||||
start_date = request.GET.get("s", session_period_start(request))
|
user: UserToken = Security(get_user, scopes=["reconcile"]),
|
||||||
finish_date = request.GET.get("f", session_period_finish(request))
|
):
|
||||||
body = build_report(account.id, start_date, finish_date, request)
|
account = db.query(AccountBase).filter(AccountBase.id == id_).first()
|
||||||
session_period_set(start_date, finish_date, request)
|
start_date = s if s is not None else session_period_start(request.session)
|
||||||
|
finish_date = f if f is not None else session_period_finish(request.session)
|
||||||
|
body = build_report(account.id, start_date, finish_date, db)
|
||||||
|
session_period_set(start_date, finish_date, request.session)
|
||||||
return {
|
return {
|
||||||
"startDate": start_date,
|
"startDate": start_date,
|
||||||
"finishDate": finish_date,
|
"finishDate": finish_date,
|
||||||
@ -46,12 +64,12 @@ def show_data(request):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def build_report(account_id, start_date, finish_date, request):
|
def build_report(account_id, start_date, finish_date, db):
|
||||||
opening = opening_balance(account_id, start_date, request.dbsession)
|
opening = opening_balance(account_id, start_date, db)
|
||||||
body = [opening]
|
body = [opening]
|
||||||
|
|
||||||
query = (
|
query = (
|
||||||
request.dbsession.query(Voucher)
|
db.query(Voucher)
|
||||||
.options(joinedload_all(Voucher.journals, Journal.account, innerjoin=True))
|
.options(joinedload_all(Voucher.journals, Journal.account, innerjoin=True))
|
||||||
.filter(Voucher.journals.any(Journal.account_id == account_id))
|
.filter(Voucher.journals.any(Journal.account_id == account_id))
|
||||||
.filter(
|
.filter(
|
||||||
@ -95,7 +113,7 @@ def build_report(account_id, start_date, finish_date, request):
|
|||||||
"id": voucher.id,
|
"id": voucher.id,
|
||||||
"date": voucher.date.strftime("%d-%b-%Y"),
|
"date": voucher.date.strftime("%d-%b-%Y"),
|
||||||
"name": name,
|
"name": name,
|
||||||
"url": get_edit_url(voucher, request),
|
"url": "", # get_edit_url(voucher, request),
|
||||||
"type": VoucherType.by_id(voucher.type).name,
|
"type": VoucherType.by_id(voucher.type).name,
|
||||||
"narration": voucher.narration,
|
"narration": voucher.narration,
|
||||||
"debit": debit,
|
"debit": debit,
|
||||||
@ -107,9 +125,9 @@ def build_report(account_id, start_date, finish_date, request):
|
|||||||
return body
|
return body
|
||||||
|
|
||||||
|
|
||||||
def opening_balance(account_id, start_date, dbsession):
|
def opening_balance(account_id, start_date, db):
|
||||||
opening = (
|
opening = (
|
||||||
dbsession.query(func.sum(Journal.amount * Journal.debit))
|
db.query(func.sum(Journal.amount * Journal.debit))
|
||||||
.join(Journal.voucher)
|
.join(Journal.voucher)
|
||||||
.filter(
|
.filter(
|
||||||
Voucher.reconcile_date < datetime.datetime.strptime(start_date, "%d-%b-%Y")
|
Voucher.reconcile_date < datetime.datetime.strptime(start_date, "%d-%b-%Y")
|
||||||
@ -140,33 +158,37 @@ def opening_balance(account_id, start_date, dbsession):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@router.post("/api/reconcile/{id}") # "Reconcile"
|
@router.post("/{id_}")
|
||||||
def save(request):
|
def save(
|
||||||
account = (
|
id_: uuid.UUID,
|
||||||
request.dbsession.query(AccountBase)
|
request: Request,
|
||||||
.filter(AccountBase.id == uuid.UUID(request.matchdict["id"]))
|
s: str = None,
|
||||||
.first()
|
f: str = None,
|
||||||
)
|
db: Session = Depends(get_db),
|
||||||
start_date = request.GET.get("s", session_period_start(request))
|
user: UserToken = Security(get_user, scopes=["reconcile"]),
|
||||||
finish_date = request.GET.get("f", session_period_finish(request))
|
):
|
||||||
for item in request.json_body["body"]:
|
account = db.query(AccountBase).filter(AccountBase.id == id_).first()
|
||||||
if "id" not in item or item["id"] is None:
|
start_date = s if s is not None else session_period_start(request.session)
|
||||||
continue
|
finish_date = f if f is not None else session_period_finish(request.session)
|
||||||
|
raise Exception("not fixed")
|
||||||
voucher = (
|
# for item in request.json_body["body"]:
|
||||||
request.dbsession.query(Voucher)
|
# if "id" not in item or item["id"] is None:
|
||||||
.filter(Voucher.id == uuid.UUID(item["id"]))
|
# continue
|
||||||
.first()
|
#
|
||||||
)
|
# voucher = (
|
||||||
is_reconciled = item["isReconciled"]
|
# request.dbsession.query(Voucher)
|
||||||
reconcile_date = datetime.datetime.strptime(item["reconcileDate"], "%d-%b-%Y")
|
# .filter(Voucher.id == uuid.UUID(item["id"]))
|
||||||
voucher.is_reconciled = is_reconciled
|
# .first()
|
||||||
voucher.reconcile_date = reconcile_date
|
# )
|
||||||
transaction.commit()
|
# is_reconciled = item["isReconciled"]
|
||||||
body = build_report(account.id, start_date, finish_date, request)
|
# reconcile_date = datetime.datetime.strptime(item["reconcileDate"], "%d-%b-%Y")
|
||||||
return {
|
# voucher.is_reconciled = is_reconciled
|
||||||
"startDate": start_date,
|
# voucher.reconcile_date = reconcile_date
|
||||||
"finishDate": finish_date,
|
# transaction.commit()
|
||||||
"account": {"id": account.id, "name": account.name},
|
# body = build_report(account.id, start_date, finish_date, request)
|
||||||
"body": body
|
# return {
|
||||||
}
|
# "startDate": start_date,
|
||||||
|
# "finishDate": finish_date,
|
||||||
|
# "account": {"id": account.id, "name": account.name},
|
||||||
|
# "body": body
|
||||||
|
# }
|
||||||
|
@ -21,7 +21,6 @@ export class CashFlowService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
list(id: string, startDate: string, finishDate: string): Observable<CashFlow> {
|
list(id: string, startDate: string, finishDate: string): Observable<CashFlow> {
|
||||||
const listUrl = (id === null) ? url : `${url}/${id}`;
|
|
||||||
const options = {params: new HttpParams()};
|
const options = {params: new HttpParams()};
|
||||||
if (startDate !== null) {
|
if (startDate !== null) {
|
||||||
options.params = options.params.set('s', startDate);
|
options.params = options.params.set('s', startDate);
|
||||||
@ -29,6 +28,7 @@ export class CashFlowService {
|
|||||||
if (finishDate !== null) {
|
if (finishDate !== null) {
|
||||||
options.params = options.params.set('f', finishDate);
|
options.params = options.params.set('f', finishDate);
|
||||||
}
|
}
|
||||||
|
const listUrl = (id === null) ? ( (startDate || finishDate) ? `${url}/data` : url) : `${url}/${id}`;
|
||||||
return <Observable<CashFlow>>this.http.get<CashFlow>(listUrl, options)
|
return <Observable<CashFlow>>this.http.get<CashFlow>(listUrl, options)
|
||||||
.pipe(
|
.pipe(
|
||||||
catchError(this.log.handleError(serviceName, 'list'))
|
catchError(this.log.handleError(serviceName, 'list'))
|
||||||
|
@ -21,14 +21,9 @@ export class DaybookService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
list(startDate: string, finishDate): Observable<Daybook> {
|
list(startDate: string, finishDate): Observable<Daybook> {
|
||||||
const options = {params: new HttpParams()};
|
startDate = startDate ? `/${startDate}` : '';
|
||||||
if (startDate !== null) {
|
finishDate = finishDate ? `/${finishDate}` : '';
|
||||||
options.params = options.params.set('s', startDate);
|
return <Observable<Daybook>>this.http.get<Daybook>(`${url}${startDate}${finishDate}`)
|
||||||
}
|
|
||||||
if (finishDate !== null) {
|
|
||||||
options.params = options.params.set('f', finishDate);
|
|
||||||
}
|
|
||||||
return <Observable<Daybook>>this.http.get<Daybook>(url, options)
|
|
||||||
.pipe(
|
.pipe(
|
||||||
catchError(this.log.handleError(serviceName, 'list'))
|
catchError(this.log.handleError(serviceName, 'list'))
|
||||||
);
|
);
|
||||||
|
@ -21,14 +21,9 @@ export class NetTransactionsService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
list(startDate: string, finishDate): Observable<NetTransactions> {
|
list(startDate: string, finishDate): Observable<NetTransactions> {
|
||||||
const options = {params: new HttpParams()};
|
startDate = startDate ? `/${startDate}` : '';
|
||||||
if (startDate !== null) {
|
finishDate = finishDate ? `/${finishDate}` : '';
|
||||||
options.params = options.params.set('s', startDate);
|
return <Observable<NetTransactions>>this.http.get<NetTransactions>(`${url}${startDate}${finishDate}`)
|
||||||
}
|
|
||||||
if (finishDate !== null) {
|
|
||||||
options.params = options.params.set('f', finishDate);
|
|
||||||
}
|
|
||||||
return <Observable<NetTransactions>>this.http.get<NetTransactions>(url, options)
|
|
||||||
.pipe(
|
.pipe(
|
||||||
catchError(this.log.handleError(serviceName, 'list'))
|
catchError(this.log.handleError(serviceName, 'list'))
|
||||||
);
|
);
|
||||||
|
@ -21,14 +21,9 @@ export class PurchaseEntriesService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
list(startDate: string, finishDate): Observable<PurchaseEntries> {
|
list(startDate: string, finishDate): Observable<PurchaseEntries> {
|
||||||
const options = {params: new HttpParams()};
|
startDate = startDate ? `/${startDate}` : '';
|
||||||
if (startDate !== null) {
|
finishDate = finishDate ? `/${finishDate}` : '';
|
||||||
options.params = options.params.set('s', startDate);
|
return <Observable<PurchaseEntries>>this.http.get<PurchaseEntries>(`${url}${startDate}${finishDate}`)
|
||||||
}
|
|
||||||
if (finishDate !== null) {
|
|
||||||
options.params = options.params.set('f', finishDate);
|
|
||||||
}
|
|
||||||
return <Observable<PurchaseEntries>>this.http.get<PurchaseEntries>(url, options)
|
|
||||||
.pipe(
|
.pipe(
|
||||||
catchError(this.log.handleError(serviceName, 'list'))
|
catchError(this.log.handleError(serviceName, 'list'))
|
||||||
);
|
);
|
||||||
|
@ -21,14 +21,9 @@ export class PurchasesService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
list(startDate: string, finishDate): Observable<Purchases> {
|
list(startDate: string, finishDate): Observable<Purchases> {
|
||||||
const options = {params: new HttpParams()};
|
startDate = startDate ? `/${startDate}` : '';
|
||||||
if (startDate !== null) {
|
finishDate = finishDate ? `/${finishDate}` : '';
|
||||||
options.params = options.params.set('s', startDate);
|
return <Observable<Purchases>>this.http.get<Purchases>(`${url}${startDate}${finishDate}`)
|
||||||
}
|
|
||||||
if (finishDate !== null) {
|
|
||||||
options.params = options.params.set('f', finishDate);
|
|
||||||
}
|
|
||||||
return <Observable<Purchases>>this.http.get<Purchases>(url, options)
|
|
||||||
.pipe(
|
.pipe(
|
||||||
catchError(this.log.handleError(serviceName, 'list'))
|
catchError(this.log.handleError(serviceName, 'list'))
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user