Merge branch 'develop' into big-44-auto-re-calculate-the-items-rate-once-changing-the-invoice

This commit is contained in:
Ahmed Bouhuolia
2024-01-11 20:27:42 +02:00
403 changed files with 24846 additions and 9622 deletions

View File

@@ -239,3 +239,33 @@ export function useEstimateSMSDetail(estimateId, props, requestProps) {
},
);
}
export function useSendSaleEstimateMail(props) {
const queryClient = useQueryClient();
const apiRequest = useApiRequest();
return useMutation(
([id, values]) => apiRequest.post(`sales/estimates/${id}/mail`, values),
{
onSuccess: (res, [id, values]) => {
// Common invalidate queries.
commonInvalidateQueries(queryClient);
},
...props,
},
);
}
export function useSaleEstimateDefaultOptions(estimateId, props) {
return useRequestQuery(
[t.SALE_ESTIMATE_MAIL_OPTIONS, estimateId],
{
method: 'get',
url: `sales/estimates/${estimateId}/mail`,
},
{
select: (res) => res.data.data,
...props,
},
);
}

View File

@@ -1,16 +1,12 @@
// @ts-nocheck
import { useRequestQuery } from '../useQueryRequest';
import {
trialBalanceSheetReducer,
generalLedgerTableRowsReducer,
journalTableRowsReducer,
ARAgingSummaryTableRowsMapper,
APAgingSummaryTableRowsMapper,
inventoryValuationReducer,
purchasesByItemsReducer,
salesByItemsReducer,
} from '@/containers/FinancialStatements/reducers';
import t from './types';
import { useDownloadFile } from '../useDownloadFile';
/**
* Retrieve balance sheet.
@@ -33,6 +29,34 @@ export function useBalanceSheet(query, props) {
);
}
export const useBalanceSheetXlsxExport = (query, args) => {
return useDownloadFile({
url: '/financial_statements/balance_sheet',
config: {
headers: {
accept: 'application/xlsx',
},
params: query,
},
filename: 'balance_sheet.xlsx',
...args,
});
};
export const useBalanceSheetCsvExport = (query, args) => {
return useDownloadFile({
url: '/financial_statements/balance_sheet',
config: {
headers: {
accept: 'application/csv',
},
params: query,
},
filename: 'balance_sheet.csv',
...args,
});
};
/**
* Retrieve trial balance sheet.
*/
@@ -43,22 +67,45 @@ export function useTrialBalanceSheet(query, props) {
method: 'get',
url: '/financial_statements/trial_balance_sheet',
params: query,
headers: {
Accept: 'application/json+table',
},
},
{
select: (res) => ({
tableRows: trialBalanceSheetReducer(res.data.data),
...res.data,
}),
defaultData: {
tableRows: [],
data: [],
query: {},
},
select: (res) => res.data,
...props,
},
);
}
export const useTrialBalanceSheetXlsxExport = (query, args) => {
return useDownloadFile({
url: '/financial_statements/trial_balance_sheet',
config: {
headers: {
accept: 'application/xlsx',
},
params: query,
},
filename: 'trial_balance_sheet.xlsx',
...args,
});
};
export const useTrialBalanceSheetCsvExport = (query, args) => {
return useDownloadFile({
url: '/financial_statements/trial_balance_sheet',
config: {
headers: {
accept: 'application/csv',
},
params: query,
},
filename: 'trial_balance_sheet.csv',
...args,
});
};
/**
* Retrieve profit/loss (P&L) sheet.
*/
@@ -80,6 +127,34 @@ export function useProfitLossSheet(query, props) {
);
}
export const useProfitLossSheetXlsxExport = (query, args) => {
return useDownloadFile({
url: '/financial_statements/profit_loss_sheet',
config: {
headers: {
accept: 'application/xlsx',
},
params: query,
},
filename: 'profit_loss_sheet.xlsx',
...args,
});
};
export const useProfitLossSheetCsvExport = (query, args) => {
return useDownloadFile({
url: '/financial_statements/profit_loss_sheet',
config: {
headers: {
accept: 'application/csv',
},
params: query,
},
filename: 'profit_loss_sheet.csv',
...args,
});
};
/**
* Retrieve general ledger (GL) sheet.
*/
@@ -90,21 +165,44 @@ export function useGeneralLedgerSheet(query, props) {
method: 'get',
url: '/financial_statements/general_ledger',
params: query,
headers: {
Accept: 'application/json+table',
},
},
{
select: (res) => ({
tableRows: generalLedgerTableRowsReducer(res.data.data),
...res.data,
}),
defaultData: {
tableRows: [],
data: {},
query: {},
},
select: (res) => res.data,
...props,
},
);
}
export const useGeneralLedgerSheetXlsxExport = (query, args) => {
return useDownloadFile({
url: '/financial_statements/general_ledger',
config: {
headers: {
accept: 'application/xlsx',
},
params: query,
},
filename: 'general_ledger.xlsx',
...args,
});
};
export const useGeneralLedgerSheetCsvExport = (query, args) => {
return useDownloadFile({
url: '/financial_statements/general_ledger',
config: {
headers: {
accept: 'application/csv',
},
params: query,
},
filename: 'general_ledger.csv',
...args,
});
};
/**
* Retrieve journal sheet.
@@ -112,22 +210,49 @@ export function useGeneralLedgerSheet(query, props) {
export function useJournalSheet(query, props) {
return useRequestQuery(
[t.FINANCIAL_REPORT, t.JOURNAL, query],
{ method: 'get', url: '/financial_statements/journal', params: query },
{
select: (res) => ({
tableRows: journalTableRowsReducer(res.data.data),
...res.data,
}),
defaultData: {
data: {},
tableRows: [],
query: {},
method: 'get',
url: '/financial_statements/journal',
params: query,
headers: {
Accept: 'application/json+table',
},
},
{
select: (res) => res.data,
...props,
},
);
}
export const useJournalSheetXlsxExport = (query, args) => {
return useDownloadFile({
url: '/financial_statements/journal',
config: {
headers: {
accept: 'application/xlsx',
},
params: query,
},
filename: 'journal.xlsx',
...args,
});
};
export const useJournalSheetCsvExport = (query, args) => {
return useDownloadFile({
url: '/financial_statements/journal',
config: {
headers: {
accept: 'application/csv',
},
params: query,
},
filename: 'journal.csv',
...args,
});
};
/**
* Retrieve A/R aging summary report.
*/
@@ -149,6 +274,34 @@ export function useARAgingSummaryReport(query, props) {
);
}
export const useARAgingSheetXlsxExport = (query, args) => {
return useDownloadFile({
url: '/financial_statements/receivable_aging_summary',
config: {
headers: {
accept: 'application/xlsx',
},
params: query,
},
filename: 'receivable_aging_summary.xlsx',
...args,
});
};
export const useARAgingSheetCsvExport = (query, args) => {
return useDownloadFile({
url: '/financial_statements/receivable_aging_summary',
config: {
headers: {
accept: 'application/csv',
},
params: query,
},
filename: 'receivable_aging_summary.csv',
...args,
});
};
/**
* Retrieve A/P aging summary report.
*/
@@ -170,6 +323,34 @@ export function useAPAgingSummaryReport(query, props) {
);
}
export const useAPAgingSheetXlsxExport = (query, args) => {
return useDownloadFile({
url: '/financial_statements/payable_aging_summary',
config: {
headers: {
accept: 'application/xlsx',
},
params: query,
},
filename: 'payable_aging_summary.xlsx',
...args,
});
};
export const useAPAgingSheetCsvExport = (query, args) => {
return useDownloadFile({
url: '/financial_statements/payable_aging_summary',
config: {
headers: {
accept: 'application/csv',
},
params: query,
},
filename: 'payable_aging_summary.csv',
...args,
});
};
/**
* Retrieve inventory valuation.
*/
@@ -275,6 +456,34 @@ export function useCustomerBalanceSummaryReport(query, props) {
);
}
export const useCustomerBalanceSummaryXlsxExport = (query, args) => {
return useDownloadFile({
url: '/financial_statements/customer-balance-summary',
config: {
headers: {
accept: 'application/xlsx',
},
params: query,
},
filename: 'customer_balance_summary.xlsx',
...args,
});
};
export const useCustomerBalanceSummaryCsvExport = (query, args) => {
return useDownloadFile({
url: '/financial_statements/customer-balance-summary',
config: {
headers: {
accept: 'application/csv',
},
params: query,
},
filename: 'customer_balance_summary.csv',
...args,
});
};
/**
* Retrieve vendors balance summary report.
*/
@@ -304,6 +513,36 @@ export function useVendorsBalanceSummaryReport(query, props) {
);
}
export const useVendorBalanceSummaryXlsxExport = (args) => {
const url = '/financial_statements/vendor-balance-summary';
const config = {
headers: {
accept: 'application/xlsx',
},
};
const filename = 'vendor_balance_summary.xlsx';
return useDownloadFile({
url,
config,
filename,
...args,
});
};
export const useVendorBalanceSummaryCsvExport = (args) => {
return useDownloadFile({
url: '/financial_statements/vendor-balance-summary',
config: {
headers: {
accept: 'application/csv',
},
},
filename: 'vendor_balance_summary.csv',
...args,
});
};
/**
* Retrieve customers transactions report.
*/
@@ -332,6 +571,38 @@ export function useCustomersTransactionsReport(query, props) {
);
}
export const useCustomersTransactionsXlsxExport = (query, args) => {
const url = '/financial_statements/transactions-by-customers';
const config = {
headers: {
accept: 'application/xlsx',
},
params: query,
};
const filename = 'customers_transactions.xlsx';
return useDownloadFile({
url,
config,
filename,
...args,
});
};
export const useCustomersTransactionsCsvExport = (query, args) => {
return useDownloadFile({
url: '/financial_statements/transactions-by-customers',
config: {
headers: {
accept: 'application/csv',
},
params: query,
},
filename: 'customers_transactions.csv',
...args,
});
};
/**
* Retrieve vendors transactions report.
*/
@@ -349,7 +620,7 @@ export function useVendorsTransactionsReport(query, props) {
{
select: (res) => ({
data: res.data.table,
tableRows: res.data.table.data,
tableRows: res.data.table.rows,
}),
defaultData: {
tableRows: [],
@@ -360,6 +631,38 @@ export function useVendorsTransactionsReport(query, props) {
);
}
export const useVendorsTransactionsXlsxExport = (query, args) => {
const url = '/financial_statements/transactions-by-vendors';
const config = {
headers: {
accept: 'application/xlsx',
},
params: query,
};
const filename = 'transactions_by_vendor.xlsx';
return useDownloadFile({
url,
config,
filename,
...args,
});
};
export const useVendorsTransactionsCsvExport = (query, args) => {
return useDownloadFile({
url: '/financial_statements/transactions-by-vendors',
config: {
headers: {
accept: 'application/csv',
},
params: query,
},
filename: 'transactions_by_vendor.csv',
...args,
});
};
/**
* Retrieve cash flow statement report.
*/
@@ -379,7 +682,7 @@ export function useCashFlowStatementReport(query, props) {
columns: res.data.table.columns,
query: res.data.query,
meta: res.data.meta,
tableRows: res.data.table.data,
tableRows: res.data.table.rows,
}),
defaultData: {
tableRows: [],
@@ -392,6 +695,42 @@ export function useCashFlowStatementReport(query, props) {
);
}
export const useCashFlowStatementXlsxExport = (query, args) => {
const url = '/financial_statements/cash-flow';
const config = {
headers: {
accept: 'application/xlsx',
},
params: query,
};
const filename = 'cashflow_statement.xlsx';
return useDownloadFile({
url,
config,
filename,
...args,
});
};
export const useCashFlowStatementCsvExport = (query, args) => {
const url = '/financial_statements/cash-flow';
const config = {
headers: {
accept: 'application/csv',
},
params: query,
};
const filename = 'cashflow_statement.csv';
return useDownloadFile({
url,
config,
filename,
...args,
});
};
/**
* Retrieve inventory item detail report.
*/
@@ -411,7 +750,7 @@ export function useInventoryItemDetailsReport(query, props) {
columns: res.data.table.columns,
query: res.data.query,
meta: res.data.meta,
tableRows: res.data.table.data,
tableRows: res.data.table.rows,
}),
defaultData: {
tableRows: [],
@@ -424,6 +763,34 @@ export function useInventoryItemDetailsReport(query, props) {
);
}
export const useInventoryItemDetailsXlsxExport = (query, args) => {
return useDownloadFile({
url: '/financial_statements/inventory-item-details',
config: {
headers: {
accept: 'application/xlsx',
},
params: query,
},
filename: 'inventory_item_details.xlsx',
...args,
});
};
export const useInventoryItemDetailsCsvExport = (query, args) => {
return useDownloadFile({
url: '/financial_statements/inventory-item-details',
config: {
headers: {
accept: 'application/csv',
},
params: query,
},
filename: 'inventory_item_details.csv',
...args,
});
};
/**
* Retrieve transactions by reference report.
*/
@@ -465,3 +832,31 @@ export function useSalesTaxLiabilitySummary(query, props) {
},
);
}
export const useSalesTaxLiabilitySummaryXlsxExport = (query, args) => {
return useDownloadFile({
url: '/financial_statements/sales-tax-liability-summary',
config: {
headers: {
accept: 'application/xlsx',
},
params: query,
},
filename: 'sales_tax_liability_summary.xlsx',
...args,
});
};
export const useSalesTaxLiabilitySummaryCsvExport = (query, args) => {
return useDownloadFile({
url: '/financial_statements/sales-tax-liability-summary',
config: {
headers: {
accept: 'application/csv',
},
params: query,
},
filename: 'sales_tax_liability_summary.csv',
...args,
});
};

