Skip to content

Commit 6b2c399

Browse files
authored
Merge pull request #231 from ELVIS-SOFTWARE/ZIGGY-1003
update prorata
2 parents c80a430 + c4f5517 commit 6b2c399

5 files changed

Lines changed: 126 additions & 6 deletions

File tree

config/routes.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@
410410

411411
post "/desired_activities/:id", to: "desired_activity#update"
412412
post "/desired_activities/:id/pricing", to: "desired_activity#set_pricing"
413-
# post "/desired_activities/:id/prorata/:prorata", to: "desired_activity#set_prorata"
413+
patch "/desired_activities/:id/update_prorata", to: "desired_activity#update_prorata"
414414

415415
get "/import_users", to: "users#upload_csv"
416416
post "/import_users", to: "users#upload_csv"

frontend/components/userPayments/PaymentsManagement.jsx

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,41 @@ class PaymentsManagement extends React.Component {
701701
});
702702
}
703703

704+
handleChangeProrataForDesiredActivity(id, prorata) {
705+
let dess = {...this.state.desiredActivities};
706+
let des = _.find(dess, i => i.id == id);
707+
708+
if (des) {
709+
dess = _.filter(dess, i => i.id != des.id);
710+
des.prorata = prorata;
711+
dess = [...dess, des];
712+
713+
fetch(`/desired_activities/${id}/update_prorata`, {
714+
method: "PATCH",
715+
credentials: "same-origin",
716+
headers: {
717+
"X-CSRF-Token": csrfToken,
718+
"Content-Type": "application/json",
719+
Accept: "application/json",
720+
},
721+
body: JSON.stringify({
722+
prorata: prorata
723+
}),
724+
})
725+
.then(response => {
726+
if (response.ok) {
727+
this.setState({desiredActivities: dess});
728+
this.forceUpdate();
729+
} else {
730+
swal("Erreur", "Impossible de mettre à jour le prorata", "error");
731+
}
732+
})
733+
.catch(() => {
734+
swal("Erreur", "Une erreur est survenue lors de la mise à jour du prorata", "error");
735+
});
736+
}
737+
}
738+
704739
handleSaveNewDuePayment(duePayment) {
705740
const schedule = this.state.schedules[duePayment.payer.id];
706741

@@ -1734,7 +1769,7 @@ class PaymentsManagement extends React.Component {
17341769
adhesionPrices={this.props.adhesionPrices}
17351770
handleChangeAdhesionPricingChoice={(userId, evt) => this.handleChangeAdhesionPricingChoice(userId, evt)}
17361771
formulas={this.props.formulas}
1737-
// handleChangeProrataForDesiredActivity={(id, prorata) => this.handleChangeProrataForDesiredActivity(id, prorata)}
1772+
handleChangeProrataForDesiredActivity={(id, prorata) => this.handleChangeProrataForDesiredActivity(id, prorata)}
17381773
/>
17391774
</div>
17401775
</div>

frontend/components/userPayments/PaymentsSummary.jsx

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,11 +361,43 @@ class PaymentsSummary extends React.Component {
361361
{
362362
Header: "Prorata",
363363
id: "prorata",
364-
maxWidth: 75,
364+
maxWidth: 100,
365365
Cell: props => {
366366
if (props.original.id === 0 || props.original.isFormula) return null;
367367
const intendedNbLessons = props.original.intended_nb_lessons;
368-
return <p>{props.original.prorata || intendedNbLessons} sur {intendedNbLessons}</p>;
368+
const currentProrata = props.original.prorata || intendedNbLessons;
369+
370+
if (this.props.isStudentView) {
371+
return <p>{currentProrata} sur {intendedNbLessons}</p>;
372+
}
373+
374+
return (
375+
<div style={{ display: "flex", alignItems: "center", fontSize: "14px" }}>
376+
<input
377+
type="number"
378+
className="form-control"
379+
style={{
380+
width: "45px",
381+
height: "28px",
382+
padding: "2px 4px",
383+
fontSize: "12px",
384+
marginRight: "3px",
385+
textAlign: "center",
386+
border: "1px solid #ccc"
387+
}}
388+
value={currentProrata}
389+
min="0"
390+
max={intendedNbLessons}
391+
onChange={e => {
392+
const newProrata = parseInt(e.target.value) || 0;
393+
if (newProrata <= intendedNbLessons && this.props.handleChangeProrataForDesiredActivity) {
394+
this.props.handleChangeProrataForDesiredActivity(props.original.id, newProrata);
395+
}
396+
}}
397+
/>
398+
<span>/ {intendedNbLessons}</span>
399+
</div>
400+
);
369401
},
370402
},
371403
{

frontend/components/userPayments/v2/UserPaymentsV2.jsx

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,27 @@ export default function UserPaymentsV2({seasons, user, is_current_user, onPayCli
1616
const [duePaymentsData, setDuePaymentsData] = useState([]);
1717
const [paymentTerms, setPaymentTerms] = useState({});
1818

19+
function handleChangeProrataForDesiredActivity(id, prorata) {
20+
const updatedData = data.map(item => {
21+
if (item.id === id) {
22+
return {...item, prorata: prorata};
23+
}
24+
return item;
25+
});
26+
setData(updatedData);
27+
28+
api.set()
29+
.success(() => {
30+
})
31+
.error(() => {
32+
getDatas(); // Recharger les données en cas d'erreur
33+
swal("Erreur", "Une erreur est survenue lors de la mise à jour du prorata", "error");
34+
})
35+
.patch(`/desired_activities/${id}/update_prorata`, {
36+
prorata: prorata
37+
});
38+
}
39+
1940
function getDatas()
2041
{
2142
api.set()
@@ -89,7 +110,39 @@ export default function UserPaymentsV2({seasons, user, is_current_user, onPayCli
89110
{data.map(d => <tr key={d.id}>
90111
<td>{d.activity}</td>
91112
<td>{d.user_full_name}</td>
92-
<td>{d.prorata ? `${d.prorata} / ${d.intended_nb_lessons}` : ""}</td>
113+
<td>
114+
{d.intended_nb_lessons ? (
115+
is_current_user ? (
116+
`${d.prorata || d.intended_nb_lessons} / ${d.intended_nb_lessons}`
117+
) : (
118+
<div style={{ display: "flex", alignItems: "center", fontSize: "14px" }}>
119+
<input
120+
type="number"
121+
className="form-control"
122+
style={{
123+
width: "45px",
124+
height: "28px",
125+
padding: "2px 4px",
126+
fontSize: "12px",
127+
marginRight: "3px",
128+
textAlign: "center",
129+
border: "1px solid #ccc"
130+
}}
131+
value={d.prorata || d.intended_nb_lessons}
132+
min="0"
133+
max={d.intended_nb_lessons}
134+
onChange={e => {
135+
const newProrata = parseInt(e.target.value) || 0;
136+
if (newProrata <= d.intended_nb_lessons) {
137+
handleChangeProrataForDesiredActivity(d.id, newProrata);
138+
}
139+
}}
140+
/>
141+
<span>/ {d.intended_nb_lessons}</span>
142+
</div>
143+
)
144+
) : ""}
145+
</td>
93146
<td>{d.amount}</td>
94147
</tr>)}
95148
</tbody>

lib/elvis/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module Elvis
4-
VERSION = "2.12.5"
4+
VERSION = "2.12.6"
55
end

0 commit comments

Comments
 (0)