mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 14:50:32 +00:00
feat: wip upload attachmentsx
This commit is contained in:
@@ -27,23 +27,23 @@ export class AttachmentsOnVendorCredits {
|
|||||||
*/
|
*/
|
||||||
public attach(bus) {
|
public attach(bus) {
|
||||||
bus.subscribe(
|
bus.subscribe(
|
||||||
events.saleInvoice.onCreating,
|
events.vendorCredit.onCreating,
|
||||||
this.validateAttachmentsOnVendorCreditCreate.bind(this)
|
this.validateAttachmentsOnVendorCreditCreate.bind(this)
|
||||||
);
|
);
|
||||||
bus.subscribe(
|
bus.subscribe(
|
||||||
events.saleInvoice.onCreated,
|
events.vendorCredit.onCreated,
|
||||||
this.handleAttachmentsOnVendorCreditCreated.bind(this)
|
this.handleAttachmentsOnVendorCreditCreated.bind(this)
|
||||||
);
|
);
|
||||||
bus.subscribe(
|
bus.subscribe(
|
||||||
events.saleInvoice.onEdited,
|
events.vendorCredit.onEdited,
|
||||||
this.handleUnlinkUnpresentedKeysOnVendorCreditEdited.bind(this)
|
this.handleUnlinkUnpresentedKeysOnVendorCreditEdited.bind(this)
|
||||||
);
|
);
|
||||||
bus.subscribe(
|
bus.subscribe(
|
||||||
events.saleInvoice.onEdited,
|
events.vendorCredit.onEdited,
|
||||||
this.handleLinkPresentedKeysOnVendorCreditEdited.bind(this)
|
this.handleLinkPresentedKeysOnVendorCreditEdited.bind(this)
|
||||||
);
|
);
|
||||||
bus.subscribe(
|
bus.subscribe(
|
||||||
events.saleInvoice.onDeleting,
|
events.vendorCredit.onDeleting,
|
||||||
this.handleUnlinkAttachmentsOnVendorCreditDeleted.bind(this)
|
this.handleUnlinkAttachmentsOnVendorCreditDeleted.bind(this)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,8 @@ export default class GetCreditNote extends BaseCreditNotes {
|
|||||||
.findById(creditNoteId)
|
.findById(creditNoteId)
|
||||||
.withGraphFetched('entries.item')
|
.withGraphFetched('entries.item')
|
||||||
.withGraphFetched('customer')
|
.withGraphFetched('customer')
|
||||||
.withGraphFetched('branch');
|
.withGraphFetched('branch')
|
||||||
|
.withGraphFetched('attachments');
|
||||||
|
|
||||||
if (!creditNote) {
|
if (!creditNote) {
|
||||||
throw new ServiceError(ERRORS.CREDIT_NOTE_NOT_FOUND);
|
throw new ServiceError(ERRORS.CREDIT_NOTE_NOT_FOUND);
|
||||||
|
|||||||
@@ -25,7 +25,8 @@ export default class BillPaymentsPages {
|
|||||||
const { BillPayment, Bill } = this.tenancy.models(tenantId);
|
const { BillPayment, Bill } = this.tenancy.models(tenantId);
|
||||||
const billPayment = await BillPayment.query()
|
const billPayment = await BillPayment.query()
|
||||||
.findById(billPaymentId)
|
.findById(billPaymentId)
|
||||||
.withGraphFetched('entries.bill');
|
.withGraphFetched('entries.bill')
|
||||||
|
.withGraphFetched('attachments');
|
||||||
|
|
||||||
// Throw not found the bill payment.
|
// Throw not found the bill payment.
|
||||||
if (!billPayment) {
|
if (!billPayment) {
|
||||||
|
|||||||
@@ -112,7 +112,6 @@ export class CreateBillPayment {
|
|||||||
const billPayment = await BillPayment.query(trx).insertGraphAndFetch({
|
const billPayment = await BillPayment.query(trx).insertGraphAndFetch({
|
||||||
...billPaymentObj,
|
...billPaymentObj,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Triggers `onBillPaymentCreated` event.
|
// Triggers `onBillPaymentCreated` event.
|
||||||
await this.eventPublisher.emitAsync(events.billPayment.onCreated, {
|
await this.eventPublisher.emitAsync(events.billPayment.onCreated, {
|
||||||
tenantId,
|
tenantId,
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ export class PaymentReceiveDTOTransformer {
|
|||||||
this.validators.validatePaymentNoRequire(paymentReceiveNo);
|
this.validators.validatePaymentNoRequire(paymentReceiveNo);
|
||||||
|
|
||||||
const initialDTO = {
|
const initialDTO = {
|
||||||
...formatDateFields(omit(paymentReceiveDTO, ['entries']), [
|
...formatDateFields(omit(paymentReceiveDTO, ['entries', 'attachments']), [
|
||||||
'paymentDate',
|
'paymentDate',
|
||||||
]),
|
]),
|
||||||
amount: paymentAmount,
|
amount: paymentAmount,
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ export default class PaymentReceivesPages {
|
|||||||
*/
|
*/
|
||||||
public async getPaymentReceiveEditPage(
|
public async getPaymentReceiveEditPage(
|
||||||
tenantId: number,
|
tenantId: number,
|
||||||
paymentReceiveId: number,
|
paymentReceiveId: number
|
||||||
): Promise<{
|
): Promise<{
|
||||||
paymentReceive: Omit<IPaymentReceive, 'entries'>;
|
paymentReceive: Omit<IPaymentReceive, 'entries'>;
|
||||||
entries: IPaymentReceivePageEntry[];
|
entries: IPaymentReceivePageEntry[];
|
||||||
@@ -76,7 +76,8 @@ export default class PaymentReceivesPages {
|
|||||||
// Retrieve payment receive.
|
// Retrieve payment receive.
|
||||||
const paymentReceive = await PaymentReceive.query()
|
const paymentReceive = await PaymentReceive.query()
|
||||||
.findById(paymentReceiveId)
|
.findById(paymentReceiveId)
|
||||||
.withGraphFetched('entries.invoice');
|
.withGraphFetched('entries.invoice')
|
||||||
|
.withGraphFetched('attachments');
|
||||||
|
|
||||||
// Throw not found the payment receive.
|
// Throw not found the payment receive.
|
||||||
if (!paymentReceive) {
|
if (!paymentReceive) {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import intl from 'react-intl-universal';
|
|||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import * as R from 'ramda';
|
import * as R from 'ramda';
|
||||||
import { Intent } from '@blueprintjs/core';
|
import { Intent } from '@blueprintjs/core';
|
||||||
import { omit, first, sumBy, round } from 'lodash';
|
import { omit, first, sumBy } from 'lodash';
|
||||||
import {
|
import {
|
||||||
compose,
|
compose,
|
||||||
transformToForm,
|
transformToForm,
|
||||||
@@ -27,6 +27,10 @@ import {
|
|||||||
ensureEntriesHaveEmptyLine,
|
ensureEntriesHaveEmptyLine,
|
||||||
} from '@/containers/Entries/utils';
|
} from '@/containers/Entries/utils';
|
||||||
import { TaxType } from '@/interfaces/TaxRates';
|
import { TaxType } from '@/interfaces/TaxRates';
|
||||||
|
import {
|
||||||
|
transformAttachmentsToForm,
|
||||||
|
transformAttachmentsToRequest,
|
||||||
|
} from '@/containers/Attachments/utils';
|
||||||
|
|
||||||
export const MIN_LINES_NUMBER = 1;
|
export const MIN_LINES_NUMBER = 1;
|
||||||
|
|
||||||
@@ -63,6 +67,7 @@ export const defaultInvoice = {
|
|||||||
warehouse_id: '',
|
warehouse_id: '',
|
||||||
project_id: '',
|
project_id: '',
|
||||||
entries: [...repeatValue(defaultInvoiceEntry, MIN_LINES_NUMBER)],
|
entries: [...repeatValue(defaultInvoiceEntry, MIN_LINES_NUMBER)],
|
||||||
|
attachments: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -89,6 +94,7 @@ export function transformToEditForm(invoice) {
|
|||||||
? TaxType.Inclusive
|
? TaxType.Inclusive
|
||||||
: TaxType.Exclusive,
|
: TaxType.Exclusive,
|
||||||
entries,
|
entries,
|
||||||
|
attachments: transformAttachmentsToForm(invoice),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -192,6 +198,7 @@ export function transformValueToRequest(values) {
|
|||||||
...omit(entry, ['amount', 'tax_amount', 'tax_rate']),
|
...omit(entry, ['amount', 'tax_amount', 'tax_rate']),
|
||||||
})),
|
})),
|
||||||
delivered: false,
|
delivered: false,
|
||||||
|
attachments: transformAttachmentsToRequest(values),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -408,3 +415,15 @@ export const useIsInvoiceTaxExclusive = () => {
|
|||||||
|
|
||||||
return values.inclusive_exclusive_tax === TaxType.Exclusive;
|
return values.inclusive_exclusive_tax === TaxType.Exclusive;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export function formatBytes(bytes, decimals = 2) {
|
||||||
|
if (bytes === 0) return '0 Bytes';
|
||||||
|
|
||||||
|
const k = 1024;
|
||||||
|
const dm = decimals < 0 ? 0 : decimals;
|
||||||
|
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
||||||
|
|
||||||
|
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
||||||
|
|
||||||
|
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user