View File

@@ -306,3 +306,34 @@ export function useInvoicePaymentTransactions(invoiceId, props) {
},
);
}
export function useSendSaleInvoiceMail(props) {
const queryClient = useQueryClient();
const apiRequest = useApiRequest();
return useMutation(
([id, values]) => apiRequest.post(`sales/invoices/${id}/mail`, values),
{
onSuccess: (res, [id, values]) => {
// Common invalidate queries.
commonInvalidateQueries(queryClient);
},
...props,
},
);
}
export function useSaleInvoiceDefaultOptions(invoiceId, props) {
return useRequestQuery(
[t.SALE_INVOICE_DEFAULT_OPTIONS, invoiceId],
{
method: 'get',
url: `sales/invoices/${invoiceId}/mail`,
},
{
select: (res) => res.data.data,
...props,
},
);
}

View File

@@ -234,3 +234,34 @@ export function usePaymentReceiveSMSDetail(
export function usePdfPaymentReceive(paymentReceiveId) {
return useRequestPdf(`sales/payment_receives/${paymentReceiveId}`);
}
export function useSendPaymentReceiveMail(props) {
const queryClient = useQueryClient();
const apiRequest = useApiRequest();
return useMutation(
([id, values]) =>
apiRequest.post(`sales/payment_receives/${id}/mail`, values),
{
onSuccess: (res, [id, values]) => {
// Common invalidate queries.
commonInvalidateQueries(queryClient);
},
...props,
},
);
}
export function usePaymentReceiveDefaultOptions(paymentReceiveId, props) {
return useRequestQuery(
[t.PAYMENT_RECEIVE_MAIL_OPTIONS, paymentReceiveId],
{
method: 'get',
url: `sales/payment_receives/${paymentReceiveId}/mail`,
},
{
select: (res) => res.data.data,
...props,
},
);
}

View File

@@ -207,3 +207,36 @@ export function useReceiptSMSDetail(receiptId, props, requestProps) {
},
);
}
/**
*
*/
export function useSendSaleReceiptMail(props) {
const queryClient = useQueryClient();
const apiRequest = useApiRequest();
return useMutation(
([id, values]) => apiRequest.post(`sales/receipts/${id}/mail`, values),
{
onSuccess: () => {
// Invalidate queries.
commonInvalidateQueries(queryClient);
},
...props,
},
);
}
export function useSaleReceiptDefaultOptions(invoiceId, props) {
return useRequestQuery(
[t.SALE_RECEIPT_MAIL_OPTIONS, invoiceId],
{
method: 'get',
url: `sales/receipts/${invoiceId}/mail`,
},
{
select: (res) => res.data.data,
...props,
},
);
}

