mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 06:10:31 +00:00
Merge pull request #885 from bigcapitalhq/refund-credit-notes
fix: refund credit notes
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import { ApiProperty } from '@nestjs/swagger';
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
import { IsNotEmpty, IsOptional, IsPositive, IsString } from 'class-validator';
|
import { ToNumber, IsOptional } from '@/common/decorators/Validators';
|
||||||
|
import { IsDateString, IsNotEmpty, IsPositive, IsString } from 'class-validator';
|
||||||
import { IsDate } from 'class-validator';
|
import { IsDate } from 'class-validator';
|
||||||
import { IsNumber } from 'class-validator';
|
import { IsNumber } from 'class-validator';
|
||||||
|
|
||||||
@@ -10,8 +11,13 @@ export class CreditNoteRefundDto {
|
|||||||
description: 'The id of the from account',
|
description: 'The id of the from account',
|
||||||
example: 1,
|
example: 1,
|
||||||
})
|
})
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The id of the from account',
|
||||||
|
example: 1,
|
||||||
|
})
|
||||||
fromAccountId: number;
|
fromAccountId: number;
|
||||||
|
|
||||||
|
@ToNumber()
|
||||||
@IsNumber()
|
@IsNumber()
|
||||||
@IsPositive()
|
@IsPositive()
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
@@ -21,6 +27,7 @@ export class CreditNoteRefundDto {
|
|||||||
})
|
})
|
||||||
amount: number;
|
amount: number;
|
||||||
|
|
||||||
|
@ToNumber()
|
||||||
@IsNumber()
|
@IsNumber()
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsPositive()
|
@IsPositive()
|
||||||
@@ -30,23 +37,23 @@ export class CreditNoteRefundDto {
|
|||||||
})
|
})
|
||||||
exchangeRate?: number;
|
exchangeRate?: number;
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
@IsString()
|
@IsString()
|
||||||
@IsNotEmpty()
|
|
||||||
@ApiProperty({
|
@ApiProperty({
|
||||||
description: 'The reference number of the credit note refund',
|
description: 'The reference number of the credit note refund',
|
||||||
example: '123456',
|
example: '123456',
|
||||||
})
|
})
|
||||||
referenceNo: string;
|
referenceNo: string;
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
@IsString()
|
@IsString()
|
||||||
@IsNotEmpty()
|
|
||||||
@ApiProperty({
|
@ApiProperty({
|
||||||
description: 'The description of the credit note refund',
|
description: 'The description of the credit note refund',
|
||||||
example: 'Credit note refund',
|
example: 'Credit note refund',
|
||||||
})
|
})
|
||||||
description: string;
|
description: string;
|
||||||
|
|
||||||
@IsDate()
|
@IsDateString()
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
@ApiProperty({
|
@ApiProperty({
|
||||||
description: 'The date of the credit note refund',
|
description: 'The date of the credit note refund',
|
||||||
@@ -54,6 +61,7 @@ export class CreditNoteRefundDto {
|
|||||||
})
|
})
|
||||||
date: Date;
|
date: Date;
|
||||||
|
|
||||||
|
@ToNumber()
|
||||||
@IsNumber()
|
@IsNumber()
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@ApiProperty({
|
@ApiProperty({
|
||||||
|
|||||||
@@ -2,19 +2,35 @@ import { Injectable } from '@nestjs/common';
|
|||||||
import { DeleteRefundVendorCreditService } from './commands/DeleteRefundVendorCredit.service';
|
import { DeleteRefundVendorCreditService } from './commands/DeleteRefundVendorCredit.service';
|
||||||
import { RefundVendorCredit } from './models/RefundVendorCredit';
|
import { RefundVendorCredit } from './models/RefundVendorCredit';
|
||||||
import { CreateRefundVendorCredit } from './commands/CreateRefundVendorCredit.service';
|
import { CreateRefundVendorCredit } from './commands/CreateRefundVendorCredit.service';
|
||||||
import { IRefundVendorCreditDTO } from './types/VendorCreditRefund.types';
|
|
||||||
import { RefundVendorCreditDto } from './dtos/RefundVendorCredit.dto';
|
import { RefundVendorCreditDto } from './dtos/RefundVendorCredit.dto';
|
||||||
|
import { GetRefundVendorCreditsService } from './queries/GetRefundVendorCredits.service';
|
||||||
|
import { IRefundVendorCreditPOJO } from './types/VendorCreditRefund.types';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class VendorCreditsRefundApplication {
|
export class VendorCreditsRefundApplication {
|
||||||
/**
|
/**
|
||||||
* @param {CreateRefundVendorCredit} createRefundVendorCreditService
|
* @param {CreateRefundVendorCredit} createRefundVendorCreditService
|
||||||
* @param {DeleteRefundVendorCreditService} deleteRefundVendorCreditService
|
* @param {DeleteRefundVendorCreditService} deleteRefundVendorCreditService
|
||||||
|
* @param {GetRefundVendorCreditsService} getRefundVendorCreditsService
|
||||||
*/
|
*/
|
||||||
constructor(
|
constructor(
|
||||||
private readonly createRefundVendorCreditService: CreateRefundVendorCredit,
|
private readonly createRefundVendorCreditService: CreateRefundVendorCredit,
|
||||||
private readonly deleteRefundVendorCreditService: DeleteRefundVendorCreditService,
|
private readonly deleteRefundVendorCreditService: DeleteRefundVendorCreditService,
|
||||||
) {}
|
private readonly getRefundVendorCreditsService: GetRefundVendorCreditsService,
|
||||||
|
) { }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the vendor credit refunds graph.
|
||||||
|
* @param {number} vendorCreditId - Vendor credit id.
|
||||||
|
* @returns {Promise<IRefundVendorCreditPOJO[]>}
|
||||||
|
*/
|
||||||
|
public getVendorCreditRefunds(
|
||||||
|
vendorCreditId: number,
|
||||||
|
): Promise<IRefundVendorCreditPOJO[]> {
|
||||||
|
return this.getRefundVendorCreditsService.getVendorCreditRefunds(
|
||||||
|
vendorCreditId,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a refund vendor credit.
|
* Creates a refund vendor credit.
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Body, Controller, Delete, Param, Post } from '@nestjs/common';
|
import { Body, Controller, Delete, Get, Param, Post } from '@nestjs/common';
|
||||||
import { VendorCreditsRefundApplication } from './VendorCreditsRefund.application';
|
import { VendorCreditsRefundApplication } from './VendorCreditsRefund.application';
|
||||||
import { RefundVendorCredit } from './models/RefundVendorCredit';
|
import { RefundVendorCredit } from './models/RefundVendorCredit';
|
||||||
import { ApiOperation, ApiTags } from '@nestjs/swagger';
|
import { ApiOperation, ApiTags } from '@nestjs/swagger';
|
||||||
@@ -9,7 +9,22 @@ import { RefundVendorCreditDto } from './dtos/RefundVendorCredit.dto';
|
|||||||
export class VendorCreditsRefundController {
|
export class VendorCreditsRefundController {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly vendorCreditsRefundApplication: VendorCreditsRefundApplication,
|
private readonly vendorCreditsRefundApplication: VendorCreditsRefundApplication,
|
||||||
) {}
|
) { }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the vendor credit refunds graph.
|
||||||
|
* @param {number} vendorCreditId - Vendor credit id.
|
||||||
|
* @returns {Promise<IRefundVendorCreditPOJO[]>}
|
||||||
|
*/
|
||||||
|
@Get(':vendorCreditId/refund')
|
||||||
|
@ApiOperation({ summary: 'Retrieve the vendor credit refunds graph.' })
|
||||||
|
public getVendorCreditRefunds(
|
||||||
|
@Param('vendorCreditId') vendorCreditId: string,
|
||||||
|
) {
|
||||||
|
return this.vendorCreditsRefundApplication.getVendorCreditRefunds(
|
||||||
|
Number(vendorCreditId),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a refund vendor credit.
|
* Creates a refund vendor credit.
|
||||||
@@ -17,7 +32,7 @@ export class VendorCreditsRefundController {
|
|||||||
* @param {IRefundVendorCreditDTO} refundVendorCreditDTO
|
* @param {IRefundVendorCreditDTO} refundVendorCreditDTO
|
||||||
* @returns {Promise<RefundVendorCredit>}
|
* @returns {Promise<RefundVendorCredit>}
|
||||||
*/
|
*/
|
||||||
@Post(':vendorCreditId/refunds')
|
@Post(':vendorCreditId/refund')
|
||||||
@ApiOperation({ summary: 'Create a refund for the given vendor credit.' })
|
@ApiOperation({ summary: 'Create a refund for the given vendor credit.' })
|
||||||
public async createRefundVendorCredit(
|
public async createRefundVendorCredit(
|
||||||
@Param('vendorCreditId') vendorCreditId: string,
|
@Param('vendorCreditId') vendorCreditId: string,
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
|
import { IsOptional, ToNumber } from '@/common/decorators/Validators';
|
||||||
import { ApiProperty } from '@nestjs/swagger';
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
import { Min } from 'class-validator';
|
import { IsDateString, Min } from 'class-validator';
|
||||||
import { IsString } from 'class-validator';
|
import { IsString } from 'class-validator';
|
||||||
import { IsDate } from 'class-validator';
|
import { IsDate } from 'class-validator';
|
||||||
import { IsNotEmpty, IsNumber, IsOptional, IsPositive } from 'class-validator';
|
import { IsNotEmpty, IsNumber, IsPositive } from 'class-validator';
|
||||||
|
|
||||||
export class RefundVendorCreditDto {
|
export class RefundVendorCreditDto {
|
||||||
|
@ToNumber()
|
||||||
@IsNumber()
|
@IsNumber()
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
@Min(0)
|
@Min(0)
|
||||||
@@ -32,6 +34,7 @@ export class RefundVendorCreditDto {
|
|||||||
})
|
})
|
||||||
depositAccountId: number;
|
depositAccountId: number;
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
@IsString()
|
@IsString()
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
@ApiProperty({
|
@ApiProperty({
|
||||||
@@ -40,7 +43,7 @@ export class RefundVendorCreditDto {
|
|||||||
})
|
})
|
||||||
description: string;
|
description: string;
|
||||||
|
|
||||||
@IsDate()
|
@IsDateString()
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
@ApiProperty({
|
@ApiProperty({
|
||||||
description: 'The date of the refund',
|
description: 'The date of the refund',
|
||||||
|
|||||||
@@ -31,6 +31,9 @@ import {
|
|||||||
FeatureCan,
|
FeatureCan,
|
||||||
FInputGroup,
|
FInputGroup,
|
||||||
FMoneyInputGroup,
|
FMoneyInputGroup,
|
||||||
|
FDateInput,
|
||||||
|
FFormGroup,
|
||||||
|
FTextArea,
|
||||||
} from '@/components';
|
} from '@/components';
|
||||||
import {
|
import {
|
||||||
inputIntent,
|
inputIntent,
|
||||||
@@ -66,16 +69,13 @@ function RefundCreditNoteFormFields({
|
|||||||
<FeatureCan feature={Features.Branches}>
|
<FeatureCan feature={Features.Branches}>
|
||||||
<Row>
|
<Row>
|
||||||
<Col xs={5}>
|
<Col xs={5}>
|
||||||
<FormGroup
|
<FFormGroup name={'branch_id'} label={<T id={'branch'} />}>
|
||||||
label={<T id={'branch'} />}
|
|
||||||
className={classNames('form-group--select-list', Classes.FILL)}
|
|
||||||
>
|
|
||||||
<BranchSelect
|
<BranchSelect
|
||||||
name={'branch_id'}
|
name={'branch_id'}
|
||||||
branches={branches}
|
branches={branches}
|
||||||
popoverProps={{ minimal: true }}
|
popoverProps={{ minimal: true }}
|
||||||
/>
|
/>
|
||||||
</FormGroup>
|
</FFormGroup>
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
<BranchRowDivider />
|
<BranchRowDivider />
|
||||||
@@ -84,29 +84,23 @@ function RefundCreditNoteFormFields({
|
|||||||
<Row>
|
<Row>
|
||||||
<Col xs={5}>
|
<Col xs={5}>
|
||||||
{/* ------------- Refund date ------------- */}
|
{/* ------------- Refund date ------------- */}
|
||||||
<FastField name={'date'}>
|
|
||||||
{({ form, field: { value }, meta: { error, touched } }) => (
|
|
||||||
<FFormGroup
|
<FFormGroup
|
||||||
name={'date'}
|
name={'date'}
|
||||||
label={<T id={'refund_credit_note.dialog.refund_date'} />}
|
label={<T id={'refund_credit_note.dialog.refund_date'} />}
|
||||||
labelInfo={<FieldRequiredHint />}
|
labelInfo={<FieldRequiredHint />}
|
||||||
fill
|
fill
|
||||||
>
|
>
|
||||||
<DateInput
|
<FDateInput
|
||||||
|
name={'date'}
|
||||||
{...momentFormatter('YYYY/MM/DD')}
|
{...momentFormatter('YYYY/MM/DD')}
|
||||||
value={tansformDateValue(value)}
|
|
||||||
onChange={handleDateChange((formattedDate) => {
|
|
||||||
form.setFieldValue('date', formattedDate);
|
|
||||||
})}
|
|
||||||
popoverProps={{ position: Position.BOTTOM, minimal: true }}
|
popoverProps={{ position: Position.BOTTOM, minimal: true }}
|
||||||
inputProps={{
|
inputProps={{
|
||||||
leftIcon: <Icon icon={'date-range'} />,
|
leftIcon: <Icon icon={'date-range'} />,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</FFormGroup>
|
</FFormGroup>
|
||||||
)}
|
|
||||||
</FastField>
|
|
||||||
</Col>
|
</Col>
|
||||||
|
|
||||||
<Col xs={5}>
|
<Col xs={5}>
|
||||||
{/* ------------ Form account ------------ */}
|
{/* ------------ Form account ------------ */}
|
||||||
<FFormGroup
|
<FFormGroup
|
||||||
@@ -114,6 +108,7 @@ function RefundCreditNoteFormFields({
|
|||||||
label={<T id={'refund_credit_note.dialog.from_account'} />}
|
label={<T id={'refund_credit_note.dialog.from_account'} />}
|
||||||
labelInfo={<FieldRequiredHint />}
|
labelInfo={<FieldRequiredHint />}
|
||||||
fill
|
fill
|
||||||
|
fastField
|
||||||
>
|
>
|
||||||
<FAccountsSuggestField
|
<FAccountsSuggestField
|
||||||
name={'from_account_id'}
|
name={'from_account_id'}
|
||||||
@@ -126,6 +121,7 @@ function RefundCreditNoteFormFields({
|
|||||||
ACCOUNT_TYPE.CASH,
|
ACCOUNT_TYPE.CASH,
|
||||||
ACCOUNT_TYPE.FIXED_ASSET,
|
ACCOUNT_TYPE.FIXED_ASSET,
|
||||||
]}
|
]}
|
||||||
|
fastField
|
||||||
/>
|
/>
|
||||||
</FFormGroup>
|
</FFormGroup>
|
||||||
</Col>
|
</Col>
|
||||||
@@ -137,6 +133,7 @@ function RefundCreditNoteFormFields({
|
|||||||
label={<T id={'refund_credit_note.dialog.amount'} />}
|
label={<T id={'refund_credit_note.dialog.amount'} />}
|
||||||
labelInfo={<FieldRequiredHint />}
|
labelInfo={<FieldRequiredHint />}
|
||||||
fill
|
fill
|
||||||
|
fastField
|
||||||
>
|
>
|
||||||
<ControlGroup>
|
<ControlGroup>
|
||||||
<InputPrependText text={values.currency_code} />
|
<InputPrependText text={values.currency_code} />
|
||||||
@@ -144,6 +141,7 @@ function RefundCreditNoteFormFields({
|
|||||||
name={'amount'}
|
name={'amount'}
|
||||||
minimal={true}
|
minimal={true}
|
||||||
inputRef={(ref) => (amountFieldRef.current = ref)}
|
inputRef={(ref) => (amountFieldRef.current = ref)}
|
||||||
|
|
||||||
/>
|
/>
|
||||||
</ControlGroup>
|
</ControlGroup>
|
||||||
</FFormGroup>
|
</FFormGroup>
|
||||||
@@ -161,21 +159,19 @@ function RefundCreditNoteFormFields({
|
|||||||
</If>
|
</If>
|
||||||
|
|
||||||
{/* ------------ Reference No. ------------ */}
|
{/* ------------ Reference No. ------------ */}
|
||||||
<FFormGroup name={'reference_no'} label={<T id={'reference_no'} />} fill>
|
<FFormGroup name={'reference_no'} label={<T id={'reference_no'} />} fill fastField>
|
||||||
<FInputGroup name={'reference_no'} minimal fill />
|
<FInputGroup name={'reference_no'} minimal fill />
|
||||||
</FFormGroup>
|
</FFormGroup>
|
||||||
|
|
||||||
{/* --------- Statement --------- */}
|
{/* --------- Statement --------- */}
|
||||||
<FastField name={'description'}>
|
<FFormGroup
|
||||||
{({ form, field, meta: { error, touched } }) => (
|
name={'description'}
|
||||||
<FormGroup
|
|
||||||
label={<T id={'refund_credit_note.dialog.description'} />}
|
label={<T id={'refund_credit_note.dialog.description'} />}
|
||||||
className={'form-group--description'}
|
fill
|
||||||
|
fastField
|
||||||
>
|
>
|
||||||
<TextArea growVertically={true} {...field} />
|
<FTextArea name={'description'} growVertically fill fastField />
|
||||||
</FormGroup>
|
</FFormGroup>
|
||||||
)}
|
|
||||||
</FastField>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -183,7 +179,12 @@ function RefundCreditNoteFormFields({
|
|||||||
export default compose(withCurrentOrganization())(RefundCreditNoteFormFields);
|
export default compose(withCurrentOrganization())(RefundCreditNoteFormFields);
|
||||||
|
|
||||||
export const BranchRowDivider = styled.div`
|
export const BranchRowDivider = styled.div`
|
||||||
|
--x-divider-color: #ebf1f6;
|
||||||
|
|
||||||
|
.bp4-dark & {
|
||||||
|
--x-divider-color: rgba(255, 255, 255, 0.1);
|
||||||
|
}
|
||||||
height: 1px;
|
height: 1px;
|
||||||
background: #ebf1f6;
|
background: var(--x-divider-color);
|
||||||
margin-bottom: 13px;
|
margin-bottom: 13px;
|
||||||
`;
|
`;
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ import {
|
|||||||
FormattedMessage as T,
|
FormattedMessage as T,
|
||||||
ExchangeRateMutedField,
|
ExchangeRateMutedField,
|
||||||
BranchSelect,
|
BranchSelect,
|
||||||
BranchSelectButton,
|
|
||||||
FeatureCan,
|
FeatureCan,
|
||||||
FFormGroup,
|
FFormGroup,
|
||||||
FDateInput,
|
FDateInput,
|
||||||
@@ -57,7 +56,6 @@ function RefundVendorCreditFormFields({
|
|||||||
<BranchSelect
|
<BranchSelect
|
||||||
name={'branch_id'}
|
name={'branch_id'}
|
||||||
branches={branches}
|
branches={branches}
|
||||||
input={BranchSelectButton}
|
|
||||||
popoverProps={{ minimal: true }}
|
popoverProps={{ minimal: true }}
|
||||||
/>
|
/>
|
||||||
</FFormGroup>
|
</FFormGroup>
|
||||||
@@ -154,8 +152,8 @@ function RefundVendorCreditFormFields({
|
|||||||
</FFormGroup>
|
</FFormGroup>
|
||||||
|
|
||||||
{/* --------- Statement --------- */}
|
{/* --------- Statement --------- */}
|
||||||
<FFormGroup name={'description'} fill fastField>
|
<FFormGroup name={'description'} label={<T id={'refund_vendor_credit.dialog.description'} />} fill fastField>
|
||||||
<FTextArea name={'description'} growVertically={true} fastField />
|
<FTextArea name={'description'} growVertically fill fastField />
|
||||||
</FFormGroup>
|
</FFormGroup>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
@@ -164,7 +162,12 @@ function RefundVendorCreditFormFields({
|
|||||||
export default compose(withCurrentOrganization())(RefundVendorCreditFormFields);
|
export default compose(withCurrentOrganization())(RefundVendorCreditFormFields);
|
||||||
|
|
||||||
export const BranchRowDivider = styled.div`
|
export const BranchRowDivider = styled.div`
|
||||||
|
--x-divider-color: #ebf1f6;
|
||||||
|
|
||||||
|
.bp4-dark & {
|
||||||
|
--x-divider-color: rgba(255, 255, 255, 0.1);
|
||||||
|
}
|
||||||
height: 1px;
|
height: 1px;
|
||||||
background: #ebf1f6;
|
background: var(--x-divider-color);
|
||||||
margin-bottom: 13px;
|
margin-bottom: 13px;
|
||||||
`;
|
`;
|
||||||
|
|||||||
Reference in New Issue
Block a user