Update readmes and imporve UI
This commit is contained in:
@@ -97,26 +97,40 @@ export const UnifiedAddWizard: React.FC<UnifiedAddWizardProps> = ({
|
||||
|
||||
// Handle Purchase Order submission
|
||||
if (selectedItemType === 'purchase-order') {
|
||||
// Validate items have positive quantities and prices
|
||||
if ((finalData.items || []).some((item: any) =>
|
||||
Number(item.ordered_quantity) < 0.01 || Number(item.unit_price) < 0.01
|
||||
)) {
|
||||
throw new Error('Todos los productos deben tener cantidad y precio mayor a 0');
|
||||
}
|
||||
|
||||
const subtotal = (finalData.items || []).reduce(
|
||||
(sum: number, item: any) => sum + (item.subtotal || 0),
|
||||
(sum: number, item: any) => sum + (Number(item.ordered_quantity) * Number(item.unit_price)),
|
||||
0
|
||||
);
|
||||
|
||||
// Convert date string to ISO datetime with timezone (start of day in local timezone)
|
||||
const deliveryDate = new Date(finalData.required_delivery_date + 'T00:00:00');
|
||||
if (isNaN(deliveryDate.getTime())) {
|
||||
throw new Error('Fecha de entrega inválida');
|
||||
}
|
||||
const requiredDeliveryDateTime = deliveryDate.toISOString();
|
||||
|
||||
await createPurchaseOrderMutation.mutateAsync({
|
||||
tenantId: currentTenant.id,
|
||||
data: {
|
||||
supplier_id: finalData.supplier_id,
|
||||
required_delivery_date: finalData.required_delivery_date,
|
||||
required_delivery_date: requiredDeliveryDateTime,
|
||||
priority: finalData.priority || 'normal',
|
||||
subtotal: String(subtotal),
|
||||
tax_amount: String(finalData.tax_amount || 0),
|
||||
shipping_cost: String(finalData.shipping_cost || 0),
|
||||
discount_amount: String(finalData.discount_amount || 0),
|
||||
subtotal: subtotal,
|
||||
tax_amount: Number(finalData.tax_amount) || 0,
|
||||
shipping_cost: Number(finalData.shipping_cost) || 0,
|
||||
discount_amount: Number(finalData.discount_amount) || 0,
|
||||
notes: finalData.notes || undefined,
|
||||
items: (finalData.items || []).map((item: any) => ({
|
||||
inventory_product_id: item.inventory_product_id,
|
||||
ordered_quantity: item.ordered_quantity,
|
||||
unit_price: String(item.unit_price),
|
||||
ordered_quantity: Number(item.ordered_quantity),
|
||||
unit_price: Number(item.unit_price),
|
||||
unit_of_measure: item.unit_of_measure,
|
||||
})),
|
||||
},
|
||||
@@ -126,17 +140,37 @@ export const UnifiedAddWizard: React.FC<UnifiedAddWizardProps> = ({
|
||||
|
||||
// Handle Production Batch submission
|
||||
if (selectedItemType === 'production-batch') {
|
||||
// Validate quantities
|
||||
if (Number(finalData.planned_quantity) < 0.01) {
|
||||
throw new Error('La cantidad planificada debe ser mayor a 0');
|
||||
}
|
||||
if (Number(finalData.planned_duration_minutes) < 1) {
|
||||
throw new Error('La duración planificada debe ser mayor a 0');
|
||||
}
|
||||
|
||||
// Convert staff_assigned from string to array
|
||||
const staffArray = finalData.staff_assigned_string
|
||||
? finalData.staff_assigned_string.split(',').map((s: string) => s.trim()).filter((s: string) => s.length > 0)
|
||||
: [];
|
||||
|
||||
// Convert datetime-local strings to ISO datetime with timezone
|
||||
const plannedStartDate = new Date(finalData.planned_start_time);
|
||||
const plannedEndDate = new Date(finalData.planned_end_time);
|
||||
|
||||
if (isNaN(plannedStartDate.getTime()) || isNaN(plannedEndDate.getTime())) {
|
||||
throw new Error('Fechas de inicio o fin inválidas');
|
||||
}
|
||||
|
||||
if (plannedEndDate <= plannedStartDate) {
|
||||
throw new Error('La fecha de fin debe ser posterior a la fecha de inicio');
|
||||
}
|
||||
|
||||
const batchData: ProductionBatchCreate = {
|
||||
product_id: finalData.product_id,
|
||||
product_name: finalData.product_name,
|
||||
recipe_id: finalData.recipe_id || undefined,
|
||||
planned_start_time: finalData.planned_start_time,
|
||||
planned_end_time: finalData.planned_end_time,
|
||||
planned_start_time: plannedStartDate.toISOString(),
|
||||
planned_end_time: plannedEndDate.toISOString(),
|
||||
planned_quantity: Number(finalData.planned_quantity),
|
||||
planned_duration_minutes: Number(finalData.planned_duration_minutes),
|
||||
priority: (finalData.priority || ProductionPriorityEnum.MEDIUM) as ProductionPriorityEnum,
|
||||
|
||||
Reference in New Issue
Block a user