View File

@@ -69,6 +69,7 @@ const SALE_ESTIMATES = {
SALE_ESTIMATE: 'SALE_ESTIMATE',
SALE_ESTIMATE_SMS_DETAIL: 'SALE_ESTIMATE_SMS_DETAIL',
NOTIFY_SALE_ESTIMATE_BY_SMS: 'NOTIFY_SALE_ESTIMATE_BY_SMS',
SALE_ESTIMATE_MAIL_OPTIONS: 'SALE_ESTIMATE_MAIL_OPTIONS',
};
const SALE_RECEIPTS = {
@@ -76,6 +77,7 @@ const SALE_RECEIPTS = {
SALE_RECEIPT: 'SALE_RECEIPT',
SALE_RECEIPT_SMS_DETAIL: 'SALE_RECEIPT_SMS_DETAIL',
NOTIFY_SALE_RECEIPT_BY_SMS: 'NOTIFY_SALE_RECEIPT_BY_SMS',
SALE_RECEIPT_MAIL_OPTIONS: 'SALE_RECEIPT_MAIL_OPTIONS'
};
const INVENTORY_ADJUSTMENTS = {
@@ -101,6 +103,7 @@ const PAYMENT_RECEIVES = {
PAYMENT_RECEIVE_EDIT_PAGE: 'PAYMENT_RECEIVE_EDIT_PAGE',
PAYMENT_RECEIVE_SMS_DETAIL: 'PAYMENT_RECEIVE_SMS_DETAIL',
NOTIFY_PAYMENT_RECEIVE_BY_SMS: 'NOTIFY_PAYMENT_RECEIVE_BY_SMS',
PAYMENT_RECEIVE_MAIL_OPTIONS: 'PAYMENT_RECEIVE_MAIL_OPTIONS',
};
const SALE_INVOICES = {
@@ -112,6 +115,7 @@ const SALE_INVOICES = {
BAD_DEBT: 'BAD_DEBT',
CANCEL_BAD_DEBT: 'CANCEL_BAD_DEBT',
SALE_INVOICE_PAYMENT_TRANSACTIONS: 'SALE_INVOICE_PAYMENT_TRANSACTIONS',
SALE_INVOICE_DEFAULT_OPTIONS: 'SALE_INVOICE_DEFAULT_OPTIONS'
};
const USERS = {

View File

@@ -0,0 +1,72 @@
// @ts-nocheck
import axios, { AxiosError, AxiosRequestConfig } from 'axios';
import { useState } from 'react';
import { useMutation } from 'react-query';
import useApiRequest from './useRequest';
interface IArgs {
url: string;
filename: string;
mime?: string;
config?: AxiosRequestConfig;
onDownloadProgress?: (progress: number) => void;
}
export const useDownloadFile = (args: IArgs) => {
const apiRequest = useApiRequest();
const mutation = useMutation<void, AxiosError, IArgs>(() =>
apiRequest
.get(args.url, {
responseType: 'blob',
onDownloadProgress: (ev) => {
args.onDownloadProgress &&
args.onDownloadProgress(Math.round((ev.loaded * 100) / ev.total));
},
...args.config,
})
.then((res) => {
downloadFile(res.data, args.filename, args.mime);
return res;
}),
);
return { ...mutation };
};
export function downloadFile(data, filename, mime, bom) {
var blobData = typeof bom !== 'undefined' ? [bom, data] : [data];
var blob = new Blob(blobData, { type: mime || 'application/octet-stream' });
if (typeof window.navigator.msSaveBlob !== 'undefined') {
// IE workaround for "HTML7007: One or more blob URLs were
// revoked by closing the blob for which they were created.
// These URLs will no longer resolve as the data backing
// the URL has been freed."
window.navigator.msSaveBlob(blob, filename);
} else {
var blobURL =
window.URL && window.URL.createObjectURL
? window.URL.createObjectURL(blob)
: window.webkitURL.createObjectURL(blob);
var tempLink = document.createElement('a');
tempLink.style.display = 'none';
tempLink.href = blobURL;
tempLink.setAttribute('download', filename);
// Safari thinks _blank anchor are pop ups. We only want to set _blank
// target if the browser does not support the HTML5 download attribute.
// This allows you to download files in desktop safari if pop up blocking
// is enabled.
if (typeof tempLink.download === 'undefined') {
tempLink.setAttribute('target', '_blank');
}
document.body.appendChild(tempLink);
tempLink.click();
// Fixes "webkit blob resource error 1"
setTimeout(function () {
document.body.removeChild(tempLink);
window.URL.revokeObjectURL(blobURL);
}, 200);
}
}

View File

@@ -30,13 +30,13 @@ export default function useApiRequest() {
const locale = currentLocale;
if (token) {
request.headers.common['X-Access-Token'] = token;
request.headers['X-Access-Token'] = token;
}
if (organizationId) {
request.headers.common['organization-id'] = organizationId;
request.headers['organization-id'] = organizationId;
}
if (locale) {
request.headers.common['Accept-Language'] = locale;
request.headers['Accept-Language'] = locale;
}
return request;
},