mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 05:10:31 +00:00
refactor: e2e
This commit is contained in:
@@ -286,12 +286,16 @@ export class CreditNote extends BaseModel {
|
||||
const {
|
||||
AccountTransaction,
|
||||
} = require('../../Accounts/models/AccountTransaction.model');
|
||||
const { ItemEntry } = require('../../Items/models/ItemEntry');
|
||||
const {
|
||||
ItemEntry,
|
||||
} = require('../../TransactionItemEntry/models/ItemEntry');
|
||||
const { Customer } = require('../../Customers/models/Customer');
|
||||
const { Branch } = require('../../Branches/models/Branch.model');
|
||||
const { Document } = require('../../ChromiumlyTenancy/models/Document');
|
||||
const { Warehouse } = require('../../Warehouses/models/Warehouse.model');
|
||||
const { PdfTemplateModel } = require('../../PdfTemplate/models/PdfTemplate');
|
||||
const {
|
||||
PdfTemplateModel,
|
||||
} = require('../../PdfTemplate/models/PdfTemplate');
|
||||
|
||||
return {
|
||||
/**
|
||||
|
||||
@@ -3,6 +3,8 @@ import {
|
||||
Controller,
|
||||
Delete,
|
||||
Get,
|
||||
HttpCode,
|
||||
HttpStatus,
|
||||
Param,
|
||||
Post,
|
||||
Put,
|
||||
@@ -37,7 +39,8 @@ export class ManualJournalsController {
|
||||
return this.manualJournalsApplication.deleteManualJournal(manualJournalId);
|
||||
}
|
||||
|
||||
@Post(':id/publish')
|
||||
@Put(':id/publish')
|
||||
@HttpCode(HttpStatus.OK)
|
||||
public publishManualJournal(@Param('id') manualJournalId: number) {
|
||||
return this.manualJournalsApplication.publishManualJournal(manualJournalId);
|
||||
}
|
||||
|
||||
@@ -26,9 +26,8 @@ export class EditManualJournal {
|
||||
|
||||
/**
|
||||
* Authorize the manual journal editing.
|
||||
* @param {number} tenantId
|
||||
* @param {number} manualJournalId
|
||||
* @param {IManualJournalDTO} manualJournalDTO
|
||||
* @param {number} manualJournalId - Manual journal id.
|
||||
* @param {IManualJournalDTO} manualJournalDTO - Manual journal DTO.
|
||||
*/
|
||||
private authorize = async (
|
||||
manualJournalId: number,
|
||||
@@ -81,10 +80,8 @@ export class EditManualJournal {
|
||||
|
||||
/**
|
||||
* Edits jouranl entries.
|
||||
* @param {number} tenantId
|
||||
* @param {number} manualJournalId
|
||||
* @param {IMakeJournalDTO} manualJournalDTO
|
||||
* @param {ISystemUser} authorizedUser
|
||||
* @param {number} manualJournalId - Manual journal id.
|
||||
* @param {IMakeJournalDTO} manualJournalDTO - Manual journal DTO.
|
||||
*/
|
||||
public async editJournalEntries(
|
||||
manualJournalId: number,
|
||||
@@ -94,7 +91,8 @@ export class EditManualJournal {
|
||||
oldManualJournal: ManualJournal;
|
||||
}> {
|
||||
// Validates the manual journal existance on the storage.
|
||||
const oldManualJournal = await ManualJournal.query()
|
||||
const oldManualJournal = await this.manualJournalModel
|
||||
.query()
|
||||
.findById(manualJournalId)
|
||||
.throwIfNotFound();
|
||||
|
||||
@@ -121,7 +119,8 @@ export class EditManualJournal {
|
||||
...manualJournalObj,
|
||||
});
|
||||
// Retrieve the given manual journal with associated entries after modifications.
|
||||
const manualJournal = await this.manualJournalModel.query(trx)
|
||||
const manualJournal = await this.manualJournalModel
|
||||
.query(trx)
|
||||
.findById(manualJournalId)
|
||||
.withGraphFetched('entries');
|
||||
|
||||
|
||||
@@ -75,6 +75,8 @@ export class ManualJournalGL {
|
||||
* @returns {ILedgerEntry[]}
|
||||
*/
|
||||
public getManualJournalGLEntries = (): ILedgerEntry[] => {
|
||||
return this.manualJournal.entries.map(this.getManualJournalEntry).flat();
|
||||
return this.manualJournal.entries
|
||||
.map((entry) => this.getManualJournalEntry(entry))
|
||||
.flat();
|
||||
};
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ import {
|
||||
import { SaleEstimate } from './models/SaleEstimate';
|
||||
import { PublicRoute } from '../Auth/Jwt.guard';
|
||||
|
||||
@Controller('sales/estimates')
|
||||
@Controller('sale-estimates')
|
||||
@PublicRoute()
|
||||
export class SaleEstimatesController {
|
||||
/**
|
||||
@@ -53,9 +53,9 @@ export class SaleEstimatesController {
|
||||
return this.saleEstimatesApplication.deleteSaleEstimate(estimateId);
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
public getSaleEstimate(@Param('id', ParseIntPipe) estimateId: number) {
|
||||
return this.saleEstimatesApplication.getSaleEstimate(estimateId);
|
||||
@Get('state')
|
||||
public getSaleEstimateState() {
|
||||
return this.saleEstimatesApplication.getSaleEstimateState();
|
||||
}
|
||||
|
||||
// @Get()
|
||||
@@ -70,14 +70,14 @@ export class SaleEstimatesController {
|
||||
return this.saleEstimatesApplication.deliverSaleEstimate(saleEstimateId);
|
||||
}
|
||||
|
||||
@Post(':id/approve')
|
||||
@Put(':id/approve')
|
||||
public approveSaleEstimate(
|
||||
@Param('id', ParseIntPipe) saleEstimateId: number,
|
||||
): Promise<void> {
|
||||
return this.saleEstimatesApplication.approveSaleEstimate(saleEstimateId);
|
||||
}
|
||||
|
||||
@Post(':id/reject')
|
||||
@Put(':id/reject')
|
||||
public rejectSaleEstimate(
|
||||
@Param('id', ParseIntPipe) saleEstimateId: number,
|
||||
): Promise<void> {
|
||||
@@ -125,8 +125,8 @@ export class SaleEstimatesController {
|
||||
return this.saleEstimatesApplication.getSaleEstimateMail(saleEstimateId);
|
||||
}
|
||||
|
||||
@Get('state')
|
||||
public getSaleEstimateState() {
|
||||
return this.saleEstimatesApplication.getSaleEstimateState();
|
||||
@Get(':id')
|
||||
public getSaleEstimate(@Param('id', ParseIntPipe) estimateId: number) {
|
||||
return this.saleEstimatesApplication.getSaleEstimate(estimateId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
} from '../types/SaleEstimates.types';
|
||||
import { ERRORS } from '../constants';
|
||||
import { Knex } from 'knex';
|
||||
import moment from 'moment';
|
||||
import * as moment from 'moment';
|
||||
import { UnitOfWork } from '@/modules/Tenancy/TenancyDB/UnitOfWork.service';
|
||||
import { SaleEstimate } from '../models/SaleEstimate';
|
||||
import { EventEmitter2 } from '@nestjs/event-emitter';
|
||||
@@ -52,8 +52,7 @@ export class ApproveSaleEstimateService {
|
||||
// Update estimate as approved.
|
||||
const saleEstimate = await this.saleEstimateModel
|
||||
.query(trx)
|
||||
.where('id', saleEstimateId)
|
||||
.patchAndFetch({
|
||||
.patchAndFetchById(saleEstimateId, {
|
||||
approvedAt: moment().toMySqlDateTime(),
|
||||
rejectedAt: null,
|
||||
});
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import moment from 'moment';
|
||||
import * as moment from 'moment';
|
||||
import { Knex } from 'knex';
|
||||
import { SaleEstimate } from '../models/SaleEstimate';
|
||||
import { EventEmitter2 } from '@nestjs/event-emitter';
|
||||
|
||||
@@ -206,65 +206,95 @@ export class SaleEstimate extends BaseModel {
|
||||
/**
|
||||
* Relationship mapping.
|
||||
*/
|
||||
// static get relationMappings() {
|
||||
// return {
|
||||
// customer: {
|
||||
// relation: Model.BelongsToOneRelation,
|
||||
// modelClass: this.customerModel,
|
||||
// join: {
|
||||
// from: 'sales_estimates.customerId',
|
||||
// to: 'contacts.id',
|
||||
// },
|
||||
// filter(query) {
|
||||
// query.where('contact_service', 'customer');
|
||||
// },
|
||||
// },
|
||||
// entries: {
|
||||
// relation: Model.HasManyRelation,
|
||||
// modelClass: this.itemEntryModel,
|
||||
// join: {
|
||||
// from: 'sales_estimates.id',
|
||||
// to: 'items_entries.referenceId',
|
||||
// },
|
||||
// filter(builder) {
|
||||
// builder.where('reference_type', 'SaleEstimate');
|
||||
// builder.orderBy('index', 'ASC');
|
||||
// },
|
||||
// },
|
||||
// branch: {
|
||||
// relation: Model.BelongsToOneRelation,
|
||||
// modelClass: this.branchModel,
|
||||
// join: {
|
||||
// from: 'sales_estimates.branchId',
|
||||
// to: 'branches.id',
|
||||
// },
|
||||
// },
|
||||
// warehouse: {
|
||||
// relation: Model.BelongsToOneRelation,
|
||||
// modelClass: this.warehouseModel,
|
||||
// join: {
|
||||
// from: 'sales_estimates.warehouseId',
|
||||
// to: 'warehouses.id',
|
||||
// },
|
||||
// },
|
||||
// attachments: {
|
||||
// relation: Model.ManyToManyRelation,
|
||||
// modelClass: this.documentModel,
|
||||
// join: {
|
||||
// from: 'sales_estimates.id',
|
||||
// through: {
|
||||
// from: 'document_links.modelId',
|
||||
// to: 'document_links.documentId',
|
||||
// },
|
||||
// to: 'documents.id',
|
||||
// },
|
||||
// filter(query) {
|
||||
// query.where('model_ref', 'SaleEstimate');
|
||||
// },
|
||||
// },
|
||||
// };
|
||||
// }
|
||||
static get relationMappings() {
|
||||
const { ItemEntry } = require('../../TransactionItemEntry/models/ItemEntry');
|
||||
const { Customer } = require('../../Customers/models/Customer');
|
||||
const { Branch } = require('../../Branches/models/Branch.model');
|
||||
const { Warehouse } = require('../../Warehouses/models/Warehouse.model');
|
||||
const { Document } = require('../../ChromiumlyTenancy/models/Document');
|
||||
const { PdfTemplateModel } = require('../../PdfTemplate/models/PdfTemplate');
|
||||
|
||||
return {
|
||||
customer: {
|
||||
relation: Model.BelongsToOneRelation,
|
||||
modelClass: Customer,
|
||||
join: {
|
||||
from: 'sales_estimates.customerId',
|
||||
to: 'contacts.id',
|
||||
},
|
||||
filter(query) {
|
||||
query.where('contact_service', 'customer');
|
||||
},
|
||||
},
|
||||
entries: {
|
||||
relation: Model.HasManyRelation,
|
||||
modelClass: ItemEntry,
|
||||
join: {
|
||||
from: 'sales_estimates.id',
|
||||
to: 'items_entries.referenceId',
|
||||
},
|
||||
filter(builder) {
|
||||
builder.where('reference_type', 'SaleEstimate');
|
||||
builder.orderBy('index', 'ASC');
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
* Sale estimate may belongs to branch.
|
||||
*/
|
||||
branch: {
|
||||
relation: Model.BelongsToOneRelation,
|
||||
modelClass: Branch,
|
||||
join: {
|
||||
from: 'sales_estimates.branchId',
|
||||
to: 'branches.id',
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
* Sale estimate may has associated warehouse.
|
||||
*/
|
||||
warehouse: {
|
||||
relation: Model.BelongsToOneRelation,
|
||||
modelClass: Warehouse,
|
||||
join: {
|
||||
from: 'sales_estimates.warehouseId',
|
||||
to: 'warehouses.id',
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
* Sale estimate transaction may has many attached attachments.
|
||||
*/
|
||||
attachments: {
|
||||
relation: Model.ManyToManyRelation,
|
||||
modelClass: Document,
|
||||
join: {
|
||||
from: 'sales_estimates.id',
|
||||
through: {
|
||||
from: 'document_links.modelId',
|
||||
to: 'document_links.documentId',
|
||||
},
|
||||
to: 'documents.id',
|
||||
},
|
||||
filter(query) {
|
||||
query.where('model_ref', 'SaleEstimate');
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
* Sale estimate may belongs to pdf branding template.
|
||||
*/
|
||||
pdfTemplate: {
|
||||
relation: Model.BelongsToOneRelation,
|
||||
modelClass: PdfTemplateModel,
|
||||
join: {
|
||||
from: 'sales_estimates.pdfTemplateId',
|
||||
to: 'pdf_templates.id',
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Model settings.
|
||||
*/
|
||||
|
||||
@@ -56,7 +56,7 @@ export class SaleInvoiceWriteoffGL {
|
||||
|
||||
return {
|
||||
...commontEntry,
|
||||
credit: this.saleInvoiceModel.localWrittenoffAmount,
|
||||
credit: this.saleInvoiceModel.writtenoffAmountLocal,
|
||||
accountId: this.ARAccountId,
|
||||
contactId: this.saleInvoiceModel.customerId,
|
||||
debit: 0,
|
||||
|
||||
@@ -295,6 +295,14 @@ export class SaleInvoice extends BaseModel {
|
||||
return Math.max(dueDateMoment.diff(dateMoment, 'days'), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Written-off amount in local currency.
|
||||
* @returns {number}
|
||||
*/
|
||||
get writtenoffAmountLocal() {
|
||||
return this.writtenoffAmount * this.exchangeRate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the overdue days in number.
|
||||
* @return {number|null}
|
||||
|
||||
@@ -38,7 +38,6 @@ export class ItemEntry extends BaseModel {
|
||||
item: Item;
|
||||
allocatedCostEntries: BillLandedCostEntry[];
|
||||
|
||||
|
||||
/**
|
||||
* Table name.
|
||||
* @returns {string}
|
||||
@@ -180,8 +179,8 @@ export class ItemEntry extends BaseModel {
|
||||
const { Bill } = require('../../Bills/models/Bill');
|
||||
const { SaleReceipt } = require('../../SaleReceipts/models/SaleReceipt');
|
||||
const { SaleEstimate } = require('../../SaleEstimates/models/SaleEstimate');
|
||||
const { Expense } = require('../../Expenses/models/Expense.model');
|
||||
const { TaxRate } = require('../../TaxRates/models/TaxRate.model');
|
||||
const { TaxRateModel } = require('../../TaxRates/models/TaxRate.model');
|
||||
// const { Expense } = require('../../Expenses/models/Expense.model');
|
||||
// const ProjectTask = require('models/Task');
|
||||
|
||||
return {
|
||||
@@ -282,7 +281,7 @@ export class ItemEntry extends BaseModel {
|
||||
*/
|
||||
tax: {
|
||||
relation: Model.HasOneRelation,
|
||||
modelClass: TaxRate,
|
||||
modelClass: TaxRateModel,
|
||||
join: {
|
||||
from: 'items_entries.taxRateId',
|
||||
to: 'tax_rates.id',
|
||||
|
||||
Reference in New Issue
Block a user