@@ -239,37 +239,11 @@ const Index = () => {
239239 id : crypto . randomUUID ( ) ,
240240 } ;
241241
242+ // Since the backend already handles chicken inventory updates when posting transactions,
243+ // we only need to fetch the updated data once after the transaction is complete
242244 if ( transaction . category === 'chicken' ) {
243- const isIncrease = transaction . type === 'expense' ;
244- const reason = isIncrease ? 'purchase' : 'sale' ;
245- const updatePromises : Promise < void > [ ] = [ ] ;
246-
247- if ( transaction . bulkQuantities ) {
248- const { hen : henCount , cock : cockCount , chicks : chicksCount } = transaction . bulkQuantities ;
249- if ( henCount > 0 ) {
250- const current = hookChickenCounts . hen ;
251- const newQty = isIncrease ? current + henCount : Math . max ( 0 , current - henCount ) ;
252- updatePromises . push ( hookUpdateChickenInventory ( 'hen' as HookChickenType , newQty , reason ) ) ;
253- }
254- if ( cockCount > 0 ) {
255- const current = hookChickenCounts . cock ;
256- const newQty = isIncrease ? current + cockCount : Math . max ( 0 , current - cockCount ) ;
257- updatePromises . push ( hookUpdateChickenInventory ( 'cock' as HookChickenType , newQty , reason ) ) ;
258- }
259- if ( chicksCount > 0 ) {
260- const current = hookChickenCounts . chicks ;
261- const newQty = isIncrease ? current + chicksCount : Math . max ( 0 , current - chicksCount ) ;
262- updatePromises . push ( hookUpdateChickenInventory ( 'chicks' as HookChickenType , newQty , reason ) ) ;
263- }
264- } else if ( transaction . chickenType && typeof transaction . quantity === 'number' ) {
265- const current = hookChickenCounts [ transaction . chickenType as HookChickenType ] ;
266- const newQty = isIncrease ? current + transaction . quantity : Math . max ( 0 , current - transaction . quantity ) ;
267- updatePromises . push ( hookUpdateChickenInventory ( transaction . chickenType as HookChickenType , newQty , reason ) ) ;
268- }
269-
270- // Wait for all chicken inventory updates to complete
271- // The updateChickenInventory function already refetches the inventory data
272- await Promise . all ( updatePromises ) ;
245+ // Fetch the updated chicken inventory data
246+ await hookFetchChickenInventory ( ) ;
273247
274248 // Only fetch history if we're on the history tab
275249 if ( activeInventoryTab === 'history' ) {
0 commit comments