File size: 5,139 Bytes
4be2b2b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
// Mock data store - Replace with actual database later
import { Party, BillBook, Lot, Invoice, LedgerEntry } from '@/types';

// Bill Books
export const billBooks: BillBook[] = [
  {
    id: 'bb1',
    name: 'Bill Book 1',
    serialFrom: 1,
    serialTo: 100,
    currentSerial: 15,
    isActive: true,
  },
  {
    id: 'bb2',
    name: 'Bill Book 2',
    serialFrom: 101,
    serialTo: 200,
    currentSerial: 101,
    isActive: false,
  },
];

// Parties
export const parties: Party[] = [
  {
    id: 'p1',
    name: 'नाळकंट, फवदापूर',
    contact: '9876543210',
    balance: 49639,
    createdAt: '2024-01-01',
  },
  {
    id: 'p2',
    name: 'ABC Traders',
    contact: '9876543211',
    balance: 125000,
    createdAt: '2024-01-01',
  },
  {
    id: 'p3',
    name: 'XYZ Enterprises',
    contact: '9876543212',
    balance: -45000,
    createdAt: '2024-01-02',
  },
  {
    id: 'p4',
    name: 'दिलीप भोर',
    contact: '9876543213',
    balance: 0,
    createdAt: '2024-01-03',
  },
];

// Lots with purchase information
export const lots: Lot[] = [
  {
    id: 'lot1',
    lotNumber: 'LOT-001',
    particular: 'Teja',
    purchaseDate: '2024-11-01',
    partyId: 'p1',
    partyName: 'नाळकंट, फवदापूर',
    gaadiDetails: 'MH12AB1234',
    quality: 'A Grade',
    totalBags: 100,
    soldBags: 30,
    availableBags: 70,
    grossWeightPerBag: 40,
    netWeightPerBag: 39,
    purchaseRate: 200,
    totalWeight: 3900,
    totalAmount: 780000,
    paidAmount: 500000,
    remainingAmount: 280000,
    paymentStatus: 'partial',
  },
  {
    id: 'lot2',
    lotNumber: 'LOT-002',
    particular: 'Garuda',
    purchaseDate: '2024-11-02',
    partyId: 'p2',
    partyName: 'ABC Traders',
    quality: 'B Grade',
    totalBags: 50,
    soldBags: 20,
    availableBags: 30,
    grossWeightPerBag: 40,
    netWeightPerBag: 39,
    purchaseRate: 180,
    totalWeight: 1950,
    totalAmount: 351000,
    paidAmount: 351000,
    remainingAmount: 0,
    paymentStatus: 'paid',
  },
  {
    id: 'lot3',
    lotNumber: 'LOT-003',
    particular: '341',
    purchaseDate: '2024-11-03',
    partyId: 'p3',
    partyName: 'XYZ Enterprises',
    gaadiDetails: 'MH14CD5678',
    quality: 'Premium',
    totalBags: 75,
    soldBags: 0,
    availableBags: 75,
    grossWeightPerBag: 40,
    netWeightPerBag: 39,
    purchaseRate: 220,
    totalWeight: 2925,
    totalAmount: 643500,
    paidAmount: 0,
    remainingAmount: 643500,
    paymentStatus: 'pending',
  },
];

// Ledger entries for a party
export const getLedgerEntriesForParty = (partyId: string): LedgerEntry[] => {
  // Sample ledger entries based on Image 1
  if (partyId === 'p1') {
    return [
      {
        id: 'l1',
        date: '2025-01-11',
        particulars: 'BN 97 म्हाळो नांवे',
        referenceNumber: 'BN 97',
        debit: 14389,
        credit: 0,
        balance: 49639,
        type: 'jawak',
      },
      {
        id: 'l2',
        date: '2025-01-14',
        particulars: 'BN 45 म्हाळो नांवे',
        referenceNumber: 'BN 45',
        debit: 5205,
        credit: 0,
        balance: 54844,
        type: 'jawak',
      },
      {
        id: 'l3',
        date: '2025-01-15',
        particulars: 'रोख -जमा',
        referenceNumber: '',
        debit: 0,
        credit: 35250,
        balance: 19594,
        type: 'payment',
      },
      {
        id: 'l4',
        date: '2025-01-21',
        particulars: 'BN 44 म्हाळो नांवे',
        referenceNumber: 'BN 44',
        debit: 1113,
        credit: 0,
        balance: 20707,
        type: 'jawak',
      },
      {
        id: 'l5',
        date: '2025-01-24',
        particulars: 'BN 88 म्हाळो नांवे',
        referenceNumber: 'BN 88',
        debit: 16612,
        credit: 0,
        balance: 37319,
        type: 'jawak',
      },
    ];
  }
  return [];
};

// Get available lots by variety
export const getAvailableLotsByVariety = (variety: string): Lot[] => {
  return lots.filter(
    (lot) => lot.particular === variety && lot.availableBags > 0
  );
};

// Get next bill number from active bill book
export const getNextBillNumber = (): { billBookId: string; serialNumber: string } => {
  const activeBillBook = billBooks.find((bb) => bb.isActive);
  if (!activeBillBook) {
    throw new Error('No active bill book found');
  }
  
  if (activeBillBook.currentSerial > activeBillBook.serialTo) {
    throw new Error(`Bill book ${activeBillBook.name} is full. Please activate a new bill book.`);
  }
  
  return {
    billBookId: activeBillBook.id,
    serialNumber: activeBillBook.currentSerial.toString(),
  };
};

// Check if bill number already exists
export const billNumberExists = (billNumber: string): boolean => {
  // In real app, check against database
  return false;
};

// Update lot after sale
export const updateLotAfterSale = (lotId: string, bagsSold: number): void => {
  const lot = lots.find((l) => l.id === lotId);
  if (lot) {
    lot.soldBags += bagsSold;
    lot.availableBags -= bagsSold;
  }
};