diff --git a/src/controllers/pharmacy/factory_to_supplier.ts b/src/controllers/pharmacy/factory_to_supplier.ts index eea88af..9560426 100644 --- a/src/controllers/pharmacy/factory_to_supplier.ts +++ b/src/controllers/pharmacy/factory_to_supplier.ts @@ -14,11 +14,10 @@ import { FactoryToSupplierModel } from "../../model/factory_to_supplier"; const log: Logger = new Logger({ name: '[FactorytoSupplierController]', type: 'pretty' }); export class FactorytoSupplierController { - static async listFactorybySupplier(req: Request, res: Response, next: NextFunction): Promise { + static async list(req: Request, res: Response, next: NextFunction): Promise { /* #swagger.tags = ['Pharmacy - FactoryToSupplier'] #swagger.security = [{ "bearerAuth": [] }] - #swagger.parameters['supplier_id'] = { in: 'query', required: true, type: 'string' } #swagger.parameters['filter'] = { description: '', in: 'query', type: 'string' } #swagger.parameters['limit'] = { in: 'query', required: true, type: 'number' } #swagger.parameters['page'] = { in: 'query', required: true, type: 'number' } @@ -28,7 +27,6 @@ export class FactorytoSupplierController { */ try { const schema = Joi.object().keys({ - supplier_id: Joi.string().uuid().required().label("Supplier ID"), filter: Joi.string().allow("").optional().label("Filter"), page: Joi.number().required().min(1).label("Page"), limit: Joi.number().required().min(1).label("Limit"), @@ -41,7 +39,7 @@ export class FactorytoSupplierController { let filter = param.filter && param.filter !== "" ? JSON.parse(param.filter) : {}; - var query = await FactoryToSupplierModel.listFactorybySupplier(param.supplier_id, filter); + var query = await FactoryToSupplierModel.list(filter); const offset = (param.page - 1) * param.limit; let limit = param.limit; @@ -76,7 +74,6 @@ export class FactorytoSupplierController { #swagger.security = [{ "bearerAuth": [] }] - #swagger.parameters['supplier_id'] = { in: 'query', required: true, type: 'string' } #swagger.parameters['filter'] = { description: 'Filter with 2 format :
  • Simple format use text plaint will filter eq:code or like %name%
  • Advance format using field existing {status:\'Y\', any:\'SAME AS PLAINT LOGIC\', etc...}
', in: 'query', @@ -102,7 +99,6 @@ export class FactorytoSupplierController { try { const schema = Joi.object().keys({ - supplier_id: Joi.string().uuid().required().label("Supplier ID"), filter: Joi.string().allow('').optional().label('Filter'), order_field: Joi.string().required().label('Order Field'), order_direction: Joi.string().allow('asc', 'desc').required().label('Order Direction'), @@ -112,7 +108,7 @@ export class FactorytoSupplierController { let filter = param.filter && param.filter !== "" ? JSON.parse(param.filter) : {}; - var query = await FactoryToSupplierModel.listFactorybySupplier(filter); + var query = await FactoryToSupplierModel.list(filter); const data = await query.getMany(); const filename = "factory_to_supplier.csv"; @@ -194,6 +190,13 @@ export class FactorytoSupplierController { const factoryRepo = OrmHelper.DB.getRepository(Factory); const supplierRepo = OrmHelper.DB.getRepository(Supplier); + await factoryToSupplierRepo + .createQueryBuilder() + .delete() + .from(FactoryToSupplier) + .where("supplier_id = :supplierId", { supplierId: param.supplier_id }) + .execute(); + let relation : FactoryToSupplier; for (const factoryId of param.factory_ids) { relation = new FactoryToSupplier(); diff --git a/src/controllers/pharmacy/initial_stock.ts b/src/controllers/pharmacy/initial_stock.ts new file mode 100644 index 0000000..3b44b48 --- /dev/null +++ b/src/controllers/pharmacy/initial_stock.ts @@ -0,0 +1,141 @@ +import { Response, NextFunction, Application } from "express"; +import { Request } from "express-jwt"; +import { ReturnHelper } from "../../helpers/express/return"; +import { OrmHelper } from "../../helpers/orm"; +import Joi from "joi"; +import { ILogObj, Logger } from "tslog"; +import { Language } from "../../langs/lang"; +import { InitialStock, ItemMaster, Room, ItemOrigin, Paging } from "entity"; +import CommonHelper from "../../helpers/common"; +import * as fastcsv from 'fast-csv'; +import dayjs from "dayjs"; +import { InitialStockModel } from "../../model/initial_stock"; + +const log: Logger = new Logger({ name: '[InitialStockController]', type: 'pretty' }); + +export class InitialStockController { + static async list(req: Request, res: Response, next: NextFunction): Promise { + /* + #swagger.tags = ['Pharmacy - InitialStock'] + #swagger.security = [{ "bearerAuth": [] }] + #swagger.parameters['filter'] = { description: '', in: 'query', type: 'string' } + #swagger.parameters['limit'] = { in: 'query', required: true, type: 'number' } + #swagger.parameters['page'] = { in: 'query', required: true, type: 'number' } + #swagger.parameters['with_deleted'] = { in: 'query', required: true, type: 'boolean' } + #swagger.parameters['order_field'] = { in: 'query', required: true, type: 'string' } + #swagger.parameters['order_direction'] = { in: 'query', required: true, schema: { '@enum': ['ASC', 'DESC'] } } + */ + try { + const schema = Joi.object().keys({ + filter: Joi.string().allow("").optional().label("Filter"), + page: Joi.number().required().min(1).label("Page"), + limit: Joi.number().required().min(1).label("Limit"), + with_deleted: Joi.bool().required().label("With Deleted"), + order_field: Joi.string().required().label("Order Field"), + order_direction: Joi.string().allow("asc", "desc").required().label("Order Direction"), + }); + + let param: any = await schema.validateAsync(req.query); + + let filter = param.filter && param.filter !== "" ? JSON.parse(param.filter) : {}; + + var query = await InitialStockModel.list(filter); + + const offset = (param.page - 1) * param.limit; + let limit = param.limit; + + const res_count = query; + const res_list = query.select([ + 'InitialStock.id', + 'InitialStock.exp_date', + 'InitialStock.stock', + 'ItemMaster.item_name', + 'Room.room', + 'ItemOrigin.origin_name', + ]) + .leftJoin("InitialStock.itemmaster", "ItemMaster") + .leftJoin("InitialStock.room", "Room") + .leftJoin("InitialStock.itemorigin", "ItemOrigin") + .orderBy("InitialStock." + param.order_field, param.order_direction) + .offset(offset) + .limit(limit); + + if (param.with_deleted) { + res_count.withDeleted(); + res_list.withDeleted(); + } + + const current_page = param.page; + const total_count_data = await res_count.getCount(); + const list_data = await res_list.getMany(); + const count_data = CommonHelper.countObject(list_data); + + return ReturnHelper.successResponselist(res, 200, Language.lang.success_view, count_data, current_page, total_count_data, list_data); + } catch (e: unknown) { + log.error(e); + const err = e as Error; + return ReturnHelper.errorResponse(res, 400, 401, Language.lang.failed_view, err.message); + } + } + + static async create(req: Request, res: Response, next: NextFunction): Promise { + /* + #swagger.tags = ['Pharmacy - InitialStock'] + #swagger.security = [{ + "bearerAuth": [] + }] + + #swagger.requestBody = { + required: true, + content: { + "application/json": { + schema: { + $ref: "#/components/schemas/initial_stock" + } + } + } + } + */ + const queryRunner = OrmHelper.DB.createQueryRunner(); + await queryRunner.startTransaction(); + try { + const schema = Joi.object().keys({ + itemmaster: Joi.string().uuid().required().label("Item Master ID"), + room: Joi.string().uuid().required().label("Room ID"), + itemorigin: Joi.string().uuid().required().label("Item Origin ID"), + batch: Joi.string().label("Batch"), + exp_date: Joi.date().required().label("Exp Date"), + stock: Joi.number().required().label("Stock"), + }); + + const param: any = await schema.validateAsync(req.body); + + const itemmaster = OrmHelper.DB.getRepository(ItemMaster).findOneBy({ id: param.itemmaster }); + const room = OrmHelper.DB.getRepository(Room).findOneBy({ id: param.room }) + const itemorigin = OrmHelper.DB.getRepository(ItemOrigin).findOneBy({ id: param.itemorigin }); + + if (!itemmaster) throw { message: "Item Master not found" }; + if (!room) throw { message: "Room not found" }; + if (!itemorigin) throw { message: "Item Origin not found" }; + + const initial_stock = new InitialStock(); + initial_stock.itemmaster = param.itemmaster; + initial_stock.room = param.room; + initial_stock.itemorigin = param.itemorigin; + initial_stock.batch = param.batch; + initial_stock.exp_date = param.exp_date; + initial_stock.stock = param.stock; + + await queryRunner.manager.save(initial_stock); + await queryRunner.commitTransaction(); + + return ReturnHelper.successResponseAny(res, 200, Language.lang.success_insert, initial_stock); + + } catch (e: unknown) { + log.error(e); + const err = e as Error; + + return ReturnHelper.errorResponse(res, 500, 401, Language.lang.failed_insert, err.message); + } + } +} \ No newline at end of file diff --git a/src/controllers/pharmacy/item_master.ts b/src/controllers/pharmacy/item_master.ts index aa197c9..472aa14 100644 --- a/src/controllers/pharmacy/item_master.ts +++ b/src/controllers/pharmacy/item_master.ts @@ -68,6 +68,35 @@ export class ItemMasterController { } } + + static async option(req: Request, res: Response, next: NextFunction): Promise { + /* + #swagger.tags = ['Pharmacy - ItemMaster'] + #swagger.security = [{ "bearerAuth": [] }] + */ + try { + const query = await ItemMasterModel.list(); + + query.select([ + "item_master.id", + "item_master.item_name", + "unit.large_unit", + "unit.small_unit", + "item_master.pack_size", + ]); + + const total_count_data = await query.getCount(); + const list_data = await query.getMany(); + const count_data = CommonHelper.countObject(list_data); + + return ReturnHelper.successResponselist(res, 200, Language.lang.success_view, count_data, 1, total_count_data, list_data); + } catch (e: unknown) { + log.error(e); + const err = e as Error; + return ReturnHelper.errorResponse(res, 400, 401, Language.lang.failed_view, err.message); + } + } + static async export(req: Request, res: Response, next: NextFunction): Promise { /* #swagger.tags = ['Pharmacy - ItemMaster'] @@ -110,7 +139,7 @@ export class ItemMasterController { var query = await ItemMasterModel.list(filter); const data = await query.getMany(); - + const filename = "item_master.csv"; res.setHeader('Content-Type', 'text/csv'); @@ -177,6 +206,7 @@ export class ItemMasterController { item_type_detail_id: Joi.string().uuid().required().label('Item Type Detail ID'), item_category_id: Joi.string().uuid().required().label('Item Category ID'), item_class_id: Joi.string().uuid().required().label('Item Class ID'), + item_class_detail_id: Joi.string().uuid().required().label('Item Class Detail ID'), item_status_id: Joi.string().uuid().required().label('Item Status ID'), factory_id: Joi.string().uuid().required().label('Factory ID'), unit_id: Joi.string().uuid().required().label('Unit ID'), @@ -191,18 +221,19 @@ export class ItemMasterController { const data = new ItemMaster() data.item_name = param.item_name, - data.generic_name = param.generic_name_id, - data.type_detail = param.item_type_detail_id, - data.category = param.item_category_id, - data.item_class = param.item_class_id, - data.status = param.item_status_id, - data.factory = param.factory_id, - data.unit = param.unit_id, - data.pack_size = param.pack_size, - data.minimum_quantity = param.minimum_quantity, - data.minimum_sales_quantity = param.minimum_sales_quantity, - data.strength = param.strength, - data.active = param.active + data.generic_name = param.generic_name_id, + data.type_detail = param.item_type_detail_id, + data.category = param.item_category_id, + data.item_class = param.item_class_id, + data.item_class_detail = param.item_class_detail_id, + data.status = param.item_status_id, + data.factory = param.factory_id, + data.unit = param.unit_id, + data.pack_size = param.pack_size, + data.minimum_quantity = param.minimum_quantity, + data.minimum_sales_quantity = param.minimum_sales_quantity, + data.strength = param.strength, + data.active = param.active data.created_by = req.auth.data.name; await OrmHelper.DB.manager.save(data); @@ -249,6 +280,7 @@ export class ItemMasterController { item_type_detail_id: Joi.string().uuid().required().label('Item Type Detail ID'), item_category_id: Joi.string().uuid().required().label('Item Category ID'), item_class_id: Joi.string().uuid().required().label('Item Class ID'), + item_class_detail_id: Joi.string().uuid().required().label('Item Class Detail ID'), item_status_id: Joi.string().uuid().required().label('Item Status ID'), factory_id: Joi.string().uuid().required().label('Factory ID'), unit_id: Joi.string().uuid().required().label('Unit ID'), @@ -269,18 +301,19 @@ export class ItemMasterController { if (data != null) { data.item_name = param.item_name, - data.generic_name = param.generic_name_id, - data.type_detail = param.item_type_detail_id, - data.category = param.item_category_id, - data.item_class = param.item_class_id, - data.status = param.item_status_id, - data.factory = param.factory_id, - data.unit = param.unit_id, - data.pack_size = param.pack_size, - data.minimum_quantity = param.minimum_quantity, - data.minimum_sales_quantity = param.minimum_sales_quantity, - data.strength = param.strength, - data.active = param.active + data.generic_name = param.generic_name_id, + data.type_detail = param.item_type_detail_id, + data.category = param.item_category_id, + data.item_class = param.item_class_id, + data.item_class_detail = param.item_class_detail_id, + data.status = param.item_status_id, + data.factory = param.factory_id, + data.unit = param.unit_id, + data.pack_size = param.pack_size, + data.minimum_quantity = param.minimum_quantity, + data.minimum_sales_quantity = param.minimum_sales_quantity, + data.strength = param.strength, + data.active = param.active data.updated_by = req.auth.data.name; await repo.save(data); diff --git a/src/controllers/pharmacy/item_origin.ts b/src/controllers/pharmacy/item_origin.ts index cfddcca..e60aff2 100644 --- a/src/controllers/pharmacy/item_origin.ts +++ b/src/controllers/pharmacy/item_origin.ts @@ -68,6 +68,31 @@ export class ItemOriginController { } } + static async option(req: Request, res: Response, next: NextFunction): Promise { + /* + #swagger.tags = ['Pharmacy - ItemOrigin'] + #swagger.security = [{ "bearerAuth": [] }] + */ + try { + const query = await ItemOriginModel.list(); + + query.select([ + "item_origin.id", + "item_origin.origin_name", + ]); + + const total_count_data = await query.getCount(); + const list_data = await query.getMany(); + const count_data = CommonHelper.countObject(list_data); + + return ReturnHelper.successResponselist(res, 200, Language.lang.success_view, count_data, 1, total_count_data, list_data); + } catch (e: unknown) { + log.error(e); + const err = e as Error; + return ReturnHelper.errorResponse(res, 400, 401, Language.lang.failed_view, err.message); + } + } + static async export(req: Request, res: Response, next: NextFunction): Promise { /* #swagger.tags = ['Pharmacy - ItemOrigin'] @@ -110,7 +135,7 @@ export class ItemOriginController { var query = await ItemOriginModel.list(filter); const data = await query.getMany(); - + const filename = "item_origin.csv"; res.setHeader('Content-Type', 'text/csv'); diff --git a/src/controllers/pharmacy/supplier.ts b/src/controllers/pharmacy/supplier.ts index f3efd11..21c3240 100644 --- a/src/controllers/pharmacy/supplier.ts +++ b/src/controllers/pharmacy/supplier.ts @@ -68,6 +68,31 @@ export class SupplierController { } } + static async option(req: Request, res: Response, next: NextFunction): Promise { + /* + #swagger.tags = ['Pharmacy - Supplier'] + #swagger.security = [{ "bearerAuth": [] }] + */ + try { + const query = await SupplierModel.list(); + + query.select([ + "supplier.id", + "supplier.supplier_name", + ]); + + const total_count_data = await query.getCount(); + const list_data = await query.getMany(); + const count_data = CommonHelper.countObject(list_data); + + return ReturnHelper.successResponselist(res, 200, Language.lang.success_view, count_data, 1, total_count_data, list_data); + } catch (e: unknown) { + log.error(e); + const err = e as Error; + return ReturnHelper.errorResponse(res, 400, 401, Language.lang.failed_view, err.message); + } + } + static async export(req: Request, res: Response, next: NextFunction): Promise { /* #swagger.tags = ['Pharmacy - Supplier'] @@ -110,7 +135,7 @@ export class SupplierController { var query = await SupplierModel.list(filter); const data = await query.getMany(); - + const filename = "supplier.csv"; res.setHeader('Content-Type', 'text/csv'); diff --git a/src/controllers/pharmacy/unit.ts b/src/controllers/pharmacy/unit.ts index e48b2cd..8f2ef92 100644 --- a/src/controllers/pharmacy/unit.ts +++ b/src/controllers/pharmacy/unit.ts @@ -110,7 +110,7 @@ export class UnitController { var query = await UnitModel.list(filter); const data = await query.getMany(); - + const filename = "unit.csv"; res.setHeader('Content-Type', 'text/csv'); @@ -173,12 +173,16 @@ export class UnitController { try { const schema = Joi.object().keys({ unit_name: Joi.string().max(256).required().label('Name'), + small_unit: Joi.string().max(256).optional().allow('').label('Small Unit'), + large_unit: Joi.string().max(256).optional().allow('').label('Large Unit'), }); const param: any = await schema.validateAsync(req.body); const data = new Unit() data.unit_name = param.unit_name + data.small_unit = param.small_unit + data.large_unit = param.large_unit data.created_by = req.auth.data.name await OrmHelper.DB.manager.save(data); @@ -221,6 +225,8 @@ export class UnitController { const schema = Joi.object().keys({ id: Joi.string().uuid().required().label('ID'), unit_name: Joi.string().max(256).required().label('Name'), + small_unit: Joi.string().max(256).optional().allow('').label('Small Unit'), + large_unit: Joi.string().max(256).optional().allow('').label('Large Unit'), }); req.body.id = req.params['id']; @@ -233,6 +239,8 @@ export class UnitController { if (data != null) { data.unit_name = param.unit_name + data.small_unit = param.small_unit + data.large_unit = param.large_unit data.updated_by = req.auth.data.name await repo.save(data); diff --git a/src/controllers/pharmacy/usage_instructions.ts b/src/controllers/pharmacy/usage_instructions.ts index 2d9cfd2..52ac896 100644 --- a/src/controllers/pharmacy/usage_instructions.ts +++ b/src/controllers/pharmacy/usage_instructions.ts @@ -180,7 +180,7 @@ export class UsageInstructionsController { const data = new UsageInstructions() data.usage_instructions_name = param.usage_instructions_name - data.usage_abbreviation = param.usage_instructions_abbreviation + data.usage_instructions_abbreviation = param.usage_instructions_abbreviation data.created_by = req.auth.data.name; await OrmHelper.DB.manager.save(data); @@ -236,7 +236,7 @@ export class UsageInstructionsController { if (data != null) { data.usage_instructions_name = param.usage_instructions_name - data.usage_abbreviation = param.usage_instructions_abbreviation + data.usage_instructions_abbreviation = param.usage_instructions_abbreviation data.updated_by = req.auth.data.name; await repo.save(data); diff --git a/src/controllers/room.ts b/src/controllers/room.ts index 3787ef5..34ab3c7 100644 --- a/src/controllers/room.ts +++ b/src/controllers/room.ts @@ -71,14 +71,39 @@ export class RoomController { const total_count_data = await res_count.getCount(); const list_data = await res_list.getMany(); const mapped_data = list_data.map((item: any) => ({ - ...item, - picture: item.picture - ? photoBaseUrl + item.picture - : null - })); + ...item, + picture: item.picture + ? photoBaseUrl + item.picture + : null + })); const count_data = CommonHelper.countObject(list_data); - return ReturnHelper.successResponselist(res, 200, Language.lang.success_view, count_data, current_page, total_count_data, mapped_data); + return ReturnHelper.successResponselist(res, 200, Language.lang.success_view, count_data, current_page, total_count_data, mapped_data); + } catch (e: unknown) { + log.error(e); + const err = e as Error; + return ReturnHelper.errorResponse(res, 400, 401, Language.lang.failed_view, err.message); + } + } + + static async option(req: Request, res: Response, next: NextFunction): Promise { + /* + #swagger.tags = ['Room'] + #swagger.security = [{ "bearerAuth": [] }] + */ + try { + const query = await RoomModel.list(); + + query.select([ + "Room.id", + "Room.room", + ]); + + const total_count_data = await query.getCount(); + const list_data = await query.getMany(); + const count_data = CommonHelper.countObject(list_data); + + return ReturnHelper.successResponselist(res, 200, Language.lang.success_view, count_data, 1, total_count_data, list_data); } catch (e: unknown) { log.error(e); const err = e as Error; diff --git a/src/helpers/orm.ts b/src/helpers/orm.ts index cc89ebb..8e304f4 100644 --- a/src/helpers/orm.ts +++ b/src/helpers/orm.ts @@ -1,7 +1,7 @@ import config from 'config'; import { DataSource } from "typeorm"; import { ILogObj, Logger } from 'tslog'; -import { Administrativu, Aldeia, District, Menu, Munisipo, Suco, Application, Nationality, Diagnosis, DiagnosticProcedure, Room, ServiceType, ServiceClass, Service, ServiceFare, ServicePackage, Department, DoctorSchedule, MeasurementUnit, ReferenceRange, QueueMonitoring, ExaminationDetail, ExaminationType, User, UserRole, HrmsEmployee, HrmsDepartment, HrmsPosition, HrmsShift,HospitalInformation, ItemOrigin, ItemType, ItemTypeDetail, Unit, ItemCategory, ItemStatus, UsageInstructions, UsageTime, ItemClass, ItemClassDetail, GenericName, Factory, Supplier, FactoryToSupplier, ItemMaster, ItemGroup, PharmacyInfo, ItemPrice, SellingPricePercentage, PatientGroup, PatientGuarantor } from 'entity' +import { Administrativu, Aldeia, District, Menu, Munisipo, Suco, Application, Nationality, Diagnosis, DiagnosticProcedure, Room, ServiceType, ServiceClass, Service, ServiceFare, ServicePackage, Department, DoctorSchedule, MeasurementUnit, ReferenceRange, QueueMonitoring, ExaminationDetail, ExaminationType, User, UserRole, HrmsEmployee, HrmsDepartment, HrmsPosition, HrmsShift,HospitalInformation, ItemOrigin, ItemType, ItemTypeDetail, Unit, ItemCategory, ItemStatus, UsageInstructions, UsageTime, ItemClass, ItemClassDetail, GenericName, Factory, Supplier, FactoryToSupplier, ItemMaster, ItemGroup, PharmacyInfo, ItemPrice, SellingPricePercentage, PatientGroup, PatientGuarantor,InitialStock } from 'entity' export class OrmHelper { static DB: DataSource = null @@ -40,7 +40,8 @@ export class OrmHelper { ItemPrice, SellingPricePercentage, PatientGroup, - PatientGuarantor + PatientGuarantor, + InitialStock ], subscribers: [], migrations: [], diff --git a/src/model/factory_to_supplier.ts b/src/model/factory_to_supplier.ts index 32a4490..410ca70 100644 --- a/src/model/factory_to_supplier.ts +++ b/src/model/factory_to_supplier.ts @@ -4,7 +4,7 @@ import { OrmHelper } from "../helpers/orm"; import { FactoryToSupplier } from "entity"; export class FactoryToSupplierModel { - static async listFactorybySupplier(supplier_id: string, filter = {}): Promise> { + static async list(filter = {}): Promise> { const repo = OrmHelper.DB.getRepository(FactoryToSupplier); let whereAttr: string[] = []; let whereVal: any = {}; @@ -16,7 +16,6 @@ export class FactoryToSupplierModel { var query = repo.createQueryBuilder("factory_to_supplier") .leftJoinAndSelect("factory_to_supplier.factory", "factory") .leftJoinAndSelect("factory_to_supplier.supplier", "supplier") - .where("factory_to_supplier.supplier_id = :supplierId", { supplierId: supplier_id }); if (whereAttr.length != 0) { query = query.where(whereAttr.join(" and "), whereVal); } diff --git a/src/model/initial_stock.ts b/src/model/initial_stock.ts new file mode 100644 index 0000000..4ea9cdf --- /dev/null +++ b/src/model/initial_stock.ts @@ -0,0 +1,23 @@ +import { InitialStock } from "entity"; +import { SelectQueryBuilder } from "typeorm"; +import CommonHelper from "../helpers/common"; +import { OrmHelper } from "../helpers/orm"; + +export class InitialStockModel { + static async list(filter = {}): Promise> { + const repo = OrmHelper.DB.getRepository(InitialStock); + let whereAttr: string[] = []; + let whereVal: any = {}; + if (filter && Object.keys(filter).length > 0) { + whereAttr = [...whereAttr, ...CommonHelper.handleQueryFilter(filter, "InitialStock").whereAttr]; + whereVal = { ...whereVal, ...CommonHelper.handleQueryFilter(filter, "InitialStock").whereVal }; + } + + var query = repo.createQueryBuilder("InitialStock"); + if (whereAttr.length != 0) { + query = query.where(whereAttr.join(" and "), whereVal); + } + + return query; + } +} \ No newline at end of file diff --git a/src/model/item_master.ts b/src/model/item_master.ts index 592d035..f76c3bb 100644 --- a/src/model/item_master.ts +++ b/src/model/item_master.ts @@ -19,7 +19,7 @@ export class ItemMasterModel { .leftJoinAndSelect("item_master.type_detail", "type_detail") .leftJoinAndSelect("item_master.category", "category") .leftJoinAndSelect("item_master.item_class", "item_class") - .leftJoinAndSelect("item_master.class_detail", "class_detail") + .leftJoinAndSelect("item_master.item_class_detail", "item_class_detail") .leftJoinAndSelect("item_master.status", "status") .leftJoinAndSelect("item_master.factory", "factory") .leftJoinAndSelect("item_master.unit", "unit") diff --git a/src/routes/private.ts b/src/routes/private.ts index 74ff9c6..4db2044 100644 --- a/src/routes/private.ts +++ b/src/routes/private.ts @@ -51,6 +51,7 @@ import { PatientGuarantorController } from '../controllers/patient_guarantor'; import { GenericNameController } from '../controllers/pharmacy/generic_name'; import { RefferalHospital } from 'entity'; import { RefferalHospitalController } from '../controllers/refferal_hospital'; +import { InitialStockController } from '../controllers/pharmacy/initial_stock'; export class RoutePrivate { static setup(app: express.Application) { @@ -130,6 +131,7 @@ export class RoutePrivate { app.put('/api/diagnostic-procedure/restore/:id', DiagnosticProcedureController.restore) app.get('/api/room/list', RoomController.list) + app.get('/api/room/option', RoomController.option) app.post('/api/room/create', RoomController.create) app.get('/api/room/detail/:id', RoomController.detail) app.put('/api/room/update/:id', RoomController.update) @@ -247,6 +249,7 @@ export class RoutePrivate { app.put('/api/pharmacy/item-group/restore/:id', ItemGroupController.restore) app.get('/api/pharmacy/item-origin/list', ItemOriginController.list) + app.get('/api/pharmacy/item-origin/option', ItemOriginController.option) app.get('/api/pharmacy/item-origin/export', ItemOriginController.export) app.post('/api/pharmacy/item-origin/create', ItemOriginController.create) app.put('/api/pharmacy/item-origin/update/:id', ItemOriginController.update) @@ -331,20 +334,22 @@ export class RoutePrivate { app.put('/api/pharmacy/factory/restore/:id', FactoryController.restore) app.get('/api/pharmacy/supplier/list', SupplierController.list) + app.get('/api/pharmacy/supplier/option', SupplierController.option) app.get('/api/pharmacy/supplier/export', SupplierController.export) app.post('/api/pharmacy/supplier/create', SupplierController.create) app.put('/api/pharmacy/supplier/update/:id', SupplierController.update) app.delete('/api/pharmacy/supplier/delete/:id/:hard', SupplierController.delete) app.put('/api/pharmacy/supplier/restore/:id', SupplierController.restore) - app.get('/api/pharmacy/factory-to-supplier/list-factory-by-supplier', FactorytoSupplierController.listFactorybySupplier) + app.get('/api/pharmacy/factory-to-supplier/list', FactorytoSupplierController.list) app.get('/api/pharmacy/factory-to-supplier/export', FactorytoSupplierController.export) app.post('/api/pharmacy/factory-to-supplier/create', FactorytoSupplierController.create) - app.put('/api/pharmacy/factory-to-supplier/update/:supplier_id', FactorytoSupplierController.update) + // app.put('/api/pharmacy/factory-to-supplier/update/:supplier_id', FactorytoSupplierController.update) // app.delete('/api/pharmacy/factory-to-supplier/delete/:supplier_id/:hard', FactorytoSupplierController.delete) // app.put('/api/pharmacy/factory-to-supplier/restore/:supplier_id', FactorytoSupplierController.restore) app.get('/api/pharmacy/item-master/list', ItemMasterController.list) + app.get('/api/pharmacy/item-master/option', ItemMasterController.option) app.get('/api/pharmacy/item-master/export', ItemMasterController.export) app.post('/api/pharmacy/item-master/create', ItemMasterController.create) app.put('/api/pharmacy/item-master/update/:id', ItemMasterController.update) @@ -395,5 +400,8 @@ export class RoutePrivate { app.put('/api/refferal-hospital/update/:id', RefferalHospitalController.update) app.delete('/api/refferal-hospital/delete/:id/:hard', RefferalHospitalController.delete) app.put('/api/refferal-hospital/restore/:id', RefferalHospitalController.restore) + + app.get('/api/initial-stock/list', InitialStockController.list) + app.post('/api/initial-stock/create', InitialStockController.create) } } \ No newline at end of file diff --git a/src/swagger/builder.js b/src/swagger/builder.js index de99f7d..00dea49 100644 --- a/src/swagger/builder.js +++ b/src/swagger/builder.js @@ -222,6 +222,8 @@ const doc = { }, unit: { $unit_name: 'Unit name', + $small_unit: 'Small unit name', + $large_unit: 'Large unit name' }, item_category: { $category_name: 'ItemCategory name', @@ -269,6 +271,7 @@ const doc = { $item_type_detail_id: 'Item type detail ID (UUID)', $item_category_id: 'Item category ID (UUID)', $item_class_id: 'Item class ID (UUID)', + $item_class_detail_id: 'Item class Detail ID (UUID)', $item_status_id: 'Item status ID (UUID)', $factory_id: 'Factory ID (UUID)', $unit_id: 'Unit ID (UUID)', @@ -295,6 +298,14 @@ const doc = { $selling_price: 'Selling Price (required, number, minimum 0)', $expired_date: 'Expired Date (required, date)' }, + initial_stock: { + $itemmaster: 'Item Master uuid', + $room: 'Room uuid', + $itemorigin: 'Item Origin uuid', + $batch: 'Batch', + $exp_date: 'Exp Date', + $stock: 'Stock' + }, selling_price_percentage: { $item_master_id: 'Item Master ID (required, UUID)', $item_origin_id: 'Item Origin ID (required, UUID)',