1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-01 12:24:28 +01:00

enlight api for cashing checks

This commit is contained in:
Sylvain 2021-02-08 08:56:01 +01:00
parent b5cdea513d
commit 58af40b8b9
4 changed files with 20 additions and 9 deletions

View File

@ -27,12 +27,12 @@ class API::PaymentSchedulesController < API::ApiController
end
def cash_check
schedule = @payment_schedule_item.payment_schedule
authorize schedule
authorize @payment_schedule_item.payment_schedule
PaymentScheduleService.new.generate_invoice(@payment_schedule_item)
@payment_schedule_item.update_attributes(state: 'paid', payment_method: 'check')
attrs = { state: 'paid', payment_method: 'check' }
@payment_schedule_item.update_attributes(attrs)
render :show, status: :ok, location: schedule
render json: attrs, status: :ok
end
private

View File

@ -1,6 +1,10 @@
import apiClient from './api-client';
import { AxiosResponse } from 'axios';
import { PaymentSchedule, PaymentScheduleIndexRequest, PaymentScheduleItem } from '../models/payment-schedule';
import {
CashCheckResponse,
PaymentSchedule,
PaymentScheduleIndexRequest,
} from '../models/payment-schedule';
import wrapPromise, { IWrapPromise } from '../lib/wrap-promise';
export default class PaymentScheduleAPI {
@ -9,7 +13,7 @@ export default class PaymentScheduleAPI {
return res?.data;
}
async cashCheck(paymentScheduleItemId: number) {
async cashCheck(paymentScheduleItemId: number): Promise<CashCheckResponse> {
const res: AxiosResponse = await apiClient.post(`/api/payment_schedules/items/${paymentScheduleItemId}/cash_check`);
return res?.data;
}

View File

@ -158,9 +158,11 @@ const PaymentSchedulesTableComponent: React.FC<PaymentSchedulesTableProps> = ({
const onCheckCashingConfirmed = (): void => {
const api = new PaymentScheduleAPI();
api.cashCheck(tempDeadline.id).then(() => {
refreshList();
toggleConfirmCashingModal();
api.cashCheck(tempDeadline.id).then((res) => {
if (res.state === PaymentScheduleItemState.Paid) {
refreshList();
toggleConfirmCashingModal();
}
});
}

View File

@ -58,3 +58,8 @@ export interface PaymentScheduleIndexRequest {
size: number
}
}
export interface CashCheckResponse {
state: PaymentScheduleItemState,
payment_method: PaymentMethod
}